Skip to content

Commit ac6200f

Browse files
committed
Small updates inspired by MOM6 output.
Support "cartesian_axis" attribute Better error messages.
1 parent 49128e3 commit ac6200f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cf_xarray/accessor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"longitude": ("Lon",),
7373
},
7474
"axis": {"T": ("T",), "Z": ("Z",), "Y": ("Y",), "X": ("X",)},
75+
"cartesian_axis": {"T": ("T",), "Z": ("Z",), "Y": ("Y",), "X": ("X",)},
7576
"positive": {"Z": ("up", "down"), "vertical": ("up", "down")},
7677
"units": {
7778
"latitude": (
@@ -175,7 +176,7 @@ def _get_axis_coord_single(var: Union[DataArray, Dataset], key: str,) -> List[st
175176
results = _get_axis_coord(var, key)
176177
if len(results) > 1:
177178
raise KeyError(
178-
f"Multiple results for {key!r} found: {results!r}. Is this valid CF? Please open an issue."
179+
f"Multiple results for {key!r} found: {results!r}. I expected only one."
179180
)
180181
elif len(results) == 0:
181182
raise KeyError(f"No results found for {key!r}.")
@@ -917,7 +918,11 @@ def __getitem__(self, key: Union[str, List[str]]):
917918
successful = dict.fromkeys(key, False)
918919
for k in key:
919920
if k in _AXIS_NAMES + _COORD_NAMES:
920-
names = axis_coord_mapper(self._obj, k)
921+
try:
922+
names = axis_coord_mapper(self._obj, k)
923+
except KeyError as e:
924+
raise ValueError(f"Receive multiple variables for key {k!r}. Expected only one. Please pass a list [{k!r}] instead to get all variables matching {k!r}.")
925+
raise e
921926
successful[k] = bool(names)
922927
coords.extend(names)
923928
elif k in _CELL_MEASURES:

0 commit comments

Comments
 (0)