Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions val/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def stats(St,Sq,Vt,Vq,IDstr,figdir):
Rsqo=[]
KGEo=[]
RMSEo=[]
nRMSEo=[]
nBIASo=[]
rRMSEo=[]
no=[]
offkey=[]
if len(Sq)<10:
for Grp in Sq:
Sq_=Sq[Grp]
Expand Down Expand Up @@ -70,20 +74,40 @@ def stats(St,Sq,Vt,Vq,IDstr,figdir):
n=len(Vq_t)
no.append(n)
#RMSE
RMSE=np.sqrt((np.sum( Sq_ - Vq_t)**2)/n)
RMSE=np.sqrt((np.sum( (Sq_ - Vq_t)**2))/n)
RMSEo.append(RMSE)
offkey.append(Grp)
#nRMSE
NRMSE=RMSE/np.mean(Vq_t)
nRMSEo.append(NRMSE)
#nBIASo
BIAS= np.sum(Sq_ - Vq_t)/len( Vq_t)
nBIAS=BIAS/np.mean(Vq_t)
nBIASo.append(nBIAS)
#rRMSE
rRMSEo.append(np.sqrt(NRMSE**2-nBIAS**2))

else:
NSEo.append(EMPTY)
Rsqo.append(EMPTY)
KGEo.append(EMPTY)
no.append(EMPTY)
RMSEo.append(EMPTY)
offkey.append(EMPTY)
nRMSEo.append(EMPTY)
nBIASo.append(EMPTY)
rRMSEo.append(EMPTY)


validout={
"algorithm": np.array(['geobam','hivdi','metroman','momma']),
"algorithm": np.array([offkey]),
"NSE":NSEo[:],
"Rsq":Rsqo[:],
"KGE":KGEo[:],
"RMSE":RMSEo[:],
"nRMSE":nRMSEo[:],
"nBIAS":nBIASo[:],
"rRMSE":rRMSEo[:],
"n":no[:],
"t":St_
}
Expand Down Expand Up @@ -138,24 +162,40 @@ def stats(St,Sq,Vt,Vq,IDstr,figdir):
n=len(Vq_t)
no.append(n)
#RMSE
RMSE=np.sqrt((np.sum( Sq_ - Vq_t)**2)/n)
RMSE=np.sqrt((np.sum( (Sq_ - Vq_t)**2))/n)
RMSEo.append(RMSE)
offkey.append(Grp)
#nRMSE
NRMSE=RMSE/np.mean(Vq_t)
nRMSEo.append(NRMSE)
#nBIASo
BIAS= np.sum(Sq_ - Vq_t)/len( Vq_t)
nBIAS=BIAS/np.mean(Vq_t)
nBIASo.append(nBIAS)
#rRMSE
rRMSEo.append(np.sqrt(NRMSE**2-nBIAS**2))
else:
NSEo.append(EMPTY)
Rsqo.append(EMPTY)
KGEo.append(EMPTY)
no.append(EMPTY)
RMSEo.append(EMPTY)
offkey.append(EMPTY)
nRMSEo.append(EMPTY)
nBIASo.append(EMPTY)
rRMSEo.append(EMPTY)
validout={
"algorithm": np.array(['geobam_q_c','hivdi_q_c','metroman_q_c','momma_q_c','sad_q_c',
'geobam_q_uc','hivdi_q_uc','metroman_q_uc','momma_q_uc','sad_q_uc']),
"algorithm": np.array([offkey]),
"NSE":NSEo[:],
"Rsq":Rsqo[:],
"KGE":KGEo[:],
"RMSE":RMSEo[:],
"nRMSE":nRMSEo[:],
"nBIAS":nBIASo[:],
"rRMSE":rRMSEo[:],
"n":no[:],
"t":St_
}

return validout


