From 8e52e0d47c7c6455a8b5b47b92a115eece415fe3 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Wed, 3 Jul 2024 09:51:24 +0200 Subject: [PATCH] #54 restore time course settings after run --- basico/task_parameterestimation.py | 3 +++ tests/test_parameterestimation.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/basico/task_parameterestimation.py b/basico/task_parameterestimation.py index 6fd053f..33e6f4b 100644 --- a/basico/task_parameterestimation.py +++ b/basico/task_parameterestimation.py @@ -1322,10 +1322,13 @@ def get_simulation_results(values_only=False, update_parameters=True, **kwargs): # run time course (getting only the data from the experiment) duration = df.iloc[-1].Time cols = ['Time'] + mapping[mapping.type == 'dependent']['cn'].to_list() + tc_settings = basico.get_task_settings(basico.T.TIME_COURSE, model=dm) if values_only: data = basico.run_time_course_with_output(output_selection=cols, values=df.Time.to_list(), start_time=df.iloc[0].Time) else: data = basico.run_time_course_with_output(output_selection=cols,duration=duration) + # restore setttings + basico.set_task_settings(basico.T.TIME_COURSE, tc_settings) exp_data.append(df) sim_data.append(data) diff --git a/tests/test_parameterestimation.py b/tests/test_parameterestimation.py index 2fc28d9..20a3aba 100644 --- a/tests/test_parameterestimation.py +++ b/tests/test_parameterestimation.py @@ -3,9 +3,9 @@ import os import sys import numpy as np +import pandas as pd import basico import COPASI -import shutil class TestBasicoParamterEstimation(unittest.TestCase): @@ -166,6 +166,22 @@ def test_current_solution(self): # ensure that the results are the same self.assertTrue(np.allclose(before[1][0].values, after[1][0].values)) + # issue #54 + # Run function output, looking only at times + function_output = basico.get_simulation_results(values_only=False) + df_first_false = pd.concat([df for df in function_output[1]])['Time'].unique() + + # Run again, changing values_only to True + function_output = basico.get_simulation_results(values_only=True) + df_first_true = pd.concat([df for df in function_output[1]])['Time'].unique() + + # Run again, changing values_only back to False + function_output = basico.get_simulation_results(values_only=False) + df_second_false = pd.concat([df for df in function_output[1]])['Time'].unique() + + # Ensure that the results are the same + self.assertTrue(np.allclose(df_first_false, df_second_false)) + def test_remove(self): fit_items = basico.get_fit_parameters()