Skip to content

Commit

Permalink
updated for chore
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Apr 26, 2024
1 parent 377ae3a commit 647e35a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ buildDockerImage.yml
process-bigraph
bigraph-schema
bigraph-builder
3.10/
Miniforge3-Darwin-arm64.sh
*.cpython-310.pyc

Binary file not shown.
15 changes: 15 additions & 0 deletions biosimulator_processes/processes/copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ def update(self, inputs, interval):
return results


def test_process_from_document():
import json
# ensure that the process is registered
CORE.process_registry.register('biosimulator_processes.processes.copasi_process.CopasiProcess', CopasiProcess)

# read the document from local file:
five_process_fp = 'notebooks/out/five_process_composite.json'
with open(five_process_fp, 'r') as fp:
instance = json.load(fp)

workflow = Composite(config={
'state': instance
})


def test_process():
CORE.process_registry.register('biosimulator_processes.processes.copasi_process.CopasiProcess', CopasiProcess)
instance = {
Expand Down
79 changes: 79 additions & 0 deletions biosimulator_processes/steps/viz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from typing import Tuple, Callable
from dataclasses import dataclass
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from process_bigraph.composite import Step


@dataclass
class PlotLabelConfig:
title: str
x_label: str
y_label: str


class ResultsAnimation:
def __init__(self,
x_data: np.array,
y_data: np.array,
plot_type_func: Callable,
plot_label_config: PlotLabelConfig,
**config):
self.x_data = x_data
self.y_data = y_data
self.plot_type_func = plot_type_func
self.plot_label_config = plot_label_config
self.config = config

def _set_axis_limits(self, ax_limit_func, data):
return ax_limit_func(data.min(), data.max())

def _prepare_animation(self, t):
plt.cla()
self.plot_type_func(
self.x_data,
self.y_data,
color=self.config.get('color', 'blue')
)

self._set_axis_limits(plt.xlim, self.x_data)
self._set_axis_limits(plt.ylim, self.y_data)
plt.axhline(0, color='grey', lw=0.5)
plt.axvline(0, color='grey', lw=0.5)
plt.title(self.plot_label_config.title)
plt.xlabel(self.plot_label_config.x_label)
plt.ylabel(self.plot_label_config.y_label)

def _create_animation_components(self) -> Tuple:
"""
Creates a matplotlib subplot setup for animation.
Returns:
Tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]: A tuple containing the figure and axes objects.
"""
plt.rcParams["animation.html"] = "jshtml"
plt.rcParams['figure.dpi'] = 150 # TODO: add this to config
plt.ioff()
fig, ax = plt.subplots()
return fig, ax

def run(self, num_frames: int):
"""
Creates and runs the animation.
Args:
num_frames (int): Number of frames to animate
Returns:
matplotlib.animation.FuncAnimation: The animation object.
"""
fig, ax = self._create_animation_components()
return FuncAnimation(fig, self._prepare_animation, frames=num_frames)


# TODO: Create plotting step for this


class Plotter2d(Step):
pass
Empty file.
Empty file.

0 comments on commit 647e35a

Please sign in to comment.