Skip to content

Commit 44660a1

Browse files
author
Cinzia Mazzetti
committed
Added dynamic test for inflow
1 parent 04914a4 commit 44660a1

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

tests/test_dyn_inflow.py

+38-16
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,95 @@ class TestInflow():
1818
case_dir = os.path.join(os.path.dirname(__file__), 'data', 'LF_ETRS89_UseCase')
1919

2020
def run(self, date_start, date_end, dtsec, type):
21-
# generate inflow (inflow.tss)
21+
# generate inflow (inflow.tss) one pixel upstream of inflow point
22+
out_path_ref = os.path.join(self.case_dir, 'reference_dyn')
2223
out_path_run = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type)
2324
settings_file = os.path.join(self.case_dir, 'settings', 'inflow.xml')
2425
settings = setoptions(settings_file,
25-
opts_to_unset = ['inflow','SplitRouting'],
26+
opts_to_unset = ['inflow'],
2627
vars_to_set={'StepStart': date_start,
2728
'StepEnd': date_end,
2829
'CalendarDayStart': date_start,
2930
'DtSec' : dtsec,
31+
# 'DtSecChannel' : dtsec, # single routing step
3032
'MaskMap': '$(PathRoot)/maps/mask.map',
31-
'Gauges': '4317500 2447500', # one cell upstream of output
33+
# 'Gauges': '4317500 2447500 4322500 2447500 4322500 2442500',
34+
'Gauges': '4317500 2447500', # one cell upstream of inflow point
3235
'ChanqTS': out_path_run+'/inflow.tss',
3336
'PathOut': out_path_run})
37+
mk_path_out(out_path_ref)
3438
mk_path_out(out_path_run)
3539
lisfloodexe(settings)
3640

37-
# generate control run
41+
# generate control run at inflow point
3842
out_path_run = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type)
3943
settings_file = os.path.join(self.case_dir, 'settings', 'inflow.xml')
4044
settings = setoptions(settings_file,
41-
opts_to_unset = ['inflow', 'SplitRouting'],
45+
opts_to_unset = ['inflow'],
4246
vars_to_set={'StepStart': date_start,
4347
'StepEnd': date_end,
4448
'CalendarDayStart': date_start,
4549
'DtSec' : dtsec,
50+
# 'DtSecChannel': dtsec, # single routing step
4651
'MaskMap': '$(PathRoot)/maps/mask.map',
52+
# 'Gauges': '4322500 2447500 4322500 2442500',
53+
# 'Gauges': '4322500 2447500 4447500 2422500', # inflow and outlet
54+
'Gauges': '4322500 2447500', # inflow point
4755
'PathOut': out_path_run})
4856
# mk_path_out(out_path_run)
4957
lisfloodexe(settings)
5058

51-
# run with inflow from dynamic reference
59+
# run with inflow from dynamic reference and generate outflow at inflow point
5260
out_path_ref = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type)
5361
out_path_run = os.path.join(self.case_dir, self.run_type)
5462
settings_file = os.path.join(self.case_dir, 'settings', 'inflow.xml')
5563
settings = setoptions(settings_file,
5664
opts_to_set=['inflow'],
57-
opts_to_unset=['SplitRouting'],
65+
# opts_to_unset=['SplitRouting'],
5866
vars_to_set={'StepStart': date_start,
5967
'StepEnd': date_end,
6068
'CalendarDayStart': date_start,
6169
'DtSec' : dtsec,
70+
# 'DtSecChannel': dtsec, # single routing step
6271
'MaskMap': '$(PathRoot)/maps/intercatchment_mask.map',
6372
'InflowPoints': '$(PathRoot)/maps/inflow_point_1.nc',
6473
'QInTS': out_path_ref+'/inflow.tss',
74+
# 'Gauges': '4322500 2447500 4322500 2442500',
75+
# 'Gauges': '4322500 2447500 4447500 2422500', # inflow and outlet
76+
'Gauges': '4322500 2447500', # inflow point
6577
'PathOut': out_path_run})
6678
mk_path_out(out_path_run)
6779
lisfloodexe(settings)
6880

69-
comparator = TSSComparator()
70-
reference = os.path.join(out_path_ref, 'dis.tss')
71-
output_tss = os.path.join(out_path_run, 'dis.tss')
81+
# set precisioon for the test
82+
atol = 3.
83+
rtol = 0.005
84+
comparator = TSSComparator(atol,rtol)
85+
86+
# test when DtSec = DtSecChannel
87+
# reference = os.path.join(out_path_ref, 'dis.tss')
88+
# output_tss = os.path.join(out_path_run, 'dis.tss')
89+
90+
# test when DtSec != DtSecChannel
91+
reference = os.path.join(out_path_ref, 'chanqWin.tss')
92+
output_tss = os.path.join(out_path_run, 'chanqWin.tss')
93+
7294
comparator.compare_files(reference, output_tss)
7395

7496
def teardown_method(self):
7597
print('Cleaning directories')
76-
# ref_path = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+type)
77-
# shutil.rmtree(ref_path, ignore_errors=True)
78-
# out_path = os.path.join(self.case_dir, self.run_type)
79-
# shutil.rmtree(out_path, ignore_errors=True)
98+
ref_path = os.path.join(self.case_dir, 'reference_dyn', 'inflow_'+ str(type))
99+
shutil.rmtree(ref_path, ignore_errors=True)
100+
out_path = os.path.join(self.case_dir, self.run_type)
101+
shutil.rmtree(out_path, ignore_errors=True)
80102

81103

82104
class TestInflowShort(TestInflow):
83105

84106
run_type = 'short'
85107

86-
# def test_inflow_6h(self):
87-
# self.run("01/03/2016 06:00", "30/03/2016 06:00", 21600,'6h')
108+
def test_inflow_6h(self):
109+
self.run("01/03/2016 06:00", "30/03/2016 06:00", 21600,'6h')
88110

89111
def test_inflow_daily(self):
90112
self.run("02/01/2016 06:00", "30/01/2016 06:00", 86400,'daily')

0 commit comments

Comments
 (0)