pyvlasiator 0.1.2__tar.gz → 0.1.4__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.2
3
+ Version: 0.1.4
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>
@@ -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>
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyvlasiator"
3
- version = "0.1.2"
3
+ version = "0.1.4"
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,
@@ -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
@@ -96,23 +97,91 @@ def plot(
96
97
  >>> axes = vlsv_file.plot("helium/vg_v", ax=my_axes) # Plot velocity on an existing axes
97
98
  """
98
99
 
99
- import matplotlib.pyplot as plt
100
+ fig, ax = set_figure(ax, figsize, **kwargs)
100
101
 
101
- fig = kwargs.pop(
102
- "figure", plt.gcf() if plt.get_fignums() else plt.figure(figsize=figsize)
102
+ return _plot1d(
103
+ self,
104
+ ax.plot,
105
+ var=var,
106
+ **kwargs,
103
107
  )
104
- if ax is None:
105
- ax = fig.gca()
106
108
 
107
- if not self.has_variable(var):
109
+
110
+ def scatter(
111
+ self: Vlsv,
112
+ var: str = "",
113
+ ax=None,
114
+ figsize: tuple[float, float] | None = None,
115
+ **kwargs,
116
+ ) -> matplotlib.collections.PathCollection:
117
+ """
118
+ Plots 1D VLSV data as scattered points.
119
+
120
+ Parameters
121
+ ----------
122
+ var : str
123
+ Name of the variable to plot from the VLSV file.
124
+ ax : matplotlib.axes._axes.Axes, optional
125
+ Axes object to plot on. If not provided, a new figure and axes will be created.
126
+ figsize : tuple[float, float], optional
127
+ Size of the figure in inches (width, height). Only used if a new
128
+ figure is created.
129
+ **kwargs
130
+ Additional keyword arguments passed to Matplotlib's `plot` function.
131
+
132
+ Returns
133
+ -------
134
+ matplotlib.collections.PathCollection
135
+
136
+ Raises
137
+ ------
138
+ ValueError
139
+ If the specified variable is not found in the VLSV file.
140
+
141
+ Examples
142
+ --------
143
+ >>> vlsv_file = Vlsv("my_vlsv_file.vlsv")
144
+ >>> axes = vlsv_file.scatter("proton/vg_rho") # Plot density on a new figure
145
+ """
146
+
147
+ fig, ax = set_figure(ax, figsize, **kwargs)
148
+
149
+ return _plot1d(
150
+ self,
151
+ ax.scatter,
152
+ var=var,
153
+ **kwargs,
154
+ )
155
+
156
+
157
+ def _plot1d(
158
+ meta: Vlsv,
159
+ plot_func: Callable,
160
+ var: str = "",
161
+ **kwargs,
162
+ ):
163
+ """
164
+ Plot 1d data with `plot_func`.
165
+
166
+ Parameters
167
+ ----------
168
+ var : str
169
+ Variable name from the VLSV file.
170
+
171
+ Returns
172
+ -------
173
+
174
+ """
175
+
176
+ if not meta.has_variable(var):
108
177
  raise ValueError(f"Variable {var} not found in the file")
109
178
 
110
- x = np.linspace(self.coordmin[0], self.coordmax[0], self.ncells[0])
179
+ x = np.linspace(meta.coordmin[0], meta.coordmax[0], meta.ncells[0])
180
+ y = meta.read_variable(var)
111
181
 
112
- data = self.read_variable(var)
113
- axes = ax.plot(x, data, **kwargs)
182
+ c = plot_func(x, y, **kwargs)
114
183
 
115
- return axes
184
+ return c
116
185
 
117
186
 
118
187
  def pcolormesh(
@@ -839,13 +908,13 @@ def configure_plot(
839
908
  cb.ax.set_ylabel(colorbar_title)
840
909
  cb.ax.tick_params(direction="in")
841
910
 
842
- # Set plot title and labels
911
+ # Set title and labels
843
912
  ax.set_title(title, fontweight="bold")
844
913
  ax.set_xlabel(x_label)
845
914
  ax.set_ylabel(y_label)
846
915
  ax.set_aspect("equal")
847
916
 
848
- # Style plot borders and ticks
917
+ # Style borders and ticks
849
918
  for spine in ax.spines.values():
850
919
  spine.set_linewidth(2.0)
851
920
  ax.tick_params(axis="both", which="major", width=2.0, length=3)
@@ -855,7 +924,6 @@ def vdfslice(
855
924
  meta: Vlsv,
856
925
  location: tuple | list,
857
926
  ax=None,
858
- limits: tuple = (float("-inf"), float("inf"), float("-inf"), float("inf")),
859
927
  verbose: bool = False,
860
928
  species: str = "proton",
861
929
  unit: AxisUnit = AxisUnit.SI,
@@ -900,7 +968,15 @@ def vdfslice(
900
968
 
901
969
  norm = matplotlib.colors.LogNorm(vmin, vmax)
902
970
 
903
- h = ax.hist2d(v1, v2, bins=(r1, r2), weights=weights, norm=norm, shading="flat")
971
+ h = ax.hist2d(
972
+ v1,
973
+ v2,
974
+ bins=(r1, r2),
975
+ weights=weights,
976
+ norm=norm,
977
+ shading="flat",
978
+ **kwargs,
979
+ )
904
980
 
905
981
  ax.set_title(str_title, fontweight="bold")
906
982
  ax.set_xlabel(strx)
@@ -1110,6 +1186,7 @@ def prep_vdf(
1110
1186
 
1111
1187
  # Append plotting functions
1112
1188
  Vlsv.plot = plot
1189
+ Vlsv.scatter = scatter
1113
1190
  Vlsv.pcolormesh = pcolormesh
1114
1191
  Vlsv.contourf = contourf
1115
1192
  Vlsv.contour = contour
@@ -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_"):
File without changes