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.

Behaviour reference

The exact rules the patchers follow at edges, on fills, under failures and across runs. Each rule lives here once; the how-tos link back. For the mental model, read Concepts first.

Fields and domains

The patcher reads a Field through its domain and select(indexer), and rebuilds results with with_data(array). Geometry × Domain dispatch is an explicit isinstance check; an unsupported pairing raises NotImplementedError.

FieldDomainBackendExtra
geopatcher.RasterFieldRasterDomain (the source itself)any geoarray.RasterSource: a GeoArray, a lazy reader—
geopatcher.fields.AsyncRasterFieldRasterDomainany geoarray.AsyncRasterSource—
geopatcher.fields.CogFieldRasterDomaina COG over geocloud.cog.CogSource[cog]
geopatcher.fields.ReprojectingRasterFieldthe destination gridany geoarray.RasterSource, warped per chip—
geopatcher.fields.RioXarrayFieldRasterDomainrioxarray DataArray[xarray-raster]
geopatcher.fields.XarrayFieldGridDomainxarray.DataArray (non-raster)[grid]
geopatcher.fields.DaskFieldGridDomaindask-backed DataArray[dask]
geopatcher.fields.GeoPandasFieldVectorDomain / PointDomaingeopandas.GeoDataFrame[vector]
geopatcher.fields.XvecFieldPointDomainxvec Dataset[point]

A RasterDomain is a protocol: a geoarray.Grid (grid: transform, CRS, (H, W)) plus the full array shape. Every RasterSource satisfies it, so a raster field’s domain is its source and costs no read; a bare geoarray.Grid works too, to plan anchors before any data exists. Raster patches are geoarray.GeoArray chips on the window’s grid, and a raster with_data / merge_to_field returns a GeoArray on the source grid. georeader objects are refused with a TypeError naming geoarray.interop.georeader.from_georeader / source_from_georeader.

DaskField.from_zarr(store, var="sst") wraps one variable of a zarr store. SpatialPatcher.to_delayed / to_dask_bag build one Dask task per patch. These are plain read tasks: on_error, hooks, journal, PatchCache and prefetch do not apply, so failures and retries are the scheduler’s job.

Boundary policy

spatial.geometry.Rectangular(boundary=...) decides what happens when a patch would overflow the domain.

Five panels on a 10 × 10 domain with 4 × 4 patches every 4 cells: drop never places the overflowing anchor at (8, 8); pad reads a full patch with nodata in the overflow; reflect mirrors the interior into the overflow; shrink clips the patch to 2 × 2; raise fails on the overflowing window
boundaryBehaviour
"drop" (default)Samplers place only anchors whose patch lies wholly in the domain; the trailing residual is not covered. A patch larger than the domain places no anchor, with a RuntimeWarning.
"pad"Samplers also place the edge anchor — the first whose patch reaches the edge, never one past it. The patch is full size, padded with the reader’s nodata or pad_value (which must fit the field’s dtype). A GeoArray source without a fill_value pads float data with NaN, declared as the chip’s fill, and raises for integer or bool data (give it a fill_value, or use "reflect" / "shrink").
"reflect"As "pad", but the overflow is mirrored from the interior (numpy mode="reflect"). Needs at least two cells on a padded axis.
"shrink"As "pad" for placement, but the window is clipped to the domain on every side, so edge patches are smaller. Weights crop to match.
"raise"As "pad" for placement; split raises ValueError on the first overflowing window. Useful with spatial.sampler.Explicit.

Window convention

spatial.window.Hann and spatial.window.Tukey are periodic tapers of period n sampled at the pixel centres, t = (k + ½) / n: per axis, Hann is sin²(π (k + ½) / n), and the two axes combine as an outer product (ADR-010).

