Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
OuyangWenyu committed May 19, 2024
2 parents 41171ce + 6ab8005 commit 051e210
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
20 changes: 11 additions & 9 deletions hydromodel/models/xaj.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Wenyu Ouyang
Date: 2021-12-10 23:01:02
LastEditTime: 2024-03-27 15:09:11
LastEditTime: 2024-05-19 11:41:06
LastEditors: Wenyu Ouyang
Description: Core code for XinAnJiang model
FilePath: /hydro-model-xaj/hydromodel/models/xaj.py
Expand Down Expand Up @@ -464,19 +464,20 @@ def sources5mm(
(fr_ds[-1], s_ds[-1]): state variables' final value;
all variables are numpy array
"""
# 由于Ki、Kg都是以24小时为时段长定义的,需根据时段长转换
# Convert Ki and Kg according to the time interval, as they are defined based on a 24-hour time interval
hours_per_day = 24
# 非整除情况,时段+1
# Non-divisible case, add 1 to the period
residue_temp = hours_per_day % time_interval_hours
if residue_temp != 0:
residue_temp = 1
period_num_1d = int(hours_per_day / time_interval_hours) + residue_temp
# 当kss+kg>1时,根式为偶数运算时,kss_period会成为复数,这里会报错;另外注意分母可能为0,kss不可取0
# 对kss+kg的取值进行限制
# When kss+kg>1, the square root becomes a complex number during even root calculation, which will cause an error here.
# Also, be aware that the denominator may be 0, kss cannot be 0.
# Restrict the value of kss+kg.
kss_period = (1 - (1 - (ki + kg)) ** (1 / period_num_1d)) / (1 + kg / ki)
kg_period = kss_period * kg / ki

# 流域最大点自由水蓄水容量深
# Maximum free water storage capacity depth of the basin
smm = sm * (1 + ex)
if s0 is None:
s0 = 0.50 * sm
Expand Down Expand Up @@ -601,7 +602,7 @@ def sources5mm(
rs = rs + rs_j
rss = rss + rss_j
rg = rg + rg_j
# 赋值s_d和fr_d到数组中,以给下一段做初值
# Assign s_d and fr_d to the arrays as initial values for the next segment
s_ds.append(s1_d)
fr_ds.append(fr_d)

Expand Down Expand Up @@ -744,6 +745,7 @@ def xaj(
model_name = kwargs.get("name", "xaj")
source_type = kwargs.get("source_type", "sources")
source_book = kwargs.get("source_book", "HF")
time_interval_hours = kwargs.get("time_interval_hours", 1)
pr_file = kwargs.get("param_range_file", None)
model_param_dict = read_model_param_dict(pr_file)
# params
Expand Down Expand Up @@ -830,7 +832,7 @@ def xaj(
)
elif source_type == "sources5mm":
(rs, ri, rg), (s, fr) = sources5mm(
pe, r, sm, ex, ki, kg, s0, fr0, book=source_book
pe, r, sm, ex, ki, kg, s0, fr0, time_interval_hours=time_interval_hours, book=source_book
)
else:
raise NotImplementedError("No such divide-sources method")
Expand All @@ -844,7 +846,7 @@ def xaj(
)
elif source_type == "sources5mm":
(rs, ri, rg), (s, fr) = sources5mm(
pe, r, sm, ex, ki, kg, s, fr, book=source_book
pe, r, sm, ex, ki, kg, s, fr, time_interval_hours=time_interval_hours, book=source_book
)
else:
raise NotImplementedError("No such divide-sources method")
Expand Down
2 changes: 2 additions & 0 deletions hydromodel/trainers/calibrate_sceua.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
"name": "xaj_mz",
"source_type": "sources5mm",
"source_book": "HF",
"time_interval_hours": 1,
}
if loss is None:
loss = {
Expand Down Expand Up @@ -204,6 +205,7 @@ def calibrate_by_sceua(
"name": "xaj_mz", # 模型
"source_type": "sources5mm",
"source_book": "HF",
"time_interval_hours": 1,
}
if algorithm is None:
algorithm = {
Expand Down
5 changes: 3 additions & 2 deletions test/test_calibrate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Author: Wenyu Ouyang
Date: 2024-03-22 17:45:18
LastEditTime: 2024-03-22 21:01:38
LastEditTime: 2024-05-19 11:57:04
LastEditors: Wenyu Ouyang
Description: Test case for calibrate
FilePath: \hydro-model-xaj\test\test_calibrate.py
FilePath: \hydromodel\test\test_calibrate.py
Copyright (c) 2023-2024 Wenyu Ouyang. All rights reserved.
"""

Expand Down Expand Up @@ -36,6 +36,7 @@ def test_calibrate_xaj_sceua(basins, p_and_e, qobs, warmup_length, db_dir):
"name": "xaj_mz",
"source_type": "sources",
"source_book": "HF",
"time_interval_hours": 1,
},
algorithm={
"name": "SCE_UA",
Expand Down
3 changes: 2 additions & 1 deletion test/test_data_visualize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Wenyu Ouyang
Date: 2022-10-25 21:16:22
LastEditTime: 2024-03-28 09:57:58
LastEditTime: 2024-05-19 11:57:19
LastEditors: Wenyu Ouyang
Description: Test for results visualization
FilePath: \hydromodel\test\test_data_visualize.py
Expand Down Expand Up @@ -75,6 +75,7 @@ def test_show_calibrate_sceua_result(p_and_e, qobs, warmup_length, db_name, basi
"name": "xaj_mz",
"source_type": "sources",
"source_book": "HF",
"time_interval_hours": 1,
},
algorithm={
"name": "SCE_UA",
Expand Down

0 comments on commit 051e210

Please sign in to comment.