sdf-xarray 0.5.0__tar.gz → 0.6.0__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.
Files changed (45) hide show
  1. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/CITATION.cff +4 -0
  2. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/PKG-INFO +3 -2
  3. sdf_xarray-0.6.0/docs/_static/jupyter_padding.css +3 -0
  4. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/animation.rst +1 -1
  5. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/conf.py +2 -3
  6. sdf_xarray-0.6.0/docs/getting_started.rst +75 -0
  7. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/key_functionality.rst +57 -34
  8. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/unit_conversion.rst +7 -8
  9. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/pyproject.toml +8 -1
  10. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/__init__.py +154 -32
  11. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/_version.py +3 -3
  12. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/tests/test_dataset.py +175 -145
  13. sdf_xarray-0.6.0/tests/test_datatree.py +376 -0
  14. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/tests/test_epoch_dataarray_accessor.py +29 -32
  15. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/uv.lock +39 -0
  16. sdf_xarray-0.5.0/docs/getting_started.rst +0 -106
  17. sdf_xarray-0.5.0/tests/test_datatree.py +0 -313
  18. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/.github/workflows/build_publish.yml +0 -0
  19. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/.github/workflows/lint.yml +0 -0
  20. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/.github/workflows/tests.yml +0 -0
  21. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/.gitignore +0 -0
  22. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/.gitmodules +0 -0
  23. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/.readthedocs.yaml +0 -0
  24. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/BEAM.png +0 -0
  25. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/CMakeLists.txt +0 -0
  26. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/CONTRIBUTING.md +0 -0
  27. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/LICENCE +0 -0
  28. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/PlasmaFAIR.svg +0 -0
  29. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/README.md +0 -0
  30. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/.gitignore +0 -0
  31. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/_static/force_render_dark_xarray_objects.css +0 -0
  32. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/_templates/custom-class-template.rst +0 -0
  33. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/_templates/custom-module-template.rst +0 -0
  34. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/api.rst +0 -0
  35. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/contributing.rst +0 -0
  36. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/index.rst +0 -0
  37. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/known_issues.rst +0 -0
  38. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/docs/make.bat +0 -0
  39. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/csdf.pxd +0 -0
  40. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/dataset_accessor.py +0 -0
  41. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/download.py +0 -0
  42. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/plotting.py +0 -0
  43. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/src/sdf_xarray/sdf_interface.pyx +0 -0
  44. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/tests/test_cython.py +0 -0
  45. {sdf_xarray-0.5.0 → sdf_xarray-0.6.0}/tests/test_epoch_dataset_accessor.py +0 -0
@@ -24,5 +24,9 @@ authors:
24
24
  given-names: Liam
25
25
  orcid: 'https://orcid.org/0000-0001-8604-6904'
26
26
  affiliation: University of York
27
+ - family-names: Shekhanov
28
+ given-names: Sviatoslav
29
+ orcid: 'https://orcid.org/0000-0002-2125-8962'
30
+ affiliation: University of York
27
31
  doi: 10.5281/zenodo.15351323
28
32
  date-released: '2024-07-25'
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdf-xarray
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Provides a backend for xarray to read SDF files as created by the EPOCH plasma PIC code.
5
- Author-Email: Peter Hill <peter.hill@york.ac.uk>, Joel Adams <joel.adams@york.ac.uk>, Shaun Doherty <shaun.doherty@york.ac.uk>, Chris Herdman <chris.herdman@york.ac.uk>, Liam Pattinson <liam.pattinson@york.ac.uk>
5
+ Author-Email: Peter Hill <peter.hill@york.ac.uk>, Joel Adams <joel.adams@york.ac.uk>, Shaun Doherty <shaun.doherty@york.ac.uk>, Chris Herdman <chris.herdman@york.ac.uk>, Liam Pattinson <liam.pattinson@york.ac.uk>, Sviatoslav Shekhanov <sviatoslav.shekhanov@york.ac.uk>
6
6
  License-Expression: BSD-3-Clause
7
7
  Classifier: Development Status :: 5 - Production/Stable
8
8
  Classifier: Intended Audience :: Science/Research
