diff --git a/tests/test_bounds.py b/tests/test_bounds.py index 1be43f5c..52a95d68 100644 --- a/tests/test_bounds.py +++ b/tests/test_bounds.py @@ -65,6 +65,21 @@ def test_adds_bounds_to_the_dataset(self): result = ds.bounds.add_missing_bounds() assert result.identical(self.ds_with_bnds) + def test_adds_bounds_to_the_dataset_skips_nondimensional_axes(self): + # generate dataset with height coordinate + ds = generate_dataset(cf_compliant=True, has_bounds=True) + ds = ds.assign_coords({"height": 2}) + + # drop bounds + dsm = ds.drop_vars(["lat_bnds", "lon_bnds"]).copy() + + # test bounds re-generation + result = dsm.bounds.add_missing_bounds() + + # dataset with missing bounds added should match dataset with bounds + # and added height coordinate + assert result.identical(ds) + class TestGetBounds: @pytest.fixture(autouse=True) diff --git a/xcdat/bounds.py b/xcdat/bounds.py index 6d3bf44b..b9a50537 100644 --- a/xcdat/bounds.py +++ b/xcdat/bounds.py @@ -140,6 +140,12 @@ def add_missing_bounds(self, width: float = 0.5) -> xr.Dataset: except KeyError: pass + # determine if the axis is also a dimension by determining + # if there is overlap between the CF axis names and the dimension + # names. If not, skip over axis for validation. + if len(set(CF_NAME_MAP[axis]) & set(self._dataset.dims.keys())) == 0: + continue + if coord_var is not None: try: self.get_bounds(axis)