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.

Patching — geometry gallery (Rectangular, SphericalCap, KNN, …)

SpatialPatcher ships five Geometry types, each dispatching on the Domain it gets handed. This notebook walks through the four canonical (Geometry × Domain) pairings against three real substrates — one per data shape:

  1. SpatialRectangular × RasterDomain — tiling a Sentinel-2 chip.
  2. SpatialSphericalCap × GridDomain — geodesic cap on a lat/lon grid (1° resolution global cell index).
  3. SpatialKNNGraph × PointDomain — k-nearest GBIF occurrence points (California live oak, Quercus agrifolia).
  4. SpatialRadiusGraph × PointDomain — same point cloud, within-radius neighbourhood.

1. SpatialRectangular × RasterDomain — tiling a real Sentinel-2 chip

The Lake Tahoe BGRN chip’s NIR band, downsampled to 256×256 so the patch overlay reads at a glance.

crop shape: (256, 256)
<Figure size 600x600 with 1 Axes>

2. SpatialSphericalCap × GridDomain — geodesic neighbourhoods

A 1° regular lat/lon grid spanning ±60° latitude is a faithful stand-in for any global gridded product (ERA5, NOAA SST, MODIS climate). The cap shrinks in pixel terms as latitude increases because grid cells are smaller meridionally at high latitudes — something a naive raster patcher would never see.

<Figure size 1200x400 with 2 Axes>

3. SpatialKNNGraph × PointDomain — k-nearest GBIF occurrences

500 GBIF occurrence records for California live oak (Quercus agrifolia, taxon key 5285750) across California. Each point is a real observation report — the cluster structure (coastal ranges, valley centres, sparse desert) is the true ecological signal.

GBIF: 300 occurrence points for Q. agrifolia
<Figure size 800x700 with 1 Axes>

4. SpatialRadiusGraph × PointDomain — within-radius neighbours

Same point cloud, but the geometry asks “every occurrence within 0.25° of the anchor” instead of “the k nearest”. The neighbourhood size now adapts to the local point density — sparse desert anchors return few neighbours, dense coastal anchors return many.

<Figure size 800x700 with 1 Axes>

5. ByIndex aggregation — irregular graph patching

When patches don’t form a dense grid (KNN, RadiusGraph, …) the natural aggregation is SpatialByIndex, which returns a {anchor: result} dict rather than trying to reconstruct a global field. We materialise 3 KNN-graph patches anchored at three different GBIF points.

materialised 3 graph patches:
  anchor=(-118.566, 36.486)  k-neighbours=5
  anchor=(-119.899, 39.290)  k-neighbours=5
  anchor=(-123.776, 39.372)  k-neighbours=5

Recap — when to reach for which geometry

GeometryDomainUse it for
SpatialRectangularRasterDomainTiled raster inference — the bread-and-butter case.
SpatialSphericalCapGridDomainCells on a global lat/lon grid (ERA5, GHCN, climate model output).
SpatialKNNGraphPointDomain“k nearest sensors / observations / waypoints” — fixed neighbourhood size.
SpatialRadiusGraphPointDomain“every record within R” — density-adaptive neighbourhood size.
SpatialPolygonIntersectionRasterDomain / VectorDomainPer-polygon zonal stats.

All five share the same (Domain, anchor) -> indices contract, so the rest of the SpatialPatcher (sampler / window / aggregation) stays unchanged when you swap one out.