Open juseg opened 3 weeks ago
I think the cf-xarray version of this only really makes sense when the assigned name is a standard name on one of the present variables, so (2) in your listing.
For (1), we should just forward on to Xarray, as usual.
if we allow multiple variables with the same standard name, the resulting Dataset is technically valid, and ds.cf shows several variables associated with one standard name, while ds.cf[standard_name] fails with a KeyError`
Yes, this is intentional. ds.cf[standard_name]
will raise an error unless there is only one result, since that is the only way to return a DataArray. to get all, use ds.cf[[standard_name]]
. Then you will get a dataset with all dataarrays with that standard name.
This pull request implements
ds.cf.assign(**standard_variables)
. The new method should:**kwargs
or dictionary.Also needed:
I would welcome opinions on the two points below.
1. Decide about the variable short name
I propose this algorithm:
2. When dataset already contains standard name
I find it more difficult to decide what the method should do here.
Dataset.assign
).existing: ignore, override, raise, warn
Note: if we allow multiple variables with the same standard name, the resulting Dataset is technically valid, and
ds.cf
shows several variables associated with one standard name, whileds.cf[standard_name] fails with a
KeyError`.