Environmental flows intelligence layer for taqsim.
Fishy provides tools for environmental flow analysis of water systems simulated with taqsim. It supports calculating IHA (Indicators of Hydrological Alteration) indices, comparing current flow regimes against natural baselines, and classifying regime alteration using DHRAM.
# Using uv (recommended)
uv add fishy
# Using pip
pip install fishyfrom fishy import naturalize, NATURAL_TAG
from taqsim.system import WaterSystem
from taqsim.edge import Edge
from taqsim.time import Frequency
# Build your water system with taqsim
system = WaterSystem(frequency=Frequency.DAILY)
# ... add nodes ...
# Tag edges on the natural flow path
system.add_edge(Edge(
id="river_reach",
source="upstream",
target="downstream",
tags=frozenset({NATURAL_TAG}), # Mark as natural
))
# Naturalize the system (remove human infrastructure)
result = naturalize(system)
# Use the naturalized system for IHA baseline
natural_system = result.system
print(result.summary())Transform water systems with human infrastructure into their natural state.
What it does:
- Removes non-natural edges (canals, diversions)
- Converts
Storagenodes toPassThrough(dams become river reaches) - Converts
Demandnodes toPassThrough(withdrawals removed) - Preserves natural river bifurcations with
NaturalRiverSplitter
Key exports:
naturalize(system)— Main transformation functionNATURAL_TAG— Tag constant for marking natural edgesNATURAL_SPLIT_RATIOS— Metadata key for mixed splitter natural ratiosNaturalRiverSplitter— Split rule for natural bifurcationsNaturalizeResult— Result with system + audit trail
from fishy.naturalize import (
naturalize,
NATURAL_TAG,
NATURAL_SPLIT_RATIOS,
NaturalRiverSplitter,
NaturalizeResult,
NoNaturalPathError,
AmbiguousSplitError,
)For natural river bifurcations (like delta distributaries):
from fishy import NaturalRiverSplitter
# Fixed ratios
splitter_rule = NaturalRiverSplitter(
ratios={"main_channel": 0.6, "side_channel": 0.4}
)
# Time-varying ratios (seasonal)
splitter_rule = NaturalRiverSplitter(
ratios={
"main": (0.7, 0.6, 0.5, 0.5, 0.6, 0.7), # monthly
"side": (0.3, 0.4, 0.5, 0.5, 0.4, 0.3),
},
cyclical=True, # Repeat pattern
)For splitters with both natural and non-natural downstream edges, use NATURAL_SPLIT_RATIOS metadata instead of assigning a NaturalRiverSplitter policy directly:
from fishy import NATURAL_SPLIT_RATIOS
from taqsim.node import Splitter
# Splitter with 2 natural + 1 canal downstream
splitter = Splitter(
id="junction",
split_policy=operational_rule, # Your operational split rule
metadata={NATURAL_SPLIT_RATIOS: {"main_channel": 0.6, "side_channel": 0.4}},
)Ratio keys must be the direct downstream target node IDs on natural edges. During naturalization, the metadata is validated and a NaturalRiverSplitter is built automatically.
Compute the 33 IHA parameters (Richter et al., 1996) from daily flow timeseries.
Key exports:
compute_iha(q, dates)— Compute IHA parameters per calendar yeariha_from_reach(system, reach_id)— Bridge from taqsim Reach node to IHApulse_thresholds_from_record(q)— Derive pulse thresholds from flow recordIHAResult— Immutable result wrapping(n_years, 33)matrix
from fishy.iha import compute_iha, iha_from_reachClassify flow regime alteration using the Dundee Hydrological Regime Alteration Method (Black et al., 2005). Produces a 1–5 classification compatible with the EU Water Framework Directive.
Key exports:
compute_dhram(natural, impacted)— Classify from IHA resultsevaluate_dhram(natural_system, impacted_system)— Full pipeline from WaterSystem pairsDHRAMResult— Classification with full audit trail
from fishy.dhram import compute_dhram, evaluate_dhram# Install dependencies
uv sync
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=src/fishy --cov-report=term-missing
# Lint and format
uv run ruff check --fix
uv run ruff format
# Update taqsim to latest and sync its documentation
make sync-docs- Naturalize Module — Detailed documentation with examples
- IHA Module — IHA parameter computation
- DHRAM Module — Flow regime alteration classification
MIT
- taqsim — Water system simulation engine