Compare commits

...
4 Commits
9 changed files with 99 additions and 100 deletions

No files matched your search

+25 -4
View File
@@ -149,9 +149,9 @@ class Distribution(SQLSubModel):
raise NotImplementedMethodeError(cls, cls._load) raise NotImplementedMethodeError(cls, cls._load)
########################### ###############################
# DISTRIBUTION IMPLEMENTATION # # DISTRIBUTION IMPLEMENTATION #
########################### ###############################
class Uniform(Distribution): class Uniform(Distribution):
_sub_classes = [] _sub_classes = []
@@ -195,6 +195,27 @@ class Normal(Distribution):
return np.random.normal(*lst) return np.random.normal(*lst)
class Binomial(Distribution):
_sub_classes = []
def __init__(self, id: int = -1,
name: str = "binomial", script: str = "",
status=None):
super(Binomial, self).__init__(
id=id, status=status,
name=name, script=script
)
self._labels = ["binomial_n", "binomial_p"]
self._default_values = [100.0, 0.3]
def random(self, params, nb):
lst = params.copy()
lst.append(nb)
return np.random.binomial(*lst)
class Poisson(Distribution): class Poisson(Distribution):
_sub_classes = [] _sub_classes = []
@@ -206,7 +227,7 @@ class Poisson(Distribution):
name=name, script=script name=name, script=script
) )
self._labels = ["lam"] self._labels = ["poisson_lam"]
self._default_values = [5.0] self._default_values = [5.0]
def random(self, params, nb): def random(self, params, nb):
@@ -229,7 +250,7 @@ class Custom(Distribution):
self._labels = ["custom"] self._labels = ["custom"]
self._type = "custom" self._type = "custom"
self._default_values = "" self._default_values = [""]
def random(self, params, nb): def random(self, params, nb):
try: try:
+5 -3
View File
@@ -30,10 +30,12 @@ class DistributionList(PamhyrModelList):
new = cls(status=data['status']) new = cls(status=data['status'])
# Default distributions # Default distributions
d = {"status": data['status']}
new._lst = [ new._lst = [
Uniform(status=data['status']), Uniform(**d),
Normal(status=data['status']), Normal(**d),
Poisson(status=data['status']), Binomial(**d),
Poisson(**d),
] ]
# DB custom distributions # DB custom distributions
+33
View File
@@ -0,0 +1,33 @@
# Translate.py -- Pamhyr
# Copyright (C) 2023-2026 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
from View.Ensembles.Translate import EnsemblesTranslate
_translate = QCoreApplication.translate
class EnsembleEditTranslate(EnsemblesTranslate):
def __init__(self):
super(EnsembleEditTranslate, self).__init__()
self._dict["binomial_n"] = _translate("Ensemble", "n")
self._dict["binomial_p"] = _translate("Ensemble", "p")
self._dict["poisson_lam"] = _translate("Ensemble", "Lam")
+11 -3
View File
@@ -45,6 +45,8 @@ from PyQt5.QtWidgets import (
QGroupBox, QTreeWidget, QGroupBox, QTreeWidget,
) )
from View.Ensembles.Edit.Translate import EnsembleEditTranslate
logger = logging.getLogger() logger = logging.getLogger()
@@ -74,7 +76,9 @@ class EnsembleEditDialog(PamhyrDialog):
_pamhyr_name = "Parameters" _pamhyr_name = "Parameters"
def __init__(self, study=None, ensemble=None, def __init__(self, study=None, ensemble=None,
trad=None, parent=None): parent=None):
trad = EnsembleEditTranslate()
super(EnsembleEditDialog, self).__init__( super(EnsembleEditDialog, self).__init__(
title=trad[self._pamhyr_name], title=trad[self._pamhyr_name],
trad=trad, trad=trad,
@@ -248,7 +252,9 @@ class Ensemble1ParamsWidget(PamhyrWidget):
def _init_default_values(self): def _init_default_values(self):
self._values = self._ensemble.params self._values = self._ensemble.params
if len(self._values) > 0: if len(self._values) != 1:
self._values = self._distribution.default_values.copy()
self.set_double_spin_box("doubleSpinBox_0", self._values[0]) self.set_double_spin_box("doubleSpinBox_0", self._values[0])
@property @property
@@ -285,7 +291,9 @@ class Ensemble2ParamsWidget(PamhyrWidget):
def _init_default_values(self): def _init_default_values(self):
self._values = self._ensemble.params self._values = self._ensemble.params
if len(self._values) > 0: if len(self._values) != 2:
self._values = self._distribution.default_values.copy()
self.set_double_spin_box("doubleSpinBox_0", self._values[0]) self.set_double_spin_box("doubleSpinBox_0", self._values[0])
self.set_double_spin_box("doubleSpinBox_1", self._values[1]) self.set_double_spin_box("doubleSpinBox_1", self._values[1])
+1
View File
@@ -114,6 +114,7 @@ class AddCommand(QUndoCommand):
else: else:
self._ensembles.insert(self._index, self._new) self._ensembles.insert(self._index, self._new)
class ImportCommand(QUndoCommand): class ImportCommand(QUndoCommand):
def __init__(self, ensembles, data, index): def __init__(self, ensembles, data, index):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
-86
View File
@@ -197,7 +197,6 @@ class EnsemblesWindow(PamhyrWindow):
dlg = EnsembleEditDialog( dlg = EnsembleEditDialog(
study=self._study, study=self._study,
ensemble=ens, ensemble=ens,
trad=self._trad,
parent=self parent=self
) )
@@ -279,88 +278,3 @@ class EnsemblesWindow(PamhyrWindow):
) )
) )
self._table.update() self._table.update()
class Ensemble1ParamsDialog(PamhyrDialog):
_pamhyr_ui = "Ensemble1ParamsDialog"
_pamhyr_name = "Parameters"
def __init__(self, ensemble=None,
trad=None, parent=None):
super(Ensemble1ParamsDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
options=[],
parent=parent
)
self._ensemble = ensemble
self._labels = ensemble.distribution.labels
self._init_default_labels()
self._init_default_values()
def _init_default_labels(self):
self.set_label_text("label_0", self._trad[self._labels[0]])
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) > 0:
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
@property
def values(self):
return self._values
def accept(self):
self._values = [
self.get_double_spin_box("doubleSpinBox_0"),
]
super().accept()
def reject(self):
self.close()
class Ensemble2ParamsDialog(PamhyrDialog):
_pamhyr_ui = "Ensemble2ParamsDialog"
_pamhyr_name = "Parameters"
def __init__(self, ensemble=None,
trad=None, parent=None):
super(Ensemble2ParamsDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
options=[],
parent=parent
)
self._ensemble = ensemble
self._labels = ensemble.distribution.labels
self._init_default_labels()
self._init_default_values()
def _init_default_labels(self):
self.set_label_text("label_0", self._trad[self._labels[0]])
self.set_label_text("label_1", self._trad[self._labels[1]])
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) > 0:
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
self.set_double_spin_box("doubleSpinBox_1", self._values[1])
@property
def values(self):
return self._values
def accept(self):
self._values = [
self.get_double_spin_box("doubleSpinBox_0"),
self.get_double_spin_box("doubleSpinBox_1")
]
super().accept()
def reject(self):
self.close()
-1
View File
@@ -45,7 +45,6 @@ class CommonWordTranslate(PamhyrTranslate):
self._dict["loc"] = _translate("CommonWord", "Loc") self._dict["loc"] = _translate("CommonWord", "Loc")
self._dict["scale"] = _translate("CommonWord", "Scale") self._dict["scale"] = _translate("CommonWord", "Scale")
self._dict["lam"] = _translate("CommonWord", "Lam")
self._dict["reach"] = _translate("CommonWord", "Reach") self._dict["reach"] = _translate("CommonWord", "Reach")
self._dict["reaches"] = _translate("CommonWord", "Reaches") self._dict["reaches"] = _translate("CommonWord", "Reaches")
+8 -1
View File
@@ -24,7 +24,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="doubleSpinBox_0"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_0">
<property name="minimum">
<double>-10000000000.000000000000000</double>
</property>
<property name="maximum">
<double>10000000000.000000000000000</double>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
+16 -2
View File
@@ -22,7 +22,14 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_0"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_0">
<property name="minimum">
<double>-10000000000.000000000000000</double>
</property>
<property name="maximum">
<double>10000000000.000000000000000</double>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_1"> <widget class="QLabel" name="label_1">
@@ -32,7 +39,14 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_1"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_1">
<property name="minimum">
<double>-10000000000.000000000000000</double>
</property>
<property name="maximum">
<double>10000000000.000000000000000</double>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>