Skip to content

Commit

Permalink
Merge pull request #37 from PlasmaFAIR/time-units
Browse files Browse the repository at this point in the history
Add time units, long_name, and full_name
  • Loading branch information
ZedThree authored Nov 19, 2024
2 parents ad76b38 + 27c3d59 commit 1172e6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sdf_xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,13 @@ def __call__(self, ds: xr.Dataset) -> xr.Dataset:
)

ds = ds.expand_dims(time=[ds.attrs["time"]])

ds = ds.assign_coords(
time=(
"time",
[ds.attrs["time"]],
{"units": "s", "long_name": "Time", "full_name": "time"},
)
)
# Particles' spartial coordinates also evolve in time
for coord, value in ds.coords.items():
if value.attrs.get("point_data", False):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def test_erroring_on_mismatched_jobid_files():
)


def test_time_dim_units():
df = xr.open_mfdataset(EXAMPLE_ARRAYS_DIR.glob("*.sdf"), preprocess=SDFPreprocess())
assert df["time"].units == "s"
assert df["time"].long_name == "Time"
assert df["time"].full_name == "time"


def test_arrays_with_no_grids():
with xr.open_dataset(EXAMPLE_ARRAYS_DIR / "0001.sdf") as df:
laser_phase = "laser_x_min_phase"
Expand Down

0 comments on commit 1172e6f

Please sign in to comment.