From 04914a4d0f39a4257c89c6f456fb1204bf44d6a9 Mon Sep 17 00:00:00 2001 From: Cinzia Mazzetti Date: Wed, 27 Mar 2024 19:40:55 +0000 Subject: [PATCH] added dynamic test for inflow --- tests/test_dyn_inflow.py | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/test_dyn_inflow.py diff --git a/tests/test_dyn_inflow.py b/tests/test_dyn_inflow.py new file mode 100644 index 00000000..ff9f436f --- /dev/null +++ b/tests/test_dyn_inflow.py @@ -0,0 +1,99 @@ +from __future__ import absolute_import +import os +import datetime +import shutil +import pytest + +from lisfloodutilities.compare.nc import NetCDFComparator +from lisfloodutilities.compare.pcr import TSSComparator + +from lisflood.main import lisfloodexe +from lisflood.global_modules.settings import LisSettings + +from .test_utils import setoptions, mk_path_out + + +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) + 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'], + vars_to_set={'StepStart': date_start, + 'StepEnd': date_end, + 'CalendarDayStart': date_start, + 'DtSec' : dtsec, + 'MaskMap': '$(PathRoot)/maps/mask.map', + 'Gauges': '4317500 2447500', # one cell upstream of output + 'ChanqTS': out_path_run+'/inflow.tss', + 'PathOut': out_path_run}) + mk_path_out(out_path_run) + lisfloodexe(settings) + + # generate control run + 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'], + vars_to_set={'StepStart': date_start, + 'StepEnd': date_end, + 'CalendarDayStart': date_start, + 'DtSec' : dtsec, + 'MaskMap': '$(PathRoot)/maps/mask.map', + 'PathOut': out_path_run}) + # mk_path_out(out_path_run) + lisfloodexe(settings) + + # run with inflow from dynamic reference + 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'], + vars_to_set={'StepStart': date_start, + 'StepEnd': date_end, + 'CalendarDayStart': date_start, + 'DtSec' : dtsec, + 'MaskMap': '$(PathRoot)/maps/intercatchment_mask.map', + 'InflowPoints': '$(PathRoot)/maps/inflow_point_1.nc', + 'QInTS': out_path_ref+'/inflow.tss', + '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') + 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) + + +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_daily(self): + self.run("02/01/2016 06:00", "30/01/2016 06:00", 86400,'daily') + + +# @pytest.mark.slow +# class TestInflowLong(TestInflow): +# +# run_type = 'long' +# +# def test_inflow_short(self): +# self.run("02/01/1986 00:00", "01/01/2018 00:00")