-
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.
better leakage parameter calculation (#783)
* Implement get_border_pixel_mask * Add leakage image parameter * Do not use lru_cache to fix pickling * Fix size in leakage
- Loading branch information
Showing
6 changed files
with
154 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
from .reducers import * | ||
from .muon import * | ||
from .geometry_converter import * | ||
from .leakage import * |
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,50 @@ | ||
""" | ||
Leakage calculation | ||
""" | ||
|
||
import numpy as np | ||
from ..io.containers import LeakageContainer | ||
|
||
|
||
__all__ = ['leakage'] | ||
|
||
|
||
def leakage(geom, image, cleaning_mask): | ||
''' | ||
Calculating the leakage-values for a given image. | ||
Image must be cleaned for example with tailcuts_clean. | ||
Leakage describes how strong a shower is on the edge of a telescope. | ||
Parameters | ||
---------- | ||
geom: ctapipe.instrument.CameraGeometry | ||
Camera geometry information | ||
image: array | ||
pixel values | ||
cleaning_mask: array, dtype=bool | ||
The pixel that survived cleaning, e.g. tailcuts_clean | ||
Returns | ||
------- | ||
LeakageContainer | ||
''' | ||
border1 = geom.get_border_pixel_mask(1) | ||
border2 = geom.get_border_pixel_mask(2) | ||
|
||
mask1 = border1 & cleaning_mask | ||
mask2 = border2 & cleaning_mask | ||
|
||
leakage_pixel1 = np.sum(mask1) | ||
leakage_pixel2 = np.sum(mask2) | ||
|
||
leakage_intensity1 = np.sum(image[mask1]) | ||
leakage_intensity2 = np.sum(image[mask2]) | ||
|
||
size = np.sum(image[cleaning_mask]) | ||
|
||
return LeakageContainer( | ||
leakage1_pixel=leakage_pixel1 / geom.n_pixels, | ||
leakage2_pixel=leakage_pixel2 / geom.n_pixels, | ||
leakage1_intensity=leakage_intensity1 / size, | ||
leakage2_intensity=leakage_intensity2 / size, | ||
) |
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,21 @@ | ||
from ctapipe.instrument.camera import CameraGeometry | ||
import numpy as np | ||
|
||
|
||
def test_leakage(): | ||
from ctapipe.image.leakage import leakage | ||
|
||
geom = CameraGeometry.from_name('LSTCam') | ||
|
||
img = np.ones(geom.n_pixels) | ||
mask = np.ones(len(geom), dtype=bool) | ||
|
||
l = leakage(geom, img, mask) | ||
|
||
ratio1 = np.sum(geom.get_border_pixel_mask(1)) / geom.n_pixels | ||
ratio2 = np.sum(geom.get_border_pixel_mask(2)) / geom.n_pixels | ||
|
||
assert l.leakage1_intensity == ratio1 | ||
assert l.leakage2_intensity == ratio2 | ||
assert l.leakage1_pixel == ratio1 | ||
assert l.leakage2_pixel == ratio2 |
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