API reference

These entries are generated from the installed Python package. See the tutorials for complete workflows and required units.

Basin

class basinforge.Basin(basin_id, dates, precipitation, pet, qobs=None, temperature=None, area_km2=100.0, latitude=0.0, timestep='daily')

Contiguous forcing record; P/PET/Q are depths per model time step.

Parameters:
  • basin_id (str)

  • dates (DatetimeIndex)

  • precipitation (ndarray)

  • pet (ndarray)

  • qobs (ndarray | None)

  • temperature (ndarray | None)

  • area_km2 (float)

  • latitude (float)

  • timestep (str)

Model

class basinforge.Model(name: str, timestep: str, defaults: dict, bounds: dict, runner: Callable, variant: str, temperature_required: bool = False, backend: str = 'python')
Parameters:
  • name (str)

  • timestep (str)

  • defaults (dict)

  • bounds (dict)

  • runner (Callable)

  • variant (str)

  • temperature_required (bool)

  • backend (str)

CalibrationConfig

class basinforge.CalibrationConfig(method: 'str' = 'de', objective: 'str | dict' = 'nse', warmup: 'int' = 365, calibration_end: 'str | None' = None, calibration_fraction: 'float | None' = None, validation_start: 'str | None' = None, seed: 'int' = 42, maxiter: 'int' = 100, popsize: 'int' = 10, samples: 'int' = 1000, polish: 'bool' = False, bounds: 'dict | None' = None, fixed: 'dict' = <factory>)
Parameters:
  • method (str)

  • objective (str | dict)

  • warmup (int)

  • calibration_end (str | None)

  • calibration_fraction (float | None)

  • validation_start (str | None)

  • seed (int)

  • maxiter (int)

  • popsize (int)

  • samples (int)

  • polish (bool)

  • bounds (dict | None)

  • fixed (dict)

calibrate

basinforge.calibrate(basin, model='GR4J', config=None, *, progress=None)
Parameters:
Return type:

CalibrationResult

calibrate_many

basinforge.calibrate_many(basins, model='GR4J', config=None, *, workers=1, output=None, resume=False, fail_fast=False, progress=None)

Independent basin fits; errors isolated, successful completed jobs reusable.

calibrate_shared

basinforge.calibrate_shared(basins, model='GR4J', config=None, *, basin_weights=None)

One common parameter vector; equal basin weighting, not pooled hydrographs.

compare_models

basinforge.compare_models(basins, models, config=None, **kwargs)

calibrate_multistart

basinforge.calibrate_multistart(basin, model='GR4J', config=None, *, seeds=(42, 43, 44), progress=None)

Repeat independent searches; select by training loss, never validation.

run_experiment

basinforge.run_experiment(basin, model='GR4J', config=None, *, sensitivity='morris', sensitivity_options=None, output=None, starts=1, seeds=None)

Fit, analyze parameter sensitivity and optionally export a complete study.

sensitivity is "morris", "sobol" or None. Sensitivity uses the calibration bounds (and fixed parameters) and scores only the chronological training segment after warmup. The validation record is reserved for fit evaluation and never enters the sensitivity indices. If output is given, fit, HTML/PNG report and sensitivity JSON are staged and published as one new directory; existing output is refused.

morris_sensitivity

basinforge.morris_sensitivity(basin, model='GR4J', config=None, *, trajectories=12, levels=4, seed=42, bounds=None)

Morris screening using normalized elementary effects.

Evaluations = trajectories * (free parameters + 1). mu_star is the mean absolute effect on the minimized configured training objective per unit change across a parameter’s declared range. sigma describes effect variability and can indicate nonlinearity or interactions.

sobol_sensitivity

basinforge.sobol_sensitivity(basin, model='GR4J', config=None, *, samples=256, seed=42, bounds=None, bootstrap=200)

Saltelli/Jansen Sobol indices from a scrambled Sobol digital net.

samples must be a power of two (minimum four). Runtime is samples * (parameters + 2) model simulations. Bootstrap intervals quantify sampling variability of the index estimators, not hydrologic predictive uncertainty.

simulate_ensemble

basinforge.simulate_ensemble(basin, model, parameter_sets, *, quantiles=(0.05, 0.5, 0.95))

Descriptive parameter-scenario spread, not a calibrated posterior.

export_report

basinforge.export_report(basin, fit, directory, *, model=None)

Create a static HTML/PNG report; never overwrite an existing directory.

get_model

