minor fixes

This commit is contained in:
Dominik Demuth 2023-09-19 11:33:52 +02:00
parent 8d994bb9b4
commit 41d90bb15f
3 changed files with 15 additions and 19 deletions

View File

@ -118,6 +118,7 @@ class FitModelWidget(QtWidgets.QWidget, Ui_FitParameter):
is_text = False
except ValueError:
is_text = True
self.global_checkbox.setCheckState(False)
self.set_fixed(is_text)

View File

@ -237,13 +237,13 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit):
for i, (p_i, g) in enumerate(zip(parameter, self.global_parameter)):
if isinstance(g, FitModelWidget):
if (p_i is None) and (not is_global[i]):
if (p_i is None) or is_global[i]:
# set has no oen value
p.append(param_general[i].copy())
else:
lb, ub = bds[i]
try:
if not (lb < p[i] < ub):
if not (lb < p_i < ub):
raise ValueError(f'Parameter {g.name} is outside bounds ({lb}, {ub})')
except TypeError:
pass

View File

@ -57,14 +57,7 @@ class Parameters(dict):
parameter.namespace = self.namespace
parameter.eval_allowed = True
# look for variables in expression and replace with valid names
for p in self.values():
if p._expr is not None:
expression = p._expr
for n, k in self._mapping.items():
expression = re.sub(re.escape(n), k, expression)
p._expr = expression
self.update_namespace()
def replace_parameter(self, key_out: str, key_in: str, parameter: Parameter):
# print('replace par', key_out, key_in, parameter)
@ -79,15 +72,6 @@ class Parameters(dict):
if key_out in self.namespace:
del self.namespace[key_out]
for p in self.values():
try:
p.value
except NameError:
expression = p._expr_disp
for n, k in self._mapping.items():
expression = re.sub(re.escape(n), k, expression)
p._expr = expression
def fix(self):
for v in self.keys():
v._value = v.value
@ -107,6 +91,17 @@ class Parameters(dict):
def get_state(self):
return {k: v.get_state() for k, v in self.items()}
def update_namespace(self):
for p in self.values():
try:
p.value
except NameError:
expression = p._expr_disp
for n, k in self._mapping.items():
expression, num_replaced = re.subn(re.escape(n), k, expression)
p._expr = expression
class Parameter:
"""