@@ -18,6 +18,7 @@ Requires-Python: <3.15,>=3.11
18
18
  Requires-Dist: numpy>=2.0.0
19
19
  Requires-Dist: xarray>=2024.1.0
20
20
  Requires-Dist: dask>=2024.7.1
21
+ Requires-Dist: epydeck~=1.0
21
22
  Provides-Extra: jupyter
22
23
  Requires-Dist: dask[diagnostics]; extra == "jupyter"
23
24
  Requires-Dist: ipykernel>=6.29.5; extra == "jupyter"
@@ -0,0 +1,3 @@
1
+ .cell_output {
2
+ margin-bottom: 0.5em;
3
+ }
@@ -125,7 +125,7 @@ the animation.
125
125
 
126
126
  .. jupyter-execute::
127
127
 
128
- ds = xr.open_dataset("tutorial_dataset_3d/0005.sdf")
128
+ ds = sdfxr.open_dataset("tutorial_dataset_3d/0005.sdf")
129
129
  da = ds["Derived_Number_Density"]
130
130
  anim = da.epoch.animate(t = "X_Grid_mid")
131
131
  anim.show()
@@ -50,6 +50,7 @@ extensions = [
50
50
  "myst_parser",
51
51
  "jupyter_sphinx",
52
52
  "sphinx_copybutton",
53
+ "sphinx_togglebutton",
53
54
  ]
54
55
 
55
56
  autosummary_generate = True
@@ -102,9 +103,7 @@ html_theme = "sphinx_book_theme"
102
103
  # relative to this directory. They are copied after the builtin static files,
103
104
  # so a file named "default.css" will overwrite the builtin "default.css".
104
105
  html_static_path = ["_static"]
105
- html_css_files = [
106
- "force_render_dark_xarray_objects.css",
107
- ]
106
+ html_css_files = ["force_render_dark_xarray_objects.css", "jupyter_padding.css"]
108
107
 
