Open in Colab

Model evaluation#

This example shows how to load model and observation data and evalute model performance.

# skip this if package has already been installed
!pip install modvis
from modvis import ATSutils
from modvis import utils
from modvis import general_plots as gp

import matplotlib.pyplot as plt

model_dir = "../data/coalcreek"

Download the sample data when running on Google Colab

# import os
# if not os.path.exists(model_dir):
#   !git clone https://github.com/pinshuai/modvis.git
#   %cd ./modvis/examples/notebooks

Load model data#

This will load the water_balance-daily.dat file generated from ATS model. The data file includes watershed variables including outlet discharge, ET, and etc.

simu_df = ATSutils.load_waterBalance(model_dir, WB_filename="water_balance-daily.dat",
                                plot = True)
../_images/e13fa18aa9870a1b617fc933ca2f90c715a59497ad08cfed9a322775f1cf404f.png

Load observation data#

obs_df = utils.load_nwis(sites= "09111250", start = '2014-10-01')
obs_df.plot()
<AxesSubplot:>
../_images/6fedcb8efccdb7486a7df434909b8a13187a7742e8d7f85778e148a68d33d807.png

Streamflow comparison#

Compare simulated streamflow with observed USGS streamflow.

fig,ax = plt.subplots(1,1, figsize=(8,4))
simu_df['watershed boundary discharge [m^3/d]'].plot(color = 'c',ax=ax, label= "simu_Q")
obs_df['Discharge [m^3/d]'].plot(color = 'k', ax=ax, label = "obs_Q")
ax.set_ylabel("Discharge [m^3/d]")
ax.legend()
<matplotlib.legend.Legend at 0x7fd7c97556f0>
../_images/935fe461316ed9f4896c16e7aed6e33c03bc9198f5cd51935b0a25f1b8c8dc71.png

FDC comparison#

Compare the simulated vs. observed flow duration curve.

fig, ax = gp.plot_FDC(dfs=[obs_df['Discharge [m^3/d]'], simu_df['watershed boundary discharge [m^3/d]']],
           labels=['obs_Q','simu_Q'], 
           colors=['k', 'c'],
           start_date="2016-10-01" 
           )
../_images/dfff1da7c610a4c937c4334858023c2008a7f09fbaf3e9f69ab9a721f15ac8cd.png

One-to-one plot#

One to one scatter plot with metrics.

gp.one2one_plot(obs_df['Discharge [m^3/d]'], simu_df['watershed boundary discharge [m^3/d]'],
               metrics=['R^2', 'NSE', 'mKGE'],
                # metrics='all',
               show_density=False,
                start_date="2016-10-01"
               )
{'R^2': 0.8721059035985849,
 'NSE': 0.8386136492066862,
 'mKGE': 0.7947371500678737}
../_images/204fb4fbb86f2cb64bbe6d4e7bfc68cc1fedc7025c65f95e8494ac22c6218064.png