Provides a backend for xarray to read SDF files as created by the EPOCH plasma PIC code.
Project description
sdf-xarray
sdf-xarray
provides a backend for xarray to
read SDF files as created by the EPOCH
plasma PIC code.
sdf-xarray
uses the SDF-C library.
[!IMPORTANT] All variable names now use snake_case to align with Epoch’s
sdf_helper
conventions. For example,Electric Field/Ex
has been updated toElectric_Field_Ex
.
Installation
Install from PyPI with:
pip install sdf-xarray
or from a local checkout:
git clone https://github.com/PlasmaFAIR/sdf-xarray.git
cd sdf-xarray
pip install .
We recommend switching to uv to manage packages.
Usage
sdf-xarray
is a backend for xarray, and so is usable directly from
xarray:
Single file loading
import xarray as xr
df = xr.open_dataset("0010.sdf")
print(df["Electric_Field_Ex"])
# <xarray.DataArray 'Electric_Field_Ex' (X_x_px_deltaf_electron_beam: 16)> Size: 128B
# [16 values with dtype=float64]
# Coordinates:
# * X_x_px_deltaf_electron_beam (X_x_px_deltaf_electron_beam) float64 128B 1...
# Attributes:
# units: V/m
# full_name: "Electric Field/Ex"
Multi file loading
To open a whole simulation at once, pass preprocess=sdf_xarray.SDFPreprocess()
to xarray.open_mfdataset
:
import xarray as xr
from sdf_xarray import SDFPreprocess
with xr.open_mfdataset("*.sdf", preprocess=SDFPreprocess()) as ds:
print(ds)
# Dimensions:
# time: 301, X_Grid_mid: 128, ...
# Coordinates: (9) ...
# Data variables: (18) ...
# Indexes: (9) ...
# Attributes: (22) ...
SDFPreprocess
checks that all the files are from the same simulation, as
ensures there's a time
dimension so the files are correctly concatenated.
If your simulation has multiple output
blocks so that not all variables are
output at every time step, then those variables will have NaN
values at the
corresponding time points.
Alternatively, we can create a separate time dimensions for each output
block
(essentially) using sdf_xarray.open_mfdataset
with separate_times=True
:
from sdf_xarray import open_mfdataset
with open_mfdataset("*.sdf", separate_times=True) as ds:
print(ds)
# Dimensions:
# time0: 301, time1: 31, time2: 61, X_Grid_mid: 128, ...
# Coordinates: (12) ...
# Data variables: (18) ...
# Indexes: (9) ...
# Attributes: (22) ...
This is better for memory consumption, at the cost of perhaps slightly less friendly comparisons between variables on different time coordinates.
Reading particle data
By default, particle data isn't kept as it takes up a lot of space. Pass
keep_particles=True
as a keyword argument to open_dataset
(for single files)
or open_mfdataset
(for multiple files):
df = xr.open_dataset("0010.sdf", keep_particles=True)
Loading SDF files directly
For debugging, sometimes it's useful to see the raw SDF files:
from sdf_xarray import SDFFile
with SDFFile("0010.sdf") as sdf_file:
print(sdf_file.variables["Electric Field/Ex"])
# Variable(_id='ex', name='Electric Field/Ex', dtype=dtype('float64'), ...
print(sdf_file.variables["Electric Field/Ex"].data)
# [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... -4.44992788e+12 1.91704994e+13 0.00000000e+00]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for sdf_xarray-0.1.2-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 323acf83233dbea7e60b40d2cdf386d22f61efcf15135f19a6016cd2ac685f00 |
|
MD5 | 9c33df0f18872becf6d92a7530a5f3ed |
|
BLAKE2b-256 | 62034fa8ae6fec0599af346f2c87be0914f664abca58d5a973c94137ac6b24b7 |
Hashes for sdf_xarray-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc77c4c8aa180fbecbbd8de1e687228202067ad749b5c3f84b9bbefaa824a185 |
|
MD5 | 802ccc793440a6a25ffed8cc2711aff8 |
|
BLAKE2b-256 | b1065821bbbd9971336addc7979f287435e37db72112235e7bb39656dc9fc3ed |
Hashes for sdf_xarray-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7d4ecefbb541d8c0d52af785cdf9bfef8e82a9962db72130d78762b1db1d58e |
|
MD5 | 5dbac4f0f24c5f597566e7f070229239 |
|
BLAKE2b-256 | d5727bbd4422ec586a7cdea60281989ebd87ee6b61b63bc453f4d0e58ea4e949 |
Hashes for sdf_xarray-0.1.2-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d40202e809f1eb378953d894bb75a7b12f5dfbcc65bcea0113db1c62aa5a868e |
|
MD5 | e771800460a87accb4da2f6453381dee |
|
BLAKE2b-256 | 0b0fcc2ecb80c0357997c96b33940f5c69b6d0bed10d44708162c7f07d09fe47 |
Hashes for sdf_xarray-0.1.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cd552828b7331d786337ca1f9ca476ab4b7ddd1ea98731a03a707a64e767916 |
|
MD5 | 0a3c5641e045136b9be85a31ec126de5 |
|
BLAKE2b-256 | 3716df7802ea5cfc46913f75cb78e721cbca93ae5a1ade1b9097f40d2ad02e3a |
Hashes for sdf_xarray-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8deecb3cbd7fae6a9452ffb6f6b4ec7ff07cdeda5c6ce0190b709e7e3f2444e8 |
|
MD5 | 94d9c69e8f35485e10c03a41d7fd9710 |
|
BLAKE2b-256 | c9fcb71d77bf0fcf6b66295fd5d94a8887a97a0e7f92bb96311adace349272cc |
Hashes for sdf_xarray-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 462561590b589f10ad6b2b8782e6b17eca799d50a9e17c6479fbf1ee2c95be46 |
|
MD5 | 303411dd5b69b615bc355a9d947b2223 |
|
BLAKE2b-256 | bda2a6e3f9d7815a8f53d6e09b9646b0e94084f42ecc36cef5d99dc3a2bbf8cf |
Hashes for sdf_xarray-0.1.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca891495a848cc443fb85d80733e90c0017be860c65139b3d87c2a088270ccc |
|
MD5 | 8f43056ea8e6afcc26da55b13f609ecd |
|
BLAKE2b-256 | 7d2ebfef17c4863c28d914246bbae2da7f13673f6a5e2957f9910e8432f78a3a |
Hashes for sdf_xarray-0.1.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6c20594c1b7a5e4c296166eddfc19472e50564e5bdfe55185212ed18090edcb |
|
MD5 | b5d15296a88db3499b750a63a01e7110 |
|
BLAKE2b-256 | 82633a05e5fbe4abf4e773d6e6f814594736975a316577f199cbcd3d68d46965 |
Hashes for sdf_xarray-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43f7d9cc5d320b86e442d0ab7942fb7771670d3df7ae9ecc5f66286ff9af51a2 |
|
MD5 | 9684a23e578e46e5522decfccd036de6 |
|
BLAKE2b-256 | b029dff3879cc13ea101bf9e0b3a5b2a3484ccd8f4ff39988afd9d6555303779 |
Hashes for sdf_xarray-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 483adb75d1130ce05e9d6ec51f92de5aea13b67243b27537c9fa3d28c12c183c |
|
MD5 | 65f1e535b9c47e1605b579fa3fcf8188 |
|
BLAKE2b-256 | ff770b862d0267c0ad7b5b34abfa41ec5ad229e495c04c44d738b727bcfd5bec |
Hashes for sdf_xarray-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b659bfd0a49e73a5d88933b20d6c7474d150fdafba0a05cb50f812f04d4feda |
|
MD5 | cab0d79dbf80bf9dcee77bb548a38799 |
|
BLAKE2b-256 | 2931d683b637cfe4787e95549cc2943817e9ee875031e86e7ed2f43a8df208bf |
Hashes for sdf_xarray-0.1.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 582bfcef75c7daf37b4ef906dedee8288281b741df29d78c5f4d489f72130a00 |
|
MD5 | 6cd590d0f856e9893432e776ad853206 |
|
BLAKE2b-256 | 9e12d93787b199573900754af98012d5a2199cb816402857a30e73b403f8bdf0 |
Hashes for sdf_xarray-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8c65d552666087b7cf5f20189f542ff018d3f88c5bbb6bf25d2202278c9ba18 |
|
MD5 | 021837bf096bc12b72817feaca3c42da |
|
BLAKE2b-256 | 29b66fbc45cad253a6e79555618f16e985ea3027a7d088311acc6de472252ef7 |
Hashes for sdf_xarray-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31c518e00cf505b05598863cb19ff7cda42959902bb9716af0de1d4182b436b8 |
|
MD5 | bb9457f02e4fc2dffeeaa1a024673578 |
|
BLAKE2b-256 | 53e4b775004abd0d0d00d38cf4ec0ecd958326c92b1ff19d8a1a0802a61259c8 |
Hashes for sdf_xarray-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 222eb25a3747a5dbc6eb7352c368bb74445da9967a17251cd684c9876b7e36e2 |
|
MD5 | 6c1262ee39732ae48279cfd78ba03f56 |
|
BLAKE2b-256 | efd5b28225f2be37c47a4f532ccf909ecde2e203b268a682e5bfb96f4b7d6346 |