Skip to content

LSTM for learning streamflow prediction error of smash.

License

Notifications You must be signed in to change notification settings

nghi-truyen/lstm-smash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Training

python3 train.py -pm demo-data/model-p1.hdf5 -pn demo-net -e 120 -k 3 -bs 1024
usage: train.py [-h] [-pm PATH_FILEMODEL] [-pn PATH_NETOUT] [-e EPOCH] 
                     [-bs BATCH_SIZE] [-k KFOLD] [-o OPTIMIZER] [-l LOSS]

options:
  -h, --help            show this help message and exit
  -pm PATH_FILEMODEL, --path_filemodel PATH_FILEMODEL
                        Select the smash Model object
  -pn PATH_NETOUT, --path_netout PATH_NETOUT
                        [optional] Select the output directory for the trained neural network
  -e EPOCH, --epoch EPOCH
                        [optional] Select the number of epochs for training
  -bs BATCH_SIZE, --batch_size BATCH_SIZE
                        [optional] Select the batch size for training
  -k KFOLD, --kfold KFOLD
                        [optional] Select the number of folds for cross-validation
  -o OPTIMIZER, --optimizer OPTIMIZER
                        [optional] Select the optimization algorithm
  -l LOSS, --loss LOSS  [optional] Select the loss function for optimization

Prediction

python3 predict.py -pm demo-data/model-p2.hdf5 -pn demo-net -po bias-p2.csv
usage: predict.py [-h] [-pm PATH_FILEMODEL] [-pn PATH_NET] [-po PATH_FILEOUT] [-bs BATCH_SIZE]

options:
  -h, --help            show this help message and exit
  -pm PATH_FILEMODEL, --path_filemodel PATH_FILEMODEL
                        Select the smash Model object to correct
  -pn PATH_NET, --path_net PATH_NET
                        Select the trained neural network to correct the Model object
  -po PATH_FILEOUT, --path_fileout PATH_FILEOUT
                        [optional] Select path for the output file
  -bs BATCH_SIZE, --batch_size BATCH_SIZE
                        [optional] Select the batch size for predicting

Validation Results

import smash
import pandas as pd

def correct_bias(model: smash.Model, df: pd.DataFrame):
    model_correct = model.copy()
    q = model_correct.response.q

    for i, code in enumerate(model.mesh.code):
        if code in df.columns[1:]:
            q[i, df["timestep"].values] += df[code].values
            q[i, q[i]<0] = 0  # Handle negative values of corrected discharges

    return model_correct

df = pd.read_csv("bias-p2.csv")
model = smash.io.read_model("demo-data/model-p2.hdf5")
model_correct = correct_bias(model, df)
print("Original model KGE: ", smash.metrics(model, "kge"))
print("Corrected model KGE: ", smash.metrics(model_correct, "kge"))
Original model KGE:  [0.72716784 0.38292903 0.68023837 0.59912944]
Corrected model KGE:  [0.849549   0.65314811 0.84928393 0.77253556]

About

LSTM for learning streamflow prediction error of smash.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages