xarray-contrib / cf-xarray

an accessor for xarray objects that interprets CF attributes
https://cf-xarray.readthedocs.io/
Apache License 2.0
159 stars 41 forks source link

Return custom name for DataArray #242

Open kthyng opened 3 years ago

kthyng commented 3 years ago

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 commented 3 years ago

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

dcherian commented 3 years ago

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