Skip to content

Commit 0ba4b68

Browse files
authored
Add get_simulation_df (#274)
Add `get_simulation_df` to load simulation `DataFrame`s.
1 parent ea36560 commit 0ba4b68

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/python/benchmark_models_petab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Python tool to access the model collection.
55
"""
66

7-
from .base import get_problem, get_problem_yaml_path
7+
from .base import get_problem, get_problem_yaml_path, get_simulation_df
88
from .C import MODEL_DIRS, MODELS, MODELS_DIR
99
from .overview import get_overview_df
1010
from importlib.metadata import PackageNotFoundError, version

src/python/benchmark_models_petab/base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from .C import MODELS_DIR
88

9+
import pandas as pd
10+
911

1012
def get_problem_yaml_path(id_: str) -> Path:
1113
"""Get the path to the PEtab problem YAML file.
@@ -40,3 +42,21 @@ def get_problem(id_: str) -> petab.Problem:
4042
yaml_file = get_problem_yaml_path(id_)
4143
petab_problem = petab.Problem.from_yaml(yaml_file)
4244
return petab_problem
45+
46+
47+
def get_simulation_df(id_: str) -> pd.DataFrame | None:
48+
"""Get the simulation dataframe for the benchmark collection problem with
49+
the given name.
50+
51+
Parameters
52+
----------
53+
id_: Problem name, as in `benchmark_models_petab.MODELS`.
54+
55+
Returns
56+
-------
57+
The simulation dataframe if it exists, else None.
58+
"""
59+
path = Path(MODELS_DIR, id_, f"simulatedData_{id_}.tsv")
60+
if path.is_file():
61+
return petab.get_simulation_df(path)
62+
return None

src/python/test/test_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ def test_get_problem():
1414
"""Test whether extracting a petab problem works."""
1515
problem = models.get_problem(models.MODELS[0])
1616
assert problem.measurement_df is not None
17+
18+
19+
def test_get_simulation_df():
20+
assert models.get_simulation_df("Elowitz_Nature2000").empty is False
21+
assert models.get_simulation_df("not a problem name") is None

0 commit comments

Comments
 (0)