Training¶
Use bakaano.neuralnet.train.train_streamflow_model for the canonical
training workflow.
Minimal working example¶
from bakaano.neuralnet.train import train_streamflow_model
model_path = train_streamflow_model(
working_dir="/path/to/working_dir",
study_area="/path/to/basin.shp",
train_start="1981-01-01",
train_end="2020-12-31",
grdc_netcdf="/path/to/GRDC.nc",
batch_size=32,
num_epochs=300,
learning_rate=1e-3,
routing_method="mfd",
area_normalize=True,
log_transform=True,
model_overwrite=True,
)
Train with station CSVs¶
model_path = train_streamflow_model(
working_dir="/path/to/working_dir",
study_area="/path/to/basin.shp",
train_start="1981-01-01",
train_end="2020-12-31",
grdc_netcdf=None,
csv_dir="/path/to/observed_csvs",
lookup_csv="/path/to/station_lookup.csv",
id_col="id",
lat_col="latitude",
lon_col="longitude",
date_col="date",
discharge_col="discharge",
file_pattern="{id}.csv",
batch_size=32,
num_epochs=300,
routing_method="mfd",
area_normalize=True,
)
Required inputs¶
Input |
Requirement |
|---|---|
|
Must contain aligned preprocessing outputs |
|
Basin shapefile in EPSG:4326 |
|
Must be fully covered by routed runoff and observations |
Observations |
Provide exactly one of |
Training outputs¶
{working_dir}/models/bakaano_model.keras{working_dir}/models/alpha_earth_scaler.pkl
Parameter guide¶
Parameter |
Guidance |
|---|---|
|
Start with 32-64 on GPU, 8-16 on CPU |
|
Typical range: 150-300 |
|
Lower if training is unstable |
|
|
|
Keep consistent between training and inference |
|
If |
|
Must match the routed runoff used to build predictors |
|
|
Optional routed rainfall¶
If runoff_output/rainfall_sparse_arrays.pkl exists and fully covers the
requested training period, Bakaano automatically appends routed rainfall as an
extra temporal feature channel. The TCN input channel count is inferred from
the prepared predictors, so runoff-only and runoff-plus-rainfall models are
both supported. A checkpoint trained with rainfall still requires rainfall at
inference time.
Common failure modes¶
Requested training dates are not covered by routed runoff.
Lookup CSV or station CSVs are missing required columns.
Observation files and routed runoff cover different date ranges.
A model trained with routed rainfall later receives only runoff during inference.