Skip to content

Commit

Permalink
fix an error in data_postprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
OuyangWenyu committed May 5, 2023
1 parent 61eb6f9 commit a2d49ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
6 changes: 3 additions & 3 deletions hydromodel/app/datapostprocess4calibrate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Wenyu Ouyang
Date: 2022-11-19 17:27:05
LastEditTime: 2022-12-25 09:14:33
LastEditTime: 2023-05-05 10:14:20
LastEditors: Wenyu Ouyang
Description: the script to postprocess calibrated models in hydro-model-xaj
FilePath: \hydro-model-xaj\hydromodel\app\datapostprocess4calibrate.py
Expand Down Expand Up @@ -135,7 +135,7 @@ def statistics(args):
"--exp",
dest="exp",
help="An exp is corresponding to one data setting",
default="exp61561",
default="example",
type=str,
)
parser.add_argument(
Expand All @@ -149,7 +149,7 @@ def statistics(args):
"--cv_fold",
dest="cv_fold",
help="The number of cross-validation fold",
default=2,
default=1,
type=int,
)
the_args = parser.parse_args()
Expand Down
30 changes: 10 additions & 20 deletions hydromodel/data/data_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,9 @@ def summarize_metrics(result_dir, model_info: dict):
test_metric = hydro_utils.unserialize_json(test_metric_file)

for key, value in train_metric.items():
if count == 0:
train_metrics[key] = value
else:
train_metrics[key] = train_metrics[key] + value
train_metrics[key] = value if count == 0 else train_metrics[key] + value
for key, value in test_metric.items():
if count == 0:
test_metrics[key] = value
else:
test_metrics[key] = test_metrics[key] + value
test_metrics[key] = value if count == 0 else test_metrics[key] + value
count = count + 1
metric_dfs_train = pd.DataFrame(train_metrics, index=basin_ids).transpose()
metric_dfs_test = pd.DataFrame(test_metrics, index=basin_ids).transpose()
Expand Down Expand Up @@ -205,35 +199,31 @@ def read_and_save_et_ouputs(result_dir, fold: int):
model_func_param = args["model"]
exp_dir = pathlib.Path(result_dir).parent
data_info_train = hydro_utils.unserialize_json(
exp_dir.joinpath("data_info_fold" + str(fold) + "_train.json")
exp_dir.joinpath(f"data_info_fold{fold}_train.json")
)
data_info_test = hydro_utils.unserialize_json(
exp_dir.joinpath("data_info_fold" + str(fold) + "_test.json")
exp_dir.joinpath(f"data_info_fold{fold}_test.json")
)
train_period = data_info_train["time"]
test_period = data_info_test["time"]
train_np_file = os.path.join(
exp_dir, "basins_lump_p_pe_q_fold" + str(fold) + "_train.npy"
)
test_np_file = os.path.join(
exp_dir, "basins_lump_p_pe_q_fold" + str(fold) + "_test.npy"
)
train_np_file = os.path.join(exp_dir, f"basins_lump_p_pe_q_fold{fold}_train.npy")
test_np_file = os.path.join(exp_dir, f"basins_lump_p_pe_q_fold{fold}_test.npy")
train_data = np.load(train_np_file)
test_data = np.load(test_np_file)
es_test = []
es_train = []
for i in range(len(basins_id)):
_, e_train = xaj(
train_data[:, :, 0:2],
train_data[:, i : i + 1, 0:2],
param_values[basins_id[i]].values.reshape(1, -1),
warmup_length=warmup_length,
**model_func_param
**model_func_param,
)
_, e_test = xaj(
test_data[:, :, 0:2],
test_data[:, i : i + 1, 0:2],
param_values[basins_id[i]].values.reshape(1, -1),
warmup_length=warmup_length,
**model_func_param
**model_func_param,
)
es_train.append(e_train.flatten())
es_test.append(e_test.flatten())
Expand Down

0 comments on commit a2d49ac

Please sign in to comment.