Skip to main content

TerraFlow: a reproducible workflow for geospatial agricultural modeling.

Project description

TerraFlow: Reproducible Geospatial Agricultural Modeling

CI Deploy Docs Publish to PyPI Build JOSS Manuscript PyPI Homebrew Tap Python Version Quality Gate Status Codecov License: MIT

TerraFlow is a reproducible, config-driven geospatial workflow for agricultural suitability modeling. Give it a land-cover raster, a climate CSV, and a YAML config — it returns a scored, location-stamped results table with full provenance.

Documentation: terraflow.marupilla.dev — see the Reproducibility page for what the run fingerprint covers and known sources of non-determinism.


At a Glance

flowchart LR
    CFG["Config<br/>(YAML + Pydantic)"] --> PIPE["Pipeline<br/>(orchestration)"]
    PIPE --> ING["Ingest<br/>(raster, climate)"]
    PIPE --> GEO["Geospatial<br/>(ROI clipping)"]
    PIPE --> MOD["Model<br/>(suitability scoring)"]
    PIPE --> OUT["Outputs<br/>(Parquet, CSV,<br/>manifest, report)"]
    ING --> GEO
    ING --> MOD
    GEO --> MOD
Property What TerraFlow guarantees
Deterministic outputs Same config + same inputs → bit-identical results, addressed by run fingerprint
Provenance Every run writes a manifest.json capturing config, input hashes, software versions, and fingerprint
Spatial validation Spatial-block CV with Cohen's κ + Moran's I on residuals (terraflow validate)
Sensitivity analysis Sobol' / Morris indices for model weights (terraflow sensitivity)
Uncertainty quantification Kriging Monte Carlo → score CIs (score_ci_low / score_ci_high)
Interop H3-indexed export for downstream tools (terraflow export --format h3)
GeoAI engines (optional) terraflow geoai {fields,landcover,canopy} runners with deterministic fingerprinted caching (pip install terraflow-agro[geoai])
Distribution PyPI (terraflow-agro) + Homebrew (gmarupilla/terraflow) + Docker
Citation Citable via CITATION.cff; JOSS paper in preparation

Installation

macOS (Homebrew) — handles GDAL and PROJ automatically:

brew tap gmarupilla/terraflow
brew install terraflow

pip / uv:

uv pip install terraflow-agro
# or
pip install terraflow-agro

For kriging-based interpolation:

pip install terraflow-agro pykrige

For the optional GeoAI engines (field-boundary detection, landcover classification, canopy regression):

pip install "terraflow-agro[geoai]"

This installs geoai-py and torch; the GeoAI runners auto-detect CUDA or Apple Silicon MPS at runtime.

See Homebrew install docs for update/uninstall instructions and troubleshooting.

Quickstart

terraflow run --config config.yml

A minimal config:

raster_path: "data/land_cover.tif"
climate_csv: "data/climate.csv"
output_dir: "outputs"
roi:
  type: bbox
  xmin: -120.5
  ymin: 34.0
  xmax: -118.0
  ymax: 35.5
model_params:
  v_min: 0.0
  v_max: 1.0
  t_min: 10.0
  t_max: 35.0
  r_min: 100.0
  r_max: 800.0
  w_v: 0.4
  w_t: 0.3
  w_r: 0.3

Results are written to outputs/runs/<fingerprint>/:

features.parquet   — scored cells (lat, lon, score, label, …)
results.csv        — same data in CSV
manifest.json      — full provenance record
report.json        — QA stats and timings

CLI subcommands

Subcommand Purpose
terraflow run -c config.yml Run the full pipeline
terraflow sensitivity -c config.yml Sobol' / Morris sensitivity indices for model weights
terraflow validate -c config.yml Spatial block CV, Cohen's kappa, Moran's I on residuals
terraflow export --format h3 -c config.yml H3-indexed export for interop with H3-native visualization tools (pip install terraflow-agro[h3])
terraflow geoai fields -c config.yml Field-boundary detection via the optional GeoAI engine (pip install terraflow-agro[geoai])
terraflow geoai landcover -c config.yml Landcover classification (GeoAI extra)
terraflow geoai canopy -c config.yml Canopy-height regression (GeoAI extra)

See CLI docs and the GeoAI guide for full reference.

