From 7ad6194198dcd3a290314fbeaaac51e0e865d6de Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Tue, 26 Jul 2022 15:52:59 +0200 Subject: [PATCH] #26: correct cast --- basico/task_parameterestimation.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/basico/task_parameterestimation.py b/basico/task_parameterestimation.py index cd0d094..b33cc46 100644 --- a/basico/task_parameterestimation.py +++ b/basico/task_parameterestimation.py @@ -1159,6 +1159,18 @@ def _apply_nth_change(change, columns, df, dm, exp_name, independent, model, num if change_set.size() > 0: model.updateInitialValues(change_set) +def _get_value_from_bound(bound): + """ + + :param bound: the bound for the fit item (a float value as string, or name of another reference) + :return: the value of the bound + :rtype: float + """ + try: + value = float(bound) + except ValueError: + value = basico.get_value(bound) + return value def _update_fit_parameters_from(dm, solution, exp_name=''): """ Utility function that updates the models fit parameters for the given solution @@ -1174,8 +1186,8 @@ def _update_fit_parameters_from(dm, solution, exp_name=''): for j in range(solution.shape[0]): name = solution.iloc[j].name value = solution.iloc[j].sol - lower= solution.iloc[j].lower - upper = solution.iloc[j].upper + lower= _get_value_from_bound(solution.iloc[j].lower) + upper = _get_value_from_bound(solution.iloc[j].upper) cn = params.iloc[j].cn if np.isnan(value): @@ -1186,16 +1198,9 @@ def _update_fit_parameters_from(dm, solution, exp_name=''): # ensure that values is within the constraint if value < lower: - try: - value = str(lower) - except ValueError: - value = basico.get_value(lower) + value = lower if value > upper: - try: - value = str(upper) - except ValueError: - value = basico.get_value(upper) - + value = upper obj = dm.getObject(COPASI.CCommonName(cn))