Skip to content

Commit

Permalink
Merge pull request #8 from virtualcell/refactor-animation-render
Browse files Browse the repository at this point in the history
fix: removed ipython in place for plt mutation
  • Loading branch information
AlexPatrie authored Feb 25, 2025
2 parents dc25fa2 + 573690a commit 8121395
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 38 deletions.
36 changes: 18 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ documentation = "https://virtualcell.github.io/pyvcell/"
readme = "README.md"
packages = [
{include = "pyvcell"},
{include = "tests"},
]

[tool.poetry.dependencies]
Expand All @@ -31,7 +30,6 @@ python-dateutil = "^2.9.0.post0"
pyvista = "^0.44.2"
python-libsbml = "^5.20.4"
matplotlib = "^3.10.0"
ipython = "^8.32.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
Expand Down
29 changes: 11 additions & 18 deletions pyvcell/data_model/plotter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any, Union, no_type_check
from typing import Union, no_type_check

import matplotlib.pyplot as plt
import numpy as np
import zarr
from IPython.display import HTML
from matplotlib import animation

from pyvcell.data_model.var_types import NDArray2D
Expand All @@ -12,6 +11,10 @@
from pyvcell.simdata.postprocessing import PostProcessing, VariableInfo
from pyvcell.utils import slice_dataset

plt.rcParams["animation.html"] = "jshtml"
plt.rcParams["figure.dpi"] = 150
plt.ioff()


class Plotter:
def __init__(
Expand Down Expand Up @@ -143,17 +146,10 @@ def update(frame: int):

# Create the animation
fig.colorbar(sc, ax=ax, label="Intensity") # type: ignore[arg-type]
ani = animation.FuncAnimation(fig, update, num_timepoints, interval=interval, blit=False)

return ani
return animation.FuncAnimation(fig, update, num_timepoints, interval=interval, blit=False)

@no_type_check
def render_animation(self, ani: animation.FuncAnimation) -> HTML:
return HTML(ani.to_jshtml())

def animate_channel_3d(self, channel_index: int) -> Any:
ani = self.get_3d_slice_animation(channel_index)
return self.render_animation(ani)
def animate_channel_3d(self, channel_index: int) -> animation.FuncAnimation:
return self.get_3d_slice_animation(channel_index)

def get_image_animation(self, image_index: int, interval: int = 200) -> animation.FuncAnimation:
"""
Expand Down Expand Up @@ -184,14 +180,11 @@ def update(frame: int):
return (img_plot,)

# Create the animation
ani = animation.FuncAnimation(fig, update, frames=self.num_timepoints, interval=interval, blit=False)

return ani
return animation.FuncAnimation(fig, update, frames=self.num_timepoints, interval=interval, blit=False)

@no_type_check
def animate_image(self, image_index: int) -> HTML:
ani = self.get_image_animation(image_index)
return self.render_animation(ani)
def animate_image(self, image_index: int) -> animation.FuncAnimation:
return self.get_image_animation(image_index)

def plot_averages(self) -> None:
var_averages: set[VariableInfo] = {var for var in self.post_processing.variables if var.statistic_type == 0}
Expand Down
5 changes: 5 additions & 0 deletions tests/data_model/test_result.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# test result class
import os
from pathlib import Path

import numpy as np
import pytest

from pyvcell.data_model.result import Result
from pyvcell.data_model.var_types import NDArray2D

IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_plot_slice_2D(solver_output_path: Path, solver_output_simid_jobid: tuple[int, int], zarr_path: Path) -> None:
sim_id, job_id = solver_output_simid_jobid
result = Result(solver_output_dir=solver_output_path, sim_id=sim_id, job_id=job_id, zarr_dir=zarr_path)
Expand Down

0 comments on commit 8121395

Please sign in to comment.