Split a geospatial field into local patches, run an operator per patch, and stitch the outputs back into a global result — along four independently composable axes.
Where it comes from¶
A model trained on 256 × 256 chips cannot see a whole Sentinel-2 tile at once, and a 1 TB output does not fit in memory. So you cut the scene into overlapping pieces, run on each, and glue the answers back without seams. Every project writes that loop again, with its own edge cases.
geopatcher splits the loop into four choices you make separately: the
Geometry (the shape of a patch), the Sampler (where patches go),
the Window (how each cell is weighted) and the Aggregation (how
local outputs merge). Any Field goes in — a raster, an xarray grid,
GeoPandas polygons, xvec points — and any per-patch callable runs. It is
the patcher of the geostack; see
how the packages interlock.

Install¶
pip install geotoolz-patcher # base — RasterField only
pip install 'geotoolz-patcher[patch-full]' # every Field adapter and runner| Extra | Pulls in | Needed for |
|---|---|---|
[grid] | xarray | geopatcher.fields.XarrayField |
[vector] | geopandas, shapely | geopatcher.fields.GeoPandasField |
[point] | xvec | geopatcher.fields.XvecField |
[xarray-raster] | rioxarray, xarray | geopatcher.fields.RioXarrayField |
[streaming] | zarr ≥ 3 | spatial.aggregation.OverlapAdd(streaming=True) |
[dask] | dask[bag], xarray | geopatcher.fields.DaskField, geopatcher.run.to_delayed |
[jax] | geotoolz-array[jax] | JAX batches: PatchBatch.patches.to_jax() after geopatcher.run.batch_split |
[cog] | geotoolz-cloud[cog] | geopatcher.fields.CogField |
[patch-full] | all of the above | everything except [pipekit] |
[pipekit] | pipekit-ops | geopatcher.integrations.pipekit (GridSampler, ApplyToChips, MergePatches) |
pipekit-ops is not on PyPI yet: install the [pipekit] extra from a clone
with uv sync --extra pipekit. A missing extra fails at the point of use
with an ImportError that names it.
Quickstart¶
Cut a 512 × 512 raster into 128-pixel patches with 32 pixels of overlap, double each patch and stitch the result with Hann-feathered seams.
import numpy as np
import rasterio
from geoarray import GeoArray
import geopatcher as gp
# 1. Wrap a GeoArray (or any lazy geoarray.RasterSource) as a Field.
arr: np.ndarray = np.outer(np.linspace(0, 1, 512), np.linspace(0, 1, 512)).astype(np.float32)[None] # (1, 512, 512) float32
field: gp.RasterField = gp.RasterField(
GeoArray(arr, rasterio.Affine(10, 0, 500_000, 0, -10, 4_300_000), "EPSG:32611")
)
# 2. Compose the four axes.
patcher: gp.SpatialPatcher = gp.SpatialPatcher(
geometry=gp.spatial.geometry.Rectangular(size=(128, 128)),
sampler=gp.spatial.sampler.RegularStride(step=(96, 96)), # 32 px overlap
window=gp.spatial.window.Hann(), # feather the seams
aggregation=gp.spatial.aggregation.OverlapAdd(),
)
# 3. Split → operate per patch → merge.
patches: list[gp.Patch] = list(patcher.split(field)) # 25 × GeoArray (1, 128, 128) float32
out: list[gp.Patch] = [p.with_data(np.asarray(p.data) * 2.0) for p in patches] # 25 × (1, 128, 128) float32
stitched: np.ndarray = patcher.merge(out, field.domain) # (1, 512, 512) float64patch.anchor is the patch origin in pixels ((0, 0), (0, 96), …).
merge returns a bare array; patcher.merge_to_field(out, field) returns
a GeoArray with the source’s transform and CRS. The Hann taper never
reaches zero, so every covered pixel — the scene’s edges included — comes
back as data; see Window convention.
What’s inside¶
| Namespace | What’s there | Read |
|---|---|---|
geopatcher | SpatialPatcher, AsyncSpatialPatcher, TemporalPatcher, SpatioTemporalPatcher; the Patch carriers; Field / Domain; RasterField | Concepts · Core API |
geopatcher.spatial | the four axes — geometry, sampler, window, aggregation | Behaviour · API |
geopatcher.temporal | the same four axes along time, plus stencils | Temporal patching · API |
geopatcher.fields | XarrayField, RioXarrayField, DaskField, GeoPandasField, XvecField, CogField, ReprojectingRasterField, the domain types | Fields · API |
geopatcher.matched | co-registered multi-source patching (MatchedField, MatchedSpatialPatcher, …) | API |
geopatcher.run | parallel_map, prefetch_iterable, Dask and JAX bridges, PatchCache, IndexedPatchView | Cache reads · API |
geopatcher.observe | PatcherHook, PatchJournal, PatchErrorRecord, strict mode | Hooks · Journal |
geopatcher.config | axis_envelope / from_config round-trips | API |
geopatcher.integrations.pipekit | GridSampler, ApplyToChips, MergePatches (re-exported as geoops.patch_ops) | API |
Cloud-Optimized GeoTIFF reads come from geotoolz-cloud;
geopatcher.fields.CogField is their Field.
Is this the right tool?¶
| Your job | Use |
|---|---|
| The operator works on the whole scene in memory | the operator directly — no patcher |
| Independent local work (inference, filters) | SpatialPatcher + spatial.aggregation.OverlapAdd with a Hann or Tukey window |
| The output is bigger than RAM | OverlapAdd(streaming=True) — Stream to disk |
| The operator needs a global statistic (scene mean / std) | patcher.two_pass — Global statistics |
| Windows along time, or space × time cubes | TemporalPatcher / SpatioTemporalPatcher — Temporal patching |
Advanced — patching as a geotoolz operator¶
The [pipekit] bridge makes split → operate → merge one more
Sequential, so a geotoolz operator runs tile by tile with no loop.
import numpy as np
import rasterio
from geoarray import GeoArray
import geopatcher as gp
import geoops as gz
from geoops.patch_ops import ApplyToChips, GridSampler, MergePatches
rng: np.random.Generator = np.random.default_rng(0)
scene: GeoArray = GeoArray(
rng.integers(1, 10_000, size=(4, 512, 512), dtype=np.uint16), # (4, 512, 512) uint16
transform=rasterio.Affine(10, 0, 500_000, 0, -10, 4_300_000),
crs="EPSG:32611",
fill_value=0,
attrs={"band_names": ["blue", "green", "red", "nir"]},
)
field: gp.RasterField = gp.RasterField(scene)
patcher: gp.SpatialPatcher = gp.SpatialPatcher(
geometry=gp.spatial.geometry.Rectangular(size=(128, 128)),
sampler=gp.spatial.sampler.RegularStride(step=(96, 96)),
window=gp.spatial.window.Hann(),
aggregation=gp.spatial.aggregation.OverlapAdd(),
)
ndvi: gz.Sequential = gz.DNToReflectance(scale=1e-4) | gz.NDVI(nir="nir", red="red")
tiled: gz.Sequential = gz.Sequential([
GridSampler(patcher=patcher), # field → 25 Patches (4, 128, 128) uint16
ApplyToChips(operator=ndvi), # (4, 128, 128) uint16 → (128, 128) float64
MergePatches(aggregation=gp.spatial.aggregation.OverlapAdd(), domain=field.domain),
])
ndvi_map: GeoArray = tiled(field) # (512, 512) float64 · NaN = no dataThe domain fixes the grid and the patches fix the bands, so NDVI’s
one-band chips merge into one (H, W) map on the scene’s transform and
CRS. The stack quickstart
runs the same pipeline on real Sentinel-2 data.
Next steps¶
Concepts — the four axes, the patch lifecycle, fields and streaming.
Quickstart — the same patcher on a real Sentinel-2 scene.
How-tos — stream to disk, handle read failures, resume a job, cache reads, mixed CRS, global statistics, temporal patching.
Tutorial — patching Sentinel-2 over Lake Tahoe, with plots.
Behaviour reference and the API reference.