Skip to main content

Basin Ledger

PyPI DOI test nightly

A basin's water, quantity and quality, balanced day by day across coupled models.

The code was written with AI assistance (Claude, by Anthropic), designed and directed by Andrew Sommerlot. See AI use.

Basin Ledger couples a watershed model, a groundwater model and the models of large water users through BMI, and steps them together one day at a time with one Python driver:

  • SWAT+ through swatplus-bmi (doi:10.5281/zenodo.23963201), which runs stock SWAT+ 62.0.1 under outside control;
  • NextGen, as finished NextGen In A Box runs replayed day by day, with results keyed to hydrofabric ids;
  • MODFLOW 6 through its own BMI/XMI (libmf6), from Python with USGS's modflowapi;
  • water users as BMI components from waterledger-models, starting with data center cooling (CoolingWaterBmi).

Every volume and mass that moves between models is entered in a ledger twice, as sent and as received. A day where they differ stops the run. Basin Ledger is a sibling of Water Ledger. Water Ledger estimates one campus's water from public data. Basin Ledger follows that water through a basin's streams and aquifers.

Status: early (0.20.0). Built and tested:

  • the water-user interface, with controls a rule can set (a withdrawal limit, dry mode), and a user's other outputs (power, time, heat not removed) booked each day;
  • routes: MODFLOW 6 wells, SWAT+ water allocation intakes (on any channel or reservoir, several to one served senior first, with swatplus-bmi 0.14.0; a user drawing from one returns only what it got, the next day) and point sources, outfalls, returns to the ground (an aquifer cell: septic drainfields, leaks), water from and to outside the basin;
  • water systems (towns as systems): sources by share or priority (reuse of a plant's effluent among them), customers by class with daily or monthly demand, losses and leaks, sewer, septic and consumption, the plant's outfall, a shortfall scaling the day and returns the next day;
  • feedback rules: curtailment, dry mode, drawdown limit;
  • SWAT+ recharge into MODFLOW 6 (one-way), per aquifer or HRU by HRU (each HRU's percolation on the cells under its ground, from swatplus-bmi 0.6.0), and the two-way stream-aquifer exchange through MODFLOW 6's river, drain or streamflow routing (SFR) packages, with SFR's reaches built from SWAT+'s channel lines, and lakes at a fixed stage coupled through their outlet channels; a floor under a river stage set from SWAT+'s depth, cell by cell from a column of the rivers' map ([rivers] stage_floor), for main stems whose bottom sits below the surveyed surface;
  • MODFLOW 6 on a structured grid (DIS) or a vertex grid (DISV, such as a quadtree refined around a site): maps, wells, head outputs and rules name cells as layer, row, col or layer, icell2d; every solve checked for non-finite heads, a run stopping at the first with the day, the iteration and the solver settings that usually fix it;
  • an existing MODFLOW 6 model taken as given (docs/design.md, "Extending an existing MODFLOW 6 model"): what Basin Ledger takes over listed at start-up, maps onto its grid, its own units and stress periods, an SFR network a study brought lined up with SWAT+'s channels and its mover cut, users' wells added or on its MAW wells, storage for a model handed over steady, several of a simulation's models coupled together, LAK lakes on SWAT+'s reservoirs and irrigation pumped from its wells (both swatplus-bmi 0.11.0), and SWAT+'s own irrigation from its channels and reservoirs booked by source, the whole-basin balance closing with it (swatplus-bmi 0.14.0);
  • groundwater up into SWAT+'s soil layers where MODFLOW 6's water table rises into the profile, by a drain at the profile's bottom (chosen) or SWAT+ gwflow's rule, with or without a cap at the layers' room (none chosen; swatplus-bmi 0.7.0), and its recirculation: gross and net recharge in the balance and the summary, and each HRU's water over the run split by land use or HRU ([outputs] recirculation, balance.recirculation);
  • the soil cover SWAT+'s soil evaporation sees, on the HRUs a study names by HRU or land use: a tree's leaves and residue, not its wood ([soil_cover] rule = "leaves"; swatplus-bmi 0.16.0);
  • a water-table link (rule = "water_table", built Nov 27, 2026, on swatplus-bmi 0.17.0's held soil layers): SWAT+'s layers below MODFLOW 6's water table held, filled from a drain at the profile's bottom (MODFLOW 6's top, checked per cell or per HRU), rain on a full profile spilling as saturation excess, and drain water the held layers can't take returned as recharge, or with cap = "room" the drain cut each day to the held layers' room; optionally each HRU's piece of a cell with its own land surface, its own table (a land_surface file per map row);
  • swatplus-bmi's fix for SWAT+'s daily Muskingum routing passed through ([swatplus] routing_fix = "muskingum_daily"; swatplus-bmi 0.18.0), off unless set;
  • conservation across every link: recharge kept on each aquifer's own area, water from outside the models booked as its own account, a channel's loss limited to what it carries, and the coupling's settings checked at start-up;
  • a start consistent with the coupling (Basin.spin_up), and warnings for a start whose soils can drift;
  • the whole-basin balance, the capture of pumping (from storage, the streams and the boundary), and depletion against Glover and Balmer (1954);
  • scenarios from a shared warm-up, and restarts from a saved day that match unbroken runs bit for bit;
  • scenarios of water users on the existing system. Users are added, scaled or removed, and a system's sources changed, and a user grows in dated phases. The runner reports each scenario's and all together's effect on flow, low flows (7Q10) and the flow duration curve, heads, capture and water, and whether the effects add up. It runs the cases in parallel processes and is restartable (basinledger scenarios);
  • operating rules for systems and reservoirs: pumped storage, releases and staged drought restrictions, with transfers from an intake to a point source, now into a reservoir too;
  • weather written into SWAT+'s gage records from a run's first day (swatplus-bmi 0.7.0): a series per gage from a CSV, gridded data mapped to gages, and a scenario's change (wetter, drier, warmer; monthly factors and shifts);
  • stream temperature as a reach heat balance, with groundwater inflow and users' returns at their own temperatures;
  • groundwater transport (MODFLOW 6 GWT): each species' mass in the ledger every day, and a user's intake concentration from the aquifer at its well; nitrate and soluble phosphorus carried with the water through every link between SWAT+ and MODFLOW 6 (SWAT+'s leached mass into the aquifer HRU by HRU, the aquifer's concentration back to the channels with gains, drains and the soil link, the channel's own with its losses), first-order decay (denitrification) and linear sorption (phosphorus) in the ledger, a steady-state start (Basin.transport_steady_state), and dispersion with or without XT3D's cross terms, or none (add_transport(..., xt3d=False));
  • salt ([salt.<species>]): conservative species (chloride, weathering's ions) through every water path of a coupled run, each day, each one's mass closed: a store per HRU (deposition, road salt by rate or by an annual amount per calendar year over its snow and ice days, land sources such as septic and potash by HRU, land use or year, groundwater up into the soil; out with runoff, lateral flow and percolation), the recharge's mass placed on the cells as its water is, GWT in the aquifer with weathering by zone, and a mass balance for every channel and reservoir upstream first; input groups scaled by multipliers a calibration can fit; specific conductance as a linear combination of the species, for scoring;
  • mass through the human-system routes: returns to the ground (septic water, leaks) and wells over several cells carry their concentrations; a water system's sources mixed by what each delivered and each class's returns at a stated septic or plant effluent concentration (a DMR's months); the plants' and users' loads on SWAT+'s point sources for nitrate and soluble P; septic counted once beside salt's land sources; all of it in a replay;
  • reported irrigation on SWAT+'s fields (land: routes; swatplus-bmi 0.15.0): an irrigator's water put on its HRUs by weight the day after it is withdrawn, with its mass (nitrate and soluble P into the top layer, chloride into salt's land);
  • replay ([replay] record, --replay): a coupled run's flow side recorded once, compactly, and the salt run again from it as often as a calibration needs, with MODFLOW 6's flow model left unsolved and no SWAT+: bit for bit from a float64 record, to float32's rounding from the default; anything that would change the flow refused;
  • NextGen as the surface model: a finished NGIAB run replayed day by day, with users on its own hourly forcing;
  • MODFLOW 6 recharge from NextGen (CFE's percolation), used as interim recharge in the Plaster Creek example;
  • the ledger and the command line, with check: every problem an example's start-up finds, without running a day (with a run's start-up hooks);
  • calibration records per model. An example is a screening run unless every model it runs is calibrated;
  • calibration parameters written into a run's copy of the models' files: SWAT+ through its own calibration.cal (swatplus-bmi 0.9.0), MODFLOW 6 as multipliers on package values everywhere, by layer or by zone; and PEST++ IES files with Basin Ledger's forward model as the model command;

Examples:

  • synthetic: SWAT+'s Osu_1hru with small MODFLOW 6 models, for the tests;
  • Plaster Creek, Michigan: the worked example below;
  • Michigan cold-stream screen: a script that scores Michigan's gaged basins for a cold-stream study from public data. A worked example on the Dowagiac River, a groundwater-fed trout stream in southwest Michigan, is planned.

Still to come (docs/design.md):

  • SWAT+ built on the NextGen hydrofabric, for water quality on the same catchments;
  • AORC forcing;
  • USGS groundwater levels as observations.

How it works

flowchart LR
  U["water users (BMI)<br/>hourly: withdrawal, consumption,<br/>return, loads, power"] -- "day's volumes" --> D
  D["driver<br/>one day at a time"] -- "update()" --> S["SWAT+<br/>(swatplus-bmi)"]
  S -- "aquifer recharge, m/s" --> D
  D -- "recharge by cell, well rates<br/>(set between prepare and solve)" --> M["MODFLOW 6<br/>(libmf6, modflowapi)"]
  M -- "simulated flows, heads" --> D
  D --> L[("ledger<br/>sent = received,<br/>every day")]

A NextGen run takes SWAT+'s place as a replay. It gives calibrated flows on NextGen geography, but without feedback (see docs/design.md).

Places are examples, not code. Each example (examples/<place>/) is one config file that wires real models for one basin and its users, plus a script that fetches its public data and a short write-up. The engine knows nothing about any place or any kind of water user.

Worked example: Plaster Creek

Plaster Creek at the gage, with and without a campus well

An assumed 300 MW campus on its own well cuts Plaster Creek's 7-day low flow at USGS 04119055 by 43 L/s (27%) in the driest year of the run. MODFLOW 6 takes 63% of the pumping from the streams in the last year. Glover's method, with nextgen-michigan's screening settings, gives 89%. On utility water from Lake Michigan the creek sees nothing.

  • Calibrated: streamflow at the gage (NextGen, KGE 0.87 in calibration and 0.81 in validation, from nextgen-michigan).
  • Not calibrated: the MODFLOW 6 model (heads RMSE 7.9 m over 55 wells; base flow too steady at low flow), the campus, which is an assumption, and water quality, which isn't run yet.
uv sync --group gis --group examples
uv run python examples/plaster-creek/fetch.py                     # checks for the NextGen run; says how to build it
uv run --group gis python examples/plaster-creek/groundwater/fetch.py
uv run --group gis python -W ignore examples/plaster-creek/groundwater/prepare.py
uv run --group gis --group examples python -W ignore examples/plaster-creek/demo.py

The NextGen run comes from nextgen-michigan (Docker, a few hours). Results are in docs/plaster-creek-demo.md.

Open problems:

  • fitting the groundwater model to heads and base flow, starting with streambed conductance, which moves the answer most;
  • a longer forcing record that includes the 2012 drought;
  • stream temperature from the change in groundwater inflow (the heat balance is built, not yet run here);
  • water quality through SWAT+ on the same catchments, against the Plaster Creek TMDL;
  • existing high-capacity wells, and more kinds of water users.

Install

Needs Python 3.11 or later. Mac, Linux and Windows are tested on every push.

pip install "basinledger[users,nextgen]"      # or: uv add "basinledger[users,nextgen]"

On Windows x86-64, Linux x86-64 (glibc 2.34 or later: Ubuntu 22.04, RHEL 9 and newer) and macOS 15 or later on Apple silicon, that's all (0.10.0). Both models come with it, nothing to compile or fetch:

  • SWAT+, built with the exchange mode, inside swatplus-bmi's wheel (swatplus-bmi 0.18.0 or later);
  • MODFLOW 6's shared library (libmf6), USGS's release unchanged (6.8.2), inside Basin Ledger's own wheel (basinledger/_lib/, with a note on its source and license).

The extras:

  • users: the water-user models from waterledger-models (CoolingWaterBmi);
  • nextgen: netCDF4, for reading NextGen runs;
  • gis: shapely, for building SFR's reaches from channel lines (coupling/sfr.py).

Elsewhere (macOS 14 or older, an Intel Mac, Linux on ARM or with an older glibc), pip installs the packages without the models, and they come separately, once:

  • SWAT+: swatplus-bmi build fetches SWAT+ 62.0.1, patches it and builds it, in a few minutes. It needs gfortran (on macOS, Homebrew's gcc; on Windows, MSYS2's, as swatplus-bmi's README says).

  • libmf6: USGS's release through flopy's get-modflow, installed with Basin Ledger. Basin Ledger looks for it in its own wheel, then where :flopy puts it, or at $LIBMF6 first:

    get-modflow :flopy --repo modflow6 --subset mf6,libmf6.dylib     # libmf6.so on Linux; mf6.exe,libmf6.dll on Windows
    

On Windows, write paths in a config with forward slashes or as TOML literal strings (project = 'D:\models\clam'): in double quotes a backslash starts an escape. A Windows PC on ARM runs the x86-64 builds of SWAT+ and libmf6 under emulation, so its Python must be x86-64 too (uv python install cpython-3.12-windows-x86_64-none), and then the x86-64 wheels come with it.

From a source checkout, for development and the tests, with uv:

git clone https://github.com/northlinehydrology/basinledger && cd basinledger
uv sync
uv run python examples/synthetic/fetch.py --get     # builds SWAT+ (swatplus-bmi build) and fetches libmf6 (get-modflow)
uv run pytest                                       # about 2.5 minutes on one core; -m "not slow" takes about 15 s
uv run --group examples marimo edit examples/synthetic/notebook.py

Continuous testing:

  • On every push: CI runs the whole suite on Ubuntu and macOS (.github/workflows/test.yml).
  • Every night: a run checks against the newest releases of swatplus-bmi, waterledger-models, flopy and MODFLOW 6 (nightly.yml).

Use

uv run python -m basinledger run examples/synthetic/surface.toml              # writes ledger.csv, series.csv, summary.json
uv run python -m basinledger run examples/synthetic/surface.toml --baseline   # the same without its water users
uv run python -m basinledger run examples/synthetic/two_way.toml --save-at 365 --save runs/warm
uv run python -m basinledger run examples/synthetic/two_way.toml --restart runs/warm --run scenario
uv run python -m basinledger status examples/synthetic/surface.toml           # calibrated, or a screening run
uv run python -m basinledger check examples/synthetic/sfr.toml                # every problem the start-up finds
uv run python -m basinledger forward basin.toml parameters.csv observations.csv simulated.csv --run-folder runs
uv run python -m basinledger run examples/synthetic/salt.toml --replay runs/flow-record   # the salt alone, from a record

A run with [replay] record = "runs/flow-record" in its config records its flow side; --replay (on run and forward) then runs only the salt from it, with the salt's settings and parameters changed and nothing else (docs/design.md, Replay).

forward is the forward model PEST++ runs. calibration.write_pest_files(basin.toml, parameters.csv, observations.csv, folder) writes the control file, the template and the instructions that call it.

Or from Python:

from basinledger.driver import Basin

b = Basin.from_config("examples/synthetic/basin.toml", run="pumping")
b.run()                       # every day of the SWAT+ project; the ledger checks each day
print(b.ledger.totals())      # m3 (and kg, MWh) per account for the whole run
b.finalize()

An example's config (abridged; the full schema is in src/basinledger/config.py):

[swatplus]
project = "{swatplus_refdata}/Osu_1hru"
# routing_fix = "muskingum_daily"  # optional: swatplus-bmi's fix for SWAT+'s daily Muskingum (rte_cha 1); off unset

[modflow6]
builder = "model:build"        # model.py writes the MODFLOW 6 simulation for the run's days

[recharge]
map = "all:aqu001"             # SWAT+ aquifers to MODFLOW 6 cells by area, or a CSV map

[[wells]]
name = "pw1"
cell = [0, 20, 28]             # layer, row, col; on a vertex grid (DISV), layer, icell2d

[[utilities]]
name = "city"
sources = [{route = "well:pw1", share = 1.0}]
losses = 0.10
outfall = "swat:point_source:wwtp"

[[users]]
name = "plant"
component = "basinledger.testing:SyntheticUser"   # or waterledger_models.datacenter.bmi:CoolingWaterBmi
withdrawal = "utility:city"
return = "utility:city"

[[rules]]
name = "plant well limit"
kind = "drawdown_limit"
user = "plant"
cell = [0, 20, 28]
head_min = 88.3
limit = 0.002

[weather]                      # optional: series written into SWAT+'s gage records, a CSV per variable
precipitation = "weather/pcp.csv"
change = {temperature = 2.0}   # a scenario's change, on the series or the project's own records

[groundwater_to_soil]          # optional: MODFLOW 6's water up into SWAT+'s soil layers (needs [recharge] source =
rule = "drain"                 #   "hru" and [exchange]); rule ("drain", "gwflow" or "water_table") and cap ("none"
cap = "none"                   #   or "room"; with water_table, "room" cuts the drain to the held layers' room) have
                               #   no default
package = "soil"               # a DRN package with one entry on each mapped cell
# held_lateral = "none"        # water_table only: "none" or "swatplus" (lateral flow from held layers); how far
# top_tolerance = 1.0          #   (m) MODFLOW 6's top may sit from the profile's bottom; each cell's land surface
# land_surface = "land.csv"    #   (land_m, and the cell as a map table gives it), else hru.con's elev per HRU;
                               #   or per map row (object and cell as [recharge] map has them, in its order),
# cell_land_surface = "cells.csv"  #   with each cell's whole land surface for the top check (partly covered cells)

[soil_cover]                   # optional: the soil cover SWAT+'s soil evaporation sees on the HRUs named
rule = "leaves"                #   "leaves" (leaves + residue) or "swat" (SWAT+'s own, set back: a check)
land_uses = ["frst_lum"]       #   and/or hrus = ["hru0001"]

A scenario changes the weather from a shared warm-up:

from basinledger import config as C
from basinledger.scenarios import run_case, warm_up

cfg = C.load("examples/synthetic/basin.toml")
state = warm_up(cfg, 365)
dry = run_case(cfg, state, "dry", change=lambda c: setattr(c, "weather", {"change": {"precipitation": 0.8}}))
dry.finalize()

Scenarios of water users are a TOML file beside the example: each scenario's users and changes, run alone and together, and compared with the baseline in tables for a paper (examples/synthetic/scenarios/data_centers.toml; docs/design.md, "Scenarios of water users"):

basinledger scenarios examples/synthetic/scenarios/data_centers.toml --workers 2

Drawdown in the synthetic example

The synthetic example: SWAT+'s Osu_1hru recharge drives a small MODFLOW 6 aquifer, and a synthetic user pumps one well. Drawdown is the difference from the same run without the user.

Water users

Any BMI component that reports its withdrawal, consumption and return can be a water user. Its gain, storage, constituent loads, return temperature and electricity are optional. A component that uses its own variable names is mapped role by role in the config. The engine checks each user's balance every step: withdrawal + gain = consumption + return + change in storage. It then integrates the hourly rates into the daily volumes the hydrologic models take. A user drawing from a SWAT+ intake that falls short uses only the share it got, and returns that share the next day. See docs/design.md.

What the tests check

What How
Hourly to daily daily volumes equal hourly rates integrated by hand; masses summed, temperature flow-weighted
A user's balance closes every hour; a component that loses water is refused
Any component plugs in a renamed component with other units, and CoolingWaterBmi, mapped by role
Area maps volume kept exactly; over-covered cells and mismatched areas refused
Vertex grids maps, wells, heads and rules by layer, icell2d; a cell in the other grid's form, outside the grid or inactive refused; a refined grid's budget closes every day and matches the ledger, with transport's mass closing; a uniform DISV grid gives the structured grid's run
MODFLOW 6 control values set between prepare and solve are the ones MODFLOW 6 uses; daily steps enforced; a solve that returns non-finite heads stops the run at once
Recharge sent = received every day, against MODFLOW 6's budget file and SWAT+'s own printed recharge
Recharge by HRU pixels split exactly among cells; each HRU's percolation × its SWAT+ area reaches its own cells and no other, every day; the total equals SWAT+'s own aquifer recharge every day
Wells pumped = requested = the user's withdrawal, every day
MODFLOW 6's budget closes every day to 1e-7 of the gross flow, with and without pumping
Physics pumping draws down most at the well, and depletes the river by less than it pumps, more over time
Surface routes SWAT+ takes what was asked (or reports the shortfall); the channel's flow changes the same day by what the users put in and took out
Intakes several on one channel, through the file's second point of diversion: the senior gets its demand or the day's outflow, the junior its demand of the rest; the route pairs close, nothing overdrawn, and the channel loses exactly what they took. On a reservoir, its daily balance closes with what they took. A short intake's user returns its delivered share the next day, never more than it got
Returns to the ground a house pumping its well and returning 80% to a drainfield: the field gets exactly the return each day, MODFLOW 6's budget closes, and against the same house returning offsite, the capture analysis puts the difference in the returns with no residual
Water systems a town drawing from an intake up to its capacity, then a well: customers by month, septic and leaks to the ground, a data center on it, and a second system reusing its plant's effluent; each day scaled by the share its sources delivered, returns the next day, every pair closing
Irrigation from streams SWAT+'s own irrigation from its channel: what the channel gave = what the HRU took = what reached the field + the loss, every day; the whole-basin balance's channels close with it
Utility chain production = delivery + losses = the sum of its sources; sewer = plant outfall
Rules act on exactly the days after the trigger; a curtailed user takes nothing; dry mode uses less water and more electricity
Two-way exchange SWAT+'s aquifer returns nothing and stores exactly its recharge; each day's river exchange reaches SWAT+ the next day, whole
SFR from channel lines reaches in order downstream with the line's length kept, on structured and vertex grids; chained within each channel; the package the exchange takes; a streambed rising downstream, a flat one and other units refused
Checked before a run a good example has no problems; several mistakes are each listed, and what depends on them isn't; a run still stops at the first; a run's start-up hooks (prepare, parameters, wrapper, heads) are checked with it
Lakes at a fixed stage the lake gains and loses; MODFLOW 6's lake term is the ledger's every day and reaches SWAT+ the next day in its outlet channel's exchange; the whole basin closes; no more taken than the channel has, with RIV and with SFR; refusals at start-up; a lake that exchanges nothing leaves the plain run bit for bit; restarts bit for bit
Through SFR a channel's water in at its top reach; no reach loses more than it carries; MODFLOW 6's budget closes and its SFR term is the exchange; reaches between channels, other units and storage refused; restarts bit for bit
Groundwater transport each species' mass closes every day; uniform recharge concentration reaches every cell at steady state; a column matches Ogata and Banks (1961) within 1% of C0; a well's user takes in the aquifer's concentration a day later
Nitrate and phosphorus across links with SWAT+ two-way, mass closes every day with decay and with sorption; the sorbed store's change is the ledger's sorbed release; each link's mass as sent and received, every day: recharge is SWAT+'s leached mass (and, for nitrate, its own aquifer recharge mass), placed on the cells its water goes to in the same shares; a gain's mass arrives in the channel; a loss takes the channel's own concentration and its mass reaches the aquifer; the soil link's mass is what left the cells; SWAT+'s aquifers send no nitrate or P; the steady start matches the transport model's own long run; restarts bit for bit
Conservation across links recharge keeps the surface model's volume; a channel never loses more than it carries; water from outside and the release from storage booked; wrong coupling settings refused at start-up
The whole basin SWAT+'s land, channel and lake budgets, the links and MODFLOW 6's close together over a run
Capture a well's pumping equals the extra release from storage, the water the streams lose and the extra boundary inflow, every day
Depletion MODFLOW 6 through the coupling within 2% of Glover and Balmer (1954) for a well beside a straight river
Stream temperature each reach's heat balance closes; a return mixes at its own temperature
Salt for each of two species, the land's store, every water body and the whole system (with GWT's storage) close every day; conductance from both species; each calendar year's road salt and each source's amount applied whole, on its days; multipliers scale an input group's mass; land to streams, recharge to GWT, the streams' losses to the aquifer's source and the soil link sent = received; the precipitation's concentration (raised by evapotranspiration, as the chloride mass balance has it) and a uniform inflow concentration reached at steady state; recharge mass placed on the cells as the water is; a pulse of road salt arrives in the stream and the rest stays in the land and the aquifer, the difference from a run without it adding to the pulse every day; gains reach the stream the next day; lakes at a fixed stage carry it; restarts bit for bit
Replay from a float64 record, the coupled run's concentrations, salt, transport and user lines bit for bit every day (dry cells too); from float32, within 1e-6; a salt multiplier changes only the salt; porosity and weathering may change; a SWAT+ or MODFLOW 6 parameter, the flow model's files, the users, starting heads or too many days refused; restarts bit for bit, from a replay's state or a full run's; a recording run restarted carries its record on day for day; the forward model replays
Weather a series equal to the files' records gives the files' run bit for bit; a run's first days are written into its files, other columns kept; a change reaches SWAT+'s records from the run's first day; a case from a warm-up takes its own weather from the first day that can be set; users read the series; a series that ends early stops the run
Groundwater into the soil for each rule and cap, what leaves MODFLOW 6's cells is what SWAT+'s layers receive the next day; the whole basin closes; a restart carries what is due; a water table below every profile changes nothing, bit for bit
Recirculation net recharge is gross less what came up; the groups add up and the split follows the soil's water; each HRU's sums agree with the ledger; the ledger is the same to the bit with the table on; a restart carries the sums
Stage floor a floor that never binds gives the same run to the bit; a floor above the stage holds cell by cell as the ledger and the CSV say; the basin closes; bad settings refused
Soil cover SWAT+'s own cover set back gives the same run to the bit; leaves and residue on a forest raise soil evaporation and the water balance still closes; HRUs by name and land use; refused without swatplus-bmi 0.16.0
Water-table link layers held below the table from the bottom up and released below their bottom; the drain fills them, rain on a full profile spills as saturation excess, and what the held layers can't take goes back as recharge, never above the table; with cap = "room" a full profile draws nothing from MODFLOW 6 and room opens the drain again, without flapping; each piece of a cell on its own land surface; recirculation counted once; the basin closes; a restart bit for bit
Routing fix the setting reaches swatplus-bmi's start file and SWAT+ routes a Muskingum channel differently; unset, no start file; refused before swatplus-bmi 0.18.0; a restart against another setting refused, with the same one bit for bit
Restarts and scenarios saved after a warm-up and carried on, runs match unbroken runs bit for bit; a case with no change matches the baseline
Start-up warnings soils that start empty, and a warm-up whose soils haven't settled, are warned of, not stopped
Command line, calibration outputs and status written; statistics on known values; the forward model writes simulated values at observations
Calibration parameters SWAT+ changes reach the run's calibration.cal after the project's own rows, and changes SWAT+ wouldn't make are refused; MODFLOW 6 multipliers everywhere, by layer and by zone, on arrays and list packages (SFR's bed included); a zero change and a multiplier of one give the plain coupled run bit for bit; restarts with parameters match; PEST++ files' template, instructions and control data agree

Prior work

Earlier SWAT and SWAT+ couplings with MODFLOW either compile MODFLOW-NWT into one program (SWAT-MODFLOW, SWAT+MODFLOW) or use SWAT+'s own gwflow module. See docs/prior-art.md.

Citing

Cite the archived software, doi:10.5281/zenodo.23967791 (all versions; 0.1.0 is doi:10.5281/zenodo.23967792), and, where SWAT+ is used, swatplus-bmi (doi:10.5281/zenodo.23963201). Details in CITATION.cff.

AI use

Basin Ledger was designed and directed by Andrew Sommerlot and built with an AI coding assistant (Claude, by Anthropic), which wrote most of the code, tests and documentation under his direction and review.

Contact

Basin Ledger is built by Northline Hydrology. To work on an example or an open problem, write to Andrew Sommerlot at andrew@northlinehydrology.com or open an issue.

License

BSD 3-Clause (LICENSE). SWAT+ is under the GNU LGPL 2.1 and runs as its own process through swatplus-bmi. MODFLOW 6 is public domain (USGS).

Metadata

Release files for basinledger 0.20.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for basinledger 0.20.0
File Size Uploaded Provenance Actions
basinledger-0.20.0.tar.gz 2.0 MB With provenance Details for basinledger-0.20.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for basinledger 0.20.0
File Actions
basinledger-0.20.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for basinledger-0.20.0-py3-none-win_amd64.whl
basinledger-0.20.0-py3-none-manylinux_2_34_x86_64.whl Python 3 none Linux glibc 2.34+ x86-64 Details for basinledger-0.20.0-py3-none-manylinux_2_34_x86_64.whl
basinledger-0.20.0-py3-none-macosx_14_0_arm64.whl Python 3 none macOS 14.0+ ARM64 Details for basinledger-0.20.0-py3-none-macosx_14_0_arm64.whl
basinledger-0.20.0-py3-none-any.whl Python 3 none any Details for basinledger-0.20.0-py3-none-any.whl

Total release size: 14.3 MB

Release files / basinledger-0.20.0.tar.gz

Download URL basinledger-0.20.0.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
4a5484006513ce751d3e05dd294fb68d5da4e0e964b2b9690812b7337cd851a7
BLAKE2b-256 checksum
How to use checksums
4bee5327d19683b4643aa0772d225ffe5657b65b7d36e279dcc946fc8f375254
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / basinledger-0.20.0-py3-none-win_amd64.whl

Download URL basinledger-0.20.0-py3-none-win_amd64.whl
Size 4.4 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
f193e3f463f2afe1523d222b9b34c53d46df64cfb6518f35ea1ee17b72cc6fb5
BLAKE2b-256 checksum
How to use checksums
9c10abc853cacad2c7875fb4ad88903c65fbbcf71dec8b66d05f8f9a7671f0f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / basinledger-0.20.0-py3-none-manylinux_2_34_x86_64.whl

Download URL basinledger-0.20.0-py3-none-manylinux_2_34_x86_64.whl
Size 5.1 MB
Tags Linux glibc 2.34+ x86-64 Python 3
SHA-256 checksum
How to use checksums
8a53f7c4ea2d531a7890f32587b1ebd5d79ab0bcf993bad4c52813cf69523582
BLAKE2b-256 checksum
How to use checksums
52f81c0a24f7e7d43813c6d8b61cad40c77bdff0301c29fe8c93b1f5247a215f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / basinledger-0.20.0-py3-none-macosx_14_0_arm64.whl

Download URL basinledger-0.20.0-py3-none-macosx_14_0_arm64.whl
Size 2.6 MB
Tags Python 3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
ed393f2a5412e8534c9533fa6595af5b1c1395fa180fe3ed5cda3e79d79fd716
BLAKE2b-256 checksum
How to use checksums
bbb23c605b84e8e7078fc096dd76b045e0e8939918297c624f9d69e93489953f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / basinledger-0.20.0-py3-none-any.whl

Download URL basinledger-0.20.0-py3-none-any.whl
Size 317.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1b69121f09935262fc5cd100a89bde108b3e24a6e7795d909520f2d6be002aa
BLAKE2b-256 checksum
How to use checksums
8a1cb1b1188b96019aee45dad34e125cdc8fc8ab45998ab23d1492623a45f500
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for basinledger 0.20.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for basinledger-0.20.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page