Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
domeniconappo committed Sep 5, 2019
1 parent ab02797 commit d8ce51f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
16 changes: 9 additions & 7 deletions src/lisflood/global_modules/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from pandas._libs.tslibs.parsing import parse_time_string
import numpy as np

from .errors import LisfloodError, LisfloodWarning
from .errors import LisfloodError, LisfloodWarning, LisfloodFileError
from .decorators import cached
from .default_options import default_options

Expand Down Expand Up @@ -190,7 +190,8 @@ def __str__(self):

def __init__(self, settings_file):
dom = xml.dom.minidom.parse(settings_file)
self.settings_path = os.path.normpath(os.path.dirname((os.path.abspath(settings_file))))
self.settings_dir = os.path.normpath(os.path.dirname((os.path.abspath(settings_file))))
self.settings_path = os.path.normpath(os.path.abspath(settings_file))
user_settings, bindings = self._bindings(dom)
self.timestep_init = None if not bindings.get('timestepInit') else bindings['timestepInit']
self.output_dir = self._out_dirs(user_settings)
Expand Down Expand Up @@ -315,7 +316,7 @@ def _bindings(self, dom):
# built-in user variables
user = {
'ProjectDir': project_dir, 'ProjectPath': project_dir,
'SettingsDir': self.settings_path, 'SettingsPath': self.settings_path,
'SettingsDir': self.settings_dir, 'SettingsPath': self.settings_dir,
}
# get all the bindings in the first part of the settingsfile = lfuser
# list of elements "lfuser" in settings file
Expand All @@ -342,9 +343,11 @@ def _bindings(self, dom):
binding[i] = expr

# Read the calendar type from the precipitation forcing NetCDF file
with Dataset(binding["PrecipitationMaps"] + ".nc") as nc:
precipitation_map_path = binding["PrecipitationMaps"] + '.nc'
if not os.path.exists(precipitation_map_path):
raise LisfloodFileError(precipitation_map_path)
with Dataset(precipitation_map_path) as nc:
binding["calendar_type"] = get_calendar_type(nc)

return user, binding

@staticmethod
Expand All @@ -358,8 +361,7 @@ def _report_steps(user_settings, bindings):
for i in repsteps:
if '..' in i:
j = list(map(int, i.split('..')))
for jj in range(j[0], j[1] + 1):
jjj.append(jj)
jjj = list(range(j[0], j[1] + 1))
else:
jjj.append(i)
res['rep'] = list(map(int, jjj))
Expand Down
20 changes: 11 additions & 9 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

class TestLis(object):
reference_files = {
'dis_drina': {'outpath': os.path.join(current_dir, 'data/Drina/reference/dis'),
'report_map': 'DischargeMaps',
'report_tss': 'DisTS'
},
'dis_madeira': {'outpath': os.path.join(current_dir, 'data/Madeira/reference/dis'),
'report_map': 'DischargeMaps',
'report_tss': 'DisTS'
}
'dis_1': {'outpath': os.path.join(current_dir, 'data/TestCatchment1/reference/dis'),
'report_map': 'DischargeMaps',
'report_tss': 'DisTS'
},
'dis_2': {'outpath': os.path.join(current_dir, 'data/TestCatchment2/reference/dis'),
'report_map': 'DischargeMaps',
'report_tss': 'DisTS'
}
}

domain = None
Expand Down Expand Up @@ -92,7 +92,9 @@ def check_var_step(cls, var, step):
perc_wrong = float(wrong_values_size * 100) / float(diff_values.size)
if perc_wrong >= cls.max_perc_wrong or perc_wrong >= cls.max_perc_wrong_large_diff and large_diff:
print('[ERROR]')
print('Var: {} - STEP {}: {:3.9f}% of values are different. max diff: {:3.4f}'.format(var, step, perc_wrong, max_diff))
print('Var: {} - STEP {}: {:3.9f}% of values are different. max diff: {:3.4f}'.format(var, step,
perc_wrong,
max_diff))
return False
else:
print('[OK] {} {}'.format(var, step))
Expand Down
12 changes: 6 additions & 6 deletions tests/smoke_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
current_dir = os.path.dirname(os.path.abspath(__file__))


class TestDrina(TestLis):
settings_path = os.path.join(current_dir, 'data/Drina/settings/lisfloodSettings_cold_day_base.xml')
class TestCatch1(TestLis):
settings_path = os.path.join(current_dir, 'data/TestCatchment1/settings/cold_day_base.xml')

def test_dis(self):
return self.listest('dis_drina')
return self.listest('dis_1')


class TestMadeira(TestLis):
settings_path = os.path.join(current_dir, 'data/Madeira/settings/settings_Madeira_prerun.xml')
class TestCatch2(TestLis):
settings_path = os.path.join(current_dir, 'data/TestCatchment2/settings/prerun.xml')

def test_dis(self):
return self.listest('dis_madeira')
return self.listest('dis_2')

0 comments on commit d8ce51f

Please sign in to comment.