mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Ensemble: Add normal low and generalise minmaxdialog.
This commit is contained in:
1 parent
6e029beafc
commit
8e77d31a5a
5 files changed
+69
-26
No files matched your search
@@ -44,11 +44,16 @@ class Function(SQLSubModel):
|
||||
self._name = name
|
||||
self._type = "generic"
|
||||
self._script = script
|
||||
self._labels = []
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def labels(self):
|
||||
return self._labels
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
@@ -154,13 +159,35 @@ class Uniform(Function):
|
||||
name=name, script=script
|
||||
)
|
||||
|
||||
def random(self, ens_range, nb):
|
||||
lst = ens_range.copy()
|
||||
self._labels = ["low", "high"]
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
lst.append(nb)
|
||||
|
||||
return np.random.uniform(*lst)
|
||||
|
||||
|
||||
class Normal(Function):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "normal", script: str = "",
|
||||
status=None):
|
||||
super(Normal, self).__init__(
|
||||
id=id, status=status,
|
||||
name=name, script=script
|
||||
)
|
||||
|
||||
self._labels = ["loc", "scale"]
|
||||
|
||||
def random(self, params, nb):
|
||||
lst = params.copy()
|
||||
lst.append(nb)
|
||||
|
||||
return np.random.normal(*lst)
|
||||
|
||||
|
||||
class Custom(Function):
|
||||
_sub_classes = []
|
||||
|
||||
@@ -172,13 +199,14 @@ class Custom(Function):
|
||||
name=name, script=script
|
||||
)
|
||||
|
||||
self._labels = ["custom"]
|
||||
self._type = "custom"
|
||||
|
||||
def random(self, ens_range, nb):
|
||||
def random(self, params, nb):
|
||||
try:
|
||||
# Run script to (re)define the sample function
|
||||
f = eval(self._script)
|
||||
return f(ens_range, nb)
|
||||
return f(params, nb)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
return None # TODO: Raise helpful exception
|
||||
@@ -32,6 +32,7 @@ class FunctionList(PamhyrModelList):
|
||||
# Default functions
|
||||
new._lst = [
|
||||
Uniform(status=data['status']),
|
||||
Normal(status=data['status']),
|
||||
]
|
||||
|
||||
# DB custom functions
|
||||
|
||||
Reference in new issue
Block a user