diff --git a/src/emsarray/conventions/shoc.py b/src/emsarray/conventions/shoc.py index eee7d2dc..3c52a426 100644 --- a/src/emsarray/conventions/shoc.py +++ b/src/emsarray/conventions/shoc.py @@ -94,12 +94,12 @@ def topology(self) -> CFGrid2DTopology: latitude = next( name for name, variable in self.dataset.variables.items() if variable.dims == self._dimensions - and variable.attrs["standard_name"] == "latitude" + and variable.attrs.get("standard_name", None) == "latitude" ) longitude = next( name for name, variable in self.dataset.variables.items() if variable.dims == self._dimensions - and variable.attrs["standard_name"] == "longitude" + and variable.attrs.get("standard_name", None) == "longitude" ) except StopIteration: raise ValueError("Could not find the necessary coordinate variables") diff --git a/tests/conventions/test_cfgrid2d.py b/tests/conventions/test_cfgrid2d.py index cbc616a8..fc055079 100644 --- a/tests/conventions/test_cfgrid2d.py +++ b/tests/conventions/test_cfgrid2d.py @@ -480,6 +480,13 @@ def test_values() -> None: assert numpy.allclose(values, eta.values.ravel(), equal_nan=True) +def test_topology_with_missing_variable_standard_name() -> None: + # Basic test showing no error when variable has no standard name + dataset = make_dataset(j_size=10, i_size=20, corner_size=5, time_size=3) + del dataset['botz'].attrs['standard_name'] + dataset.ems.topology + + @pytest.mark.matplotlib def test_plot_on_figure() -> None: # Not much to test here, mostly that it doesn't throw an error