109
108
  html_theme_options = {
110
109
  "repository_url": "https://github.com/epochpic/sdf-xarray",
@@ -0,0 +1,75 @@
1
+ .. _sec-getting-started:
2
+
3
+ =================
4
+ Getting Started
5
+ =================
6
+
7
+ Installation
8
+ ------------
9
+
10
+ .. |python_versions_pypi| image:: https://img.shields.io/pypi/pyversions/sdf-xarray.svg
11
+ :alt: Supported Python versions
12
+ :target: https://pypi.org/project/sdf-xarray/
13
+
14
+ .. important::
15
+
16
+ To install this package, ensure that you are using one of the supported Python
17
+ versions |python_versions_pypi|
18
+
19
+ Install sdf-xarray from PyPI with:
20
+
21
+ .. code-block:: bash
22
+
23
+ pip install sdf-xarray
24
+
25
+ or download this code locally:
26
+
27
+ .. code-block:: bash
28
+
29
+ git clone --recursive https://github.com/epochpic/sdf-xarray.git
30
+ cd sdf-xarray
31
+ pip install .
32
+
33
+
34
+ Interaction
35
+ -----------
36
+
37
+ There are two main ways to load EPOCH SDF files into xarray objects: using the dedicated
38
+ `sdf_xarray` functions or using the standard `xarray` interface with our custom engine.
39
+ For examples of how to use these functions see :ref:`loading-sdf-files`.
40
+
41
+ All code examples throughout this documentation are visualised using Jupyter notebooks
42
+ so that you can interactively explore the datasets. To do this on your machine make
43
+ sure that you have the necessary dependencies installed:
44
+
45
+ .. code-block:: bash
46
+
47
+ pip install "sdf-xarray[jupyter]"
48
+
49
+ .. important::
50
+
51
+ When loading SDF files, variables related to ``boundaries``, ``cpu`` and ``output file``
52
+ are excluded as they are problematic. If you wish to load these variables in see
53
+ :ref:`loading-raw-files`.
54
+
55
+
56
+ Using sdf_xarray (Recommended)
57
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
+
59
+ These functions are wrappers designed specifically for SDF data, providing the most
60
+ straightforward experience:
61
+
62
+ - **Single files**: Use `sdf_xarray.open_dataset` or `sdf_xarray.open_datatree`
63
+ - **Multiple files**: Use `sdf_xarray.open_mfdataset` or `sdf_xarray.open_mfdatatree`
64
+ - **Raw files**: use `sdf_xarray.sdf_interface.SDFFile`
65
+
66
+ Using xarray
67
+ ~~~~~~~~~~~~
68
+
69
+ If you prefer using the native `xarray` functions, you can use the `xarray.open_dataset`,
70
+ `xarray.open_datatree` and `xarray.open_mfdataset`. Strangely there is no function in
71
+ `xarray` for ``xarray.open_mfdatatree``.
72
+
73
+ These functions should all work out of the box as long as `sdf_xarray` is installed on your
74
+ system, if you are having issues with it reading files, you might need to pass the parameter
75
+ ``engine=sdf_engine`` when calling any of the above xarray functions.
@@ -11,37 +11,19 @@ Key Functionality
11
11
  import matplotlib.pyplot as plt
12
12
  %matplotlib inline
13
13
 
14
+ .. _loading-sdf-files:
15
+
14
16
  Loading SDF files
15
17
  -----------------
16
- There are several ways to load SDF files:
17
-
18
- - To load a single file, use `xarray.open_dataset`, `sdf_xarray.open_datatree` or `xarray.open_datatree`
19
- - To load multiple files, use `sdf_xarray.open_mfdataset`, `xarray.open_mfdataset` or `sdf_xarray.open_mfdatatree`.
20
- - To access the raw contents of a single SDF file, use `sdf_xarray.sdf_interface.SDFFile`.
21
-
22
- .. note::
23
-
24
- When loading SDF files, variables related to ``boundaries``, ``cpu`` and ``output file`` are excluded as they are problematic. If you wish to load these in please use the
25
- :ref:`loading-raw-files` approach.
26
-
27
- .. tip::
28
-
29
- All code examples throughout this documentation are visualised using Jupyter notebooks
30
- so that you can interactively explore `xarray.Dataset` objects. To do this on your machine
31
- make sure that you have the necessary dependencies installed:
32
-
33
- .. code-block:: bash
34
-
35
- pip install "sdf-xarray[jupyter]"
36
18
 
37
19
  Loading single files
38
20
  ~~~~~~~~~~~~~~~~~~~~
39
21
 
40
22
  .. jupyter-execute::
41
23
 
42
- xr.open_dataset("tutorial_dataset_1d/0010.sdf")
24
+ sdfxr.open_dataset("tutorial_dataset_1d/0010.sdf")
43
25
 
44
- Alternatively, you can load the data in as a `xarray.DataTree`, which organises the data
26
+ You can also load the data in as a `xarray.DataTree`, which organises the data
45
27
  hierarchically into ``groups`` (for example grouping related quantities such as the individual
46
28
  components of the electric and magnetic fields) while keeping each item as a `xarray.Dataset`.
47
29
 
@@ -72,22 +54,14 @@ is by using the `sdf_xarray.open_mfdataset`.
72
54
 
73
55
  If your simulation includes multiple ``output`` blocks that specify different variables
74
56
  for output at various time steps, variables not present at a specific step will default
75
- to a nan value. To clean your dataset by removing these nan values we suggest using the
76
- `xarray.DataArray.dropna` function or :ref:`loading-sparse-data`.
57
+ to a nan value. To remove these nan values we suggest using the `xarray.DataArray.dropna`
58
+ function or following our implmentation in :ref:`loading-sparse-data`.
77
59
 
78
60
  .. jupyter-execute::
79
61
 
80
62
  sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
81
63
 
82
- Alternatively, you can load the data in as a `xarray.DataTree`, which organises the data
83
- hierarchically into ``groups`` (for example grouping related quantities such as the individual
84
- components of the electric and magnetic fields) while keeping each item as a `xarray.Dataset`.
85
-
86
- .. jupyter-execute::
87
-
88
- sdfxr.open_mfdatatree("tutorial_dataset_1d/*.sdf")
89
-
90
- Alternatively files can be loaded using `xarray.open_mfdataset` however when loading in
64
+ Alternatively, files can be loaded using `xarray.open_mfdataset` however when loading in
91
65
  all the files we have do some processing of the data so that we can correctly align it along
92
66
  the time dimension; This is done via the ``preprocess`` parameter utilising the
93
67
  `sdf_xarray.SDFPreprocess` function.
@@ -101,6 +75,14 @@ the time dimension; This is done via the ``preprocess`` parameter utilising the
101
75
  preprocess=sdfxr.SDFPreprocess()
102
76
  )
