diff --git a/cmip6_preprocessing/preprocessing.py b/cmip6_preprocessing/preprocessing.py index 7306dedc..8b855429 100644 --- a/cmip6_preprocessing/preprocessing.py +++ b/cmip6_preprocessing/preprocessing.py @@ -68,6 +68,10 @@ def _invert_dict(rdict): return exploded_dict +def _parse_cf(dataset): + dataset = dataset.cf.guess_coord_axis() + return dataset + def rename_cmip6(ds, rename_dict=None): """Homogenizes cmip6 dataasets to common naming""" ds = ds.copy() @@ -109,6 +113,8 @@ def _maybe_rename(obj, rdict): # restore attributes ds.attrs = attrs + # use cf conventions where they can be inferred by cf_xarray + ds = _parse_cf(ds) return ds diff --git a/tests/test_preprocessing.py b/tests/test_preprocessing.py index 4e2a2a4d..3d96ab15 100644 --- a/tests/test_preprocessing.py +++ b/tests/test_preprocessing.py @@ -66,6 +66,12 @@ def test_rename_cmip6(xname, yname, zname, missing_dim): assert ylen == len(ds_renamed.y) if not missing_dim == "z": assert zlen == len(ds_renamed.lev) + + # check if cf conventions were inferred + for dim, axis in [('x', 'X'), ('y', 'Y'), ('lev','Z'), ('time', 'T')]: + if dim in ds_renamed.dims: + #check that the axis is in the cf object + assert axis in ds_renamed.cf.axes.keys() @pytest.mark.parametrize("xname", ["i", "x"]) diff --git a/tests/test_preprocessing_cloud.py b/tests/test_preprocessing_cloud.py index d48d1ef6..704c8247 100644 --- a/tests/test_preprocessing_cloud.py +++ b/tests/test_preprocessing_cloud.py @@ -236,6 +236,12 @@ def test_check_dim_coord_values_wo_intake( if unit: assert unit == expected_unit + # check if cf conventions were inferred + for dim, axis in [('x', 'X'), ('y', 'Y'), ('lev','Z'), ('time', 'T')]: + if dim in ds.dims: + #check that the axis is in the cf object + assert axis in ds.cf.axes.keys() + # this fixture has to be redifined every time to account for different fail cases for each test @pytest.fixture