Ensemble: Function: Rename get_sample to random and use np.random.

scenario-dev-pa
Pierre-Antoine 2026-09-10 11:40:57 +02:00
parent f5a7cd5984
commit 6e029beafc
5 changed files with 14 additions and 19 deletions

View File

@ -130,7 +130,7 @@ class Ensemble(SQLSubModel):
None
)
rdata = cls._decode_params(params, params_len)
rdata = list(cls._decode_params(params, params_len))
new_ensemble = cls(
id, name=name,
@ -201,9 +201,9 @@ class Ensemble(SQLSubModel):
return struct.unpack(data_format, bparams)
def get_sample(self, nb):
def random(self, nb):
return np.nditer(
self._function.get_sample(
self._function.random(
self._params, nb
)
)

View File

@ -135,7 +135,7 @@ class Function(SQLSubModel):
if predicate(self, data):
modifier(self, data)
def get_sample(self, r):
def random(self, r):
raise NotImplementedMethodeError(cls, cls._load)
@ -154,16 +154,11 @@ class Uniform(Function):
name=name, script=script
)
def get_sample(self, ens_range, nb):
b = ens_range[0]
t = ens_range[1]
def random(self, ens_range, nb):
lst = ens_range.copy()
lst.append(nb)
step = (t - b) / nb
r = np.arange(b, t, step)
np.random.shuffle(r)
return r
return np.random.uniform(*lst)
class Custom(Function):
@ -179,7 +174,7 @@ class Custom(Function):
self._type = "custom"
def get_sample(self, ens_range, nb):
def random(self, ens_range, nb):
try:
# Run script to (re)define the sample function
f = eval(self._script)

View File

@ -277,9 +277,9 @@ class TableData(SQLSubModel):
if len(shape) == 2:
shape_x, shape_y = shape
elif len(shape == 1):
elif len(shape) == 1:
shape_x, = shape
elif len(shape == 3):
elif len(shape) == 3:
shape_x, shape_y, shape_z = shape
else:
logger.error(

View File

@ -474,7 +474,7 @@ class SolverLogEnsWindow(SolverLogWindow):
if ens.function is None:
continue
self._samples[ens] = ens.get_sample(self._run_number)
self._samples[ens] = ens.random(self._run_number)
self._results = None
self._run_samples = []

View File

@ -19,7 +19,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Min:</string>
<string>Low:</string>
</property>
</widget>
</item>
@ -40,7 +40,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Max:</string>
<string>High:</string>
</property>
</widget>
</item>