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.

The geostack

Find the data, read it, cut it to size, compute on it — one composable stack. Six Python packages that interlock end to end, with the Operator / Sequential / Graph composition core supplied by pipekit.

The geostack stage by stage: search an archive, catalog it, save what you need, stream windows lazily, split into overlapping patches, apply an operator per patch, combine with a window-weighted merge, write a COG or zarr; two proposed stages, drawn dashed, commit the result as a version and publish a record of it

Where it comes from

If you have used xarray, you know split → apply → combine: group the data, run a function on each group, glue the results back together. A geospatial pipeline is the same idea with more steps on either side. Before you can split a scene you have to search an archive for it, catalog what you found so the next question is a query rather than a crawl, save (stage) only the files that matter, and stream them as lazy windows because the scene does not fit in memory. After you combine, you write a georeferenced result.

Two further stages are proposed and drawn dashed: commit the result as a version that appears all at once (#665), and publish a record of it to a product catalog, where the next search can find it (#671).

Most codebases rebuild that loop per project, so every step is hard-wired to the next. The geostack gives each step its own package and one small, typed seam between neighbours: a GeoSlice is the request every catalog answers, a geoarray.GeoArray is the array every reader returns and every operator takes, and a Patch is what the patcher hands an operator. Because operators are plain pipekit objects, the patcher itself becomes an operator — tile → predict → stitch is one more Sequential.

The packages

PackageImportUse it to…Docs
geotoolz-opsgeoopscompute on rasters with carrier-preserving operators (radiometry, indices, masks, geometry, ML, …)Operators
geotoolz-patchergeopatchersplit a field into patches, run an operator per patch, stitch back (Geometry × Sampler × Window × Aggregation)Patcher
geotoolz-cataloggeocatalogfind, index, join, load and stage files (GeoSlice queries over GeoParquet)Catalog
geotoolz-cloudgeocloudreach object storage: one client pool, file verbs, credentials, COG reads and writesCloud
geotoolz-productsgeoproductsread Earth-observation products (GOES-R ABI, Himawari AHI, Carbon Mapper, …) as geoarray.RasterSources that read GeoArraysProducts
geotoolz-arraygeoarraycarry rasters: GeoArray (NumPy or JAX data with transform, CRS, fill and attrs; a JAX pytree), Grid / PixelWindow, the RasterSource protocol, the georeader bridgeArray
Dependency layers: every package stands on geotoolz-array (the GeoArray carrier); object storage in geotoolz-cloud; geotoolz-ops on pipekit; georeader is an internal engine; cross-package links are opt-in extras

Solid arrows are hard dependencies, dotted ones opt-in extras, and nothing points back up: install only the packages you need. How the packages interlock walks through every seam.

Install

pip install geotoolz                          # operators
pip install geotoolz-patcher                  # patcher
pip install geotoolz-catalog                  # catalog
pip install geotoolz-cloud                    # object storage, COG writes
pip install geotoolz-products                 # product readers
pip install geotoolz-array                    # the GeoArray carrier alone (`[jax]` for JAX)
To connect…Install
operators ↔ patcher (geoops.patch_ops)geotoolz-ops[patch]
catalog → patcher (geocatalog.patch.field_for)geotoolz-catalog[patch]
catalog staging from buckets (geocatalog.staging.stage)geotoolz-catalog[cloud]
catalog ← STAC searches (geocatalog.sources.from_stac_search)geotoolz-catalog[stac]
patcher ↔ COGs in buckets (geopatcher.fields.CogField)geotoolz-patcher[cog]
COG reads (geocloud.cog.CogSource)geotoolz-cloud[cog]
a sensor’s reader and its bucket helpersgeotoolz-products[goes] / [himawari] / [carbonmapper]
a sensor’s presets as geotoolz operatorsgeotoolz-products[operators]

Each package page lists its own extras. Pre-PyPI, install from a clone:

git clone https://github.com/jejjohnson/geotoolz && cd geotoolz
uv sync --all-packages --all-groups --all-extras

Quickstart — catalog → patcher → operators

Summer-2024 NDVI over Lake Tahoe: discover Sentinel-2 L2A on the Planetary Computer, mosaic the red and near-infrared bands onto one grid, and run NDVI tile by tile with feathered seams. Every binding is typed and every array is annotated with its shape. It needs pip install 'geotoolz-ops[patch]' 'geotoolz-catalog[stac,cloud,patch]'.

import numpy as np
import pandas as pd
import planetary_computer
import pystac_client
from geoarray import GeoArray

import geocatalog as gc
import geopatcher as gp
import geoops as gz
from geoops.patch_ops import ApplyToChips, GridSampler, MergePatches

client: pystac_client.Client = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
    modifier=planetary_computer.sign_inplace,
)
aoi: gc.GeoSlice = gc.GeoSlice(
    bounds=(-120.25, 38.85, -119.85, 39.30),              # Lake Tahoe, lon/lat
    interval=pd.Interval(pd.Timestamp("2024-06-01"), pd.Timestamp("2024-09-30"), closed="both"),
    resolution=(0.0001, 0.0001),                          # ≈ 10 m → grid (H, W) = (4500, 4000)
    crs="EPSG:4326",
)

# 1 · find — one catalog per band, staged to local disk
bands: dict[str, gc.GeoCatalog] = {
    band: gc.staging.stage(
        gc.sources.from_stac_search(client, collections=["sentinel-2-l2a"], bounds=aoi.bounds,
                            datetime="2024-06-01/2024-09-30", asset_key=band),
        dest="./cache",
    )
    for band in ("B04", "B08")
}

# 2 · read — mosaic each band onto the AOI grid, stack red + NIR
red: gp.RasterField = gc.patch.field_for(bands["B04"].query(aoi), aoi)   # (1, 4500, 4000) uint16
nir: gp.RasterField = gc.patch.field_for(bands["B08"].query(aoi), aoi)   # (1, 4500, 4000) uint16
scene: GeoArray = gz.StackBands()([red.reader, nir.reader])         # (2, 4500, 4000) uint16

# 3 · cut + compute — 256² tiles, 64 px overlap, Hann-feathered seams
patcher: gp.SpatialPatcher = gp.SpatialPatcher(
    geometry=gp.spatial.geometry.Rectangular(size=(256, 256), boundary="pad"),
    sampler=gp.spatial.sampler.RegularStride(step=(192, 192)),
    window=gp.spatial.window.Hann(),
    aggregation=gp.spatial.aggregation.OverlapAdd(),
)
ndvi: gz.Sequential = gz.DNToReflectance(scale=1e-4) | gz.NDVI(red=0, nir=1)  # (2, h, w) → (h, w)
field: gp.RasterField = gp.RasterField(scene)
tiled: gz.Sequential = gz.Sequential([
    GridSampler(patcher=patcher),                        # field → list[Patch]       (2, 256, 256) each
    ApplyToChips(operator=ndvi),                         # list[Patch] → list[Patch] (256, 256) each
    MergePatches(aggregation=gp.spatial.aggregation.OverlapAdd(), domain=field.domain),
])
result: GeoArray = tiled(field)                        # (4500, 4000) float64 · NaN = no data

MergePatches places the chips on the domain’s grid and keeps the band axes the chips carry, so NDVI’s (h, w) chips merge into one (H, W) GeoArray on the scene’s transform and CRS.

Next steps