Skip to content

Commit ade7bf4

Browse files
authored
Merge pull request #180 from csiro-coasts/178-shocsimpletopology-can-raise-an-error-on-variables-without-a-standard_name
178 shocsimpletopology can raise an error on variables without a standard name
2 parents 82ad399 + 123b37f commit ade7bf4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/emsarray/conventions/shoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def topology(self) -> CFGrid2DTopology:
9494
latitude = next(
9595
name for name, variable in self.dataset.variables.items()
9696
if variable.dims == self._dimensions
97-
and variable.attrs["standard_name"] == "latitude"
97+
and variable.attrs.get("standard_name", None) == "latitude"
9898
)
9999
longitude = next(
100100
name for name, variable in self.dataset.variables.items()
101101
if variable.dims == self._dimensions
102-
and variable.attrs["standard_name"] == "longitude"
102+
and variable.attrs.get("standard_name", None) == "longitude"
103103
)
104104
except StopIteration:
105105
raise ValueError("Could not find the necessary coordinate variables")

tests/conventions/test_cfgrid2d.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ def test_values() -> None:
480480
assert numpy.allclose(values, eta.values.ravel(), equal_nan=True)
481481

482482

483+
def test_topology_with_missing_variable_standard_name() -> None:
484+
# Basic test showing no error when variable has no standard name
485+
dataset = make_dataset(j_size=10, i_size=20, corner_size=5, time_size=3)
486+
del dataset['botz'].attrs['standard_name']
487+
dataset.ems.topology
488+
489+
483490
@pytest.mark.matplotlib
484491
def test_plot_on_figure() -> None:
485492
# Not much to test here, mostly that it doesn't throw an error

0 commit comments

Comments
 (0)