mirror of https://gitlab.com/pamhyr/pamhyr2
Ensemble: Function: Add Poisson law and 1 params dialog.
parent
8e77d31a5a
commit
4040b2456c
|
|
@ -188,6 +188,26 @@ class Normal(Function):
|
|||
return np.random.normal(*lst)
|
||||
|
||||
|
||||
class Poisson(Function):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "poisson", script: str = "",
|
||||
status=None):
|
||||
super(Poisson, self).__init__(
|
||||
id=id, status=status,
|
||||
name=name, script=script
|
||||
)
|
||||
|
||||
self._labels = ["lam"]
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
lst.append(nb)
|
||||
|
||||
return np.random.poisson(*lst)
|
||||
|
||||
|
||||
class Custom(Function):
|
||||
_sub_classes = []
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class FunctionList(PamhyrModelList):
|
|||
new._lst = [
|
||||
Uniform(status=data['status']),
|
||||
Normal(status=data['status']),
|
||||
Poisson(status=data['status']),
|
||||
]
|
||||
|
||||
# DB custom functions
|
||||
|
|
|
|||
|
|
@ -185,11 +185,21 @@ class EnsemblesWindow(PamhyrWindow):
|
|||
for row in rows:
|
||||
try:
|
||||
ens = self._ensembles.get(row)
|
||||
dlg = Ensemble2ParamsDialog(
|
||||
ensemble=ens,
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
len_params = len(ens.function.labels)
|
||||
|
||||
if len_params == 1:
|
||||
dlg = Ensemble1ParamsDialog(
|
||||
ensemble=ens,
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
else:
|
||||
dlg = Ensemble2ParamsDialog(
|
||||
ensemble=ens,
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
|
||||
if dlg.exec():
|
||||
self._ensembles.get(row).params = dlg._values
|
||||
except Exception as e:
|
||||
|
|
@ -197,6 +207,48 @@ class EnsemblesWindow(PamhyrWindow):
|
|||
return
|
||||
|
||||
|
||||
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.function.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"
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class CommonWordTranslate(PamhyrTranslate):
|
|||
|
||||
self._dict["loc"] = _translate("CommonWord", "Loc")
|
||||
self._dict["scale"] = _translate("CommonWord", "Scale")
|
||||
self._dict["lam"] = _translate("CommonWord", "Lam")
|
||||
|
||||
self._dict["reach"] = _translate("CommonWord", "Reach")
|
||||
self._dict["reaches"] = _translate("CommonWord", "Reaches")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>416</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_0">
|
||||
<property name="text">
|
||||
<string>@param0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_0">
|
||||
<property name="minimum">
|
||||
<double>-100000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>100000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Loading…
Reference in New Issue