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.

End to end — summer NDVI over Lake Tahoe

Open In Colab

You turn a Sentinel-2 search into an NDVI map of Lake Tahoe in about thirty lines. This notebook owns step 1 of a three-part story, find, and runs the other two steps briefly. The patcher notebook goes deeper on cut, the operators notebook on compute.

SettingValue
AOILake Tahoe, lon/lat (-120.25, 38.85, -119.85, 39.30)
Season2024-06-01 to 2024-09-30
ArchiveSentinel-2 L2A on the Microsoft Planetary Computer
Bandsred B04 and near-infrared B08

What you’ll learn:

  1. Turn a STAC search into a queryable catalog with gc.sources.from_stac_search.

  2. Filter it by space, time and cloud cover with query and where.

  3. Pick the clearest date that covers the whole AOI.

  4. Stage the files and build a patcher field with gc.patch.field_for.

  5. Tile, compute NDVI and stitch 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
pystac_client: 0.9.0
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. Discover — a STAC search becomes a catalog

gc.sources.from_stac_search runs the search and returns one catalog row per (item, asset). asset_key="*" keeps every asset, so later steps can pick bands. extra_properties copies eo:cloud_cover into a column you can filter on.

2181 (item, asset) rows
temporal extent: [2024-06-02 18:49:21.024000, 2024-09-30 18:52:11.024000]
Loading...

2. Filter — space, time, cloud cover and bands

A GeoSlice is the request every catalog answers: bounds, time interval, resolution and CRS. query filters by space and time; where filters on any other column with a pandas query string. See Catalog concepts for the GeoSlice contract.

162 rows: red + NIR, under 20 % cloud

3. Choose — the clearest date that covers the whole AOI

Lake Tahoe sits where UTM zones 10 and 11 meet, so each date brings two or more tiles. The lowest-cloud tile is not enough: some tiles are mostly no-data, and a 0 % cloud cover over no pixels is useless.

Each footprint traces a tile’s valid data. Group the rows by date, keep the dates whose footprints cover the AOI, and take the clearest.

lowest-cloud tile S2B_MSIL2A_20240806T184919_R113_T11SKD_20240806T235408 covers 0.0% of the AOI
40 of 40 dates cover the AOI; clearest: 2024-09-22
Loading...
<Figure size 1200x500 with 1 Axes>

4. Stage and load — local files, then a patcher field

gc.staging.stage downloads each row’s file once into a local cache and returns a catalog that points at the copies. gc.patch.field_for mosaics them onto the slice grid as one geoarray.GeoArray and wraps it as a gp.RasterField. Both tiles are reprojected onto the slice’s lon/lat grid on the way in.

scene: (2, 1500, 1333) uint16, crs=EPSG:4326, fill=0.0

5. Cut and compute — NDVI tile by tile

Three patch_ops operators put the patcher inside a Sequential: split the field, run an operator on every chip, stitch the chips back. The chip operator is gz.DNToReflectance (Sentinel-2 L2A stores reflectance × 10 000) followed by gz.NDVI. The cut and compute notebooks explain each half.

56 chips → ndvi (1500, 1333) float64
NDVI range: [-0.23, 0.71]

NDVI is a per-pixel index, so the tiled result matches NDVI of the whole scene, edges included: the Hann window never reaches zero, so every pixel a chip covers keeps its value (see Window convention).

max |tiled − whole|: 2.2e-16
<Figure size 1200x500 with 3 Axes>

Forest around the lake reads green, the lake and bare granite read red. Fallen Leaf Lake is the small water body south-west of the lake.

Summary

  • from_stac_search turned a STAC search into a catalog you can query and filter with where.

  • Footprints and cloud cover picked one clear date that covers the whole AOI.

  • stage and field_for turned that date’s rows into a RasterField on your grid.

  • GridSampler → ApplyToChips → MergePatches computed NDVI tile by tile.

Next: cut the same scene into patches and see why the window matters, or compute a cloud-masked NDVI with a Graph. To keep the catalog between sessions, write it with gc.storage.to_geoparquet; see From STAC.