Description:
- Strategies for fast GroupBy reductions with dask.array
Resources:
- [GitHub] https://github.com/xarray-contrib/flox
- [Docs] https://flox.readthedocs.io/en/latest/
- [Pangeo Showcase talk] https://discourse.pangeo.io/t/november-17-2021-flox-fast-furious-groupby-reductions-with-dask-at-pangeo-scale/2016
Example 1
Section titled “Example 1”GroupBy single variable with numpy and xarray
import numpy as npimport xarray as xr
from flox.xarray import xarray_reduce
labels = xr.DataArray( [1, 2, 3, 1, 2, 3, 0, 0, 0], dims="x", name="label",)
da = xr.DataArray( np.ones((9,)), dims="x", name="array")
xarray_reduce(da, labels, func="sum")Example 2
Section titled “Example 2”GroupBy with Dask and Xarray
import xarray as xrfrom flox.xarray import xarray_reduce
da = xr.DataArray( np.ones((9,)), dims="x", name="array")da_chunked = da.chunk(x=2)
labels = xr.DataArray( [1, 2, 3, 1, 2, 3, 0, 0, 0], dims="x", name="label",)labels_chunked = labels.chunk(x=3)
xarray_reduce(da_chunked, labels, func="sum")ganymede is made by Eugo