Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 115 raise an error if input parameter has a wrong numerical value #134

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1eeaeb7
add error for too low and too large values #115
jerabekjak Oct 3, 2022
9b504ff
prepare checking values function
jerabekjak Oct 3, 2022
73e80ac
fix typo #115
jerabekjak Oct 3, 2022
bf41a86
check values of parameters (2 paramters TODO)#115
jerabekjak Oct 3, 2022
f1dc20f
move method to superior class #115
jerabekjak Oct 11, 2022
3452e15
add retention margins
jerabekjak Nov 4, 2022
6daf703
add check for critical tau ne v
jerabekjak Nov 4, 2022
51ac005
add documentation of check parameters function
jerabekjak Nov 4, 2022
edae6da
simplified errors for values check in data praperation
jerabekjak Nov 8, 2022
80458e3
all checks must be after rr and rc are created
jerabekjak Nov 8, 2022
3581805
check valus in rr and rc loop
jerabekjak Nov 8, 2022
2bf08d1
put rr and rc in checking function for paramter values
jerabekjak Nov 8, 2022
1da2b1e
retentino values from m to mm during a check
jerabekjak Nov 8, 2022
a56f598
add mesage that values were checked
jerabekjak Nov 8, 2022
38ee22d
typo in info msg
jerabekjak Nov 8, 2022
dc42fd4
name error accoring to conventions
jerabekjak Nov 8, 2022
3d6b231
Merge branch 'master' into issue_115-raise-an-error-if-input-paramete…
pesekon2 Oct 13, 2023
793c4bd
Update smoderp2d/exceptions.py
jerabekjak Oct 27, 2023
c49a3d5
Update smoderp2d/exceptions.py
jerabekjak Oct 27, 2023
72c25a0
Update smoderp2d/exceptions.py
jerabekjak Oct 27, 2023
00c24a9
Update smoderp2d/exceptions.py
jerabekjak Oct 27, 2023
518f149
Merge branch 'master' into issue_115-raise-an-error-if-input-paramete…
pesekon2 Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions smoderp2d/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,31 @@ class ConfigError(Exception):
pass


class SmallParameterValueError(ConfigError):
""" Exception raised if a parameter reaches a wrong (too small) numeric value
"""
def __init__(self, param, value, limit):
self.msg = "Parameter '{}' has low value ({} < {}).".format(
param, value, limit
)
Logger.fatal(self.msg)


class LargeParameterValueError(ConfigError):
""" Exception raised if a parameter reaches a wrong (too large) numeric value
"""
def __init__(self, param, value, limit):
self.msg = "Parameter '{}' has a wrong value ({} > {}).".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong or large?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"{} parameter value is too large ({} > {})"

param, value, limit
)
Logger.fatal(self.msg)


class WrongParameterValue(ConfigError):
""" Exception raised if a parameter reaches a wrong numeric value
"""
def __init__(self, param, value):
self.msg = "Parameter '{}' has a wrong value ({}).".format(
param, value
)
super().__init__(self.msg)

def __str__(self):
return self.msg
Logger.fatal(self.msg)
65 changes: 61 additions & 4 deletions smoderp2d/providers/base/data_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from smoderp2d.core import CompType
from smoderp2d.core.general import GridGlobals, Globals
from smoderp2d.providers.base import Logger
from smoderp2d.providers.base.exceptions import DataPreparationError, \
DataPreparationInvalidInput
from smoderp2d.providers.base.exceptions import SmallParameterValueError, \
LargeParameterValueError, DataPreparationError, DataPreparationInvalidInput


class PrepareDataBase(ABC):
Expand Down Expand Up @@ -133,7 +133,6 @@ def _get_inf_combinat_index(r, c, mat_k, mat_s):

return mat_inf_index, combinatIndex

@staticmethod
def _get_mat_nan(r, c, no_data_value, mat_slope, mat_dem):
# vyrezani krajnich bunek, kde byly chyby, je to vyrazeno u
# sklonu a acc
Expand Down Expand Up @@ -172,7 +171,6 @@ def _get_rr_rc(r, c, mat_boundary):
for i in nr:
one_col = []
for j in nc:

if mat_boundary[i][j] == -99:
one_col.append(j)
rr_insert = True
Expand All @@ -186,6 +184,41 @@ def _get_rr_rc(r, c, mat_boundary):
rr_insert = False
rc.append(one_col)

# all checks must be after rr and rc are created. check Ks and S for
# infiltraiton
self._check_parameter_value(self.data['rr'], self.data['rc'], 'Ks',
all_attrib[0], [0,1])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'S',
all_attrib[1], [0,1])

self._check_parameter_value(self.data['rr'], self.data['rc'], 'X',
all_attrib[7], [1,200])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'Y',
all_attrib[8], [0.01,1])
# check the critical tension and velocity
self._check_parameter_value(self.data['rr'], self.data['rc'], 'tau',
all_attrib[9], [1,100])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'v',
all_attrib[10], [0.1,5])

self._check_parameter_value(self.data['rr'], self.data['rc'], 'n',
self.data['mat_n'], [0,10])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'pi',
self.data['mat_pi'], [0,10])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'ppl',
self.data['mat_ppl'], [0,1])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'reten',
self.data['mat_reten'], [0,100])
self._check_parameter_value(self.data['rr'], self.data['rc'], 'b',
self.data['mat_b'], [1,2.5])


self.data['mfda'] = False
self.data['mat_boundary'] = None
self.data['spix'] = None
self.data['vpix'] = None
#Logger.progress(100)

return rr, rc


Expand Down Expand Up @@ -260,6 +293,30 @@ def __init__(self, writter):
self.fieldnames['channel_q365']
]

def _check_parameter_value(self, rr, rc, name, arr, range_):
jerabekjak marked this conversation as resolved.
Show resolved Hide resolved
""" check the parameter margins

:param list rr: list of i indices in the computaion domain
:param list rc: list of j indices in the computaion domain
:param str name: name of the variable
:param np.array arr: the array holding the parameter values
:param list range_: range of appropriate parameters
"""

for i in rr:
for j in rc[i]:
val = arr[i][j]
if (range_[0] > val) : raise SmallParameterValueError(name, val, range_[0])
if (range_[1] < val) : raise LargeParameterValueError(name, val, range_[1])

Logger.info('{} parameter values checked.'.format(name))


def _set_output_data(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this new method called?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is more of a rhetoric question, but the answer is nowhere (at least at this moment).

"""
Creates dictionary to which model parameters are computed.
"""
# output data
self.data = {
'mat_boundary': None,
'outletCells': None,
Expand Down