Accompanying code for the paper "Rainfall–Runoff Prediction at Multiple Timescales with a Single Long Short-Term Memory Network"
Gauch, M., Kratzert, F., Klotz, D., Nearing, G., Lin, J., and Hochreiter, S.:
Rainfall--Runoff Prediction at Multiple Timescales with a Single Long Short-Term Memory Network, 2020.
The code in this repository, together with the neuralhydrology
Python package, was used to produce all results and figures in our paper.
If you want to play around and train models yourself, we recommend taking a look at the neuralhydrology documentation, which also contains some tutorials on how to get started.
results_analysis.ipynb
-- Jupyter notebook to reproduce tables and figures from the paperodelstm-analysis.ipynb
-- Jupyter notebook to reproduce our results on time-continuous predictionenvironment.yml
-- Conda environment used to train and evaluate the modelsconfigs/
-- configuration files to train the models from scratchresults/
-- Folder to place ensembled model predictions used inresults-analysis.ipynb
(available on Zenodo, see below)data/datadir/
-- Folder to place datasets (see below on where to obtain the data)
- Create the conda environment:
conda env create -f environment.yml
- Activate the environment:
conda activate pytorch
- Install the neuralhydrology package:
pip install https://github.com/neuralhydrology/neuralhydrology/archive/9626578.zip
(for the most up-to-date version, use the installation instructions on the neuralhydrology documentation). - Download the following data:
- the CAMELS US dataset (CAMELS time series meteorology, observed flow, meta data, version 1.2) from NCAR into
data/datadir/CAMELS_US
. - for experiments with Maurer forcings, we use an extended forcings set available on HydroShare. Place this dataset in the folder
data/datadir/CAMELS_US/basin_mean_forcing/maurer_extended
. - the hourly NLDAS forcings and USGS streamflow data from Zenodo (data). We recommend using the combined NetCDF file, but you can also use the csv files (but it will take much longer to load the data). Place this NetCDF file in the folder
data/datadir/CAMELS_US/hourly
.
- the CAMELS US dataset (CAMELS time series meteorology, observed flow, meta data, version 1.2) from NCAR into
- If you don't want to train models yourself but use pre-trained models or simply run the Jupyter notebooks that analyze the results, you find the trained models and their predictions on Zenodo (models).
The folder configs/
contains one configuration .yml file for each model. To train models from scratch, use these configuration files. If you wish to use pretrained models, download them from Zenodo (see above). Then follow these steps:
- Activate the conda environment:
conda activate pytorch
- Start training with
nh-run train --config-file config.yml
(unless you use pretrained models) - Start the inference and evaluation with
nh-run evaluate --run-dir <run directory> --period test
(to evaluate on the validation period, use--period validation
)
To average the predictions of a number of runs (located in $DIR1
, $DIR2
, ...) into one ensemble prediction, calculate the ensemble's metrics (NSE, MSE, ...), and store the results in $RESULTS_FILE
, run:
nh-results-ensemble --run-dirs $DIR1 $DIR2 ... --period test --save-file $RESULTS_FILE --metrics NSE MSE ...
.
Martin Gauch: gauch (at) ml.jku.at
@article{Gauch2020mtslstm,
author = {Gauch, Martin and Kratzert, Frederik and Klotz, Daniel and Nearing, Grey and Lin, Jimmy and Hochreiter, Sepp},
title = {Rainfall--Runoff Prediction at Multiple Timescales with a Single Long Short-Term Memory Network},
journal = {n/a},
volume = {n/a},
number = {n/a},
pages = {},
doi = {n/a}
}