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 4 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
22 changes: 22 additions & 0 deletions smoderp2d/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ def __init__(self):
class ConfigError(Exception):
pass

class SmallParameterValue(ConfigError):
""" Exception raised if a parameter reaches a wrong numeric value
jerabekjak marked this conversation as resolved.
Show resolved Hide resolved
"""
def __init__(self,param,value,limit):
self.msg = "Parameter '{}' has low value ({} < {}).".format(
param,value,limit)
super().__init__(self.msg)

def __str__(self):
return self.msg
jerabekjak marked this conversation as resolved.
Show resolved Hide resolved

class LargeParameterValue(ConfigError):
""" Exception raised if a parameter reaches a wrong numeric value
jerabekjak marked this conversation as resolved.
Show resolved Hide resolved
"""
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)
super().__init__(self.msg)

def __str__(self):
return self.msg

class WrongParameterValue(ConfigError):
""" Exception raised if a parameter reaches a wrong numeric value
"""
Expand Down
33 changes: 33 additions & 0 deletions smoderp2d/providers/base/data_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import smoderp2d.processes.rainfall as rainfall

from smoderp2d.providers.base import Logger
from smoderp2d.exceptions import SmallParameterValue
from smoderp2d.exceptions import LargeParameterValue

class PrepareDataBase(object):
def __init__(self, writter):
Expand Down Expand Up @@ -92,17 +94,34 @@ def run(self):

# build numpy array from selected attributes
all_attrib = self._get_attrib(sfield, intersect)

# check Ks and S for infiltraiton
self._check_parameter_value('Ks', all_attrib[0], [0,1])
self._check_parameter_value('S', all_attrib[1], [0,1])

self.data['mat_inf_index'], self.data['combinatIndex'] = \
self._get_inf_combinat_index(self.data['r'], self.data['c'],
all_attrib[0], all_attrib[1])
#Logger.progress(30)

self.data['mat_n'] = all_attrib[2]
self._check_parameter_value('n', self.data['mat_n'], [0,10])

self.data['mat_pi'] = all_attrib[3]
self._check_parameter_value('pi', self.data['mat_pi'], [0,10])

self.data['mat_ppl'] = all_attrib[4]
self._check_parameter_value('ppl', self.data['mat_ppl'], [0,1])

self.data['mat_reten'] = all_attrib[5]
# TODO check extremely low valus in testing dataset
jerabekjak marked this conversation as resolved.
Show resolved Hide resolved
# self._check_parameter_value('reten', self.data['mat_reten'], [0,50])

self.data['mat_b'] = all_attrib[6]
self._check_parameter_value('b', self.data['mat_b'], [1,2.5])



self.data['mat_nan'], self.data['mat_slope'], self.data['mat_dem'] = \
self._get_mat_nan(self.data['r'], self.data['c'],
self.data['NoDataValue'], self.data['mat_slope'],
Expand All @@ -113,13 +132,21 @@ def run(self):
self._get_array_points()

# build a/aa arrays
self._check_parameter_value('X', all_attrib[7], [1,200])
self._check_parameter_value('Y', all_attrib[8], [0.01,1])

self.data['mat_a'], self.data['mat_aa'] = self._get_a(
all_attrib[2], all_attrib[7], all_attrib[8], self.data['r'],
self.data['c'], self.data['NoDataValue'], self.data['mat_slope']
)
#Logger.progress(40)

Logger.info("Computing critical level...")

# check the critical tension and celocity TODO
# self._check_parameter_value('xxx', all_attrib[9], [1,200])
# self._check_parameter_value('xxx', all_attrib[10], [0.01,1])
jerabekjak marked this conversation as resolved.
Show resolved Hide resolved

self.data['mat_hcrit'] = self._get_crit_water(
self.data['mat_b'], all_attrib[9], all_attrib[10], self.data['r'],
self.data['c'], self.data['mat_slope'],
Expand Down Expand Up @@ -155,6 +182,12 @@ def run(self):

return self.data

def _check_parameter_value(self, name, arr, range_):
min_ = (np.nanmin(arr))
max_ = (np.nanmax(arr))
if (range_[0] > min_) : raise SmallParameterValue(name, min_, range_[0])
if (range_[1] < max_) : raise LargeParameterValue(name, max_, range_[1])

jerabekjak marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down