Skip to content

Commit

Permalink
Added dynamic test for inflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinzia Mazzetti committed Apr 3, 2024
1 parent 04914a4 commit 44660a1
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions tests/test_dyn_inflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 44660a1

Please sign in to comment.