Skip to content

Commit

Permalink
enhance the ability to auto fix missing parameters in df_state
Browse files Browse the repository at this point in the history
  • Loading branch information
sunt05 committed Jul 4, 2024
1 parent f2212f3 commit 69bfbdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/supy/_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def check_state(df_state: pd.DataFrame, fix=True) -> List:
# these variables dont have to be checked
list_var_exclude = [
"ts5mindata_ir",
"metforcingblock",
"len_sim",
]

# variables defined in the rule json file:
Expand Down Expand Up @@ -383,7 +385,7 @@ def upgrade_df_state(df_state: pd.DataFrame) -> pd.DataFrame:
from ._supy_module import init_supy

# load base df_state
path_SampleData = Path(trv_supy_module) / "sample_run"
path_SampleData = trv_supy_module.joinpath("sample_run")
path_runcontrol = path_SampleData / "RunControl.nml"
df_state_base = init_supy(path_runcontrol, force_reload=False)

Expand Down
10 changes: 7 additions & 3 deletions src/supy/_supy_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def run_supy(
logging_level=logging.INFO,
check_input=False,
serial_mode=False,
debug_mode=False,
debug_mode=False, # TODO: #275 to be implemented to enable debug mode
) -> Tuple[pandas.DataFrame, pandas.DataFrame]:
"""Perform supy simulation.
Expand Down Expand Up @@ -337,12 +337,16 @@ def run_supy(
"SuPy stopped entering simulation due to invalid forcing!"
)
# initial model states:
list_issues_state = check_state(df_state_init)
if isinstance(list_issues_state, list):
res_check_state = check_state(df_state_init)
if isinstance(res_check_state, list):
logger_supy.critical(f"`df_state_init` is NOT valid to initialise SuPy!")
raise RuntimeError(
"SuPy stopped entering simulation due to invalid initial states!"
)
else:
logger_supy.info(f"SuPy simulation is starting ...")
if isinstance(res_check_state, pd.DataFrame):
df_state_init = res_check_state

# set up a timer for simulation time
start = time.time()
Expand Down

0 comments on commit 69bfbdc

Please sign in to comment.