Closed
Description
Looks like .cf.weighted
breaks with DataArrays.
from cf_xarray.datasets import airds
weights = xr.ones_like(airds["air"])
weights.attrs = {}
airds.cf.weighted(weights)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Note that I can't do this, because only Datasets
and DataArrays
have the .cf
accessor:
airds.weighted(weights).cf.mean("T")
AttributeError: 'DatasetWeighted' object has no attribute 'cf'
One possible workaround is:
airds.weighted(weights).mean(airds.cf.axes["T"])
or
airds = airds.assign_coords(weights=weights)
airds["air"].attrs["cell_measures"] += " weights: weights"
airds.cf.weighted("weights").mean("T")
but I don't think that's what we want.
Metadata
Metadata
Assignees
Labels
No labels