Skip to content
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

Skip DRS4 calibrations already performed by EVB. #229

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- astropy >=5.2,<7
- python=3.11 # nail the python version, so conda does not try upgrading / dowgrading
- ctapipe
- protozfits=2.4
- protozfits >=2.4,<3
- eventio
- corsikaio
- zeromq
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ zip_safe = False
install_requires=
astropy >=5.2,<7.0.0a0
ctapipe >=0.19.0,<0.22.0a0
protozfits ~=2.4
protozfits ~=2.5
numpy >=1.20
scipy <1.14

Expand Down
11 changes: 7 additions & 4 deletions src/ctapipe_io_lst/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from .compat import CTAPIPE_GE_0_21
from .containers import LSTArrayEventContainer
from .evb_preprocessing import EVBPreprocessingFlag


from .constants import (
Expand Down Expand Up @@ -225,6 +226,9 @@ def __init__(self, subarray, config=None, parent=None, **kwargs):
def apply_drs4_corrections(self, event: LSTArrayEventContainer):

for tel_id in event.trigger.tels_with_trigger:
tdp_action = event.lst.tel[tel_id].evt.tdp_action
preprocessing = EVBPreprocessingFlag(tdp_action or 0)

r1 = event.r1.tel[tel_id]
# If r1 was not yet filled, copy of r0 converted
if r1.waveform is None:
Expand All @@ -244,21 +248,20 @@ def apply_drs4_corrections(self, event: LSTArrayEventContainer):
r1.waveform = r1.waveform.astype(np.float32, copy=False)

# apply drs4 corrections
if self.apply_drs4_pedestal_correction:
if self.apply_drs4_pedestal_correction and EVBPreprocessingFlag.BASELINE_SUBTRACTION not in preprocessing:
self.subtract_pedestal(event, tel_id)

if self.apply_timelapse_correction:
if self.apply_timelapse_correction and EVBPreprocessingFlag.DELTA_T_CORRECTION not in preprocessing:
self.time_lapse_corr(event, tel_id)
else:
self.update_last_readout_times(event, tel_id)

if self.apply_spike_correction:
if self.apply_spike_correction and EVBPreprocessingFlag.SPIKE_REMOVAL not in preprocessing:
if self.spike_correction_method == 'subtraction':
self.subtract_spikes(event, tel_id)
else:
self.interpolate_spikes(event, tel_id)


# remove samples at beginning / end of waveform
start = self.r1_sample_start.tel[tel_id]
end = self.r1_sample_end.tel[tel_id]
Expand Down
47 changes: 14 additions & 33 deletions src/ctapipe_io_lst/tests/test_cta_r1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
from ctapipe.containers import EventType

import protozfits
from protozfits.CoreMessages_pb2 import AnyArray
from protozfits.R1v1_pb2 import CameraConfiguration, Event, TelescopeDataStream
from protozfits.R1v1_debug_pb2 import DebugEvent, DebugCameraConfiguration
from protozfits.CoreMessages_pb2 import AnyArray
from protozfits.any_array_to_numpy import numpy_to_any_array

from ctapipe_io_lst import LSTEventSource, CTAPIPE_GE_0_21
from ctapipe_io_lst.anyarray_dtypes import CDTS_AFTER_37201_DTYPE, TIB_DTYPE
Expand All @@ -29,22 +30,6 @@
test_drs4_pedestal_path = test_data / 'real/monitoring/PixelCalibration/LevelA/drs4_baseline/20200218/v0.8.2.post2.dev48+gb1343281/drs4_pedestal.Run02005.0000.h5'


ANY_ARRAY_TYPE_TO_NUMPY_TYPE = {
1: np.int8,
2: np.uint8,
3: np.int16,
4: np.uint16,
5: np.int32,
6: np.uint32,
7: np.int64,
8: np.uint64,
9: np.float32,
10: np.float64,
}

DTYPE_TO_ANYARRAY_TYPE = {v: k for k, v in ANY_ARRAY_TYPE_TO_NUMPY_TYPE.items()}


subarray = LSTEventSource.create_subarray(tel_id=1)
GEOMETRY = subarray.tel[1].camera.geometry
pulse_shape = subarray.tel[1].camera.readout.reference_pulse_shape[0]
Expand Down Expand Up @@ -107,10 +92,6 @@ def create_pedestal(rng):
return image, peak_time


def to_anyarray(array):
type_ = DTYPE_TO_ANYARRAY_TYPE[array.dtype.type]
return AnyArray(type=type_, data=array.tobytes())


@pytest.fixture(scope="session")
def dummy_cta_r1_dir(tmp_path_factory):
Expand Down Expand Up @@ -169,17 +150,17 @@ def dummy_cta_r1(dummy_cta_r1_dir):
num_channels=2,
data_model_version="1.0",
num_samples_nominal=num_samples,
pixel_id_map=to_anyarray(np.arange(num_pixels).astype(np.uint16)),
module_id_map=to_anyarray(np.arange(num_modules).astype(np.uint16)),
pixel_id_map=numpy_to_any_array(np.arange(num_pixels).astype(np.uint16)),
module_id_map=numpy_to_any_array(np.arange(num_modules).astype(np.uint16)),

debug=DebugCameraConfiguration(
cs_serial="???",
evb_version="evb-dummy",
cdhs_version="evb-dummy",
tdp_type=to_anyarray(tdp_type),
tdp_action=to_anyarray(np.zeros(16, dtype=np.uint16)),
tdp_type=numpy_to_any_array(tdp_type),
tdp_action=numpy_to_any_array(np.zeros(16, dtype=np.uint16)),
# at the moment, the tdp_action and ttype_pattern fields are mixed up in EVB
ttype_pattern=to_anyarray(tdp_action),
ttype_pattern=numpy_to_any_array(tdp_action),
)
)

Expand Down Expand Up @@ -280,15 +261,15 @@ def dummy_cta_r1(dummy_cta_r1_dir):
num_channels=num_channels,
num_pixels=num_pixels,
num_samples=num_samples,
pixel_status=to_anyarray(pixel_status),
waveform=to_anyarray(waveform),
first_cell_id=to_anyarray(first_cell_id),
module_hires_local_clock_counter=to_anyarray(module_hires_local_clock_counter),
pixel_status=numpy_to_any_array(pixel_status),
waveform=numpy_to_any_array(waveform),
first_cell_id=numpy_to_any_array(first_cell_id),
module_hires_local_clock_counter=numpy_to_any_array(module_hires_local_clock_counter),
debug=DebugEvent(
module_status=to_anyarray(np.ones(num_modules, dtype=np.uint8)),
module_status=numpy_to_any_array(np.ones(num_modules, dtype=np.uint8)),
extdevices_presence=0b011,
cdts_data=to_anyarray(cdts_data.view(np.uint8)),
tib_data=to_anyarray(tib_data.view(np.uint8)),
cdts_data=numpy_to_any_array(cdts_data.view(np.uint8)),
tib_data=numpy_to_any_array(tib_data.view(np.uint8)),
)
)

Expand Down