From 27c3d59ea628523eee52c8226e4d6df66ce2c469 Mon Sep 17 00:00:00 2001 From: JoelLucaAdams Date: Tue, 19 Nov 2024 13:50:11 +0000 Subject: [PATCH] Add time units, long_name, and full_name --- src/sdf_xarray/__init__.py | 8 +++++++- tests/test_basic.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sdf_xarray/__init__.py b/src/sdf_xarray/__init__.py index 74137b7..711fbef 100644 --- a/src/sdf_xarray/__init__.py +++ b/src/sdf_xarray/__init__.py @@ -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): diff --git a/tests/test_basic.py b/tests/test_basic.py index e7634de..83a5f43 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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"