From a97c31325f6779e1c76aa1237d6557870278f0b5 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Wed, 27 Sep 2023 15:32:19 +0200 Subject: [PATCH] 1/p bounds in ui --- src/gui_qt/fit/fit_forms.py | 22 ++++++++++++++-------- src/nmreval/fit/minimizer.py | 9 +++++++-- src/nmreval/fit/parameter.py | 2 ++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gui_qt/fit/fit_forms.py b/src/gui_qt/fit/fit_forms.py index 67f27d2..6f2a424 100644 --- a/src/gui_qt/fit/fit_forms.py +++ b/src/gui_qt/fit/fit_forms.py @@ -86,15 +86,21 @@ class FitModelWidget(QtWidgets.QWidget, Ui_FitParameter): p = self.parameter_line.text().replace(',', '.') if self.checkBox.isChecked(): - try: - lb = float(self.lineEdit.text().replace(',', '.')) - except ValueError: - lb = None + lb_text = self.lineEdit.text() + lb = None + if lb_text: + try: + lb = float(lb_text.replace(',', '.')) + except ValueError: + lb = lb_text - try: - rb = float(self.lineEdit_2.text().replace(',', '.')) - except ValueError: - rb = None + ub_text = self.lineEdit_2.text() + rb = None + if ub_text: + try: + rb = float(ub_text.replace(',', '.')) + except ValueError: + rb = ub_text else: lb = rb = None diff --git a/src/nmreval/fit/minimizer.py b/src/nmreval/fit/minimizer.py index 5594fd1..2b8bf54 100644 --- a/src/nmreval/fit/minimizer.py +++ b/src/nmreval/fit/minimizer.py @@ -278,10 +278,12 @@ class FitRoutine(object): data._model = self.fit_model self._no_own_model.append(data) + data.parameter.prepare_bounds() + return self._prep_parameter(data.parameter) @staticmethod - def _prep_parameter(parameter): + def _prep_parameter(parameter: Parameters): vals = [] var_pars = [] for p_k, v_k in parameter.items(): @@ -293,7 +295,8 @@ class FitRoutine(object): return pp, lb, ub, var_pars - def _prep_global(self, data_group, linked): + @staticmethod + def _prep_global(data_group: list[Data], linked): p0 = [] lb = [] ub = [] @@ -306,6 +309,8 @@ class FitRoutine(object): for k, v in data.model.parameter.items(): data.replace_parameter(k, v) + data.parameter.prepare_bounds() + actual_pars = [] for i, p_k in enumerate(data.para_keys): p_k_used = p_k diff --git a/src/nmreval/fit/parameter.py b/src/nmreval/fit/parameter.py index 7ae525e..c68b8d0 100644 --- a/src/nmreval/fit/parameter.py +++ b/src/nmreval/fit/parameter.py @@ -102,10 +102,12 @@ class Parameters(dict): p._expr = expression def prepare_bounds(self): + print('prepare_bounds') original_values = list(self.values()) for param in original_values: already_with_expression = False for mode, value in (('lower', param.lb), ('upper', param.ub)): + print(mode, value) if already_with_expression: raise ValueError('Only one boundary can be an expression') already_with_expression = self.parse(param, value, bnd=mode)