diff --git a/cordex/preprocessing/__init__.py b/cordex/preprocessing/__init__.py index 8de3e1f..c570105 100644 --- a/cordex/preprocessing/__init__.py +++ b/cordex/preprocessing/__init__.py @@ -4,7 +4,6 @@ fix_known_issues, get_grid_mapping, get_grid_mapping_name, - get_grid_mapping_varname, member_id_to_dset_id, promote_empty_dims, remap_lambert_conformal, diff --git a/cordex/preprocessing/preprocessing.py b/cordex/preprocessing/preprocessing.py index 8e7f65e..89b0677 100644 --- a/cordex/preprocessing/preprocessing.py +++ b/cordex/preprocessing/preprocessing.py @@ -405,31 +405,13 @@ def get_grid_mapping_name(ds): grid_mapping_name attribute. """ - return get_grid_mapping(ds).grid_mapping_name - - -def get_grid_mapping_varname(ds): - """Returns grid mapping dataarray name. - - Returns the variable name of the first grid mapping found - in the dataset. - - Parameters - ---------- - ds : xr.Dataset - CORDEX like dataset. - - Returns - ------- - grid_mapping_varname : str - Variable name of the grid mapping. - - """ - return next( - ds[va].attrs["grid_mapping"] - for va in ds.data_vars - if "grid_mapping" in ds[va].attrs + message = ( + "get_grid_mapping_name is deprecated, please use cf_xarray " + 'accessor ds.cf["grid_mapping"].grid_mapping_name instead.' ) + warn(message, DeprecationWarning, stacklevel=2) + return ds.cf["grid_mapping"].grid_mapping_name + # return get_grid_mapping(ds).grid_mapping_name def get_grid_mapping(ds): @@ -455,7 +437,8 @@ def get_grid_mapping(ds): ) warn(message, DeprecationWarning, stacklevel=2) - return ds[get_grid_mapping_varname(ds)] + return ds.cf["grid_mapping"] + # return ds[get_grid_mapping_varname(ds)] def remap_lambert_conformal(ds, regridder=None, domain=None): diff --git a/docs/api.rst b/docs/api.rst index 05fa2d8..f0597cf 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -27,13 +27,11 @@ Preprocessing :toctree: generated/ preprocessing.rename_cordex - preprocessing.get_grid_mapping preprocessing.replace_coords preprocessing.cordex_dataset_id preprocessing.promote_empty_dims preprocessing.remap_lambert_conformal preprocessing.sort_ds_dict_by_attr - preprocessing.get_grid_mapping_name preprocessing.member_id_to_dset_id preprocessing.attr_to_coord diff --git a/docs/whats_new.rst b/docs/whats_new.rst index 241302e..dbe2989 100644 --- a/docs/whats_new.rst +++ b/docs/whats_new.rst @@ -25,6 +25,11 @@ Breaking Changes - The keyword name for the CORDEX domain identifier has changed from ``short_name`` to ``domain_id``, e.g., in :py:meth:`cordex_domain` or :py:meth:`domain_info`. If you have explicitly set this keyword, e.g., ``short_name="EUR-11"``, please change this to ``domain_id="EUR-11"``. This will be more consistent with the attribues in the updated domain tables. - Default branch is now ``main`` instead of ``master``. +Deprecations +~~~~~~~~~~~~ + +- Deprecation of :py:meth:`preprocessing.get_grid_mapping` and :py:meth:`preprocessing.get_grid_mapping_name` in favour of `cf_xarray `_ (:pull:`144`). + Documentation ~~~~~~~~~~~~~