cf-xarray icon indicating copy to clipboard operation
cf-xarray copied to clipboard

Return custom name for DataArray

Open kthyng opened this issue 3 years ago • 2 comments

This came up in #234 and I want to capture the idea here:

I'd like to be able to not just ask for the "ssh" variable for example, but ask which type of variable I have. So in addition to:

ds.cf["ssh"]

returning the "ssh"-matching variable, I would like to be able to, for a DataArray da:

da.cf._get_custom_type()

to return "ssh", or somehow do the inverse search, returning the custom names that match the DataArray.

kthyng avatar Jun 28 '21 21:06 kthyng

@dcherian is there an analogous function in the accessor code that would make sense to copy for this?

kthyng avatar Jun 28 '21 21:06 kthyng

This may be useful: https://github.com/xarray-contrib/cf-xarray/blob/770f40cd49617c703b2aec6fa1bacf2d1b344106/cf_xarray/accessor.py#L547-L569

It rewrites things like .chunks and .sizes when a one-to-one mapping is possible

dcherian avatar Jul 02 '21 18:07 dcherian