mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7eb39e5896 | ||
|
|
28cc88b4b8 | ||
|
|
c9925cd03c | ||
|
|
40f9465929 | ||
|
|
359805b713 | ||
|
|
31565b9170 |
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -4,7 +4,7 @@ PyQt5-sip==12.18.0
|
||||
PyQtWebEngine==5.15.6
|
||||
QScintilla>=2.14.1
|
||||
pyqtgraph>=0.12.1
|
||||
matplotlib==3.8.3
|
||||
matplotlib==3.10.8
|
||||
numpy>=1.24.2
|
||||
colorama>=0.4.3
|
||||
pyinstaller>=5.11.0
|
||||
@@ -14,3 +14,4 @@ platformdirs>=4.2.0
|
||||
pyshp>=2.3.1
|
||||
rasterio==1.3.11
|
||||
#fortranformat==2.0.3
|
||||
psutil>=7.2.2
|
||||
@@ -46,6 +46,8 @@ class Distribution(SQLSubModel):
|
||||
self._script = script
|
||||
self._labels = []
|
||||
self._default_values = []
|
||||
self._params_checkers = []
|
||||
self._params_tips = []
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -145,6 +147,21 @@ class Distribution(SQLSubModel):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
def is_valid_parameters(self, parameters):
|
||||
valid = True
|
||||
tips = []
|
||||
|
||||
for i, checker in enumerate(self._params_checkers):
|
||||
ok = checker(parameters)
|
||||
if not ok:
|
||||
tips.append(self._params_tips[i])
|
||||
valid = False
|
||||
|
||||
return (valid, tips)
|
||||
|
||||
def check_params(self, params):
|
||||
return True
|
||||
|
||||
def random(self, r):
|
||||
raise NotImplementedMethodeError(cls, cls._load)
|
||||
|
||||
@@ -166,6 +183,11 @@ class Uniform(Distribution):
|
||||
|
||||
self._labels = ["low", "high"]
|
||||
self._default_values = [20.0, 40.0]
|
||||
self._params_checkers = [self.check_params, self.check_params]
|
||||
self._params_tips = ["uniform_low_tips", "uniform_high_tips"]
|
||||
|
||||
def check_params(self, params):
|
||||
return (params[0] < params[1])
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
@@ -187,6 +209,11 @@ class Normal(Distribution):
|
||||
|
||||
self._labels = ["loc", "scale"]
|
||||
self._default_values = [30.0, 5.0]
|
||||
self._params_checkers = [self.check_params, self.check_scale]
|
||||
self._params_tips = ["normal_loc_tips", "normal_scale_tips"]
|
||||
|
||||
def check_scale(self, params):
|
||||
return 0 <= params[1]
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
@@ -208,6 +235,16 @@ class Binomial(Distribution):
|
||||
|
||||
self._labels = ["binomial_n", "binomial_p"]
|
||||
self._default_values = [100.0, 0.3]
|
||||
self._params_checkers = [self.check_n, self.check_p]
|
||||
self._params_tips = ["binomial_n_tips", "binomial_p_tips"]
|
||||
|
||||
def check_n(self, params):
|
||||
n = params[0]
|
||||
return (0 <= n) and (n == round(n))
|
||||
|
||||
def check_p(self, params):
|
||||
p = params[1]
|
||||
return 0 <= p <= 1
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
@@ -229,6 +266,12 @@ class Poisson(Distribution):
|
||||
|
||||
self._labels = ["poisson_lam"]
|
||||
self._default_values = [5.0]
|
||||
self._params_checkers = [self.check_lam]
|
||||
self._params_tips = ["poisson_lam_tips"]
|
||||
|
||||
def check_lam(self, params):
|
||||
lam = params[0]
|
||||
return 0 <= lam
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
@@ -251,6 +294,8 @@ class Custom(Distribution):
|
||||
self._labels = ["custom"]
|
||||
self._type = "custom"
|
||||
self._default_values = [""]
|
||||
self._params_checkers = [self.check_params]
|
||||
self._params_tips = ["custom_params_tips"]
|
||||
|
||||
def random(self, params, nb):
|
||||
try:
|
||||
|
||||
@@ -31,3 +31,34 @@ class EnsembleEditTranslate(EnsemblesTranslate):
|
||||
self._dict["binomial_p"] = _translate("Ensemble", "p")
|
||||
|
||||
self._dict["poisson_lam"] = _translate("Ensemble", "Lam")
|
||||
|
||||
self._dict["checker_failed_title"] = _translate(
|
||||
"Ensemble",
|
||||
"Invalid parameter"
|
||||
)
|
||||
self._dict["checker_failed_text"] = _translate(
|
||||
"Ensemble",
|
||||
"This parameter is not valid for selected distribution: "
|
||||
)
|
||||
|
||||
uniform = _translate(
|
||||
"Ensemble", "(High - Low) must be non-negative."
|
||||
)
|
||||
self._dict["uniform_low_tips"] = uniform
|
||||
self._dict["uniform_high_tips"] = uniform
|
||||
|
||||
self._dict["normal_scale_tips"] = _translate(
|
||||
"Ensemble", "Scale must be non-negative."
|
||||
)
|
||||
|
||||
self._dict["binomial_n_tips"] = _translate(
|
||||
"Ensemble", "N must be non-negative and must be an integers."
|
||||
)
|
||||
|
||||
self._dict["binomial_p_tips"] = _translate(
|
||||
"Ensemble", "P must be >= 0 and <=1."
|
||||
)
|
||||
|
||||
self._dict["poisson_lam_tips"] = _translate(
|
||||
"Ensemble", "Lam must be >= 0."
|
||||
)
|
||||
@@ -213,13 +213,26 @@ class EnsembleEditDialog(PamhyrDialog):
|
||||
),
|
||||
None
|
||||
)
|
||||
parameters = self._params_widget.values
|
||||
|
||||
if distribution is not None:
|
||||
ok, tips = distribution.is_valid_parameters(parameters)
|
||||
if not ok:
|
||||
self.message_box(
|
||||
text=self._trad["checker_failed_text"],
|
||||
informative_text="\n".join(
|
||||
map(lambda t: " - " + self._trad[t], tips)
|
||||
),
|
||||
window_title=self._trad["checker_failed_title"],
|
||||
)
|
||||
return
|
||||
|
||||
self._values = {
|
||||
"name": self.get_line_edit_text("lineEdit_name"),
|
||||
"data_type": self._target_data[0],
|
||||
"target_data": self._target_data[1],
|
||||
"distribution": distribution,
|
||||
"params": self._params_widget.values,
|
||||
"params": parameters,
|
||||
}
|
||||
|
||||
super().accept()
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user