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.

geotoolz-ops (geoops)

Compose remote-sensing pipelines like you compose functions. Sentinel-2 to cloud-free NDVI in a handful of small operators, with the same code shape as your unit tests.

Where it comes from

Remote-sensing code tends to grow into long functions that mix band indexing, nodata handling, rescaling and georeferencing. Nothing in them can be reused or tested alone.

geotoolz cuts each step into an Operator: a typed callable with a keyword-only constructor. It takes a geoarray.GeoArray (or a plain ndarray) and returns the same kind of carrier on the same CRS and transform, with band names and a fill value that match the output.

Chain operators with | into a Sequential, or wire them into a named Graph when the pipeline branches. Both are operators too, so pipelines nest, and get_config() turns any pipeline into JSON. The composition core comes from pipekit; about 275 remote-sensing operators sit on top. How geotoolz meets the other packages is on How the packages interlock.

Sequential and Graph composition of geoops operators, with the output shape and dtype of every step

Install

Until the first PyPI release, install from a clone (see the stack install); after it:

pip install geotoolz                 # every operator family
pip install geotoolz-ops             # the slim base: kernels on NumPy, SciPy, pandas
pip install 'geotoolz-ops[raster,vector,morph,sensors]'   # what geotoolz installs
pip install 'geotoolz-ops[patch]'        # + tile → operate → stitch with geopatcher

The base install costs NumPy, SciPy, pandas, pyproj and affine: indices, radiometry arithmetic, masks and normalisation run on it. GDAL, the vector stack, scikit-image and georeader are extras. Operators that need an extra import without it and raise an ImportError naming the extra when called.

ExtraPulls inNeeded for
rasterrasterioio file reads and writes, geom windows and resampling, patch_ops windows
vectorgeopandas, shapelyvector outputs and inputs: feature detections, mask polygons, measure contours, plume geometry
morphscikit-imagesegment, feature, measure, connected components and skeletons, geom registration, the resampling behind geom.Resize / Resample
sensorsgeoreader (which brings rasterio, geopandas, shapely)the engine behind geom.Reproject / ReprojectLike / Mosaic / Vectorize / Resize / Resample (which also need morph), viz.AnnotatePolygons, io.LoadFromEE, io reads, mask rasterising, radiometry solar geometry
vizmatplotlibviz.ApplyColormap (named matplotlib colormaps)
learnscikit-learn, jobliblearn.SklearnOp / Pixelwise* imputer NaN strategies and save_state / load_state / state_path=; plume DBSCAN clump counting
zarrzarr>=3io.WriteZarr
cloudgeotoolz-cloudio.WriteCOG (validated COGs, local or to a bucket)
hdf5geotoolz-cloud with h5pyio.ReadHDF on HDF5, local or remote
hdf4geotoolz-cloud with pyhdfio.ReadHDF on HDF4
netcdfgeotoolz-cloud with netCDF4io.ReadNetCDF
vector-cubexvec (+ xarray)geom.coregister.RasterToPoints / PointsToRaster, bilinear point sampling
hydrahydra-zenYAML builds() / instantiate() round-trips
patchgeotoolz-patcher[pipekit]geoops.patch_ops (tile → map → stitch, label-aware samplers)
allevery extra aboveeverything

Quickstart

Cloud-free NDVI from a Sentinel-2 L2A scene, first as a chain, then as a graph that masks clouds with the SCL band. The scene here is synthetic: 12 reflectance bands plus SCL on a real UTM grid, named through attrs["band_names"] as the geoproducts readers and geocatalog loaders do.

import numpy as np
from geoarray import GeoArray
from rasterio.transform import from_origin

import geoops as gz

L2A: list[str] = ["B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B8A", "B9", "B11", "B12"]
rng: np.random.Generator = np.random.default_rng(0)
dn: np.ndarray = rng.integers(200, 4000, size=(12, 64, 64), dtype=np.uint16)  # (12, 64, 64) uint16
scl: np.ndarray = rng.choice([4, 5, 8, 9], size=(1, 64, 64)).astype(np.uint16) # (1, 64, 64) uint16 · 8, 9 = cloud
scene: GeoArray = GeoArray(
    np.concatenate([dn, scl]),                                                 # (13, 64, 64) uint16
    transform=from_origin(750_000, 4_350_000, 10, 10),                         # 10 m pixels
    crs="EPSG:32610",                                                          # UTM zone 10N
    fill_value=0,
    attrs={"band_names": [*L2A, "SCL"]},
)