RuleConsequence
Hann is COLA at hop N/2With an even size and step = size // 2, even OverlapAdd(normalize_by_window=False) reproduces a constant. Other overlapping strides still reconstruct exactly under the default normalisation.
Tukey(alpha=1.0) is Hann, alpha=0.0 is BoxcarTukey is COLA at hop N · (1 − alpha/2).
No sample is zero, and the window is symmetricEvery pixel a chip covers keeps a non-zero weight, so the scene’s outer rows and columns come back as data. With step == size the normalised merge reproduces the field exactly; the taper only blends where chips overlap.
An axis shorter than 3 samplesThe taper is flat (all ones) on that axis.

spatial.window.Gaussian(sigma=...) takes sigma as a fraction of the patch half-width (std = sigma · n / 2 pixels per axis).

Determinism

spatial.sampler.Random, spatial.sampler.JitteredStride, spatial.sampler.PoissonDisk and temporal.sampler.Random take seed: int | None.

seedBehaviour
intTwo samplers with the same config return bit-identical anchors, across calls and across instances. Use it for ML evaluation, CI and journal resume.
None (default)Re-seeds from OS entropy on every call, so anchors differ.

The round-trip property tests rely on the int contract to replay a failing (shape, stride, seed) exactly.

Streaming aggregations

Every spatial.aggregation.Aggregation declares streaming_safe: ClassVar[bool]. A streaming-safe aggregation folds one patch at a time; the others hold every patch in memory.

FamilyMembersResult
Exact, streamingSum, Mean, Variance, OverlapAdd, WeightedSum, InvVarWeightedMean, HardVote, SoftVotea per-cell field
Not streamingMedian, Mode, Learneda per-cell field, all patches in RAM
Sketches, streamingApproxQuantile, ApproxCardinality, ApproxMode, StreamingHistogram, Reservoirone summary for the whole field (e.g. {"0.5": 12.3})

Merging a non-streaming aggregation emits a RuntimeWarning naming the streamable substitute: Mode → HardVote, Learned → patcher.two_pass; Median has none. geopatcher.observe.set_strict(True) turns the warning into a RuntimeError. Sketches are global, not a per-cell replacement for Median / Mode; combine partial sketches with a.merge_state(b).

OverlapAdd(streaming=True, target_path=..., chunks=...) accumulates in a zarr store on disk, or finishes as a COG with writer="cog": see Stream to disk.

Aggregation fill and ties

Every dense aggregation follows the same per-cell rules.

AggregationDefault fill_valueNotes
Sum, Mean, Max, Min, WeightedSum, OverlapAdd, Median, ModeNaN
VarianceNaNalso for cells with fewer than 2 samples (np.nanvar(ddof=1))
InvVarWeightedMeanNaN in mu and varvar == 0 is an exact observation: the cell takes that mu
HardVote, SoftVote-1 (“no class”)
TiesWinner
HardVote, SoftVotethe lowest class index
Modethe smallest value

On-error policies

SpatialPatcher(on_error=...) decides what a failed patch read does. TemporalPatcher takes the same knobs.

on_errorBehaviour
"raise" (default)Fail on the first error.
"skip"Record a PatchErrorRecord in patcher.errors; the anchor is not yielded.
"mask"Yield a NaN-valued patch of the geometry’s shape.
"retry"Retry exceptions matching retry_on up to max_retries times, then behave as "skip". Every failed attempt is recorded with its retry_count. retry_on defaults to (OSError, TimeoutError); other exceptions raise.

Handle read failures shows each policy in use and how it combines with parallel_map.

One anchor walk

SpatialPatcher.split / asplit, AsyncSpatialPatcher.asplit, TemporalPatcher.split / asplit and both SpatioTemporalPatcher couplings run on one anchor-walk core. So these behave the same on every path:

Temporal boundary policy

Every integer temporal geometry takes boundary for a window that overflows the time axis.

boundaryBehaviour
"drop" (default)The anchor yields no patch, so every window is full length. MultiScale drops an anchor whose longest scale overflows; PhaseWindow drops each overflowing cycle slot.
"shrink"The window is clipped to [0, time_len).
"raise"ValueError naming the anchor and the window.

Temporal and spatiotemporal keys