Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Fix a bug when the csv file of qobs start or end with start_time or end_time #146

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
5 changes: 3 additions & 2 deletions smash/core/model/_read_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,20 @@ def _read_qobs(setup: SetupDT, mesh: MeshDT, input_data: Input_DataDT):
f"is not a valid date"
) from None

file_end_time = file_start_time + pd.Timedelta(seconds=setup.dt * len(dat))
file_end_time = file_start_time + pd.Timedelta(seconds=setup.dt * (len(dat) - 1))
start_diff = int((start_time - file_start_time).total_seconds() / setup.dt) + 1
end_diff = int((end_time - file_start_time).total_seconds() / setup.dt) + 1

# % Check if observed discharge file contains data for corresponding simulation period
if start_time > file_end_time or end_time < file_start_time:
if start_diff > dat.index.max() or end_diff < 0:
warnings.warn(
f"The provided observed discharge file for catchment '{c}' does not contain data for the "
f"selected simulation period ['{start_time}', '{end_time}']. The file covers the period "
f"['{file_start_time}', '{file_end_time}']",
stacklevel=2,
)
else:

ind_start_dat = max(0, start_diff)
ind_end_dat = min(dat.index.max(), end_diff)
ind_start_arr = max(0, -start_diff)
Expand Down
Loading