Skip to content

Commit

Permalink
Use one figure per test, not the global one. Save the resulting plot.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbiederbeck committed Jan 12, 2023
1 parent a6dc892 commit ff94eed
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ctapipe/visualization/tests/test_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def test_camera_display_single(prod5_lst_cam, tmp_path):
"""test CameraDisplay functionality"""
from ..mpl_camera import CameraDisplay

fig, ax = plt.subplots()
geom = prod5_lst_cam
disp = CameraDisplay(geom)
disp = CameraDisplay(geom, ax=ax)
image = np.random.normal(size=len(geom.pix_x))
disp.image = image
disp.add_colorbar()
Expand All @@ -86,36 +87,41 @@ def test_camera_display_single(prod5_lst_cam, tmp_path):

disp.add_ellipse(centroid=(0, 0), width=0.1, length=0.1, angle=0.1)
disp.clear_overlays()
fig.savefig(tmp_path / "result.png")


def test_hillas_overlay(prod5_lst_cam):
def test_hillas_overlay(prod5_lst_cam, tmp_path):
from ctapipe.visualization import CameraDisplay

disp = CameraDisplay(prod5_lst_cam)
fig, ax = plt.subplots()
disp = CameraDisplay(prod5_lst_cam, ax=ax)
hillas = CameraHillasParametersContainer(
x=0.1 * u.m, y=-0.1 * u.m, length=0.5 * u.m, width=0.2 * u.m, psi=90 * u.deg
)

disp.overlay_moments(hillas)
disp.overlay_moments(hillas, color="w")
fig.savefig(tmp_path / "result.png")


@pytest.mark.parametrize("pix_type", PixelShape.__members__.values())
def test_pixel_shapes(pix_type, prod5_lst_cam):
def test_pixel_shapes(pix_type, prod5_lst_cam, tmp_path):
"""test CameraDisplay functionality"""
from ..mpl_camera import CameraDisplay

geom = prod5_lst_cam
geom.pix_type = pix_type

disp = CameraDisplay(geom)
fig, ax = plt.subplots()
disp = CameraDisplay(geom, ax=ax)
image = np.random.normal(size=len(geom.pix_x))
disp.image = image
disp.add_colorbar()
disp.highlight_pixels([1, 2, 3, 4, 5])
disp.add_ellipse(centroid=(0, 0), width=0.1, length=0.1, angle=0.1)
fig.savefig(tmp_path / "result.png")


def test_camera_display_multiple(prod5_lst_cam):
def test_camera_display_multiple(prod5_lst_cam, tmp_path):
"""create a figure with 2 subplots, each with a CameraDisplay"""
from ..mpl_camera import CameraDisplay

Expand All @@ -128,6 +134,7 @@ def test_camera_display_multiple(prod5_lst_cam):
image = np.ones(len(geom.pix_x), dtype=float)
d1.image = image
d2.image = image
fig.savefig(tmp_path / "result.png")


def test_array_display(prod5_mst_nectarcam):
Expand Down

0 comments on commit ff94eed

Please sign in to comment.