Skip to content

Commit

Permalink
Make sure a fixed random seed is used for toymodel test also when tes…
Browse files Browse the repository at this point in the history
…ting calling it without seed
  • Loading branch information
maxnoe committed Nov 26, 2021
1 parent 22655d1 commit d68cdbe
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ctapipe/image/tests/test_toy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@


@pytest.mark.parametrize("seed", [None, 0])
def test_intensity(seed):
from ctapipe.image.toymodel import Gaussian
def test_intensity(seed, monkeypatch):
"""
Test generation of the toymodel roughly follows the given intensity.
Tests once with passing a custom rng instance, once with relying on the
modules rng.
"""
from ctapipe.image import toymodel

geom = CameraGeometry.from_name("LSTCam")

Expand All @@ -19,8 +25,12 @@ def test_intensity(seed):
intensity = 200
psi = "30d"

# make sure we set a fixed seed for this test even when testing the
# API without giving the rng
monkeypatch.setattr(toymodel, "TOYMODEL_RNG", np.random.default_rng(0))

# make a toymodel shower model
model = Gaussian(x=x, y=y, width=width, length=length, psi=psi)
model = toymodel.Gaussian(x=x, y=y, width=width, length=length, psi=psi)

if seed is None:
_, signal, _ = model.generate_image(geom, intensity=intensity, nsb_level_pe=5)
Expand Down

0 comments on commit d68cdbe

Please sign in to comment.