-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
weighted for xr.corr #4768
Comments
Hello, I wrote a modification of _cor_cov which allows using weights in the computation of correlation and covariance (see below). In contrast to the version available on xskillscore, this code aligns the weights with the data, consistently with how xarray treats weights in general. Is this something useful/interesting to merge into xarray? If so I could prepare a PR and so on.
|
Thanks @lluritu a PR would be very welcome! |
Is your feature request related to a problem? Please describe.
I want to make weighted correlation, e.g. spatial correlation but weighted
xr.corr(fct,obs,dim=['lon','lat'], weights=np.cos(np.abs(fct.lat)))
So far,xr.corr
does not acceptweights
orinput.weighted(weights)
. A more straightforward case would be weighting of different members:xr.corr(fct,obs,dim='member',weights=np.arange(fct.member.size))
Describe the solution you'd like
We started xskillscore https://github.com/xarray-contrib/xskillscore some time ago, before xr.corr was implemented and have keywords
weighted
,skipna
andkeep_attrs
implemented. We also have xs.rmse, xs.mse, ... implemented viaxr.apply_ufunc
https://github.com/aaronspring/xskillscore/blob/150f7b9b2360750e6077036c7c3fd6e4439c60b6/xskillscore/core/deterministic.py#L849 which are faster than xr-based versions ofmse
https://github.com/aaronspring/xskillscore/blob/150f7b9b2360750e6077036c7c3fd6e4439c60b6/xskillscore/xr/deterministic.py#L6 orxr.corr
, see xarray-contrib/xskillscore#231Additional context
My question here is whether it would be better to move these xskillscore metrics upward into xarray or start a PR for weighted and skipna for
xr.corr
(what I prefer).The text was updated successfully, but these errors were encountered: