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.

Cut — patching a Sentinel-2 scene over Lake Tahoe

Open In Colab

You split a 10 km box of a Sentinel-2 scene into overlapping patches, run an operator on each one, and stitch the results back. This is step 2 of the Lake Tahoe story. The find notebook chose the scene, 2024-09-22; the compute notebook covers the operators.

The four patcher axes (geometry, sampler, window, aggregation) are explained once in Patcher concepts. Here you see them on real pixels.

What you’ll learn:

  1. Read a decimated overview of a whole tile, without downloading it.

  2. Load a 10 km box at native 10 m resolution through the catalog.

  3. Inspect a SpatialPatcher’s anchors and the Patch objects it yields.

  4. See why the window axis matters for operators that look at a whole chip.

  5. Run split → apply → stitch as one operator with geoops.patch_ops.

Python implementation: CPython
Python version       : 3.13.16
IPython version      : 9.13.0

numpy     : 2.4.5
matplotlib: 3.10.9
geocatalog: 0.5.0
geopatcher: 0.10.0
geotoolz  : 0.10.0

Compiler    : GCC 13.3.0
OS          : Linux
Release     : 6.18.44-fc-v114
Machine     : x86_64
Processor   : x86_64
CPU cores   : 4
Architecture: 64bit

1. Find the scene

Search the one date the find notebook chose, and keep red and NIR from the UTM zone 10 tile. That tile covers the whole AOI, so its native grid needs no reprojection.

Loading...

2. Preview the tile from an overview

A Cloud-Optimized GeoTIFF stores downsampled copies of itself. overview_level=2 reads the 1/8 copy, about 80 m per pixel, so the whole 110 km tile costs a few megabytes. The orange square is the South Shore box you patch below.

<Figure size 1200x500 with 1 Axes>

3. Load the box as a field

gc.load.load_raster reads only the box’s pixels from each remote file. Stack red and NIR, then wrap the result as a gp.RasterField, the object a patcher splits.

scene: (2, 1000, 1000) uint16, crs=EPSG:32610

4. Build the patcher and look at its anchors

256 × 256 chips every 192 px give a 64 px overlap. boundary="pad" lets the last row and column of chips run past the edge, so every pixel is covered (see Boundary policies).

25 anchors, first three: [(0, 0), (0, 192), (0, 384)]
<Figure size 1200x500 with 1 Axes>

5. Inspect one patch

split yields Patch objects lazily. Each carries its chip (data), where it sits in the field (anchor, indices) and its window weights.

data:    GeoTensor (2, 256, 256) uint16
anchor:  (0, 0)
indices: Window(col_off=0, row_off=0, width=256, height=256)
weights: (256, 256), 1.4e-09 at the edge, 1.00 inside

6. Why the window matters

A per-pixel operator such as NDVI stitches exactly with any window; the find notebook checked that. An operator that reads the whole chip does not. gz.PercentileClip stretches each chip by its own 2nd–98th percentiles, so neighbouring chips disagree where they overlap.

With Boxcar (flat weights) those disagreements show as hard seams. Hann tapers each chip towards its edge (to a small weight, never zero), so overlap-add blends one chip into the next and still keeps every pixel. See Window convention for the details.

<Figure size 1800x500 with 3 Axes>

The panels zoom on the top-left 3 × 3 chips, where lake meets shore. Boxcar shows hard edges where one chip’s stretch hands over to the next. Hann turns those edges into smooth gradients, though the lake’s shading still varies because each chip stretched it differently.

7. The same loop as one operator

geoops.patch_ops wraps split, apply and stitch as three pipekit operators. Chained in a Sequential, they become one operator you can compose, serialise and drop into a larger pipeline.

result: (2, 1000, 1000) float64; matches the manual Hann loop: True

Summary

  • An overview read previews a whole tile for a few megabytes.

  • load_raster read a native-resolution window; RasterField made it splittable.

  • split yields Patch objects with data, position and window weights; merge stitches them.

  • Operators that read a whole chip need a tapered window such as Hann to hide seams.

  • GridSampler → ApplyToChips → MergePatches turns the loop into one operator.

Next: compute a cloud-masked NDVI on this window. For outputs too big for memory, see Streaming overlap-add.