Skip to content

Best way to add an alias for a dimension name #8570

Answered by dcherian
matthew-brett asked this question in Q&A
Discussion options

You must be logged in to vote

Yes. set_xindex sets an "index" which translates from coordinate-space to index-space. We haven't enabled "index-space" selection with .isel on such additional coordinates. (cc @benbovy )

For completeness here's the cf-xarray version if you wanted to experiment with the accessor style interface:

import xarray as xr
import numpy as np

img = xr.DataArray(
    dims=("i", "j", "k"),
    data=np.ones((120, 120, 120)),
    coords={"k": ("k", np.arange(120))},
)
img.k.attrs["alias"] = "slice"

import cf_xarray as cfxr  # registers .cf

cfxr.set_options(custom_criteria={"slice": {"alias": "slice"}})
img.cf.isel(slice=2)
img.cf.sel(slice=2)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@matthew-brett
Comment options

@dcherian
Comment options

@matthew-brett
Comment options

@dcherian
Comment options

Answer selected by matthew-brett
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants