Repository: PlasmaFAIR/sdf-xarray

Issue:
Time not assigned units when using `open_mfdataset`
`X_Grid` will be defined with attributes such as:

```
Attributes:
    long_name:   X
    units:       m
    point_data:  False
    full_name:   Grid/Grid
```

Ideally the same should be defined on the time grid when loading multiple SDF files.

Discussion:

Patch:
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 @@ class SDFPreprocess:
             )
 
         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):


Test patch:
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"