From 44660a15914d0b93bfc82f9473220f48b4fb7608 Mon Sep 17 00:00:00 2001 From: Cinzia Mazzetti Date: Wed, 3 Apr 2024 15:41:15 +0000 Subject: [PATCH] Added dynamic test for inflow --- tests/test_dyn_inflow.py | 54 ++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/tests/test_dyn_inflow.py b/tests/test_dyn_inflow.py index ff9f436..21470c3 100644 --- a/tests/test_dyn_inflow.py +++ b/tests/test_dyn_inflow.py @@ -18,73 +18,95 @@ class TestInflow(): case_dir = os.path.join(os.path.dirname(__file__), 'data', 'LF_ETRS89_UseCase') def run(self, date_start, date_end, dtsec, type): - # generate inflow (inflow.tss) + # generate inflow (inflow.tss) one pixel upstream of inflow point + out_path_ref = os.path.join(self.case_dir, 'reference_dyn') out_path_run = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type) settings_file = os.path.join(self.case_dir, 'settings', 'inflow.xml') settings = setoptions(settings_file, - opts_to_unset = ['inflow','SplitRouting'], + opts_to_unset = ['inflow'], vars_to_set={'StepStart': date_start, 'StepEnd': date_end, 'CalendarDayStart': date_start, 'DtSec' : dtsec, + # 'DtSecChannel' : dtsec, # single routing step 'MaskMap': '$(PathRoot)/maps/mask.map', - 'Gauges': '4317500 2447500', # one cell upstream of output + # 'Gauges': '4317500 2447500 4322500 2447500 4322500 2442500', + 'Gauges': '4317500 2447500', # one cell upstream of inflow point 'ChanqTS': out_path_run+'/inflow.tss', 'PathOut': out_path_run}) + mk_path_out(out_path_ref) mk_path_out(out_path_run) lisfloodexe(settings) - # generate control run + # generate control run at inflow point out_path_run = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type) settings_file = os.path.join(self.case_dir, 'settings', 'inflow.xml') settings = setoptions(settings_file, - opts_to_unset = ['inflow', 'SplitRouting'], + opts_to_unset = ['inflow'], vars_to_set={'StepStart': date_start, 'StepEnd': date_end, 'CalendarDayStart': date_start, 'DtSec' : dtsec, + # 'DtSecChannel': dtsec, # single routing step 'MaskMap': '$(PathRoot)/maps/mask.map', + # 'Gauges': '4322500 2447500 4322500 2442500', + # 'Gauges': '4322500 2447500 4447500 2422500', # inflow and outlet + 'Gauges': '4322500 2447500', # inflow point 'PathOut': out_path_run}) # mk_path_out(out_path_run) lisfloodexe(settings) - # run with inflow from dynamic reference + # run with inflow from dynamic reference and generate outflow at inflow point out_path_ref = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type) out_path_run = os.path.join(self.case_dir, self.run_type) settings_file = os.path.join(self.case_dir, 'settings', 'inflow.xml') settings = setoptions(settings_file, opts_to_set=['inflow'], - opts_to_unset=['SplitRouting'], + # opts_to_unset=['SplitRouting'], vars_to_set={'StepStart': date_start, 'StepEnd': date_end, 'CalendarDayStart': date_start, 'DtSec' : dtsec, + # 'DtSecChannel': dtsec, # single routing step 'MaskMap': '$(PathRoot)/maps/intercatchment_mask.map', 'InflowPoints': '$(PathRoot)/maps/inflow_point_1.nc', 'QInTS': out_path_ref+'/inflow.tss', + # 'Gauges': '4322500 2447500 4322500 2442500', + # 'Gauges': '4322500 2447500 4447500 2422500', # inflow and outlet + 'Gauges': '4322500 2447500', # inflow point 'PathOut': out_path_run}) mk_path_out(out_path_run) lisfloodexe(settings) - comparator = TSSComparator() - reference = os.path.join(out_path_ref, 'dis.tss') - output_tss = os.path.join(out_path_run, 'dis.tss') + # set precisioon for the test + atol = 3. + rtol = 0.005 + comparator = TSSComparator(atol,rtol) + + # test when DtSec = DtSecChannel + # reference = os.path.join(out_path_ref, 'dis.tss') + # output_tss = os.path.join(out_path_run, 'dis.tss') + + # test when DtSec != DtSecChannel + reference = os.path.join(out_path_ref, 'chanqWin.tss') + output_tss = os.path.join(out_path_run, 'chanqWin.tss') + comparator.compare_files(reference, output_tss) def teardown_method(self): print('Cleaning directories') - # ref_path = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type) - # shutil.rmtree(ref_path, ignore_errors=True) - # out_path = os.path.join(self.case_dir, self.run_type) - # shutil.rmtree(out_path, ignore_errors=True) + ref_path = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+ str(type)) + shutil.rmtree(ref_path, ignore_errors=True) + out_path = os.path.join(self.case_dir, self.run_type) + shutil.rmtree(out_path, ignore_errors=True) class TestInflowShort(TestInflow): run_type = 'short' - # def test_inflow_6h(self): - # self.run("01/03/2016 06:00", "30/03/2016 06:00", 21600,'6h') + def test_inflow_6h(self): + self.run("01/03/2016 06:00", "30/03/2016 06:00", 21600,'6h') def test_inflow_daily(self): self.run("02/01/2016 06:00", "30/01/2016 06:00", 86400,'daily')