-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing the toy image generator (#790)
* Add test for toy image generator * Fix toymodel generator and test event * The evaluation of the 2d gaussian was missing the normalisation for the pixel area * Length and width were not squared * Adapted test image to show a more realistic shower image * Remove print * Adapt hillas example * Adapt shower image size to camera geometry * Use larger tolerance * Adapt test image to camera geometry * Use itertools for test loop * Make hillas test agnostic to 180deg rotations * Adapt examples to new toy generator
- Loading branch information
Showing
13 changed files
with
177 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
from ctapipe.instrument import CameraGeometry | ||
from pytest import approx | ||
from scipy.stats import poisson | ||
|
||
|
||
def test_intensity(): | ||
from .. import toymodel | ||
|
||
np.random.seed(0) | ||
|
||
geom = CameraGeometry.from_name('LSTCam') | ||
|
||
width = 0.05 | ||
length = 0.15 | ||
intensity = 50 | ||
|
||
# make a toymodel shower model | ||
model = toymodel.generate_2d_shower_model( | ||
centroid=(0.2, 0.3), | ||
width=width, length=length, | ||
psi='30d', | ||
) | ||
|
||
image, signal, noise = toymodel.make_toymodel_shower_image( | ||
geom, model.pdf, intensity=intensity, nsb_level_pe=5, | ||
) | ||
|
||
# test if signal reproduces given cog values | ||
assert np.average(geom.pix_x.value, weights=signal) == approx(0.2, rel=0.15) | ||
assert np.average(geom.pix_y.value, weights=signal) == approx(0.3, rel=0.15) | ||
|
||
# test if signal reproduces given width/length values | ||
cov = np.cov(geom.pix_x.value, geom.pix_y.value, aweights=signal) | ||
eigvals, eigvecs = np.linalg.eigh(cov) | ||
|
||
assert np.sqrt(eigvals[0]) == approx(width, rel=0.15) | ||
assert np.sqrt(eigvals[1]) == approx(length, rel=0.15) | ||
|
||
# test if total intensity is inside in 99 percent confidence interval | ||
assert poisson(intensity).ppf(0.05) <= signal.sum() <= poisson(intensity).ppf(0.95) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.