-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variance calibration #2636
base: main
Are you sure you want to change the base?
Variance calibration #2636
Changes from 7 commits
7c328fa
ceaf91b
dd3a59f
4a5e93b
cb1929d
e5d6fa6
f24dfed
9861948
460857a
13f83aa
e1f4e13
29b9009
9c7d4dc
86b5db5
554586f
6b3d336
c7a8126
b9d7efb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Makes changes to the CameraCalibrator in ctapipe.calib.camera.calibrator that allows it to correctly variance images generated with the VarianceExtractor | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -218,7 +218,7 @@ | |||||
calibration_monitoring_id=r1.calibration_monitoring_id, | ||||||
) | ||||||
|
||||||
def _calibrate_dl1(self, event, tel_id): | ||||||
waveforms = event.dl0.tel[tel_id].waveform | ||||||
if self._check_dl0_empty(waveforms): | ||||||
return | ||||||
|
@@ -283,7 +283,11 @@ | |||||
) | ||||||
|
||||||
# correct non-integer remainder of the shift if given | ||||||
if self.apply_peak_time_shift.tel[tel_id] and remaining_shift is not None: | ||||||
if ( | ||||||
self.apply_peak_time_shift.tel[tel_id] | ||||||
and remaining_shift is not None | ||||||
and dl1.peak_time is not None | ||||||
): | ||||||
dl1.peak_time -= remaining_shift | ||||||
|
||||||
# Calibrate extracted charge | ||||||
|
@@ -292,13 +296,21 @@ | |||||
and dl1_calib.absolute_factor is not None | ||||||
): | ||||||
if selected_gain_channel is None: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this section could use some refactoring to make it easier to follow. I think the logic is the same if we simplify to: if selected_gain_channel is None:
calibration = dl1_calib.relative_factor / dl1_calib.absolute_factor
else:
calibration = (
dl1_calib.relative_factor[selected_gain_channel, pixel_index]
/ dl1_calib.absolute_factor[selected_gain_channel, pixel_index]
)
if isinstance(extractor, VarianceExtractor):
calibration = calibration**2
dl1.image *= calibration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, I'll get to it when I arrive home There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i put it in |
||||||
dl1.image *= dl1_calib.relative_factor / dl1_calib.absolute_factor | ||||||
if extractor.__class__.__name__ == "VarianceExtractor": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
dl1.image *= np.sqrt( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be square, not square root |
||||||
dl1_calib.relative_factor / dl1_calib.absolute_factor | ||||||
) | ||||||
else: | ||||||
dl1.image *= dl1_calib.relative_factor / dl1_calib.absolute_factor | ||||||
else: | ||||||
corr = ( | ||||||
dl1_calib.relative_factor[selected_gain_channel, pixel_index] | ||||||
/ dl1_calib.absolute_factor[selected_gain_channel, pixel_index] | ||||||
) | ||||||
dl1.image *= corr | ||||||
if extractor.__class__.__name__ == "VarianceExtractor": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use this to check type, not a string comparison (which is slower and makes refactoring more difficult later)
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, im changing it now |
||||||
dl1.image *= np.sqrt(corr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as l.300 |
||||||
else: | ||||||
dl1.image *= corr | ||||||
|
||||||
# handle invalid pixels | ||||||
if self.invalid_pixel_handler is not None: | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
GlobalPeakWindowSum, | ||
LocalPeakWindowSum, | ||
NeighborPeakWindowSum, | ||
VarianceExtractor, | ||
) | ||
from ctapipe.image.reducer import NullDataVolumeReducer, TailCutsDataVolumeReducer | ||
|
||
|
@@ -130,6 +131,23 @@ def test_check_dl0_empty(example_event, example_subarray): | |
assert (event.dl1.tel[tel_id].image == 2).all() | ||
|
||
|
||
def test_dl1_variance_calib(example_event, example_subarray): | ||
# test the calibration of variance images | ||
tel_id = list(example_event.r0.tel)[0] | ||
calibrator = CameraCalibrator( | ||
subarray=example_subarray, | ||
image_extractor=VarianceExtractor(subarray=example_subarray), | ||
apply_waveform_time_shift=False, | ||
) | ||
calibrator(example_event) | ||
image = example_event.dl1.tel[tel_id].image | ||
assert image is not None | ||
assert image.shape == ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test with the LST (two gains) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make sense to add a test for other extractor with the LST? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use a parametrized test here to test all telescope types. ( |
||
1, | ||
1764, | ||
) | ||
|
||
|
||
def test_dl1_charge_calib(example_subarray): | ||
# copy because we mutate the camera, should not affect other tests | ||
subarray = deepcopy(example_subarray) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1308,7 +1308,7 @@ def __call__( | |
self, waveforms, tel_id, selected_gain_channel, broken_pixels | ||
) -> DL1CameraContainer: | ||
container = DL1CameraContainer( | ||
image=np.nanvar(waveforms, dtype="float32", axis=2), | ||
image=np.nanvar(waveforms, dtype="float32", keepdims=False, axis=2), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit weird that you need to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will check again if i make it work without that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should work without it: x = np.random.uniform(size=(2,1800, 1000))
In [1]: np.nanvar(x, axis=2).shape
Out[2]: (2, 1800)
In [2]: np.nanvar(x, axis=2, keepdims=True).shape
Out[2]: (2, 1800, 1)
In [3]: np.nanvar(x, axis=2, keepdims=False).shape
Out[3]: (2, 1800) |
||
) | ||
container.meta["ExtractionMethod"] = str(VarianceType.WAVEFORM) | ||
return container | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please describe the actual change, not just say "there are changes". Also there is a verb missing here (calibrate?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added some explanation