Skip to content

Commit

Permalink
Support indexing by cf_role for DSG datasets (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Jun 29, 2021
1 parent ed36d29 commit 2f46ee3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from xarray import DataArray, Dataset
from xarray.core.arithmetic import SupportsArithmetic

from .criteria import coordinate_criteria, regex
from .criteria import cf_role_criteria, coordinate_criteria, regex
from .helpers import bounds_to_vertices
from .utils import (
_get_version,
Expand Down Expand Up @@ -372,6 +372,7 @@ def _get_all(obj: Union[DataArray, Dataset], key: str) -> List[str]:
"""
all_mappers = (
_get_custom_criteria,
functools.partial(_get_custom_criteria, criteria=cf_role_criteria),
_get_axis_coord,
_get_measure,
_get_with_standard_name,
Expand Down Expand Up @@ -665,7 +666,7 @@ def check_results(names, key):
successful[k] = bool(measure)
if measure:
varnames.extend(measure)
elif k in custom_criteria:
elif k in custom_criteria or k in cf_role_criteria:
names = _get_all(obj, k)
check_results(names, k)
successful[k] = bool(names)
Expand Down
6 changes: 5 additions & 1 deletion cf_xarray/criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@


import re
from typing import MutableMapping, Tuple
from typing import Mapping, MutableMapping, Tuple

cf_role_criteria: Mapping[str, Mapping[str, str]] = {
k: {"cf_role": k} for k in ("timeseries_id", "profile_id", "trajectory_id")
}

coordinate_criteria: MutableMapping[str, MutableMapping[str, Tuple]] = {
"latitude": {
Expand Down
1 change: 1 addition & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ What's New

v0.5.3 (unreleased)
===================
- Support indexing by ``cf_role`` attribute. By `Deepak Cherian`_.
- Implemented :py:meth:`Dataset.cf.add_canonical_attributes` and :py:meth:`DataArray.cf.add_canonical_attributes`
to add CF canonical attributes. By `Mattia Almansi`_.
- Begin adding support for units with a unit registry for pint arrays. :pr:`197`.
Expand Down

0 comments on commit 2f46ee3

Please sign in to comment.