From c9c79d32d8ca1875c4bb7e410feb02e75ab63267 Mon Sep 17 00:00:00 2001 From: Franca Cassol Date: Wed, 8 Feb 2023 16:25:10 +0000 Subject: [PATCH 1/4] Add config to write interleaved events with DataWriter --- lstchain/data/lstchain_standard_config.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lstchain/data/lstchain_standard_config.json b/lstchain/data/lstchain_standard_config.json index 727a92ad3b..9059e14a62 100644 --- a/lstchain/data/lstchain_standard_config.json +++ b/lstchain/data/lstchain_standard_config.json @@ -275,5 +275,17 @@ "nsb_tuning": false, "nsb_tuning_ratio": 0.52, "spe_location": "lstchain/data/SinglePhE_ResponseInPhE_expo2Gaus.dat" + }, + "write_interleaved_events":{ + "DataWriter": { + "overwrite": true, + "write_images": false, + "write_parameters": false, + "write_waveforms": true, + "transform_waveform": true, + "waveform_dtype": "uint16", + "waveform_offset": 400, + "waveform_scale": 1 + } } } From 3728ea3402fd3dd8feeb2a2898d8d41f01452c22 Mon Sep 17 00:00:00 2001 From: Franca Cassol Date: Wed, 8 Feb 2023 16:26:07 +0000 Subject: [PATCH 2/4] Add code to write interleaved events with DataWriter --- lstchain/reco/r0_to_dl1.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lstchain/reco/r0_to_dl1.py b/lstchain/reco/r0_to_dl1.py index acdc712ed2..92187a317f 100644 --- a/lstchain/reco/r0_to_dl1.py +++ b/lstchain/reco/r0_to_dl1.py @@ -23,7 +23,7 @@ tailcuts_clean, ) from ctapipe.image import number_of_islands, apply_time_delta_cleaning -from ctapipe.io import EventSource, HDF5TableWriter +from ctapipe.io import EventSource, HDF5TableWriter, DataWriter from ctapipe.utils import get_dataset_path from traitlets.config import Config @@ -444,7 +444,17 @@ def r0_to_dl1( lhfit_fitter_config = {'TimeWaveformFitter': config['lh_fit_config']} lhfit_fitter = TimeWaveformFitter(subarray=subarray, config=Config(lhfit_fitter_config)) - with HDF5TableWriter( + # initialize the writer of the interleaved events + interleaved_writer = None + if 'write_interleaved_events' in config.keys(): + interleaved_writer_config = Config(config['write_interleaved_events']) + dir, name = os.path.split(output_filename) + name = name.replace('dl1', 'interleaved').replace('LST-1.1', 'LST-1') + interleaved_output_file = Path(dir, name) + interleaved_writer = DataWriter(event_source=source,output_path=interleaved_output_file,config=interleaved_writer_config) + + + with HDF5TableWriter( filename=output_filename, group_name='dl1/event', mode='a', @@ -510,8 +520,14 @@ def r0_to_dl1( calibration_index, event.mon.tel[tel_id], new_ped=new_ped_event, new_ff=new_ff_event) - + + # write the calibrated R1 waveform without gain selection + source.r0_r1_calibrator.select_gain = False + source.r0_r1_calibrator.calibrate(event) + interleaved_writer(event) + # calibrate and gain select the event by hand for DL1 + source.r0_r1_calibrator.select_gain = True source.r0_r1_calibrator.calibrate(event) # Option to add nsb in waveforms @@ -746,6 +762,11 @@ def r0_to_dl1( muon_output_filename = Path(dir, name) table = Table(muon_parameters) table.write(muon_output_filename, format='fits', overwrite=True) + + # close the interleaved output file and write metadata + if 'write_interleaved_events' in config.keys(): + interleaved_writer.finish() + def add_disp_to_parameters_table(dl1_file, table_path, focal): From 84df23892487068f6fe4a2f75dc6249be812e238 Mon Sep 17 00:00:00 2001 From: Franca Cassol Date: Mon, 13 Feb 2023 11:31:44 +0000 Subject: [PATCH 3/4] Correct the waveform_scaling factor --- lstchain/data/lstchain_standard_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/data/lstchain_standard_config.json b/lstchain/data/lstchain_standard_config.json index 9059e14a62..f855907bf9 100644 --- a/lstchain/data/lstchain_standard_config.json +++ b/lstchain/data/lstchain_standard_config.json @@ -285,7 +285,7 @@ "transform_waveform": true, "waveform_dtype": "uint16", "waveform_offset": 400, - "waveform_scale": 1 + "waveform_scale": 80 } } } From 6b6e1e9e4149320fd77613237dbba059eca0d0bb Mon Sep 17 00:00:00 2001 From: Franca Cassol Date: Mon, 15 May 2023 16:32:26 +0000 Subject: [PATCH 4/4] Improve "if" checks --- lstchain/reco/r0_to_dl1.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lstchain/reco/r0_to_dl1.py b/lstchain/reco/r0_to_dl1.py index 92187a317f..f6c87031b4 100644 --- a/lstchain/reco/r0_to_dl1.py +++ b/lstchain/reco/r0_to_dl1.py @@ -446,7 +446,7 @@ def r0_to_dl1( # initialize the writer of the interleaved events interleaved_writer = None - if 'write_interleaved_events' in config.keys(): + if 'write_interleaved_events' in config: interleaved_writer_config = Config(config['write_interleaved_events']) dir, name = os.path.split(output_filename) name = name.replace('dl1', 'interleaved').replace('LST-1.1', 'LST-1') @@ -524,7 +524,8 @@ def r0_to_dl1( # write the calibrated R1 waveform without gain selection source.r0_r1_calibrator.select_gain = False source.r0_r1_calibrator.calibrate(event) - interleaved_writer(event) + if interleaved_writer is not None: + interleaved_writer(event) # calibrate and gain select the event by hand for DL1 source.r0_r1_calibrator.select_gain = True @@ -764,7 +765,7 @@ def r0_to_dl1( table.write(muon_output_filename, format='fits', overwrite=True) # close the interleaved output file and write metadata - if 'write_interleaved_events' in config.keys(): + if interleaved_writer is not None: interleaved_writer.finish()