From dcf10f3938ab1de5578ca799b1e74aa9fac39f9f Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 19 Mar 2026 12:52:48 -0400 Subject: [PATCH 1/4] pre-commit: update validate-pyproject v fixing this error: KeyError: 'https://json.schemastore.org/tox.json' --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01ae19f..c767c48 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,7 +89,7 @@ repos: # - id: cmake-format - repo: https://github.com/abravalheri/validate-pyproject - rev: "v0.23" + rev: "v0.25" hooks: - id: validate-pyproject additional_dependencies: ["validate-pyproject-schema-store[all]"] From 5fdaa8ae91eb69fae7437b02583531392a8f5e4e Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 19 Mar 2026 12:53:51 -0400 Subject: [PATCH 2/4] psc: get dims from ds --- src/pscpy/psc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pscpy/psc.py b/src/pscpy/psc.py index fd3859c..0037401 100644 --- a/src/pscpy/psc.py +++ b/src/pscpy/psc.py @@ -68,17 +68,17 @@ def decode_psc( length: ArrayLike | None = None, corner: ArrayLike | None = None, ) -> xr.Dataset: - da = ds[next(iter(ds))] # first dataset - if da.dims[0] == "dim_0_1": + dims = list(ds.dims) + if "dim_0_1" in dims: # for compatibility, if dimensions weren't saved as attribute in the .bp file, # fix them up here ds = ds.rename_dims( { - da.dims[0]: "step", + dims[0]: "step", # dims[1] is the "component" dimension, which gets removed later - da.dims[2]: "z", - da.dims[3]: "y", - da.dims[4]: "x", + dims[2]: "z", + dims[3]: "y", + dims[4]: "x", } ) ds = ds.squeeze("step") From 51086bbc7901d0771c2e02c08f28a24eafc9db63 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 19 Mar 2026 13:00:22 -0400 Subject: [PATCH 3/4] psc; test: add t as coord --- src/pscpy/psc.py | 2 ++ tests/test_xarray_adios2.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pscpy/psc.py b/src/pscpy/psc.py index 0037401..b79dbf7 100644 --- a/src/pscpy/psc.py +++ b/src/pscpy/psc.py @@ -37,6 +37,7 @@ def __init__( self.x = self._get_coord(0) self.y = self._get_coord(1) self.z = self._get_coord(2) + self.t = float(ds.attrs["time"]) def _get_coord(self, coord_idx: int) -> NDArray[Any]: return np.linspace( @@ -95,6 +96,7 @@ def decode_psc( "x": ("x", run_info.x), "y": ("y", run_info.y), "z": ("z", run_info.z), + "t": run_info.t, } ds = ds.assign_coords(coords) diff --git a/tests/test_xarray_adios2.py b/tests/test_xarray_adios2.py index aafbe89..a5acce6 100644 --- a/tests/test_xarray_adios2.py +++ b/tests/test_xarray_adios2.py @@ -98,7 +98,7 @@ def ds_pfd_moments_decoded(ds_pfd_moments_raw) -> xr.Dataset: def test_open_dataset(ds_pfd_decoded): assert "jx_ec" in ds_pfd_decoded - assert ds_pfd_decoded.coords.keys() == set({"x", "y", "z"}) + assert ds_pfd_decoded.coords.keys() == set({"x", "y", "z", "t"}) assert ds_pfd_decoded.jx_ec.sizes == dict(x=1, y=128, z=512) # noqa: C408 assert np.allclose( ds_pfd_decoded.jx_ec.z.data, np.linspace(-25.6, 25.6, 512, endpoint=False).data From eb2a1b3f728e8220c0e1c00e455577e3bdc74476 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 19 Mar 2026 14:14:47 -0400 Subject: [PATCH 4/4] psc: rename dim to component; isel it --- src/pscpy/psc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pscpy/psc.py b/src/pscpy/psc.py index b79dbf7..a8d5ba3 100644 --- a/src/pscpy/psc.py +++ b/src/pscpy/psc.py @@ -76,7 +76,7 @@ def decode_psc( ds = ds.rename_dims( { dims[0]: "step", - # dims[1] is the "component" dimension, which gets removed later + dims[1]: "component", dims[2]: "z", dims[3]: "y", dims[4]: "x", @@ -87,7 +87,7 @@ def decode_psc( for var_name in ds: components = list(iter_components(var_name, species_names)) for component_idx, component in enumerate(components): - ds = ds.assign({component: ds[var_name][component_idx, :, :, :]}) + ds = ds.assign({component: ds[var_name].isel(component=component_idx)}) if var_name not in components: ds = ds.drop_vars([var_name])