Model evaluation¶
This example shows how to load model and observation data and evalute model performance.
In [ ]:
Copied!
# skip this if package has already been installed
!pip install modvis
# skip this if package has already been installed
!pip install modvis
In [1]:
Copied!
from modvis import ATSutils
from modvis import utils
from modvis import general_plots as gp
import matplotlib.pyplot as plt
model_dir = "../data/coalcreek"
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
In [2]:
Copied!
# import os
# if not os.path.exists(model_dir):
# !git clone https://github.com/pinshuai/modvis.git
# %cd ./modvis/examples/notebooks
# 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.
In [3]:
Copied!
simu_df = ATSutils.load_waterBalance(model_dir, WB_filename="water_balance-daily.dat",
plot = True)
simu_df = ATSutils.load_waterBalance(model_dir, WB_filename="water_balance-daily.dat",
plot = True)
Load observation data¶
In [4]:
Copied!
obs_df = utils.load_nwis(sites= "09111250", start = '2014-10-01')
obs_df = utils.load_nwis(sites= "09111250", start = '2014-10-01')
In [5]:
Copied!
obs_df.plot()
obs_df.plot()
Out[5]:
<AxesSubplot:>
Streamflow comparison¶
Compare simulated streamflow with observed USGS streamflow.
In [6]:
Copied!
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()
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()
Out[6]:
<matplotlib.legend.Legend at 0x7fd7c97556f0>
FDC comparison¶
Compare the simulated vs. observed flow duration curve.
In [7]:
Copied!
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"
)
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"
)
One-to-one plot¶
One to one scatter plot with metrics.
In [8]:
Copied!
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"
)
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"
)
Out[8]:
{'R^2': 0.8721059035985849,
'NSE': 0.8386136492066862,
'mKGE': 0.7947371500678737}
In [ ]:
Copied!