basinforge.get_model(name)
Parameters:

name (str | Model)

Return type:

Model

list_models

basinforge.list_models(*, include_optional=False)

WaterDemand

class basinforge.WaterDemand(name, demand, source='mixed', priority=1, consumption_fraction=0.5, groundwater_return_fraction=0.0, return_delay_days=1, max_withdrawal=inf)

Sector demand in m3/day. Lower priority numbers are served first.

source is surface, groundwater, or mixed. Mixed users prefer surface water and can use groundwater for their remaining demand. Returns are generated from actual supplied water, never from unmet requests.

Parameters:
  • name (str)

  • demand (object)

  • source (str)

  • priority (int)

  • consumption_fraction (float)

  • groundwater_return_fraction (float)

  • return_delay_days (int)

  • max_withdrawal (object)

WaterUseConfig

class basinforge.WaterUseConfig(allocation='priority', environmental_flow=0.0, pumping_capacity=inf, external_recharge=0.0, baseflow_fraction=0.0, groundwater_recession=0.0, groundwater_initial=0.0, groundwater_capacity=inf, reservoir_capacity=0.0, reservoir_initial=0.0, reservoir_release=inf, reservoir_evaporation=0.0)

Daily conceptual stores; all volumes/capacities are m3.

baseflow_fraction partitions natural-model runoff into aquifer recharge instead of adding a second copy of that water. External recharge must be supplied separately and must not duplicate natural-model runoff.

Parameters:
  • allocation (str)

  • environmental_flow (object)

  • pumping_capacity (object)

  • external_recharge (object)

  • baseflow_fraction (float)

  • groundwater_recession (float)

  • groundwater_initial (float)

  • groundwater_capacity (float)

  • reservoir_capacity (float)

  • reservoir_initial (float)

  • reservoir_release (object)

  • reservoir_evaporation (object)

WaterUseResult

class basinforge.WaterUseResult(daily, sectors, initial_storage)

Daily accounting table and per-sector supplied/consumed/unmet volumes.

Parameters:
  • daily (DataFrame)

  • sectors (dict[str, DataFrame])

  • initial_storage (float)

WaterUseScenario

class basinforge.WaterUseScenario(dates, demands=(), config=<factory>)

Date-aligned demand/configuration for one basin.

Parameters:

simulate_water_use

basinforge.simulate_water_use(dates, natural_runoff, demands=(), config=None, *, upstream=0.0)

Run native managed-water accounting; inputs are m3/day, not m3/s.

Natural runoff is an external input to this managed-water subsystem. Pending returns remain in the final balance instead of disappearing at the end of the record. Same-day returns cannot be reused within that day.

irrigation_demand

basinforge.irrigation_demand(pet_mm, precipitation_mm, *, irrigated_area_km2, crop_coefficient=1.0, efficiency=0.7, effective_rainfall_fraction=0.8)

Simple climatic gross irrigation demand, m3/day; not a crop/soil model.

domestic_demand

basinforge.domestic_demand(population, *, litres_per_person_day=100.0)

Gross household demand in m3/day.

managed_model

basinforge.managed_model(model='GR4J', *, scenarios)

Wrap a daily model for existing calibration, sensitivity and batch APIs.

Mapping keys are basin IDs. Use a mapping for independent/shared multi- basin calibration. Water parameters have the wu_ prefix; use explicit calibration bounds/fixed parameters to avoid unidentifiable joint fits.

managed_accounting

basinforge.managed_accounting(basin, model, params=None)

Retrieve complete accounting from a managed model, including a fitted one.

run_water_network

basinforge.run_water_network(dates, natural_runoff, scenarios, downstream, *, travel_days=None)

Route managed outflows through a directed, non-splitting basin network.

Each basin drains to one other basin or None. Cycles are refused. Natural runoff must be local/incremental, not whole-upstream catchment runoff. Travel delays are integer days. Unarrived water is reported as final transit.

configure_marrmot

basinforge.configure_marrmot(*, octave=None, package_list=None, timeout=300)

Configure picklable runners; settings survive spawned basin workers.

check_marrmot

basinforge.check_marrmot(*, octave=None, package_list=None, timeout=30)

Start the runtime and instantiate every class, checking optim too.

marrmot_details

basinforge.marrmot_details(basin, model, parameters=None)

Expose actual ET, stores and solver residuals for diagnostics.

close_marrmot

basinforge.close_marrmot()

Release only Octave workers owned by this Python process.