Encode

Work

Basin forcing data gateway for more than 460 catchments

One configuration-driven pipeline for more than 460 catchments in four countries, from a 100 km2 gauge catchment to a 441-unit national grid with no code change between them (October 2026).

One configuration-driven pipeline that serves a single gauge catchment of about 100 km2 and a 441-unit national elevation-band grid alike, turning gridded weather data into the per-basin series that hydrological forecasting models run on. Built for hydrosolutions GmbH under the SAPPHIRE Central Asia programme, as a rewrite of a fetch script into a platform.

Data gateway: geometry apart from values, weights computed once Sources Pipeline Results Basin geometry GeoPackage, WGS84 ERA5-Land reanalysis IFS ensemble 50 members Snow products hourly grid Configuration Django admin Weights cell fractions, cached Once Aggregation exactextract Exact Per-basin series daily, sub-daily Storage port object store or local Parity and provenance diffed, source columns Orange: fifty members reuse one intersection, keyed by the polygon bytes.
Data gateway: geometry apart from values, weights computed once

Situation

Every forecasting model in the programme needs the same input before it can run: meteorological variables such as precipitation and 2 m temperature, averaged over each gauged basin's polygon, for the reanalysis history it trains on and for the forecast cycle it runs on. The data arrive as gridded files from ECMWF and Copernicus. The models want one column per basin and one row per hour.

A fetch script does this for one country, one dataset and one storage location, and does not survive the second of any of them. Each new basin set meant an edit, each new source a branch, and a deployment forbidden from using cloud storage meant a rewrite. The original script had reached that point. The client needed onboarding to be an act of configuration, aggregation to be exact and reproducible whatever the geometry looks like, and storage to be a deployment choice rather than an architectural one.

What we built

We scoped the rewrite with the client and the downstream forecasting team before writing code, which settled the division of responsibilities early. Their systems own and validate basin geometry. The gateway extracts against exactly the bytes it is given, on each source's native grid, with no reprojection or resampling.

Datasets, variables and geometry subscriptions are rows in configuration tables, and pipeline factories generate the pipelines from them. A new geometry is a GeoPackage uploaded with a code, confirmed as ready, subscribed to the variables it needs, then given its history by one targeted backfill and its recent forecasts by a seven-day backfill. A one-polygon file and a 441-polygon file are the same case to the platform.

Aggregation from grid to basin is exact and area-weighted: each grid cell counts by the fraction of its area inside the polygon rather than by where its centre falls. Storage sits behind a port with interchangeable adapters, so when a spin-off deployment required that no cloud storage be used, the same code ran against a local filesystem without a rewrite. The aggregation backend was replaced behind its port with the old one kept as a rollback. Exports carry per-row provenance columns so a consumer can separate reanalysis from forecast fill and build training sets without leakage. Consumers fetch per-unit series as data frames through an API-key-protected Python client, published by the client as open source.

The hard part

The geometry sets have little in common, and the pipeline is not allowed to care. One file holds a polygon. Another holds 441 polygons of about 7,000 vertices each, 49 MB on disk. One set is plain basins and its sibling the same basins with glacier areas cut out, a 17-polygon file with 10,250 holes. Another is 290 watersheds in 359 parts. Each meets reanalysis grids a few hundred cells a side, forecast grids of fifty members, and a snow grid of 966 by 1,923 cells with 241 hourly steps. Configuration says which geometry meets which source. From there the code must produce the same kind of result, exactly, every time, and fast enough that fifty members a cycle and 365 days a backfill year do not become the schedule.

Two decisions carried most of that weight. The first separates geometry from values: the fraction of each cell inside each polygon is computed once per grid geometry and polygon file and cached under a content digest of the polygon bytes, so an ensemble's fifty members reuse one intersection and a wrong cache hit is impossible rather than unlikely. The second is to read only what the weights say is needed. The first version read whole raster bands, which was fine on reanalysis grids and far too slow on the snow grid, whose file is chunked so that each tile holds all 241 hours. One 515-cell catchment ran for over ten minutes before the task was killed. Reading that catchment's 30 by 27 window across all hours in one request takes 0.08 s, and the whole aggregation went from 71 s with the command-line tool to 0.11 s warm, with identical values. The smallest geometry on the largest grid broke the first implementation, and the fix had to be a rule about what to read, because the next geometry set will not look like the last.

Outcome

Counts from a development copy of the geometry store and benchmarks from a developer machine, October 2026.

  • More than 460 gauged catchments across four countries and more than 1,000 aggregation units from ten geometry sets, 370 of the catchments in three Central Asian countries.
  • One pipeline from a single catchment of about 100 km2 to a 441-unit national elevation-band grid, with no code change between them.
  • A year task extrapolated at 5.7 minutes in-process against 49 minutes with the command-line tool, from a benchmark over three geometry sets and four dates.
  • Results from the two aggregation backends identical on real ensemble runs and within 5e-13 on reanalysis temperature.
  • The same code against object storage and against a local filesystem, for a deployment that forbade cloud storage.
  • As arithmetic, a 50-member ensemble cycle at 85 steps over the full unit set is about 4.6 million area-weighted values per variable per cycle.

What changed: a script that had to be edited for every new basin set and rewritten for a new storage rule became a platform where a second country, a second dataset or a data-sovereignty constraint is configuration.

In their words

We've worked together on multiple successful projects, and we're still going.

Fact sheet

Clienthydrosolutions GmbH, Zürich, Switzerland, under the SDC-funded SAPPHIRE Central Asia programme. Consumers: the programme's forecasting team and its open-source forecast tools.
Engagementa component built under the programme's implementation mandate as a full rewrite of a fetch script, scoped with the client and the forecasting team before code, and continued as the Himalayan Data Gateway spin-off under a separate agreement.
PlatformPython, Apache Airflow with configuration-driven pipeline factories, Django with configuration in its admin, a hexagonal architecture with a framework-free domain and adapters for every source, tool and store, exactextract zonal statistics in-process, GRIB and NetCDF, ECMWF IFS ensemble (51 members), ERA5-Land reanalysis and snow-model outputs, GeoPackage in WGS84, a storage port with object-storage and local-filesystem adapters, a REST API with API-key authentication and a published Python client.
Numbers, with their dates465 gauged catchments, 1,081 aggregation units, 10 geometry sets, 441 elevation-band units over one country (development store, October 2026). 5.7 against 49 minutes per year task, 0.11 against 71 s on the snow-grid case (developer machine, October 2026). 51 ensemble members. About 50 fetches per forecast step on the open-data mirrors.
CompanyEncode d.o.o., Zagrebačka cesta 145A, Zagreb, Croatia
info@encode.hr
SiteWork Services About Contact
LegalImpressum / Legal notice Privacy
OIB 04954819540, MBS 060325736