# Sequential — a linear chain, built with |
ndvi_pipeline: gz.Sequential = (
    gz.SelectBands(bands=L2A)                                                  # (13, 64, 64) uint16 → (12, 64, 64) uint16
    | gz.DNToReflectance(scale=1e-4)                                           # (12, 64, 64) uint16 → (12, 64, 64) float64
    | gz.NDVI(red="B4", nir="B8")                                              # (12, 64, 64) float64 → (64, 64) float64
)
ndvi: GeoArray = ndvi_pipeline(scene)                                         # (13, 64, 64) uint16 → (64, 64) float64 · NaN = no data
config: dict = ndvi_pipeline.get_config()  # {"operators": [{"class": "SelectBands", "config": {...}}, ...]}

# Graph — the same steps, plus a cloud mask on a second branch
x: gz.Input = gz.Input("scene")
reflectance: gz.Node = gz.DNToReflectance(scale=1e-4)(gz.SelectBands(bands=L2A)(x))  # (12, 64, 64) float64
ndvi_node: gz.Node = gz.NDVI(red="B4", nir="B8")(reflectance)                        # (64, 64) float64
cloud: gz.Node = gz.S2SCL(targets=["cloud_shadow", "cloud", "cirrus"])(x)           # (64, 64) bool · True = drop
clean: gz.Node = gz.ApplyMask()(ndvi_node, cloud)                                   # (64, 64) float64 · NaN under cloud

graph: gz.Graph = gz.Graph(inputs={"scene": x}, outputs={"ndvi": clean, "cloud": cloud})
out: dict[str, GeoArray] = graph(scene=scene)  # {"ndvi": (64, 64) float64, "cloud": (64, 64) bool}
assert out["ndvi"].grid == scene.grid

Both results keep the scene’s CRS and transform. NDVI declares NaN as its fill because it is a new float quantity; the mask uses False.

Is this the right tool?

You want to…Use
run one array operation on one scenerasterio + numpy directly
reuse a remote-sensing step across scenes and scriptsan Operator (define one)
chain two to six stepsSequential (a | b | c)
branch, fan in, or return several named outputsGraph (branching pipelines)
run a model tile by tile over a large rastergeoops.patch_ops (tile → operate → stitch)
find and load scenes from STAC or local filesgeocatalog, then pass the GeoArray in

What’s inside

Every public operator is importable from the top level (gz.NDVI) and from its family (gz.indices.NDVI). Each family also exports its pure numpy primitives (gz.indices.ndvi).

NamespaceWhat it doesReference
coreOperator, Sequential, Graph, Input, Branch, Switch, Fanout, Tap, Snapshot, … (from pipekit) and ModelOpCore
geoops.carrier, geoops.testinghelpers that keep the GeoArray contract, and check_operatorCarrier
radiometryDN ↔ radiance ↔ reflectance, sun geometry, brightness temperature, DOS1, stretchesRadiometry
indicesspectral indices: NDVI, EVI, NDWI, NBR, NDSI, …Indices
qacloud and quality masks from QA bits, SCL classes and sensor presetsQA
maskgeometry and DEM masks, mask morphology and algebra, ApplyMaskMask
spectralband selection, stacking, band math, spectral resamplingSpectral
geom (+ geom.coregister)reproject, resample, crop, tile, rasterise, swath geometry, registrationGeometry
compositingtemporal composites and multi-source fusionCompositing
restoredenoising, despeckling, destriping, gap filling, MNFRestore
segmentthresholds, superpixels, watershed and other skimage segmentationsSegment
measureconnected components, region properties, contoursMeasure
featureedges, blobs, corners, Hough transforms, local featuresFeature
plumemethane and CO₂ plume retrieval, masks, footprints, mass and fluxPlume
matched_filterhyperspectral matched filters and background statisticsMatched filter
augmentaugmentations that respect georeferencing and physical bandsAugment
normalizeper-band scalers, non-linear scaling, histogram stretch and matchingNormalize · how-to
learnscikit-learn estimators as pixel-wise operatorsLearn
einxeinstein-notation tensor operations that keep georeferencingEinx
vizcomposites, display stretches, colormaps, hillshade, overlaysViz
iowindow readers, HDF and NetCDF readers, GeoTIFF / COG / Zarr writersIO · how-to
patch_opsgeopatcher as operators: GridSampler, ApplyToChips, MergePatches, label-aware samplersTile → operate → stitch

Next steps