pyvlasiator 0.1.1__tar.gz → 0.1.3__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
1
  Metadata-Version: 2.1
2
2
  Name: pyvlasiator
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Python utilities for processing Vlasiator data
5
5
  Author: Hongyang Zhou
6
6
  Author-email: hyzhou@umich.edu
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyvlasiator"
3
- version = "0.1.1"
3
+ version = "0.1.3"
4
4
  description = "Python utilities for processing Vlasiator data"
5
5
  authors = ["Hongyang Zhou <hyzhou@umich.edu>"]
6
6
  readme = "README.md"
@@ -6,6 +6,7 @@ This provides supports for plotting VLSV data via Matplotlib.
6
6
 
7
7
  from pyvlasiator.plot.plot import (
8
8
  plot,
9
+ scatter,
9
10
  pcolormesh,
10
11
  contour,
11
12
  contourf,
@@ -96,24 +96,91 @@ def plot(
96
96
  >>> axes = vlsv_file.plot("helium/vg_v", ax=my_axes) # Plot velocity on an existing axes
97
97
  """
98
98
 
99
- import matplotlib.pyplot as plt
99
+ fig, ax = set_figure(ax, figsize, **kwargs)
100
100
 
101
- fig = kwargs.pop(
102
- "figure", plt.gcf() if plt.get_fignums() else plt.figure(figsize=figsize)
101
+ return _plot1d(
102
+ self,
103
+ ax.plot,
104
+ var=var,
105
+ **kwargs,
103
106
  )
104
- if ax is None:
105
- ax = fig.gca()
106
107
 
107
- if not self.has_variable(var):
108
- raise ValueError(f"Variable {var} not found in the file")
109
108
 
110
- x = np.linspace(self.coordmin[0], self.coordmax[0], self.ncells[0])
109
+ def scatter(
110
+ self: Vlsv,
111
+ var: str = "",
112
+ ax=None,
113
+ figsize: tuple[float, float] | None = None,
114
+ **kwargs,
115
+ ) -> matplotlib.collections.PathCollection:
116
+ """
117
+ Plots 1D VLSV data as scattered points.
111
118
 
112
- data = self.read_variable(var)
113
- axes = ax.plot(x, data, **kwargs)
119
+ Parameters
120
+ ----------
121
+ var : str
122
+ Name of the variable to plot from the VLSV file.
123
+ ax : matplotlib.axes._axes.Axes, optional
124
+ Axes object to plot on. If not provided, a new figure and axes will be created.
125
+ figsize : tuple[float, float], optional
126
+ Size of the figure in inches (width, height). Only used if a new
127
+ figure is created.
128
+ **kwargs
129
+ Additional keyword arguments passed to Matplotlib's `plot` function.
114
130
 
115
- return axes
131
+ Returns
132
+ -------
133
+ matplotlib.collections.PathCollection
116
134
 
135
+ Raises
136
+ ------
137
+ ValueError
138
+ If the specified variable is not found in the VLSV file.
139
+
140
+ Examples
141
+ --------
142
+ >>> vlsv_file = Vlsv("my_vlsv_file.vlsv")
143
+ >>> axes = vlsv_file.scatter("proton/vg_rho") # Plot density on a new figure
144
+ """
145
+
146
+ fig, ax = set_figure(ax, figsize, **kwargs)
147
+
148
+ return _plot1d(
149
+ self,
150
+ ax.scatter,
151
+ var=var,
152
+ **kwargs,
153
+ )
154
+
155
+
156
+ def _plot1d(
157
+ meta: Vlsv,
158
+ plot_func: Callable,
159
+ var: str = "",
160
+ **kwargs,
161
+ ):
162
+ """
163
+ Plot 1d data with `plot_func`.
164
+
165
+ Parameters
166
+ ----------
167
+ var : str
168
+ Variable name from the VLSV file.
169
+
170
+ Returns
171
+ -------
172
+
173
+ """
174
+
175
+ if not meta.has_variable(var):
176
+ raise ValueError(f"Variable {var} not found in the file")
177
+
178
+ x = np.linspace(meta.coordmin[0], meta.coordmax[0], meta.ncells[0])
179
+ y = meta.read_variable(var)
180
+
181
+ c = plot_func(x, y, **kwargs)
182
+
183
+ return c
117
184
 
118
185
  def pcolormesh(
119
186
  self: Vlsv,
@@ -839,13 +906,13 @@ def configure_plot(
839
906
  cb.ax.set_ylabel(colorbar_title)
840
907
  cb.ax.tick_params(direction="in")
841
908
 
842
- # Set plot title and labels
909
+ # Set title and labels
843
910
  ax.set_title(title, fontweight="bold")
844
911
  ax.set_xlabel(x_label)
845
912
  ax.set_ylabel(y_label)
846
913
  ax.set_aspect("equal")
847
914
 
848
- # Style plot borders and ticks
915
+ # Style borders and ticks
849
916
  for spine in ax.spines.values():
850
917
  spine.set_linewidth(2.0)
851
918
  ax.tick_params(axis="both", which="major", width=2.0, length=3)
@@ -867,6 +934,7 @@ def vdfslice(
867
934
  center: str = None,
868
935
  weight: str = "particle",
869
936
  flimit: float = -1.0,
937
+ addcolorbar: bool = True,
870
938
  **kwargs,
871
939
  ):
872
940
  v1, v2, r1, r2, weights, strx, stry, str_title = prep_vdf(
@@ -908,9 +976,10 @@ def vdfslice(
908
976
  ax.grid(color="grey", linestyle="-")
909
977
  ax.tick_params(direction="in")
910
978
 
911
- cb = plt.colorbar(h[3], ax=ax, fraction=0.04, pad=0.02)
912
- cb.ax.tick_params(which="both", direction="in")
913
- cb_title = cb.ax.set_ylabel("f(v)")
979
+ if addcolorbar:
980
+ cb = plt.colorbar(h[3], ax=ax, fraction=0.04, pad=0.02)
981
+ cb.ax.tick_params(which="both", direction="in")
982
+ cb_title = cb.ax.set_ylabel("f(v)")
914
983
 
915
984
  # TODO: Draw vector of magnetic field direction
916
985
  # if slicetype in ("xy", "xz", "yz"):
@@ -1108,6 +1177,7 @@ def prep_vdf(
1108
1177
 
1109
1178
  # Append plotting functions
1110
1179
  Vlsv.plot = plot
1180
+ Vlsv.scatter = scatter
1111
1181
  Vlsv.pcolormesh = pcolormesh
1112
1182
  Vlsv.contourf = contourf
1113
1183
  Vlsv.contour = contour
@@ -405,14 +405,16 @@ class Vlsv:
405
405
  )
406
406
  if hasattr(cellids, "__len__"): # part of cells requested
407
407
  return np.float32(raw)
408
-
409
- if sorted:
410
- if raw.ndim == 1:
411
- v = raw[self.cellindex]
408
+ elif cellids == -1:
409
+ if sorted:
410
+ if raw.ndim == 1:
411
+ v = raw[self.cellindex]
412
+ else:
413
+ v = raw[self.cellindex, :]
414
+ if v.dtype == np.float64: # 32-bit is enough for analysis
415
+ v = np.float32(v)
412
416
  else:
413
- v = raw[self.cellindex, :]
414
- if v.dtype == np.float64: # 32-bit is enough for analysis
415
- v = np.float32(v)
417
+ v = raw
416
418
  else:
417
419
  v = raw
418
420
 
File without changes
File without changes