From 41d90bb15f3c20415d70e522a6dc580af8b366cb Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 19 Sep 2023 11:33:52 +0200 Subject: [PATCH] minor fixes --- src/gui_qt/fit/fit_forms.py | 1 + src/gui_qt/fit/fit_parameter.py | 4 ++-- src/nmreval/fit/parameter.py | 29 ++++++++++++----------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/gui_qt/fit/fit_forms.py b/src/gui_qt/fit/fit_forms.py index 13e225b..67f27d2 100644 --- a/src/gui_qt/fit/fit_forms.py +++ b/src/gui_qt/fit/fit_forms.py @@ -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) diff --git a/src/gui_qt/fit/fit_parameter.py b/src/gui_qt/fit/fit_parameter.py index 49568cf..e6b5a11 100644 --- a/src/gui_qt/fit/fit_parameter.py +++ b/src/gui_qt/fit/fit_parameter.py @@ -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 diff --git a/src/nmreval/fit/parameter.py b/src/nmreval/fit/parameter.py index bc79daa..502f35f 100644 --- a/src/nmreval/fit/parameter.py +++ b/src/nmreval/fit/parameter.py @@ -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: """