Description
I'm trying to count unique samples when resampling to a square kilometre from a 5x5m input grid. I'd like to be able to apply the Dask.array.unique()
function with return_counts=True
to give me a new dimension with the original integer values and their counts.
In order to resample along spatial dimensions I assume I need to use .coarsen()
, unfortunately the core.rolling.DataArrayCoarsen
object does not yet implement either a .map()
or .reduce()
function for applying an arbitrary function when coarsening.
MCVE Code Sample
import xarray as xr
from dask.array import unique
da = xr.DataArray([1, 1, 2, 3, 5, 3], [('x', range(0, 6))])
coarse = da2.coarsen(dim={'x': 2}).map(unique, kwargs={'return_counts': True})
coarse
outputs;
AttributeError: 'DataArrayCoarsen' object has no attribute 'map'
N.B. core.groupby.DataArrayGroupBy
has both .map()
and .reduce()
while core.rolling.DataArrayRolling
has .reduce()
. Would it make sense for all three to have the same interface?
Output of xr.show_versions()
xarray: 0.15.0
pandas: 1.0.0
numpy: 1.18.1
scipy: 1.4.1
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.1.2
cfgrib: None
iris: None
bottleneck: None
dask: 2.10.1
distributed: 2.10.0
matplotlib: 3.1.2
cartopy: None
seaborn: None
numbagg: None
setuptools: 40.8.0
pip: 19.0.3
conda: None
pytest: 5.3.5
IPython: 7.11.1
sphinx: None