Climate interpolation

Three spatial algorithms are available via interpolation_method:

Method Notes
linear (default) scipy.griddata — fast, no extra deps
kriging Ordinary Kriging via pykrige; adds {var}_krig_std uncertainty columns
idw Inverse Distance Weighting (power=2) — faster than kriging, no uncertainty

Combine interpolation_method: kriging with uncertainty_samples: N in model_params to get Monte Carlo score confidence intervals (score_ci_low / score_ci_high). For kriging, variogram_mode: extended evaluates additional nested variogram candidates and records all LOOCV candidate scores in report.json; use the default standard mode for large station networks unless nested structures are needed. See the extended variogram notebook in the docs for a worked synthetic example.

See Config Schema for the full reference.

Python API

from terraflow.pipeline import run_pipeline

results_df = run_pipeline("config.yml")

Development

git clone https://github.com/gmarupilla/AgroTerraFlow.git
cd AgroTerraFlow
make dev       # create .venv and install dev deps
make test      # run test suite
make lint      # ruff + black
make docs-build

Architecture

Core modules: cli, config, climate, core/run_identity, exceptions, export, geo, ingest, model, pipeline, sensitivity, stats, utils, validation, viz.

Run artifacts under <output_dir>/runs/<fingerprint>/ include features.parquet, manifest.json, report.json, and results.csv. When kriging is configured, report.json also carries kriging_diagnostics (model, nugget, sill, range), kriging_loocv RMSE per variable, uncertainty coverage, and an interpolation_fallback block with per-variable fallback-to-mean counts. Multi-band rasters are supported via the top-level raster_band field (1-based; default 1).

Key design decisions are documented in Architecture Decision Records under docs/architecture/. See docs/reproducibility.md for the run fingerprint contract and known sources of non-determinism.

Project Scope

TerraFlow is a reproducible pipeline for geospatial agricultural modeling. It handles raster ingestion, ROI clipping, climate interpolation, suitability scoring, and deterministic artifact generation.

In scope:

  • Configuration-driven pipeline execution (YAML → Parquet + provenance artifacts)
  • Spatial interpolation of point climate observations (linear, kriging, IDW)
  • Per-cell suitability scoring with uncertainty quantification (Monte Carlo)
  • Deterministic run fingerprinting and artifact caching

Out of scope:

  • Real-time data ingestion or streaming workflows
  • General-purpose raster analysis (use rioxarray or rasterstats instead)
  • Cloud-scale distributed processing (no Dask/Spark integration planned)
  • Web application or GUI layer

Maintenance & Support

TerraFlow is actively maintained. Bug fixes are prioritized; the test suite and CI pipeline are kept green on every commit.

Feature requests are evaluated against project scope — open an issue to discuss before building. Not all requests will be accepted.

Support is provided on a best-effort basis via GitHub Issues. Response time is typically within a week. There is no paid support tier.

Contributing

See CONTRIBUTING.md.

Citation

If you use TerraFlow in your research, please cite our JOSS paper (manuscript in preparation).

License

MIT License — free for academic, commercial, and open-source use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

terraflow_agro-0.4.0.tar.gz (91.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

terraflow_agro-0.4.0-py3-none-any.whl (56.7 kB view details)

Uploaded Python 3

File details

Details for the file terraflow_agro-0.4.0.tar.gz.

File metadata

  • Download URL: terraflow_agro-0.4.0.tar.gz
  • Upload date:
  • Size: 91.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for terraflow_agro-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a4603b84ed1eb7c0045b76f6808bde167fda4e9838cfc8e5d9260d690afcffd5
MD5 e7d366ab0fb4cbcc311a6524030149bd
BLAKE2b-256 53c746d34f40fafcdbcbcb3c7bb7c8b72ab8ab95683939b6b48fd8bcc0d8b42d

See more details on using hashes here.

File details

Details for the file terraflow_agro-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: terraflow_agro-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 56.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for terraflow_agro-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9f78671585473e5cdc017f088e3dbf845377d9bf77c51e931686120965c6051
MD5 18b49b66c77073a8347b8d9f42696583
BLAKE2b-256 7c141df86dd2e768a4a6dbdc0c39eaa801a7529d516756215bb04f30d87feaf6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page