Skip to content

Commit

Permalink
#54 restore time course settings after run
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jul 3, 2024
1 parent aac87d5 commit 8e52e0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions basico/task_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8e52e0d

Please sign in to comment.