issue_comments: 656060893
This data as json
| html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
|---|---|---|---|---|---|---|---|---|---|---|---|
| https://github.com/pydata/xarray/issues/3937#issuecomment-656060893 | https://api.github.com/repos/pydata/xarray/issues/3937 | 656060893 | MDEyOklzc3VlQ29tbWVudDY1NjA2MDg5Mw== | 10194086 | 2020-07-09T11:00:46Z | 2020-07-09T11:00:46Z | MEMBER | No that won't work. You need to mask the weights where the data is NaN. An untested and not very efficient way may be: ```python def coarsen_weighted_mean(da, weights, dims, skipna=None, boundary="exact"):
``` An example (without NaNs though): ```python import xarray as xr import numpy as np air = xr.tutorial.open_dataset("air_temperature").air weights = np.cos(np.deg2rad(air.lat)) we need to rename them from "lat"weights.name = "weights" c_w_m = coarsen_weighted_mean(air, weights, dict(lat=2), boundary="trim") to compare do it for one slicealt = air.isel(lat=slice(0, 2)).weighted(weights).mean("lat") compare if it is the samexr.testing.assert_allclose(c_w_m.isel(lat=0, drop=True), alt) ``` |
{
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} |
594669577 |