Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Dask

Every xrtoolz operator accepts dask-backed (chunked) xarray inputs, not just eager numpy ones. Where an operator’s kernel is naturally per-chunk it stays lazy — the work is deferred into the dask graph and only runs on .compute(). Where the algorithm needs the whole array (a global neighbour search, a global fit), the operator still accepts dask input but materialises internally, with an identical result.

A lazy pipeline

The composition layer is dask-transparent — chunk once at the source and the whole Sequential / Graph stays lazy until you ask for a result:

import xarray as xr
from pipekit_ops import Sequential
from xrops.anomaly import RemoveMean
from xrops.ocn.operators import Streamfunction, GeostrophicVelocities

ds = xr.open_mfdataset("ssh_*.nc").chunk({"time": 1, "lat": -1, "lon": -1})

pipeline = Sequential(
    RemoveMean("time"),
    Streamfunction(),
    GeostrophicVelocities(),
)

lazy = pipeline(ds)        # nothing computed yet — a dask graph
result = lazy.compute()    # run it (optionally under a dask scheduler/cluster)

Declared backends

Every xrops operator declares backends from pipekit’s vocabulary (OP-O6); today all declare ("numpy", "dask"). A DataArray counts by the backend of its data and a Dataset by its variables’, so a JAX-backed input goes to the host and the result comes back as JAX (pipekit_ops.guard reports it; JAX beside dask, or traced data, raises a BackendError), while a NumPy operand beside a dask one (a static mask, an in-memory reference) joins the lazy computation. geoops geometry operators, which need a GeoArray per item, run over a cube through xrops.lift.

Per-operator tiers

Every operator falls into one of three tiers. The tests/test_dask_compat.py sweep asserts numpy/dask result parity for all of them, and asserts laziness for the lazy tiers.

TierBehaviourOperators
Lazystays a dask graphxrops.grad (partial, gradient, divergence, curl, laplacian, Gradient, Difference; stencils run per chunk with a halo, so the result equals the in-memory one) and the ocn diagnostics on it (KE, streamfunction, velocity magnitude, RelativeVorticity, Divergence, GeostrophicVelocities, OkuboWeiss); geo (RemoveMean, climatology, validators, masks); transforms.PowerSpectrum; Coarsen; RegridLike; all pixel/spectral metrics; the gap-fillers (FillNaN{Laplacian,Spatial,RBF,Biharmonic,IDW}); the smoothers (GaussianSmooth, MovingAverage, fir_filter, lowpass_filter); morphology
Eager (dask-safe)accepts dask, computes internally, identical resultbinning (Bin2D, Histogram2D); the sklearn bridge (XarrayEstimator, decompositions, SklearnModelOp)
N/Anumpy-array primitives — no xarray, so no daskpoints_to_grid, idw_to_grid, kde_to_grid (use the *ToGrid operators for the xarray surface)

Testing your own pipelines

The array_backend / maybe_chunk fixtures (in tests/conftest.py) let a single test body run against both backends:

def test_my_pipeline(array_backend, maybe_chunk):
    ds = maybe_chunk(build_dataset(), array_backend, {"time": 1})
    out = my_pipeline(ds)
    if array_backend == "dask":
        assert out["u"].chunks is not None     # stayed lazy
        out = out.compute()
    xr.testing.assert_allclose(out, expected)