Skip to content

Commit

Permalink
deprecation of grid_mapping functions (#144)
Browse files Browse the repository at this point in the history
* deprecation

* Update whats_new.rst

* update api docs

* fix api

* update docs
  • Loading branch information
larsbuntemeyer authored Jul 3, 2023
1 parent 96bc68d commit 371c7bf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
1 change: 0 additions & 1 deletion cordex/preprocessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 8 additions & 25 deletions cordex/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://cf-xarray.readthedocs.io/en/latest/grid_mappings.html>`_ (:pull:`144`).

Documentation
~~~~~~~~~~~~~

Expand Down

0 comments on commit 371c7bf

Please sign in to comment.