Skip to content

Commit

Permalink
update docs, add coord alias reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Apr 3, 2024
1 parent 65b71e6 commit db3c9dc
Show file tree
Hide file tree
Showing 5 changed files with 1,098 additions and 23 deletions.
1,089 changes: 1,070 additions & 19 deletions docs/examples/example_002_coord_aliases.ipynb

Large diffs are not rendered by default.

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

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

Expand Down
2 changes: 1 addition & 1 deletion yt_xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# import the xarray accessor so it is registered with xarray

from .accessor import YtAccessor
from .accessor._xr_to_yt import known_coord_aliases
from .accessor._xr_to_yt import known_coord_aliases, reset_coordinate_aliases
from .yt_xarray import open_dataset
20 changes: 18 additions & 2 deletions yt_xarray/accessor/_xr_to_yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,26 @@ def interp_validation(self, geometry):
}


known_coord_aliases = {}
_default_known_coord_aliases = {}
for ky, vals in _coord_aliases.items():
for val in vals:
known_coord_aliases[val] = ky
_default_known_coord_aliases[val] = ky

known_coord_aliases = _default_known_coord_aliases.copy()


def reset_coordinate_aliases():
kys_to_pop = [
ky
for ky in known_coord_aliases.keys()
if ky not in _default_known_coord_aliases
]
for ky in kys_to_pop:
known_coord_aliases.pop(ky)

for ky, val in _default_known_coord_aliases.items():
known_coord_aliases[ky] = val


_expected_yt_axes = {
"cartesian": set(["x", "y", "z"]),
Expand Down
6 changes: 6 additions & 0 deletions yt_xarray/tests/test_xr_to_yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,9 @@ def _bad_import(name, globals=None, locals=None, fromlist=(), level=0):
with pytest.raises(ValueError, match=f"{clist[0]} is not"):

_ = xr2yt._convert_to_yt_internal_coords(clist, xr_da)


def test_coord_alias_reset():
xr2yt.known_coord_aliases["blah"] = "lwkerj"
xr2yt.reset_coordinate_aliases()
assert "blah" not in xr2yt.known_coord_aliases

0 comments on commit db3c9dc

Please sign in to comment.