pyvlasiator 0.1.3__tar.gz → 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyvlasiator might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: pyvlasiator
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Python utilities for processing Vlasiator data
5
5
  Author: Hongyang Zhou
6
6
  Author-email: hyzhou@umich.edu
@@ -17,6 +17,9 @@ Description-Content-Type: text/markdown
17
17
  # pyvlasiator
18
18
 
19
19
  <p align="center">
20
+ <a href="https://badge.fury.io/py/pyvlasiator">
21
+ <img src="https://badge.fury.io/py/pyvlasiator.svg" alt="PyPI version" height="18">
22
+ </a>
20
23
  <a href="https://github.com/henry2004y/pyvlasiator/actions">
21
24
  <img src="https://github.com/henry2004y/pyvlasiator/actions/workflows/CI.yml/badge.svg">
22
25
  </a>
@@ -31,7 +34,7 @@ Description-Content-Type: text/markdown
31
34
  </a>
32
35
  </p>
33
36
 
34
- Lightweight Python package for processing Vlasiator data.
37
+ Lightweight Python package for processing [Vlasiator](https://github.com/fmihpc/vlasiator) data, alternative to [Analysator](https://github.com/fmihpc/analysator).
35
38
 
36
39
  ## Installation
37
40
 
@@ -1,6 +1,9 @@
1
1
  # pyvlasiator
2
2
 
3
3
  <p align="center">
4
+ <a href="https://badge.fury.io/py/pyvlasiator">
5
+ <img src="https://badge.fury.io/py/pyvlasiator.svg" alt="PyPI version" height="18">
6
+ </a>
4
7
  <a href="https://github.com/henry2004y/pyvlasiator/actions">
5
8
  <img src="https://github.com/henry2004y/pyvlasiator/actions/workflows/CI.yml/badge.svg">
6
9
  </a>
@@ -15,7 +18,7 @@
15
18
  </a>
16
19
  </p>
17
20
 
18
- Lightweight Python package for processing Vlasiator data.
21
+ Lightweight Python package for processing [Vlasiator](https://github.com/fmihpc/vlasiator) data, alternative to [Analysator](https://github.com/fmihpc/analysator).
19
22
 
20
23
  ## Installation
21
24
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyvlasiator"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "Python utilities for processing Vlasiator data"
5
5
  authors = ["Hongyang Zhou <hyzhou@umich.edu>"]
6
6
  readme = "README.md"
@@ -12,4 +12,6 @@ from pyvlasiator.plot.plot import (
12
12
  contourf,
13
13
  streamplot,
14
14
  vdfslice,
15
+ AxisUnit,
16
+ ColorScale,
15
17
  )
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import numpy as np
4
+ from numpy.typing import ArrayLike
4
5
  import math
5
6
  import warnings
6
7
  from typing import Callable
@@ -8,7 +9,7 @@ from collections import namedtuple
8
9
  from enum import Enum
9
10
  from pyvlasiator.vlsv import Vlsv
10
11
  from pyvlasiator.vlsv.reader import _getdim2d
11
- from pyvlasiator.vlsv.variables import RE
12
+ from pyvlasiator.vlsv.variables import RE, RMERCURY
12
13
 
13
14
 
14
15
  class ColorScale(Enum):
@@ -35,8 +36,10 @@ class AxisUnit(Enum):
35
36
  - SI (2): Units from the International System of Units (SI), such as meters, seconds, kilograms, etc.
36
37
  """
37
38
 
38
- EARTH = 1
39
- SI = 2
39
+ SI = 1
40
+ KSI = 2
41
+ EARTH = 3
42
+ MERCURY = 4
40
43
 
41
44
 
42
45
  # Plotting arguments
@@ -182,6 +185,7 @@ def _plot1d(
182
185
 
183
186
  return c
184
187
 
188
+
185
189
  def pcolormesh(
186
190
  self: Vlsv,
187
191
  var: str = "",
@@ -609,8 +613,12 @@ def set_args(
609
613
 
610
614
  if axisunit == AxisUnit.EARTH:
611
615
  unitstr = r"$R_E$"
612
- else:
613
- unitstr = r"$m$"
616
+ elif axisunit == AxisUnit.SI:
617
+ unitstr = "m"
618
+ elif axisunit == AxisUnit.MERCURY:
619
+ unitstr = r"$R_M$"
620
+ elif axisunit == AxisUnit.KSI:
621
+ unitstr = "km"
614
622
  strx = axislabels[0] + " [" + unitstr + "]"
615
623
  stry = axislabels[1] + " [" + unitstr + "]"
616
624
 
@@ -771,7 +779,15 @@ def get_axis(axisunit: AxisUnit, plotrange: tuple, sizes: tuple) -> tuple:
771
779
  A tuple containing the x and y axis coordinates.
772
780
  """
773
781
 
774
- scale_factor = 1.0 / RE if axisunit == AxisUnit.EARTH else 1.0
782
+ if axisunit == AxisUnit.EARTH:
783
+ scale_factor = 1.0 / RE
784
+ elif axisunit == AxisUnit.MERCURY:
785
+ scale_factor = 1.0 / RMERCURY
786
+ elif axisunit == AxisUnit.KSI:
787
+ scale_factor = 1.0 / 1e3
788
+ else: # SI
789
+ scale_factor = 1.0
790
+
775
791
  start = tuple(s * scale_factor for s in plotrange[:2])
776
792
  stop = tuple(s * scale_factor for s in plotrange[2:])
777
793
 
@@ -794,7 +810,6 @@ def set_colorbar(
794
810
  v2: float = np.nan,
795
811
  data: np.ndarray = np.array([1.0]),
796
812
  linthresh: float = 1.0,
797
- logstep: float = 1.0,
798
813
  linscale: float = 0.03,
799
814
  ):
800
815
  """
@@ -816,8 +831,6 @@ def set_colorbar(
816
831
  not provided. Defaults to np.array([1.0]).
817
832
  linthresh: float, optional
818
833
  The threshold value for symmetric log color scales. Defaults to 1.0.
819
- logstep: float, optional
820
- The step size for tick values in log color scales. Defaults to 1.0.
821
834
  linscale: float, optional
822
835
  A scaling factor for linear regions in symmetric log color scales.
823
836
  Defaults to 0.03.
@@ -833,10 +846,6 @@ def set_colorbar(
833
846
  ------
834
847
  ValueError
835
848
  If an invalid colorscale type is provided.
836
-
837
- Notes
838
- -----
839
- - The 'SymLog' colorscale is currently not fully implemented.
840
849
  """
841
850
  import matplotlib
842
851
 
@@ -849,13 +858,10 @@ def set_colorbar(
849
858
  norm = matplotlib.colors.LogNorm(vmin, vmax)
850
859
  ticks = matplotlib.ticker.LogLocator(base=10, subs=range(0, 9))
851
860
  else: # symmetric log
852
- logthresh = int(math.floor(math.log10(linthresh)))
853
- minlog = int(math.ceil(math.log10(-vmin)))
854
- maxlog = int(math.ceil(math.log10(vmax)))
855
- # TODO: fix this!
856
- # norm = matplotlib.colors.SymLogNorm(linthresh, linscale, vmin, vmax, base=10)
857
- # ticks = [ [-(10.0**x) for x in minlog:-logstep:logthresh]..., 0.0,
858
- # [10.0**x for x in logthresh:logstep:maxlog]..., ]
861
+ norm = matplotlib.colors.SymLogNorm(
862
+ linthresh=linthresh, linscale=linscale, vmin=vmin, vmax=vmax, base=10
863
+ )
864
+ ticks = matplotlib.ticker.SymmetricalLogLocator(linthresh=linthresh, base=10)
859
865
 
860
866
  return norm, ticks
861
867
 
@@ -922,7 +928,6 @@ def vdfslice(
922
928
  meta: Vlsv,
923
929
  location: tuple | list,
924
930
  ax=None,
925
- limits: tuple = (float("-inf"), float("inf"), float("-inf"), float("inf")),
926
931
  verbose: bool = False,
927
932
  species: str = "proton",
928
933
  unit: AxisUnit = AxisUnit.SI,
@@ -967,7 +972,15 @@ def vdfslice(
967
972
 
968
973
  norm = matplotlib.colors.LogNorm(vmin, vmax)
969
974
 
970
- h = ax.hist2d(v1, v2, bins=(r1, r2), weights=weights, norm=norm, shading="flat")
975
+ h = ax.hist2d(
976
+ v1,
977
+ v2,
978
+ bins=(r1, r2),
979
+ weights=weights,
980
+ norm=norm,
981
+ shading="flat",
982
+ **kwargs,
983
+ )
971
984
 
972
985
  ax.set_title(str_title, fontweight="bold")
973
986
  ax.set_xlabel(strx)
@@ -1012,6 +1025,10 @@ def prep_vdf(
1012
1025
 
1013
1026
  if unit == AxisUnit.EARTH:
1014
1027
  location = [loc * RE for loc in location]
1028
+ elif unit == AxisUnit.MERCURY:
1029
+ location = [loc * RMERCURY for loc in location]
1030
+ elif unit == AxisUnit.KSI:
1031
+ location = [loc * 1e3 for loc in location]
1015
1032
 
1016
1033
  # Set unit conversion factor
1017
1034
  unitvfactor = 1e3 if unitv == "km/s" else 1.0
@@ -375,16 +375,17 @@ class Vlsv:
375
375
  """
376
376
  Read variables as numpy arrays from the open vlsv file.
377
377
 
378
- Parameters
379
- ----------
380
- cellids : int or list[int] or np.ndarray
381
- If -1 then all data is read. If nonzero then only the vector for the specified
382
- cell id or cellids is read.
383
- sorted : bool
384
- If the returned array is sorted by cell IDs. Only applied for full arrays.
385
- Returns
386
- -------
387
- numpy.ndarray
378
+ Args:
379
+ name (str): The name of the variable to read.
380
+ cellids (int, list[int], np.ndarray, optional):
381
+ Specifies which cell IDs to read data for. Defaults to -1, which reads data for all cells.
382
+ - If an integer (except -1), only the data for that specific cell ID is read.
383
+ - If a list or NumPy array of integers, only the data for the specified cell IDs are read.
384
+ - Specifying cell IDs is not supported for "FSgrid" or "ionosphere" variables.
385
+ sorted (bool, optional): If True, the returned array is sorted by cell IDs (only applicable when reading all cells, cellids=-1). Defaults to True.
386
+
387
+ Returns:
388
+ numpy.ndarray
388
389
  """
389
390
 
390
391
  if self.has_variable(name) and name.startswith("fg_"):
@@ -11,6 +11,7 @@ MU0 = 4 * pi * 1e-7 # Vacuum permeability, [H/m]
11
11
  EPSILON0 = 1 / (C**2 * MU0) # Vacuum permittivity, [F/m]
12
12
  KB = 1.38064852e-23 # Boltzmann constant, [m²kg/(s²K)]
13
13
  RE = 6.371e6 # Earth radius, [m]
14
+ RMERCURY = 4.8794e6 # Mercury radius, [m]
14
15
 
15
16
  speciesdict = {
16
17
  "avgs": "p",
File without changes