From 4e869e0fa1a33bb4ff220e534ce1075480070605 Mon Sep 17 00:00:00 2001 From: Lukas Kluft Date: Sat, 7 Feb 2026 08:12:39 +0100 Subject: [PATCH 1/3] Make CRS in tests non-dimensional --- tests/test_healpix_coords.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_healpix_coords.py b/tests/test_healpix_coords.py index 432a8a7..ed77304 100644 --- a/tests/test_healpix_coords.py +++ b/tests/test_healpix_coords.py @@ -25,10 +25,9 @@ def raw_ds(request): return xr.Dataset( coords={ - crs_name: ( - ("crs",), - [0], - { + crs_name: xr.DataArray( + name=crs_name, + attrs={ "grid_mapping_name": "healpix", **map_parameters, }, From 9b7b40af7fcd3c9eea8c796b765ff7cf380f584e Mon Sep 17 00:00:00 2001 From: Lukas Kluft Date: Sat, 7 Feb 2026 08:16:42 +0100 Subject: [PATCH 2/3] Test refinement level inspection on data arrays --- tests/test_healpix_coords.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_healpix_coords.py b/tests/test_healpix_coords.py index ed77304..df495a0 100644 --- a/tests/test_healpix_coords.py +++ b/tests/test_healpix_coords.py @@ -36,6 +36,16 @@ def raw_ds(request): ) +@pytest.fixture +def ds(raw_ds): + ds = raw_ds.assign_coords( + cell=(("cell",), np.arange(12), {"standard_name": "healpix_index"}) + ) + ds = ds.assign(variable=(("cell",), np.ones(12), {"grid_mapping": "healpix"})) + + return ds + + def test_attach_coords_fixes_crs(raw_ds): ds = attach_coords(raw_ds) @@ -75,6 +85,16 @@ def test_get_nside(raw_ds): assert get_nside(np.arange(12)) == 1 +def test_get_nside_dataarray(ds): + da = ds["variable"] + + # Should work with... + assert get_nside(da) == 1 + + # .. and without CRS on data arrays + assert get_nside(da.drop_vars(da.cf["grid_mapping"].name)) == 1 + + def test_get_nest(raw_ds): assert get_nest(raw_ds) From b07e1073e0dba988768e2f496a0ba47cc2a68732 Mon Sep 17 00:00:00 2001 From: Lukas Kluft Date: Sat, 7 Feb 2026 08:46:02 +0100 Subject: [PATCH 3/3] Fix `get_nside()` for data arrays without CRS --- easygems/healpix/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easygems/healpix/__init__.py b/easygems/healpix/__init__.py index 919775b..9d6ddab 100644 --- a/easygems/healpix/__init__.py +++ b/easygems/healpix/__init__.py @@ -25,7 +25,8 @@ def get_nest(dx): def get_nside(dx): try: grid_mapping = dx.cf["grid_mapping"] - except AttributeError: + except (KeyError, AttributeError): + # Catch no CF (KeyError) and no grid mapping (AttributeError) if dx.squeeze().ndim > 1: raise ValueError( "Cannot infer the HEALPix resolution from a multidimensional dataset.\n"