-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cinzia Mazzetti
committed
Mar 27, 2024
1 parent
51f9f3c
commit 04914a4
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |