diff --git a/environment.yml b/environment.yml index f9df547e..44637fc2 100644 --- a/environment.yml +++ b/environment.yml @@ -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 diff --git a/setup.cfg b/setup.cfg index 66d3406c..35c7afca 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/src/ctapipe_io_lst/calibration.py b/src/ctapipe_io_lst/calibration.py index ac2683d3..7acd6cd1 100644 --- a/src/ctapipe_io_lst/calibration.py +++ b/src/ctapipe_io_lst/calibration.py @@ -18,6 +18,7 @@ from .compat import CTAPIPE_GE_0_21 from .containers import LSTArrayEventContainer +from .evb_preprocessing import EVBPreprocessingFlag from .constants import ( @@ -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: @@ -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] diff --git a/src/ctapipe_io_lst/tests/test_cta_r1.py b/src/ctapipe_io_lst/tests/test_cta_r1.py index 794fea0f..b8f63abc 100644 --- a/src/ctapipe_io_lst/tests/test_cta_r1.py +++ b/src/ctapipe_io_lst/tests/test_cta_r1.py @@ -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 @@ -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] @@ -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): @@ -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), ) ) @@ -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)), ) )