Package: data#
Everything a run reads from outside is here: provider APIs, the files of the user, their cache and the typed records handed to the layers above. Each [data.<name>] section of a project TOML is one variable, and VARIABLE_SPECS in loading/_dispatch.py is the one list of them. A variable owns its cache and the unit of its records and leaves the provider to a class of the DataSource port (source/, with its own README), so adding a provider touches no variable. The data folder is the cache, each fetched file has a JSON sidecar beside it, and there is no database. The package is a layer because the loaders, the workflow and the calibration need data in one typed form, and none of them should know which provider or file it came from.
A run loads data through loading/ (DataConfig, DataPlanner, DataLoader), and a user loads it by hand with DataStore. A request from outside a project goes through request/ and hmp data get. Every load ends in a LoadResult of point, field and table records. They carry the unit of the provider, and core/units converts to SI at the entry of the model.
The package reads core, schema, catchment, mesh and model, and never results. It is read by config, calibration, workflow, project, cli and the root facade. The twelve subpackages are ordered in tests/unit/architecture/data_layout.yaml, and test_package_layouts.py checks every import.
The page of the package lists its modules with the first line of their docstring. It also gives the template of a variable, the rules between the subpackages, the cache, the site catalog and where to add what.
Modules#
common/
Module |
What it does |
Lines |
|---|---|---|
api_client.py |
HTTP helpers for API adapters (JSON GET, pagination). |
101 |
export.py |
CSV export: chronicles, metadata, and table of contents. |
99 |
files.py |
I/O helpers: CSV, Parquet, SHP/GPKG readers and filename conventions. |
209 |
geometry.py |
Spatial helpers: bbox, haversine, nearest station, mask filtering. |
119 |
land_cover.py |
The land cover pivot: the ESA CCI legend, its GCN250 curve numbers, and the crosswalks. |
216 |
source_extent.py |
Where a variable gets the box it asks a provider for. |
271 |
stations.py |
Common station management utilities and reporting for dropped stations. |
65 |
units.py |
Unit conversion helpers backed by |
220 |
common/clients/
Module |
What it does |
Lines |
|---|---|---|
explore2_files.py |
DRIAS Explore2 NetCDF reader, shared by precipitation, ETP, recharge and runoff. |
389 |
hubeau.py |
Helpers shared by the four Hub’Eau providers. |
108 |
ocsge.py |
OCS GE of the IGN: the department archives, their cover polygons, and a 10 m grid to burn. |
213 |
sandre_topage.py |
Read BD Topage layers from the Sandre WFS over a Lambert-93 box. |
274 |
sim2_edr.py |
Shared client for the GéoSAS SIM2 (SAFRAN-ISBA) EDR API. |
182 |
sim2_products.py |
SIM2 (SAFRAN-ISBA) products read by HydroModPy variables, and their download. |
297 |
worldcover.py |
ESA WorldCover: the 10 m class map of a box, read by window from the public tiles. |
86 |
contracts/
Module |
What it does |
Lines |
|---|---|---|
completeness.py |
Validation: completeness diagnostics and column checks. |
76 |
file_record.py |
A file a fetch hands back, with the digest of its bytes. |
123 |
load_result.py |
Structured result from the load() call of a data variable. |
46 |
location.py |
Station location contract. |
30 |
spatial_field.py |
Gridded / spatial field contract. |
59 |
table.py |
Tabular (non-timeseries, non-gridded) dataset contract. |
48 |
timeseries.py |
Point time-series contract. |
103 |
families/
Module |
What it does |
Lines |
|---|---|---|
base_config.py |
Shared Pydantic base classes for variable config files. |
123 |
common.py |
Shared base for the station and grid variables. |
294 |
files.py |
Variables read only from the user’s own files. |
164 |
grids.py |
Abstract base class for the grid-data (field) variables. |
421 |
stations.py |
Abstract base class for the station variables (gauges, wells, quality points). |
745 |
timeseries_config.py |
Shared Pydantic bases for the configs of point and station time-series variables. |
260 |
ingest/
Module |
What it does |
Lines |
|---|---|---|
custom_grids.py |
Common loaders for custom gridded data (NetCDF and GeoTIFF). |
373 |
custom_points.py |
Generic custom point loader for user-provided CSV files. |
510 |
line_trace.py |
Polyline trace ingest from CSV or vector formats into shapely LineString. |
71 |
observations.py |
Persist loaded observation timeseries into the run. |
108 |
raster.py |
Convert Esri ASCII grids (.asc) to Cloud Optimized GeoTIFF. |
74 |
tables.py |
Read user-facing CSV files and convert some of them into the internal Parquet pivot format. |
369 |
vector.py |
Convert user-facing vector files into OGC GeoParquet 1.1 vector tables. |
80 |
loading/
Module |
What it does |
Lines |
|---|---|---|
_dispatch.py |
The one registry of the |
425 |
config_schema.py |
Validated schema for the top-level |
634 |
inputs.py |
Resolve declared user files and URLs before run registration. |
114 |
loader.py |
Runtime data loading orchestrator driven by a resolved data plan. |
524 |
plan.py |
Immutable runtime objects for resolved data variable activation. |
49 |
planner.py |
Resolve the active data variables from explicit config plus inference rules. |
216 |
store.py |
DataStore: unified entry point for all data loading operations. |
339 |
provenance/
Module |
What it does |
Lines |
|---|---|---|
archive.py |
Pack the data cache of a workspace into one archive, and restore it elsewhere. |
207 |
derived.py |
Where a copy derived from a user file lives, and what it is named. |
49 |
lockfile.py |
|
696 |
sidecars.py |
The data cache of a workspace: one JSON sidecar next to each fetched file. |
1 169 |
request/
Module |
What it does |
Lines |
|---|---|---|
artefacts.py |
One file per variable and source, cut to the extent and the period asked for. |
330 |
cache_verbs.py |
Verbs of |
155 |
engine.py |
|
627 |
job.py |
|
394 |
model.py |
|
286 |
schemas/
Module |
What it does |
Lines |
|---|---|---|
abacus.py |
pandera contract for lake stage-volume-area abacus tables. |
97 |
catchment.py |
Contract for catchment polygon payloads. |
83 |
lithology.py |
pandera contract for zone-based lithology tables. |
52 |
stations.py |
pandera contract for station collections (hydrometry, piezometry, …). |
58 |
timeseries.py |
pandera contract for tabular time series (date + value). |
43 |
validation.py |
Warn-only Pandera validation helper used by ingestion adapters. |
91 |
sites/
Module |
What it does |
Lines |
|---|---|---|
catalog.py |
The site catalog of a workspace: |
203 |
gauge.py |
|
170 |
importers.py |
Turn a source of sites into |
321 |
outlet_snap.py |
Move an outlet onto the nearest line of a river network. |
144 |
single_site.py |
A |
103 |
source/: A data source answers one question about one provider: what may it be asked for, and what does it hand back. Every provider of this tree is a class of the port, from BD Topage to Hub’Eau and SIM2, so one form covers all of them. The port has no cache: a source receives its request, owns its out_dir, and asks nothing about the catalog, the workspace, a lock or a run. port.py holds the Protocol and its value types, and registry.py holds data_sources.
Module |
What it does |
Lines |
|---|---|---|
file.py |
The generic |
279 |
permanence.py |
Whether water flows all year: the column a mapped network or water body carries. |
44 |
port.py |
The data-source port: what a fetch owes its callers, and no more. |
676 |
registry.py |
|
299 |
url.py |
The generic |
356 |
variables/crossings/apis/
Module |
What it does |
Lines |
|---|---|---|
bdtopo.py |
Roads and railways of the IGN BD TOPO, from the Geoplateforme WFS. |
268 |
roe.py |
Obstacles to flow of the Sandre ROE (Referentiel des Obstacles a l’Ecoulement). |
212 |
wfs.py |
Page through a WFS 2.0 layer over a Lambert-93 box. |
158 |
variables/crossings/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for crossings data sources. |
149 |
custom.py |
Custom crossings loader: a vector file the user drew or collected. |
96 |
records.py |
The shape every crossings source answers in, and how its pages are written. |
75 |
resolver.py |
Bridge between |
396 |
variable.py |
Crossings variable: download or read the structures laid across the channels. |
178 |
variables/curve_number/
Module |
What it does |
Lines |
|---|---|---|
config.py |
The |
252 |
from_land_cover.py |
The three sources that build a curve number map from land cover. |
317 |
maps.py |
The curve number of a land cover grid: each class to the ESA CCI pivot, then its GCN250 row. |
167 |
variable.py |
Load the curve number: a raster read as it is, or one built from land cover. |
15 |
variables/dem/apis/
Module |
What it does |
Lines |
|---|---|---|
_bdalti_archive_index.py |
Internal BD ALTI 25 m archive index and extraction helpers. |
185 |
geoplateforme_download.py |
Geoplateforme download API helpers for DEM archives. |
394 |
geoplateforme_wms.py |
Geoplateforme WMS-Raster client for elevation grids. |
182 |
ign_dem_fr.py |
French IGN DEM archive discovery through Geoplateforme. |
1 157 |
variables/dem/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for DEM data sources. |
234 |
custom.py |
Custom DEM data loaders. |
213 |
resolver.py |
Resolve the DEM raster file from |
240 |
variable.py |
DEM variable, in the standard variable pattern. |
196 |
variables/
Module |
What it does |
Lines |
|---|---|---|
forcing_series.py |
Radiation, ETP and precipitation, the atmospheric forcing series variables. |
295 |
lake_series.py |
Lake levels, inflow, outflow and withdrawal, the observed series of a lake. |
244 |
sim2_series.py |
Wind, humidity, runoff, soil moisture and temperature, the SIM2 series variables. |
251 |
user_rasters.py |
Soil capacity, substratum, layer base and property maps, the user’s rasters. |
318 |
variables/geology/apis/
Module |
What it does |
Lines |
|---|---|---|
brgm_1m.py |
Download and cache the BRGM 1:1M national geological map. |
194 |
brgm_50k.py |
Download and cache BRGM 1:50K departmental geological maps. |
268 |
fgeol.py |
Helpers shared by the two BRGM geology downloads. |
20 |
variables/geology/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for geology data sources. |
259 |
custom.py |
Custom geology data loaders. |
303 |
field.py |
The geology field of a run, built from the file the geology variable returned. |
136 |
io.py |
Input/output layer for geology sources. |
519 |
processing.py |
Geology raster post-processing helpers. |
185 |
variable.py |
Geology variable, in the standard variable pattern. |
151 |
variables/hydrography/
Module |
What it does |
Lines |
|---|---|---|
api_source.py |
From a |
122 |
config.py |
Pydantic configuration for hydrography data sources. |
176 |
custom.py |
Load hydrography data from a local file or directory. |
76 |
resolver.py |
Bridge between |
117 |
variable.py |
Hydrography variable: fetch, clip, rasterize. |
641 |
variables/hydrography/apis/
Module |
What it does |
Lines |
|---|---|---|
bdtopage.py |
Fetch hydrography from the Sandre BD Topage WFS service. |
173 |
euhydro.py |
Fetch hydrography from the EU-Hydro River Network Database (EEA Discomap). |
246 |
features.py |
What the three river-network sources share behind the data-source port. |
81 |
osm.py |
Fetch hydrography from OpenStreetMap via Overpass API. |
144 |
variables/hydrometry/apis/
Module |
What it does |
Lines |
|---|---|---|
hubeau.py |
Hub’Eau Hydrométrie API adapter. |
504 |
variables/hydrometry/
Module |
What it does |
Lines |
|---|---|---|
catchment_area_check.py |
Check a delineated catchment against the drainage area its gauge publishes. |
178 |
config.py |
Pydantic configuration for hydrometry data sources. |
179 |
variable.py |
Hydrometry variable: custom chronicles and Hub’Eau. |
17 |
variables/impervious/
Module |
What it does |
Lines |
|---|---|---|
config.py |
The |
141 |
ocsge.py |
The sealed share from OCS GE of the IGN, rasterized at 10 m over the request. |
109 |
variable.py |
Load the sealed share: the user’s raster, a url, or a provider asked over the watershed. |
15 |
worldcover.py |
The sealed share from ESA WorldCover, its built-up class at 10 m, over the world. |
123 |
variables/infiltration_ratio/
Module |
What it does |
Lines |
|---|---|---|
config.py |
The |
157 |
ocsge.py |
The infiltration ratio from OCS GE of the IGN, one ratio per cover, rasterized at 10 m. |
144 |
variable.py |
Load the infiltration ratio: the user’s raster, a url, or OCS GE over the watershed. |
15 |
variables/intermittency/apis/
Module |
What it does |
Lines |
|---|---|---|
hubeau.py |
Hub’Eau stream-flow (ecoulement) API adapter. |
346 |
variables/intermittency/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for intermittency (ONDE) data sources. |
87 |
variable.py |
Intermittency variable: custom flow-state chronicles and Hub’Eau ONDE. |
85 |
variables/lake_abacus/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for lake abacus (stage-volume-area) data sources. |
87 |
custom.py |
Custom lake-abacus data loader. |
63 |
read.py |
Lake abacus reader extracting stage-volume-area curves from loaded tables. |
47 |
variable.py |
Lake-abacus variable: stage-volume-area tables from the user’s files. |
20 |
variables/lake_bathymetry/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for lake bathymetry data sources. |
90 |
read.py |
Lake bathymetry reader matching raster paths to lake ids. |
36 |
variable.py |
Lake-bathymetry variable: lake-bed elevation rasters from the user’s files. |
9 |
variables/lake_geometry/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for lake geometry data sources. |
83 |
custom.py |
Custom lake-geometry data loader. |
68 |
read.py |
Lake geometry reader extracting footprint polygons from loaded data. |
41 |
variable.py |
Lake-geometry variable: lake and reservoir footprints from the user’s files. |
20 |
variables/oceanic/apis/
Module |
What it does |
Lines |
|---|---|---|
shom.py |
SHOM tide gauge API client for sea-level data. |
424 |
variables/oceanic/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for oceanic data sources. |
101 |
constant.py |
Constant sea-level source for the oceanic data variable. |
104 |
variable.py |
Oceanic variable: custom files, SHOM tide gauges, or a constant sea level. |
40 |
variables/piezometry/apis/
Module |
What it does |
Lines |
|---|---|---|
hubeau.py |
Hub’Eau Piézométrie API adapter. |
389 |
variables/piezometry/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for piezometry data sources. |
99 |
variable.py |
Piezometry variable: custom chronicles and Hub’Eau. |
17 |
variables/recharge/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for recharge data sources. |
319 |
synthetic.py |
Synthetic recharge generation. |
222 |
variable.py |
Recharge variable: custom files, SIM2, and a synthetic series. |
10 |
variables/water_quality/apis/
Module |
What it does |
Lines |
|---|---|---|
hubeau.py |
Hub’Eau water quality API adapter. |
392 |
variables/water_quality/
Module |
What it does |
Lines |
|---|---|---|
config.py |
Pydantic configuration for water quality data sources. |
96 |
variable.py |
Water quality variable: custom chronicles and Hub’Eau. |
12 |
workspace/
Module |
What it does |
Lines |
|---|---|---|
example_files.py |
Minimal, valid example files for each accepted custom input format. |
353 |
folders.py |
Folders of a workspace and of its projects: create, list, delete, clean. |
201 |
scaffold.py |
Workspace scaffolding. |
531 |
Inside the package#
How a run loads data#
The data layer answers three questions before any solver work starts. Which families are active, which class loads each one, and which provider or local file feeds it.
DataConfig(loading/config_schema.py) validates[data]and reads each typed section with the config class thatVARIABLE_SPECSnames for it.DataPlanner.build(loading/planner.py) merges the explicitdata.typeswith the inference rules and returns an immutableDataLoadPlanwith one reason per inferred type. An explicit type always wins. Ageologysupport activatesgeology, astreamboundary activateshydrography, anoceanone activatesoceanic, and a soil reservoir activatesprecipitationandetp. Withdata.inference_mode = "warn"the inferences are accepted and recorded. With"strict"each one needs an explicit section.project/phases.pybuilds the plan.LoadDataStep(workflow/steps/data.py) then runsDataLoader, which applies the simulation window and the basin mask, calls<V>Variable.load()for each planned variable and collects aLoadResult.The loader fills
LoadedDataContext(core/state/run_state.py), one field per variable. The step then binds geology into theDomainzones withapply_geology_to_domain, and oceanic levels, recharge, ETP, lakes and barriers into theFlowwith theapply_*_to_flowfunctions. Hydrometry stays in the loaded state.
VARIABLE_SPECS in loading/_dispatch.py is the one list of variables. It names the
classes as text paths, so nothing is imported before it is needed, and it holds the columns
that the workspace scaffold writes. A new variable still needs a field in DataConfig, a
field of LoadedDataContext and, for a provider, an entry in schema/sources.py.
tests/unit/data/test_variable_families.py names the list you missed. Outside a project,
DataStore().load_variable("hydrometry", cfg) loads one variable by hand.
The variables and their bases#
Each [data.<name>] section is one variable, and Data sources lists the
sources of each. A variable leaves every provider to the registry and names only itself and its unit, for example VARIABLE_NAME = "hydrometry" and
INTERNAL_UNIT = "m3/s".
families/ holds three bases. StationVariable keeps one chronicle per station and asks
only for the missing periods. GridVariable keeps one NetCDF or GeoTIFF per box and period.
FileVariable reads only the user’s own file. dem, geology, hydrography and
crossings are written by hand and inherit only SourceTable.
A variable with real code is a package, variables/<v>/, with config.py, variable.py
and an apis/ folder for its network providers. A thin variable has no code of its own, so
its three classes sit in a flat module of its family (sim2_series.py, forcing_series.py,
lake_series.py or user_rasters.py). dem, crossings and hydrography also
keep a resolver.py, because the geographic step runs before any variable loads and needs
their files on disk first.
The extent of a variable comes from its source config alone (resolve_source_extent in
common/source_extent.py), with mask_path first. No variable takes a project object and
no variable reads the project geometry. During a run, DataLoader writes the delineated
watershed into mask_path before it hands the config to the store. A mask with no CRS is refused.
The DataSource port#
source/README.md is the contract of the port. Every provider is one class of the port,
found with data_sources.get(section, source_id). A source knows nothing of the catalog, the
workspace, a lock or a cache, and it converts no value, because the SI is reached at the entry
of the Model through core/units. The variable builds the request and keeps the cache,
and the source only fetches.
source/registry.py names the shipped classes by a dotted path in _BUILTIN_PATHS and
imports each on first use, so a third-party plugin joins the same table through the
hydromodpy.data.source entry-point group. Source modules import heavy libraries inside their functions, so a lookup loads
nothing heavy. file is never in SOURCES, because the base class loads the user’s files itself
and a user file is no row of the cache.
The cache is its sidecars#
The data folder is the cache, and there is no database. Next to each fetched file,
<file>.json records the variable, the source, the extent and period, the sha256 and the
licence. CacheIndex (provenance/sidecars.py) scans the folder once and answers find.
A fetched file is written beside its name and renamed in place, then its sidecar is written. A
station chronicle is written inside index.chronicle(folder, stem), which holds the lock of
that station. A variable that downloads needs the data folder of the call, and without one it
is refused. Your own files live under inputs/ and are never a row, so prune keeps them.
A frozen run reads only what hydromodpy.lock names. read_locked_inputs reads it once
and the run hands the result down as the argument locked. No module global holds the mode,
so two threads of one process never see each other as frozen.
Requests from outside a project#
request/engine.run_request serves a DataRequest with no project, through
hmp data get. A failed source loses its files and is listed, and the others keep theirs.
file and custom sources are refused, since a request has no project folder.
Boundaries#
A subpackage imports only what its row of tests/unit/architecture/data_layout.yaml allows,
and the generated layers page gives the edges between packages. A
variable never imports another variable. Another layer imports only the modules listed under
public in data_layout.yaml, and a variable reaches its providers through the registry,
so an if on a source name has no reason to appear. data never imports results.
Where to add what#
A provider for an existing variable is Add a data source, and a new variable
is Add a data variable. A user-file format goes in ingest/, and an import
rule in data_layout.yaml. To start reading, take variables/hydrometry/
and families/stations.py for a station variable, then variables/sim2_series.py for a
grid variable, then loading/loader.py and loading/planner.py.