103
77
 
78
+ You can also load the data in as a `xarray.DataTree`, which organises the data
79
+ hierarchically into ``groups`` (for example grouping related quantities such as the individual
80
+ components of the electric and magnetic fields) while keeping each item as a `xarray.Dataset`.
81
+
82
+ .. jupyter-execute::
83
+
84
+ sdfxr.open_mfdatatree("tutorial_dataset_1d/*.sdf")
85
+
104
86
  .. _loading-sparse-data:
105
87
 
106
88
  Loading sparse data
@@ -142,7 +124,7 @@ multiple files).
142
124
 
143
125
  .. jupyter-execute::
144
126
 
145
- xr.open_dataset("tutorial_dataset_1d/0010.sdf", keep_particles=True)
127
+ sdfxr.open_dataset("tutorial_dataset_1d/0010.sdf", keep_particles=True)
146
128
 
147
129
  Loading specific variables
148
130
  ~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -161,6 +143,47 @@ consumption.
161
143
 
162
144
  sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf", data_vars=["Electric_Field_Ex"])
163
145
 
146
+ .. _loading-input-deck:
147
+
148
+ Loading the input.deck
149
+ ~~~~~~~~~~~~~~~~~~~~~~
150
+
151
+ When loading SDF files, `sdf_xarray` will attempt to automatically load
152
+ the ``input.deck`` file used to initialise the simulation from the same
153
+ directory as the SDF file. If the file is not found, it will silently fail
154
+ and continue loading the SDF file as normal. This file contains the initial
155
+ simulation setup information which is not present in SDF outputs. By loading
156
+ this file, you can access these parameters as part of your dataset's metadata.
157
+ To do this, use the ``deck_path`` parameter when loading an SDF file with
158
+ `sdf_xarray.open_dataset`, `xarray.open_dataset`, `sdf_xarray.open_datatree`,
159
+ `xarray.open_datatree`, `sdf_xarray.open_mfdataset` or `sdf_xarray.open_mfdatatree`.
160
+
161
+ There are a few ways you can load an input deck:
162
+
163
+ - **Default behaviour**: The input deck is loaded from the same directory
164
+ as the SDF file if it exists. If it does not exist, it will silently fail.
165
+ - **Relative path**: (e.g. ``"template.deck"``) Searches for that specific filename
166
+ within the same directory as the SDF file.
167
+ - **Absolute path**: (e.g. ``"/path/to/input.deck"``) Uses the full, specified path
168
+ to locate the file.
169
+
170
+ An example of loading a deck can be seen below
171
+
172
+ .. toggle::
173
+
174
+ .. jupyter-execute::
175
+
176
+ import json
177
+ from IPython.display import Code
178
+
179
+ ds = xr.open_dataset("tutorial_dataset_1d/0010.sdf")
180
+ # The results are accessible by calling
181
+ deck = ds.attrs["deck"]
182
+
183
+ # Some prettification to make it looks nice in jupyter notebooks
184
+ json_str = json.dumps(deck, indent=4)
185
+ Code(json_str, language='json')
186
+
164
187
  Data interaction examples
165
188
  -------------------------
166
189
 
@@ -15,9 +15,10 @@ to femto-seconds or particle energy from Joules to electron-volts.
15
15
 
16
16
  .. jupyter-execute::
17
17
 
18
- from sdf_xarray import open_mfdataset
18
+ import sdf_xarray as sdfxr
19
19
  import matplotlib.pyplot as plt
