sdf-xarray 0.2.0__cp312-cp312-win_amd64.whl → 0.5.0__cp312-cp312-win_amd64.whl
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.
- lib/SDFC_14.4.7/sdfc.lib +0 -0
- sdf_xarray/__init__.py +496 -57
- sdf_xarray/_version.py +22 -4
- sdf_xarray/dataset_accessor.py +124 -0
- sdf_xarray/download.py +88 -0
- sdf_xarray/plotting.py +484 -101
- sdf_xarray/sdf_interface.cp312-win_amd64.pyd +0 -0
- sdf_xarray/sdf_interface.pyx +5 -3
- sdf_xarray-0.5.0.dist-info/METADATA +150 -0
- {sdf_xarray-0.2.0.dist-info → sdf_xarray-0.5.0.dist-info}/RECORD +13 -11
- {sdf_xarray-0.2.0.dist-info → sdf_xarray-0.5.0.dist-info}/WHEEL +1 -1
- {sdf_xarray-0.2.0.dist-info → sdf_xarray-0.5.0.dist-info}/entry_points.txt +3 -0
- {sdf_xarray-0.2.0.dist-info → sdf_xarray-0.5.0.dist-info}/licenses/LICENCE +1 -1
- sdf_xarray-0.2.0.dist-info/METADATA +0 -190
sdf_xarray/sdf_interface.pyx
CHANGED
|
@@ -39,7 +39,7 @@ cdef class Block:
|
|
|
39
39
|
|
|
40
40
|
@dataclasses.dataclass
|
|
41
41
|
cdef class Variable(Block):
|
|
42
|
-
units:
|
|
42
|
+
units: str | None
|
|
43
43
|
mult: float | None
|
|
44
44
|
grid: str | None
|
|
45
45
|
grid_mid: str | None
|
|
@@ -110,12 +110,12 @@ _CONSTANT_UNITS_RE = re.compile(r"(?P<name>.*) \((?P<units>.*)\)$")
|
|
|
110
110
|
cdef class Constant:
|
|
111
111
|
_id: str
|
|
112
112
|
name: str
|
|
113
|
-
data: int | str | float
|
|
113
|
+
data: int | str | float | bool
|
|
114
114
|
units: str | None
|
|
115
115
|
|
|
116
116
|
@staticmethod
|
|
117
117
|
cdef Constant from_block(str name, csdf.sdf_block_t* block):
|
|
118
|
-
data: int | str | float | double
|
|
118
|
+
data: int | str | float | double | bool
|
|
119
119
|
|
|
120
120
|
if block.datatype == csdf.SDF_DATATYPE_REAL4:
|
|
121
121
|
data = (<float*>block.const_value)[0]
|
|
@@ -125,6 +125,8 @@ cdef class Constant:
|
|
|
125
125
|
data = (<csdf.int32_t*>block.const_value)[0]
|
|
126
126
|
if block.datatype == csdf.SDF_DATATYPE_INTEGER8:
|
|
127
127
|
data = (<csdf.int64_t*>block.const_value)[0]
|
|
128
|
+
if block.datatype == csdf.SDF_DATATYPE_LOGICAL:
|
|
129
|
+
data = (<bint*>block.const_value)[0]
|
|
128
130
|
|
|
129
131
|
# There's no metadata with e.g. units, but there's a
|
|
130
132
|
# convention to put one in brackets at the end of the name,
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sdf-xarray
|
|
3
|
+
Version: 0.5.0
|
|
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>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: Topic :: Scientific/Engineering
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Requires-Python: <3.15,>=3.11
|
|
18
|
+
Requires-Dist: numpy>=2.0.0
|
|
19
|
+
Requires-Dist: xarray>=2024.1.0
|
|
20
|
+
Requires-Dist: dask>=2024.7.1
|
|
21
|
+
Provides-Extra: jupyter
|
|
22
|
+
Requires-Dist: dask[diagnostics]; extra == "jupyter"
|
|
23
|
+
Requires-Dist: ipykernel>=6.29.5; extra == "jupyter"
|
|
24
|
+
Provides-Extra: pint
|
|
25
|
+
Requires-Dist: pint; extra == "pint"
|
|
26
|
+
Requires-Dist: pint-xarray; extra == "pint"
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# sdf-xarray
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
[](https://pypi.org/project/sdf-xarray/)
|
|
33
|
+
[](https://doi.org/10.5281/zenodo.15351323)
|
|
34
|
+

|
|
35
|
+

|
|
36
|
+
[](https://sdf-xarray.readthedocs.io)
|
|
37
|
+
[](https://github.com/astral-sh/ruff)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
sdf-xarray provides a backend for [xarray](https://xarray.dev) to read SDF files as created by
|
|
41
|
+
[EPOCH](https://epochpic.github.io) using the [SDF-C](https://github.com/epochpic/SDF_C) library.
|
|
42
|
+
Part of [BEAM](#broad-epoch-analysis-modules-beam) (Broad EPOCH Analysis Modules).
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
> [!IMPORTANT]
|
|
47
|
+
> To install this package make sure you are using one of the Python versions listed above.
|
|
48
|
+
|
|
49
|
+
Install from PyPI with:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install sdf-xarray
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
or download this code locally:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
git clone --recursive https://github.com/epochpic/sdf-xarray.git
|
|
59
|
+
cd sdf-xarray
|
|
60
|
+
pip install .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
We recommend switching to [uv](https://docs.astral.sh/uv/) to manage packages.
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
Below are some simple examples to get you started. Please read the full
|
|
68
|
+
documentation here <https://sdf-xarray.readthedocs.io>.
|
|
69
|
+
|
|
70
|
+
### Single file loading
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import xarray as xr
|
|
74
|
+
|
|
75
|
+
df = xr.open_dataset("0010.sdf")
|
|
76
|
+
|
|
77
|
+
print(df["Electric_Field_Ex"])
|
|
78
|
+
|
|
79
|
+
# <xarray.DataArray 'Electric_Field_Ex' (X_x_px_deltaf_electron_beam: 16)> Size: 128B
|
|
80
|
+
# [16 values with dtype=float64]
|
|
81
|
+
# Coordinates:
|
|
82
|
+
# * X_x_px_deltaf_electron_beam (X_x_px_deltaf_electron_beam) float64 128B 1...
|
|
83
|
+
# Attributes:
|
|
84
|
+
# units: V/m
|
|
85
|
+
# full_name: "Electric Field/Ex"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Multi-file loading
|
|
89
|
+
|
|
90
|
+
You can open all the SDF files for a given simulation by calling the `open_mfdataset`
|
|
91
|
+
function from `sdf_xarray`. This will additionally add a time dimension using the `"time"`
|
|
92
|
+
value stored in each files attributes.
|
|
93
|
+
|
|
94
|
+
> [!IMPORTANT]
|
|
95
|
+
> If your simulation has multiple `output` blocks so that not all variables are
|
|
96
|
+
> output at every time step, then at the timesteps where those variables are not
|
|
97
|
+
> present they will have have a value of nan. To clean your dataset by removing
|
|
98
|
+
> these nan values we suggest using the `xarray.DataArray.dropna` function or
|
|
99
|
+
> loading sparse data along separate time dimensions using `separate_times=True`.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from sdf_xarray import open_mfdataset
|
|
103
|
+
|
|
104
|
+
ds = open_mfdataset("*.sdf")
|
|
105
|
+
print(ds)
|
|
106
|
+
|
|
107
|
+
# Dimensions:
|
|
108
|
+
# time: 301, X_Grid_mid: 128, ...
|
|
109
|
+
# Coordinates: (9) ...
|
|
110
|
+
# Data variables: (18) ...
|
|
111
|
+
# Indexes: (9) ...
|
|
112
|
+
# Attributes: (22) ...
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Citing
|
|
116
|
+
|
|
117
|
+
If sdf-xarray contributes to a project that leads to publication, please acknowledge this by citing sdf-xarray. This can be done by clicking the "cite this repository" button located near the top right of this page.
|
|
118
|
+
|
|
119
|
+
## Contributing
|
|
120
|
+
|
|
121
|
+
We welcome contributions to the BEAM ecosystem! Whether it's reporting issues, suggesting features, or submitting pull requests, your input helps improve these tools for the community.
|
|
122
|
+
|
|
123
|
+
### How to Contribute
|
|
124
|
+
|
|
125
|
+
There are many ways to get involved:
|
|
126
|
+
- **Report bugs**: Found something not working as expected? Open an issue with as much detail as possible.
|
|
127
|
+
- **Request a feature**: Got an idea for a new feature or enhancement? Open a feature request on [GitHub Issues](https://github.com/epochpic/sdf-xarray/issues)!
|
|
128
|
+
- **Improve the documentation**: We aim to keep our docs clear and helpful—if something's missing or unclear, feel free to suggest edits.
|
|
129
|
+
- **Submit code changes**: Bug fixes, refactoring, or new features are welcome.
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
All code is automatically linted, formatted, and tested via GitHub Actions.
|
|
133
|
+
|
|
134
|
+
To run checks locally before opening a pull request, see [CONTRIBUTING.md](CONTRIBUTING.md) or [readthedocs documentation](https://sdf-xarray.readthedocs.io/en/latest/contributing.html)
|
|
135
|
+
|
|
136
|
+
## Broad EPOCH Analysis Modules (BEAM)
|
|
137
|
+
|
|
138
|
+

|
|
139
|
+
|
|
140
|
+
**BEAM** is a collection of independent yet complementary open-source tools for analysing EPOCH simulations, designed to be modular so researchers can adopt only the components they require without being constrained by a rigid framework. In line with the **FAIR principles — Findable**, **Accessible**, **Interoperable**, and **Reusable** — each package is openly published with clear documentation and versioning (Findable), distributed via public repositories (Accessible), designed to follow common standards for data structures and interfaces (Interoperable), and includes licensing and metadata to support long-term use and adaptation (Reusable). The packages are as follows:
|
|
141
|
+
|
|
142
|
+
- [sdf-xarray](https://github.com/epochpic/sdf-xarray): Reading and processing SDF files and converting them to [xarray](https://docs.xarray.dev/en/stable/).
|
|
143
|
+
- [epydeck](https://github.com/epochpic/epydeck): Input deck reader and writer.
|
|
144
|
+
- [epyscan](https://github.com/epochpic/epyscan): Create campaigns over a given parameter space using various sampling methods.
|
|
145
|
+
|
|
146
|
+
## PlasmaFAIR
|
|
147
|
+
|
|
148
|
+

|
|
149
|
+
|
|
150
|
+
Originally developed by [PlasmaFAIR](https://plasmafair.github.io), EPSRC Grant EP/V051822/1
|
|
@@ -6,19 +6,21 @@ include/SDFC_14.4.7/sdf_list_type.h,sha256=Quu8v0-SEsQuJpGtEZnm09tAyXqWNitx0sXl5
|
|
|
6
6
|
include/SDFC_14.4.7/sdf_vector_type.h,sha256=dbKjhzRRsvhzrnTwVjtVlvnuisEnRMKY-vvdm94ok_Q,1595
|
|
7
7
|
include/SDFC_14.4.7/stack_allocator.h,sha256=L7U9vmGiVSw3VQLIv9EzTaVq7JbFxs9aNonKStTkUSg,1335
|
|
8
8
|
include/SDFC_14.4.7/uthash.h,sha256=rIyy_-ylY6S_7WaZCCC3VtvXaC9q37rFyA0f1U9xc4w,63030
|
|
9
|
-
lib/SDFC_14.4.7/sdfc.lib,sha256=
|
|
9
|
+
lib/SDFC_14.4.7/sdfc.lib,sha256=ABEAPa767DQyIFFzUpsXkT9-F93atuPapAjmpRTpVvo,350158
|
|
10
10
|
lib/SDFC_14.4.7/SDFCConfig.cmake,sha256=IOA1eusC-KvUK4LNTEiOAmEdaPH1ZvNvbYPgiG1oZio,802
|
|
11
11
|
lib/SDFC_14.4.7/SDFCConfigVersion.cmake,sha256=pN7Qqyf04s3izw7PYQ0XK6imvmhaVegSdR_nEl3Ok_o,2830
|
|
12
12
|
lib/SDFC_14.4.7/SDFCTargets-release.cmake,sha256=G4zdx5PyjePigeD_a6rmZAxbk7L8Nf0klUnV78Lm2fI,828
|
|
13
13
|
lib/SDFC_14.4.7/SDFCTargets.cmake,sha256=OVt1Gm8n7Ew4fiTmA9yHoef3vIIGwsXUZfqeG9p9Bys,4152
|
|
14
|
-
sdf_xarray/__init__.py,sha256=
|
|
15
|
-
sdf_xarray/_version.py,sha256=
|
|
14
|
+
sdf_xarray/__init__.py,sha256=eFVAdNklw3LFGvU3NLsdraGXnRe3k_dtOhnyI0XtUHA,35371
|
|
15
|
+
sdf_xarray/_version.py,sha256=DbdCWfYFkRJvAt-jOwagEQlh0JevGHTJX-w-tGxtNFg,746
|
|
16
16
|
sdf_xarray/csdf.pxd,sha256=ADPjAuHsodAvdOz96Z_XlFF7VL3KmVaXcTifWDP3rK0,4205
|
|
17
|
-
sdf_xarray/
|
|
18
|
-
sdf_xarray/
|
|
19
|
-
sdf_xarray/
|
|
20
|
-
sdf_xarray-
|
|
21
|
-
sdf_xarray
|
|
22
|
-
sdf_xarray-0.
|
|
23
|
-
sdf_xarray-0.
|
|
24
|
-
sdf_xarray-0.
|
|
17
|
+
sdf_xarray/dataset_accessor.py,sha256=u3yJvT3Eg64gOWd_3NUYJwaTO5VVPA1k-TpW2FCNdzg,3984
|
|
18
|
+
sdf_xarray/download.py,sha256=fD3267jwpsprKDOoj5lEQEvMKPjiguwyfTkbKj7UgiM,3166
|
|
19
|
+
sdf_xarray/plotting.py,sha256=KHjJfO_n-3zXo6mNNbSW2Sv9oSxc06rr6RMtSIxLE24,17612
|
|
20
|
+
sdf_xarray/sdf_interface.cp312-win_amd64.pyd,sha256=eKNPfwSeI8t-O4DCPtPSDVVFG7Q9lRxTaFgNzXPpq8w,343040
|
|
21
|
+
sdf_xarray/sdf_interface.pyx,sha256=j0BpaltExUI_T-DMQvWaavKSrq9vqHkrmkJMJfCwDsA,12096
|
|
22
|
+
sdf_xarray-0.5.0.dist-info/METADATA,sha256=zVDIkM4EqPq_bvqWZ6StSPz9SKzydWQUkWjsOmrQfDo,6909
|
|
23
|
+
sdf_xarray-0.5.0.dist-info/WHEEL,sha256=chqeLhPBtPdrOoreR34YMcofSk3yWDQhkrsDJ2n48LU,106
|
|
24
|
+
sdf_xarray-0.5.0.dist-info/entry_points.txt,sha256=mmd-BWj57UCrpJxhzUQgscB7-13_bnbhYH8SUZxXIqU,110
|
|
25
|
+
sdf_xarray-0.5.0.dist-info/licenses/LICENCE,sha256=aHWuyELjtzIL1jTXFHTbI3tr9vyVyhnw3I9_QYPdEX8,1515
|
|
26
|
+
sdf_xarray-0.5.0.dist-info/RECORD,,
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: sdf-xarray
|
|
3
|
-
Version: 0.2.0
|
|
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>
|
|
6
|
-
License: Copyright 2024, Peter Hill, Joel Adams, PlasmaFAIR team
|
|
7
|
-
|
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
|
9
|
-
modification, are permitted provided that the following conditions are
|
|
10
|
-
met:
|
|
11
|
-
|
|
12
|
-
1. Redistributions of source code must retain the above copyright
|
|
13
|
-
notice, this list of conditions and the following disclaimer.
|
|
14
|
-
|
|
15
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
16
|
-
notice, this list of conditions and the following disclaimer in the
|
|
17
|
-
documentation and/or other materials provided with the distribution.
|
|
18
|
-
|
|
19
|
-
3. Neither the name of the copyright holder nor the names of its
|
|
20
|
-
contributors may be used to endorse or promote products derived from
|
|
21
|
-
this software without specific prior written permission.
|
|
22
|
-
|
|
23
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
24
|
-
“AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
25
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
26
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
27
|
-
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
28
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
29
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
30
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
31
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
32
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
|
-
Requires-Python: >=3.10
|
|
35
|
-
Requires-Dist: numpy>=2.0.0
|
|
36
|
-
Requires-Dist: xarray>=2024.1.0
|
|
37
|
-
Requires-Dist: dask>=2024.7.1
|
|
38
|
-
Requires-Dist: cython>=3.0
|
|
39
|
-
Requires-Dist: sphinx>=5.3; extra == "docs"
|
|
40
|
-
Requires-Dist: sphinx_autodoc_typehints>=1.19; extra == "docs"
|
|
41
|
-
Requires-Dist: sphinx-book-theme>=0.4.0rc1; extra == "docs"
|
|
42
|
-
Requires-Dist: sphinx-argparse-cli>=1.10.0; extra == "docs"
|
|
43
|
-
Requires-Dist: sphinx-inline-tabs; extra == "docs"
|
|
44
|
-
Requires-Dist: pickleshare; extra == "docs"
|
|
45
|
-
Requires-Dist: ipython; extra == "docs"
|
|
46
|
-
Requires-Dist: matplotlib; extra == "docs"
|
|
47
|
-
Requires-Dist: pytest>=3.3.0; extra == "test"
|
|
48
|
-
Requires-Dist: dask[complete]; extra == "test"
|
|
49
|
-
Requires-Dist: ruff; extra == "lint"
|
|
50
|
-
Requires-Dist: cibuildwheel[uv]; extra == "build"
|
|
51
|
-
Requires-Dist: dask[diagnostics]; extra == "jupyter"
|
|
52
|
-
Requires-Dist: ipykernel>=6.29.5; extra == "jupyter"
|
|
53
|
-
Provides-Extra: docs
|
|
54
|
-
Provides-Extra: test
|
|
55
|
-
Provides-Extra: lint
|
|
56
|
-
Provides-Extra: build
|
|
57
|
-
Provides-Extra: jupyter
|
|
58
|
-
Description-Content-Type: text/markdown
|
|
59
|
-
|
|
60
|
-
# sdf-xarray
|
|
61
|
-
|
|
62
|
-

|
|
63
|
-

|
|
64
|
-

|
|
65
|
-
|
|
66
|
-
`sdf-xarray` provides a backend for [xarray](https://xarray.dev) to
|
|
67
|
-
read SDF files as created by the [EPOCH](https://epochpic.github.io)
|
|
68
|
-
plasma PIC code using the [SDF-C](https://github.com/Warwick-Plasma/SDF_C) library.
|
|
69
|
-
|
|
70
|
-
## Installation
|
|
71
|
-
|
|
72
|
-
Install from PyPI with:
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
pip install sdf-xarray
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
> [!NOTE]
|
|
79
|
-
> For use within jupyter notebooks, run this additional command after installation:
|
|
80
|
-
>
|
|
81
|
-
> ```bash
|
|
82
|
-
> pip install "sdf-xarray[jupyter]"
|
|
83
|
-
> ```
|
|
84
|
-
|
|
85
|
-
or from a local checkout:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
git clone https://github.com/PlasmaFAIR/sdf-xarray.git
|
|
89
|
-
cd sdf-xarray
|
|
90
|
-
pip install .
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
We recommend switching to [uv](https://docs.astral.sh/uv/) to manage packages.
|
|
94
|
-
|
|
95
|
-
## Usage
|
|
96
|
-
|
|
97
|
-
For more in depth documentation please visit <https://sdf-xarray.readthedocs.io/>
|
|
98
|
-
|
|
99
|
-
`sdf-xarray` is a backend for xarray, and so is usable directly from
|
|
100
|
-
xarray:
|
|
101
|
-
|
|
102
|
-
### Single file loading
|
|
103
|
-
|
|
104
|
-
```python
|
|
105
|
-
import xarray as xr
|
|
106
|
-
|
|
107
|
-
df = xr.open_dataset("0010.sdf")
|
|
108
|
-
|
|
109
|
-
print(df["Electric_Field_Ex"])
|
|
110
|
-
|
|
111
|
-
# <xarray.DataArray 'Electric_Field_Ex' (X_x_px_deltaf_electron_beam: 16)> Size: 128B
|
|
112
|
-
# [16 values with dtype=float64]
|
|
113
|
-
# Coordinates:
|
|
114
|
-
# * X_x_px_deltaf_electron_beam (X_x_px_deltaf_electron_beam) float64 128B 1...
|
|
115
|
-
# Attributes:
|
|
116
|
-
# units: V/m
|
|
117
|
-
# full_name: "Electric Field/Ex"
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
To open a whole simulation at once, pass `preprocess=sdf_xarray.SDFPreprocess()`
|
|
121
|
-
to `xarray.open_mfdataset`:
|
|
122
|
-
|
|
123
|
-
```python
|
|
124
|
-
import xarray as xr
|
|
125
|
-
from sdf_xarray import SDFPreprocess
|
|
126
|
-
|
|
127
|
-
with xr.open_mfdataset("*.sdf", preprocess=SDFPreprocess()) as ds:
|
|
128
|
-
print(ds)
|
|
129
|
-
|
|
130
|
-
# Dimensions:
|
|
131
|
-
# time: 301, X_Grid_mid: 128, ...
|
|
132
|
-
# Coordinates: (9) ...
|
|
133
|
-
# Data variables: (18) ...
|
|
134
|
-
# Indexes: (9) ...
|
|
135
|
-
# Attributes: (22) ...
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
`SDFPreprocess` checks that all the files are from the same simulation, as
|
|
139
|
-
ensures there's a `time` dimension so the files are correctly concatenated.
|
|
140
|
-
|
|
141
|
-
If your simulation has multiple `output` blocks so that not all variables are
|
|
142
|
-
output at every time step, then those variables will have `NaN` values at the
|
|
143
|
-
corresponding time points.
|
|
144
|
-
|
|
145
|
-
Alternatively, we can create a separate time dimensions for each `output` block
|
|
146
|
-
(essentially) using `sdf_xarray.open_mfdataset` with `separate_times=True`:
|
|
147
|
-
|
|
148
|
-
```python
|
|
149
|
-
from sdf_xarray import open_mfdataset
|
|
150
|
-
|
|
151
|
-
with open_mfdataset("*.sdf", separate_times=True) as ds:
|
|
152
|
-
print(ds)
|
|
153
|
-
|
|
154
|
-
# Dimensions:
|
|
155
|
-
# time0: 301, time1: 31, time2: 61, X_Grid_mid: 128, ...
|
|
156
|
-
# Coordinates: (12) ...
|
|
157
|
-
# Data variables: (18) ...
|
|
158
|
-
# Indexes: (9) ...
|
|
159
|
-
# Attributes: (22) ...
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
This is better for memory consumption, at the cost of perhaps slightly less
|
|
163
|
-
friendly comparisons between variables on different time coordinates.
|
|
164
|
-
|
|
165
|
-
### Reading particle data
|
|
166
|
-
|
|
167
|
-
By default, particle data isn't kept as it takes up a lot of space. Pass
|
|
168
|
-
`keep_particles=True` as a keyword argument to `open_dataset` (for single files)
|
|
169
|
-
or `open_mfdataset` (for multiple files):
|
|
170
|
-
|
|
171
|
-
```python
|
|
172
|
-
df = xr.open_dataset("0010.sdf", keep_particles=True)
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Loading SDF files directly
|
|
176
|
-
|
|
177
|
-
For debugging, sometimes it's useful to see the raw SDF files:
|
|
178
|
-
|
|
179
|
-
```python
|
|
180
|
-
from sdf_xarray import SDFFile
|
|
181
|
-
|
|
182
|
-
with SDFFile("0010.sdf") as sdf_file:
|
|
183
|
-
print(sdf_file.variables["Electric Field/Ex"])
|
|
184
|
-
|
|
185
|
-
# Variable(_id='ex', name='Electric Field/Ex', dtype=dtype('float64'), ...
|
|
186
|
-
|
|
187
|
-
print(sdf_file.variables["Electric Field/Ex"].data)
|
|
188
|
-
|
|
189
|
-
# [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... -4.44992788e+12 1.91704994e+13 0.00000000e+00]
|
|
190
|
-
```
|