Skip to content

Commit db3c9dc

Browse files
committed
update docs, add coord alias reset function
1 parent 65b71e6 commit db3c9dc

File tree

5 files changed

+1098
-23
lines changed

5 files changed

+1098
-23
lines changed

docs/examples/example_002_coord_aliases.ipynb

Lines changed: 1070 additions & 19 deletions
Large diffs are not rendered by default.

docs/faq.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ yt datasets have a fixed expectation for coordinate names. In cartesian, these
2626
coordinate names are ``'x'``, ``'y'``, ``'z'`` while for geographic coordinate systems
2727
the coordinate names are ``'latitude'``, ``'longtiude'`` and then either ``'altitude'``
2828
or ``'depth'``. To work with xarray variables defined with coordinate names that
29-
differ from these, yt_xarray provides some coordinate aliasing.
29+
differ from these, yt_xarray provides some coordinate aliasing, which in part relies
30+
on `cf_xarray <https://cf-xarray.readthedocs.io>`_ (if it is installed) for
31+
additional conversion to standard names.
3032

3133
See :doc:`examples/example_002_coord_aliases` for an example.
3234

yt_xarray/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
# import the xarray accessor so it is registered with xarray
99

1010
from .accessor import YtAccessor
11-
from .accessor._xr_to_yt import known_coord_aliases
11+
from .accessor._xr_to_yt import known_coord_aliases, reset_coordinate_aliases
1212
from .yt_xarray import open_dataset

yt_xarray/accessor/_xr_to_yt.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,26 @@ def interp_validation(self, geometry):
324324
}
325325

326326

327-
known_coord_aliases = {}
327+
_default_known_coord_aliases = {}
328328
for ky, vals in _coord_aliases.items():
329329
for val in vals:
330-
known_coord_aliases[val] = ky
330+
_default_known_coord_aliases[val] = ky
331+
332+
known_coord_aliases = _default_known_coord_aliases.copy()
333+
334+
335+
def reset_coordinate_aliases():
336+
kys_to_pop = [
337+
ky
338+
for ky in known_coord_aliases.keys()
339+
if ky not in _default_known_coord_aliases
340+
]
341+
for ky in kys_to_pop:
342+
known_coord_aliases.pop(ky)
343+
344+
for ky, val in _default_known_coord_aliases.items():
345+
known_coord_aliases[ky] = val
346+
331347

332348
_expected_yt_axes = {
333349
"cartesian": set(["x", "y", "z"]),

yt_xarray/tests/test_xr_to_yt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,9 @@ def _bad_import(name, globals=None, locals=None, fromlist=(), level=0):
566566
with pytest.raises(ValueError, match=f"{clist[0]} is not"):
567567

568568
_ = xr2yt._convert_to_yt_internal_coords(clist, xr_da)
569+
570+
571+
def test_coord_alias_reset():
572+
xr2yt.known_coord_aliases["blah"] = "lwkerj"
573+
xr2yt.reset_coordinate_aliases()
574+
assert "blah" not in xr2yt.known_coord_aliases

0 commit comments

Comments
 (0)