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.

Concepts

geopatcher answers one question: what slice of the data does my operator see at once, and how do local outputs become a global field? It answers it with four independent axes over a Field. This page is the mental model; exact edge, fill and determinism rules live in the Behaviour reference.

The four-axis abstraction

Each axis is a small strategy object you pick on its own. Swapping one never forces a change in the other three.

SpatialPatcher: a Field is split along the Geometry, Sampler, Window and Aggregation axes, your operator runs on each Patch, and the aggregation merges the patches into a stitched field

Geometry — the shape of a patch

The geometry turns an anchor into the cells a patch covers.

spatial.geometry.Patch shapeDomain
Rectangular(size=(h, w))an h × w window; takes boundary= for the edgesraster, grid
SphericalCap(radius_km)a cap of great-circle radius on the spheregrid
KNNGraph(k)the k nearest neighbourspoints
RadiusGraph(radius)every neighbour within a metric radiuspoints
PolygonIntersection(polygons)an arbitrary polygonraster, vector

Sampler — where patches go

The sampler places anchors. Overlap is not a parameter: it follows from the stride relative to the geometry size (overlap = size − step).

spatial.sampler.Anchors
RegularStride(step)a regular grid
JitteredStride(step, jitter, seed)a grid plus bounded noise
Random(n_samples, seed)uniform random
PoissonDisk(min_dist, seed)random with a minimum spacing
Explicit(anchors_)pixel anchors you supply
ExplicitCoords(coords, crs)map coordinates you supply, centred
AlongTrack(track, spacing, crs)evenly spaced along a track

Window — how each cell is weighted

The window weights each cell of a patch. Overlap-add divides by the summed weights, so a taper feathers the seams.

spatial.window.Weights
Boxcar()flat 1.0 — exact for non-overlapping tiles
Hann()periodic cosine taper
Tukey(alpha)flat top with cosine flanks
Gaussian(sigma)radial Gaussian, never zero
Custom(fn)any callable of the geometry

Aggregation — how local outputs merge

The aggregation folds patches into a result on the domain’s grid.

spatial.aggregation.Result
OverlapAddweighted sum ÷ summed weights; streaming=True writes zarr or a COG
Sum, Mean, Max, Min, WeightedSum, Variance, InvVarWeightedMeanper-cell statistics
HardVote, SoftVoteper-cell class votes
Median, Mode, Learnedper-cell, but need every patch in memory
MeanStd, MinMax, ApproxQuantile, ApproxMode, …one summary for the whole field
ByIndexthe [(anchor, data), …] pairs, for ragged geometries

Patch lifecycle

A run reads each anchor once, hands you a Patch, and merges what you hand back. split is an iterator, so only the patches you hold are in memory.

import numpy as np
import rasterio
from geoarray import GeoArray

import geopatcher as gp

field: gp.RasterField = gp.RasterField(
    GeoArray(
        np.ones((1, 256, 256), dtype=np.float32),                   # (1, 256, 256) float32
        transform=rasterio.Affine(10, 0, 500_000, 0, -10, 4_300_000),
        crs="EPSG:32611",
    )
)
patcher: gp.SpatialPatcher = gp.SpatialPatcher(
    geometry=gp.spatial.geometry.Rectangular(size=(64, 64)),
    sampler=gp.spatial.sampler.RegularStride(step=(48, 48)),
    window=gp.spatial.window.Hann(),
    aggregation=gp.spatial.aggregation.OverlapAdd(),
)

patch: gp.Patch = next(patcher.split(field))
print(patch.anchor, patch.indices)                  # (0, 0) Window(col_off=0, row_off=0, width=64, height=64)
weights: np.ndarray = patch.weights                 # (64, 64) float64

doubled: list[gp.Patch] = [
    p.with_data(np.asarray(p.data) * 2.0)           # (1, 64, 64) float32 → (1, 64, 64) float32
    for p in patcher.split(field)
]
merged: np.ndarray = patcher.merge(doubled, field.domain)          # (1, 256, 256) float64
stitched: GeoArray = patcher.merge_to_field(doubled, field)       # (1, 256, 256) float32, georeferenced
Patch attributeSet byHolds
datathe field’s selectthe payload — a GeoArray, DataArray, GeoDataFrame, …
anchorthe samplerthe patch origin ((row, col) on a raster)
indicesthe geometrywhat was read: a rasterio Window, neighbour ids, a polygon
weightsthe windowper-cell weights for the merge

patch.with_data(new) keeps the anchor, indices and weights, so your operator only touches the payload. merge returns the aggregation’s raw output; merge_to_field rebuilds the field’s carrier around it.

Fields and domains

A Field is anything with three members: domain (I/O-free metadata such as shape, CRS and transform), select(indexer) (read one patch) and with_data(array) (rebuild the carrier). The raster path wraps a geoarray.GeoArray or any lazy geoarray.RasterSource in geopatcher.RasterField: the source is the domain (its grid and shape), every patch is a GeoArray on its window’s grid, and merge_to_field returns a GeoArray on the source grid. A georeader reader crosses with geoarray.interop.georeader.source_from_georeader (a GeoTensor with from_georeader); passing one directly raises a TypeError that names the adapter. The other adapters live in geopatcher.fields behind extras. The Fields and domains table lists each adapter and its domain.

Samplers and geometries only read the domain. Patches read pixels, one window at a time, so a lazy reader never loads the whole scene.

Streaming and eager

Streaming is the default: split yields one patch at a time and a streaming-safe aggregation folds it in and drops it. Materialise with list(patcher.split(field)) when the field is small. For outputs bigger than RAM, OverlapAdd(streaming=True) keeps its accumulators on disk — see Stream to disk; which aggregations can stream is in Streaming aggregations.

Patcher families

PatcherSplitsTypical use
SpatialPatcherspace — raster, grid, points, polygonssliding-window inference, tiling, training chips
AsyncSpatialPatcherspace, over an AsyncFieldhigh-latency cloud reads — Async and prefetch
TemporalPatchera time axislookback / horizon windows, forecasts
SpatioTemporalPatcherspace × timedense cubes, event-triggered patches
geopatcher.matched.MatchedSpatialPatcher (and temporal siblings)several co-registered sourcesmulti-sensor matchups — API

The temporal side mirrors the four axes and adds coordinate-aware TimeStencil windows: see Temporal patching and Temporal stencils.

Random access

split is the canonical, lazy path. ML loaders that need dataset[i] wrap the patcher and field in geopatcher.run.IndexedPatchView, a picklable Sequence[Patch] — see xarray N-D patching.

Where the framework draws the line

The design decisions record why each of these choices was made.