Skip to content

Commit

Permalink
fixed plotting and updated deps for latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Sep 23, 2024
1 parent 0e21c12 commit 55e59c8
Show file tree
Hide file tree
Showing 6 changed files with 44,946 additions and 169 deletions.
6 changes: 4 additions & 2 deletions bio_compose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
get_output,
get_compatible_verification_simulators,
verify,
run_simulation
run_simulation,
visualize_observables
)


Expand All @@ -21,5 +22,6 @@
'get_output',
'get_compatible_verification_simulators',
'verify',
'run_simulation'
'run_simulation',
'visualize_observables'
]
20 changes: 18 additions & 2 deletions bio_compose/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def verify(*args) -> VerificationResult:
buffer_time = 5
poll_time = 5
submission_generator = verifier.verify_sbml if run_sbml else verifier.verify_omex
print("Submitting verification...")
print("Submitting verification...", end='\r')
time.sleep(buffer_time)

# fetch params
Expand Down Expand Up @@ -168,4 +168,20 @@ def run_simulation(*args, **kwargs) -> SimulationResult:
break
else:
i += 1
return SimulationResult(data=output)
return SimulationResult(data=output)


def visualize_observables(job_id: str, save_dest: str = None, hspace: float = 0.25, use_grid: bool = False):
"""
Visualize simulation output (observables) data, not comparison data, with subplots for each species.
:param job_id: (`str`) job id for the simulation observable output you wish to visualize.
:param save_dest: (`str`) path to save the figure. If this value is passed, the figure will be saved in pdf format to this location.
:param hspace: (`float`) horizontal spacing between subplots. Defaults to 0.25.
:param use_grid: (`bool`) whether to use a grid for each subplot. Defaults to False.
:rtype: `Tuple[matplotlib.Figure, Dict]`
:return: matplotlib Figure and simulation observables indexed by simulator
"""
return API_VERIFIER.visualize_observables(job_id=job_id, save_dest=save_dest, hspace=hspace, use_grid=use_grid)

10 changes: 10 additions & 0 deletions bio_compose/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ def visualize_observables(self, job_id: str, hspace: float = 0.25, use_grid: boo
observables = [key for key in species_data_content.keys() if key not in excluded_observables]
first_observable = species_data_content[observables[0]]
simulators = list(first_observable['output_data'].keys())

# post-process to handle any strings (errors)
for sim in simulators:
data = first_observable['output_data'][sim]
if isinstance(data, str):
simulators.remove(sim)

# count post processed sims
n_simulators = len(simulators)

# create subplots
Expand All @@ -302,6 +310,8 @@ def visualize_observables(self, job_id: str, hspace: float = 0.25, use_grid: boo
ax = axes[idx]
for observable in observables:
value_data = species_data_content[observable]['output_data'][simulator]
if isinstance(value_data, str):
continue
obs[observable][simulator] = value_data
sns.lineplot(data=value_data, ax=ax, label=observable)

Expand Down
Loading

0 comments on commit 55e59c8

Please sign in to comment.