20
20
  %matplotlib inline
21
+
21
22
  plt.rcParams.update({
22
23
  "axes.labelsize": 16,
23
24
  "xtick.labelsize": 14,
@@ -45,7 +46,7 @@ We can use the |rescale_coords_accessor| method to convert X, Y, and Z coordinat
45
46
 
46
47
  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6))
47
48
 
48
- ds = open_mfdataset("tutorial_dataset_2d/*.sdf")
49
+ ds = sdfxr.open_mfdataset("tutorial_dataset_2d/*.sdf")
49
50
  ds_in_microns = ds.epoch.rescale_coords(1e6, "µm", ["X_Grid_mid", "Y_Grid_mid"])
50
51
 
51
52
  ds["Derived_Number_Density_Electron"].isel(time=0).plot(ax=ax1, x="X_Grid_mid", y="Y_Grid_mid")
@@ -65,7 +66,7 @@ seconds (``s``) to femto-seconds (``fs``) by applying a multiplier of ``1e15``.
65
66
 
66
67
  .. jupyter-execute::
67
68
 
68
- ds = open_mfdataset("tutorial_dataset_2d/*.sdf")
69
+ ds = sdfxr.open_mfdataset("tutorial_dataset_2d/*.sdf")
69
70
  ds["time"]
70
71
 
71
72
  .. jupyter-execute::
@@ -97,15 +98,13 @@ Installation
97
98
 
98
99
  To install the pint libraries you can simply run the following optional
99
100
  dependency pip command which will install both the ``pint`` and ``pint-xarray``
100
- libraries. You can install these optional dependencies via pip:
101
+ libraries. Once installed the ``xarray.Dataset.pint`` accessor should become
102
+ accessible. You can install these optional dependencies via pip:
101
103
 
102
104
  .. code:: console
103
105
 
104
106
  $ pip install "sdf_xarray[pint]"
105
107
 
106
- .. note::
107
- Once you install ``pint-xarray`` it is automatically picked up and loaded
108
- by the code so you should have access to the ``xarray.Dataset.pint`` accessor.
109
108
 
110
109
  Quantifying DataArrays
111
110
  ~~~~~~~~~~~~~~~~~~~~~~
@@ -117,7 +116,7 @@ Joules and convert it to electron volts.
117
116
 
118
117
  .. jupyter-execute::
119
118
 
120
- ds = open_mfdataset("tutorial_dataset_1d/*.sdf")
119
+ ds = sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
121
120
  ds["Total_Particle_Energy_Electron"]
122
121
 
123
122
  Once you call `xarray.DataArray.pint.quantify` the type is inferred the original
@@ -18,9 +18,15 @@ authors = [
18
18
  { name = "Shaun Doherty", email = "shaun.doherty@york.ac.uk" },
19
19
  { name = "Chris Herdman", email = "chris.herdman@york.ac.uk" },
20
20
  { name = "Liam Pattinson", email = "liam.pattinson@york.ac.uk" },
21
+ { name = "Sviatoslav Shekhanov", email = "sviatoslav.shekhanov@york.ac.uk" },
21
22
  ]
22
23
  requires-python = ">=3.11,<3.15"
23
- dependencies = ["numpy>=2.0.0", "xarray>=2024.1.0", "dask>=2024.7.1"]
24
+ dependencies = [
25
+ "numpy>=2.0.0",
26
+ "xarray>=2024.1.0",
27
+ "dask>=2024.7.1",
28
+ "epydeck~=1.0"
29
+ ]
24
30
  description = "Provides a backend for xarray to read SDF files as created by the EPOCH plasma PIC code."
25
31
  classifiers = [
26
32
  "Development Status :: 5 - Production/Stable",
@@ -49,6 +55,7 @@ dev = [
49
55
  docs = [
50
56
  "sphinx>=5.3",
51
57
  "sphinx_autodoc_typehints>=1.19",
58
+ "sphinx-togglebutton",
52
59
  "sphinx-book-theme>=0.4.0rc1",
53
60
  "sphinx-argparse-cli>=1.10.0",
54
61
  "sphinx-inline-tabs",