1
0
forked from IPKM/nmreval

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 is_text = False
except ValueError: except ValueError:
is_text = True is_text = True
self.global_checkbox.setCheckState(False)
self.set_fixed(is_text) 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)): for i, (p_i, g) in enumerate(zip(parameter, self.global_parameter)):
if isinstance(g, FitModelWidget): 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 # set has no oen value
p.append(param_general[i].copy()) p.append(param_general[i].copy())
else: else:
lb, ub = bds[i] lb, ub = bds[i]
try: try:
if not (lb < p[i] < ub): if not (lb < p_i < ub):
raise ValueError(f'Parameter {g.name} is outside bounds ({lb}, {ub})') raise ValueError(f'Parameter {g.name} is outside bounds ({lb}, {ub})')
except TypeError: except TypeError:
pass pass

View File

@ -57,14 +57,7 @@ class Parameters(dict):
parameter.namespace = self.namespace parameter.namespace = self.namespace
parameter.eval_allowed = True parameter.eval_allowed = True
# look for variables in expression and replace with valid names self.update_namespace()
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
def replace_parameter(self, key_out: str, key_in: str, parameter: Parameter): def replace_parameter(self, key_out: str, key_in: str, parameter: Parameter):
# print('replace par', key_out, key_in, parameter) # print('replace par', key_out, key_in, parameter)
@ -79,15 +72,6 @@ class Parameters(dict):
if key_out in self.namespace: if key_out in self.namespace:
del self.namespace[key_out] 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): def fix(self):
for v in self.keys(): for v in self.keys():
v._value = v.value v._value = v.value
@ -107,6 +91,17 @@ class Parameters(dict):
def get_state(self): def get_state(self):
return {k: v.get_state() for k, v in self.items()} 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: class Parameter:
""" """