39 changes: 28 additions & 11 deletions validation_confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,18 @@ def read_offline_data(self, offline_dir):
offline_file = f"{offline_dir}/{self.reach_id}_offline.nc"
off = Dataset(offline_file, 'r')
offline_data = {}
offline_data["geobam_q_c"] = off[convention_dict["bam_q_c"]][:].filled(np.nan)
offline_data["hivdi_q_c"] = off[convention_dict["hivdi_q_c"]][:].filled(np.nan)
offline_data["metroman_q_c"] = off[convention_dict["metro_q_c"]][:].filled(np.nan)
offline_data["momma_q_c"] = off[convention_dict["momma_q_c"]][:].filled(np.nan)
offline_data["sad_q_c"] = off[convention_dict["sads_q_c"]][:].filled(np.nan)
offline_data["geobam_q_uc"] = off[convention_dict["bam_q_uc"]][:].filled(np.nan)
offline_data["hivdi_q_uc"] = off[convention_dict["hivdi_q_uc"]][:].filled(np.nan)
offline_data["metroman_q_uc"] = off[convention_dict["metro_q_uc"]][:].filled(np.nan)
offline_data["momma_q_uc"] = off[convention_dict["momma_q_uc"]][:].filled(np.nan)
offline_data["sad_q_uc"] = off[convention_dict["sads_q_uc"]][:].filled(np.nan)
offline_data[convention_dict["bam_q_c"]] = off[convention_dict["bam_q_c"]][:].filled(np.nan)
offline_data[convention_dict["hivdi_q_c"]] = off[convention_dict["hivdi_q_c"]][:].filled(np.nan)
offline_data[convention_dict["metro_q_c"]] = off[convention_dict["metro_q_c"]][:].filled(np.nan)
offline_data[convention_dict["momma_q_c"]] = off[convention_dict["momma_q_c"]][:].filled(np.nan)
offline_data[convention_dict["sads_q_c"]] = off[convention_dict["sads_q_c"]][:].filled(np.nan)
offline_data[convention_dict["bam_q_uc"]] = off[convention_dict["bam_q_uc"]][:].filled(np.nan)
offline_data[convention_dict["hivdi_q_uc"]] = off[convention_dict["hivdi_q_uc"]][:].filled(np.nan)
offline_data[convention_dict["metro_q_uc"]] = off[convention_dict["metro_q_uc"]][:].filled(np.nan)
offline_data[convention_dict["momma_q_uc"]] = off[convention_dict["momma_q_uc"]][:].filled(np.nan)
offline_data[convention_dict["sads_q_uc"]] = off[convention_dict["sads_q_uc"]][:].filled(np.nan)
offline_data[convention_dict["consensus_q_c"]] = off[convention_dict["consensus_q_c"]][:].filled(np.nan)
offline_data[convention_dict["consensus_q_uc"]] = off[convention_dict["consensus_q_uc"]][:].filled(np.nan)
off.close()

if self.is_offline_valid(offline_data):
Expand Down Expand Up @@ -292,6 +294,9 @@ def validate(self):
"KGE": np.full((self.NUM_ALGOS), fill_value=-9999),
"RMSE": np.full((self.NUM_ALGOS), fill_value=-9999),
"n": np.full((self.NUM_ALGOS), fill_value=-9999),
"nRMSE":np.full((self.NUM_ALGOS), fill_value=-9999),
"nBIAS":np.full((self.NUM_ALGOS), fill_value=-9999),
"rRMSE":np.full((self.NUM_ALGOS), fill_value=-9999),
}
no_offline = False
# Check if there is data to validate
Expand Down Expand Up @@ -344,7 +349,7 @@ def write(self, stats, reach_id, gage_type):
t_v[:] = stats["t"]

a_v = out.createVariable("algorithm", 'S1', ("num_algos", "nchar"),)
a_v[:] = stringtochar(stats["algorithm"].astype("S16"))
a_v[:] = stringtochar(stats["algorithm"][0].astype("S16"))

nse_v = out.createVariable("NSE", "f8", ("num_algos",), fill_value=fill)
nse_v[:] = np.where(np.isclose(stats["NSE"], empty), fill, stats["NSE"])
Expand All @@ -358,6 +363,18 @@ def write(self, stats, reach_id, gage_type):
rmse_v = out.createVariable("RMSE", "f8", ("num_algos",), fill_value=fill)
rmse_v.units = "m^3/s"
rmse_v[:] = np.where(np.isclose(stats["RMSE"], empty), fill, stats["RMSE"])

nrmse_v = out.createVariable("nRMSE", "f8", ("num_algos",), fill_value=fill)
nrmse_v.units = "none"
nrmse_v[:] = np.where(np.isclose(stats["nRMSE"], empty), fill, stats["nRMSE"])

nb_v = out.createVariable("nBIAS", "f8", ("num_algos",), fill_value=fill)
nb_v.units = "none"
nb_v[:] = np.where(np.isclose(stats["nBIAS"], empty), fill, stats["nBIAS"])

rrmse_v = out.createVariable("rRMSE", "f8", ("num_algos",), fill_value=fill)
rrmse_v.units = "none"
rrmse_v[:] = np.where(np.isclose(stats["rRMSE"], empty), fill, stats["rRMSE"])

n_v = out.createVariable("testn", "f8", ("num_algos",), fill_value=fill)
n_v[:] = np.where(np.isclose(stats["n"], empty), fill, stats["n"])
Expand Down