Skip to content

DataArrayCoarsen does not have a map or reduce function #3741

Closed
@aidenprice

Description

@aidenprice

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()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.4 (default, Sep 7 2019, 18:27:02) [Clang 10.0.1 (clang-1001.0.46.4)] python-bits: 64 OS: Darwin OS-release: 19.3.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_AU.UTF-8 LOCALE: en_AU.UTF-8 libhdf5: None libnetcdf: None

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions