From 3780d1e06b4cb2989789fff60cd62686648cd88f Mon Sep 17 00:00:00 2001 From: Sean Horvath Date: Tue, 21 Nov 2023 16:43:09 +0000 Subject: [PATCH 1/3] fix checking for lite_restart and config test for lite_restart_directory --- src/troute-config/troute/config/config.py | 11 +++++++++++ src/troute-nwm/src/nwm_routing/__main__.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/troute-config/troute/config/config.py b/src/troute-config/troute/config/config.py index 0e5ae03cc..84301ed02 100644 --- a/src/troute-config/troute/config/config.py +++ b/src/troute-config/troute/config/config.py @@ -223,4 +223,15 @@ def check_flowpath_edge_list(cls, values): assert Path(flowpath_edge_list).suffix=='.json', "geo_file_path is json, but flowpath_edge_list is a different file type." return values + + @root_validator(skip_on_failure=True) + def check_lite_restart_directory(cls, values): + if values['output_parameters']: + lite_restart = values['output_parameters'].lite_restart + import pdb; pdb.set_trace() + if lite_restart is not None: + lite_restart_directory = lite_restart.lite_restart_output_directory + assert lite_restart_directory, "lite_restart is present in output parameters, but no lite_restart_output_directory is provided." + + return values \ No newline at end of file diff --git a/src/troute-nwm/src/nwm_routing/__main__.py b/src/troute-nwm/src/nwm_routing/__main__.py index baa575fcb..927c8474a 100644 --- a/src/troute-nwm/src/nwm_routing/__main__.py +++ b/src/troute-nwm/src/nwm_routing/__main__.py @@ -216,7 +216,7 @@ def main_v04(argv): data_assimilation.update_after_compute(run_results, dt*nts) # TODO move the conditional call to write_lite_restart to nwm_output_generator. - if output_parameters.get('lite_restart',{}).get('lite_restart_output_directory', None): + if output_parameters['lite_restart'] is not None: nhd_io.write_lite_restart( network.q0, network._waterbody_df, From 626f0b68aa75d8ca7121258cd188ccbf9ac9755d Mon Sep 17 00:00:00 2001 From: Sean Horvath Date: Tue, 21 Nov 2023 16:53:24 +0000 Subject: [PATCH 2/3] check that output_parameters exist first --- src/troute-nwm/src/nwm_routing/__main__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/troute-nwm/src/nwm_routing/__main__.py b/src/troute-nwm/src/nwm_routing/__main__.py index 927c8474a..789d5323f 100644 --- a/src/troute-nwm/src/nwm_routing/__main__.py +++ b/src/troute-nwm/src/nwm_routing/__main__.py @@ -216,13 +216,14 @@ def main_v04(argv): data_assimilation.update_after_compute(run_results, dt*nts) # TODO move the conditional call to write_lite_restart to nwm_output_generator. - if output_parameters['lite_restart'] is not None: - nhd_io.write_lite_restart( - network.q0, - network._waterbody_df, - t0 + timedelta(seconds = dt * nts), - output_parameters['lite_restart'] - ) + if output_parameters: + if output_parameters['lite_restart'] is not None: + nhd_io.write_lite_restart( + network.q0, + network._waterbody_df, + t0 + timedelta(seconds = dt * nts), + output_parameters['lite_restart'] + ) # Prepare input forcing for next time loop simulation when mutiple time loops are presented. if run_set_iterator < len(run_sets) - 1: From 903f9af0a0659c775cd0cc5f7a3cb6adfa319f9f Mon Sep 17 00:00:00 2001 From: Sean Horvath Date: Tue, 21 Nov 2023 16:54:44 +0000 Subject: [PATCH 3/3] delete pdb.set_trace() --- src/troute-config/troute/config/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/troute-config/troute/config/config.py b/src/troute-config/troute/config/config.py index 84301ed02..fc98a80df 100644 --- a/src/troute-config/troute/config/config.py +++ b/src/troute-config/troute/config/config.py @@ -228,7 +228,6 @@ def check_flowpath_edge_list(cls, values): def check_lite_restart_directory(cls, values): if values['output_parameters']: lite_restart = values['output_parameters'].lite_restart - import pdb; pdb.set_trace() if lite_restart is not None: lite_restart_directory = lite_restart.lite_restart_output_directory assert lite_restart_directory, "lite_restart is present in output parameters, but no lite_restart_output_directory is provided."