Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time units, long_name, and full_name #37

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading