diff --git a/ctapipe/calib/camera/__init__.py b/ctapipe/calib/camera/__init__.py index 385056a67a3..9b8b02d0a11 100644 --- a/ctapipe/calib/camera/__init__.py +++ b/ctapipe/calib/camera/__init__.py @@ -3,7 +3,6 @@ Camera calibration module. """ -from .r1 import * from .dl0 import * from .dl1 import * from .calibrator import * diff --git a/ctapipe/calib/camera/calibrator.py b/ctapipe/calib/camera/calibrator.py index a8e6812614e..edc0aa795e2 100644 --- a/ctapipe/calib/camera/calibrator.py +++ b/ctapipe/calib/camera/calibrator.py @@ -6,7 +6,6 @@ from ctapipe.core import Component from ctapipe.calib.camera import ( - CameraR1Calibrator, CameraDL0Reducer, CameraDL1Calibrator, ) @@ -25,9 +24,7 @@ class CameraCalibrator(Component): """ def __init__(self, config=None, parent=None, - r1_product=None, extractor_name='NeighborPeakWindowSum', - eventsource=None, **kwargs): """ Parameters @@ -40,14 +37,8 @@ def __init__(self, config=None, parent=None, Tool executable that is calling this component. Passes the correct logger to the component. Set to None if no Tool to pass. - r1_product : str - The R1 calibrator to use. Manually overrides the Factory. extractor_name : str The name of the ImageExtractor to use. - eventsource : ctapipe.io.eventsource.EventSource - EventSource that is being used to read the events. The EventSource - contains information (such as metadata or inst) which indicates - the appropriate R1Calibrator to use. kwargs """ super().__init__(config=config, parent=parent, **kwargs) @@ -57,17 +48,6 @@ def __init__(self, config=None, parent=None, parent=self, ) - if r1_product: - self.r1 = CameraR1Calibrator.from_name( - r1_product, - parent=self, - ) - else: - self.r1 = CameraR1Calibrator.from_eventsource( - eventsource, - parent=self, - ) - self.dl0 = CameraDL0Reducer(parent=parent) self.dl1 = CameraDL1Calibrator( parent=self, @@ -85,6 +65,5 @@ def calibrate(self, event): event : container A `ctapipe` event container """ - self.r1.calibrate(event) self.dl0.reduce(event) self.dl1.calibrate(event) diff --git a/ctapipe/calib/camera/r1.py b/ctapipe/calib/camera/r1.py deleted file mode 100644 index ce55769c13a..00000000000 --- a/ctapipe/calib/camera/r1.py +++ /dev/null @@ -1,214 +0,0 @@ -""" -Calibrator for the R0 -> R1 data level transition. - -This module handles the calibration from the R0 data level to R1. This data -level transition will be handled by the camera servers, not in the pipeline, -however the pipeline can be used as a test-bench in the comissioning stage of -the cameras. - -As the R1 calibration is camera specific, each camera (and seperately the MC) -requires their own calibrator class with inherits from `CameraR1Calibrator`. -`HessioR1Calibrator` is the calibrator for the MC data obtained from readhess. -Through the use of `CameraR1Calibrator.from_eventsource()`, the correct -`CameraR1Calibrator` can be obtained based on the origin (MC/Camera format) -of the data. -""" -from abc import abstractmethod - -from ...core import Component - -__all__ = [ - 'NullR1Calibrator', - 'HESSIOR1Calibrator', - 'CameraR1Calibrator', -] - - -class CameraR1Calibrator(Component): - """ - The base R1-level calibrator. Fills the r1 container. - - The R1 calibrator performs the camera-specific R1 calibration that is - usually performed on the raw data by the camera server. This calibrator - exists in ctapipe for testing and prototyping purposes. - - Parameters - ---------- - config : traitlets.loader.Config - Configuration specified by config file or cmdline arguments. - Used to set traitlet values. - Set to None if no configuration to pass. - tool : ctapipe.core.Tool or None - Tool executable that is calling this component. - Passes the correct logger to the component. - Set to None if no Tool to pass. - kwargs - """ - def __init__(self, config=None, parent=None, **kwargs): - """ - Parent class for the r1 calibrators. Fills the r1 container. - - Parameters - ---------- - config : traitlets.loader.Config - Configuration specified by config file or cmdline arguments. - Used to set traitlet values. - Set to None if no configuration to pass. - tool : ctapipe.core.Tool or None - Tool executable that is calling this component. - Passes the correct logger to the component. - Set to None if no Tool to pass. - kwargs - """ - super().__init__(config=config, parent=parent, **kwargs) - self._r0_empty_warn = False - - @abstractmethod - def calibrate(self, event): - """ - Abstract method to be defined in child class. - - Perform the conversion from raw R0 data to R1 data - (ADC Samples -> PE Samples), and fill the r1 container. - - Parameters - ---------- - event : container - A `ctapipe` event container - """ - - def check_r0_exists(self, event, telid): - """ - Check that r0 data exists. If it does not, then do not change r1. - - This ensures that if the containers were filled from a file containing - r0 data, it is not overwritten by non-existant data. - - Parameters - ---------- - event : container - A `ctapipe` event container - telid : int - The telescope id. - - Returns - ------- - bool - True if r0.tel[telid].waveform is not None, else false. - """ - r0 = event.r0.tel[telid].waveform - if r0 is not None: - return True - else: - if not self._r0_empty_warn: - self.log.warning("Encountered an event with no R0 data. " - "R1 is unchanged in this circumstance.") - self._r0_empty_warn = True - return False - - @classmethod - def from_eventsource(cls, eventsource, **kwargs): - """ - Obtain the correct `CameraR1Calibrator` according the the `EventSource` - of the file. - - Parameters - ---------- - eventsource : ctapipe.io.EventSource - Subclass of `ctapipe.io.EventSource` - kwargs - Named arguments to pass to the `CameraR1Calibrator` - - Returns - ------- - calibrator - Subclass of `CameraR1Calibrator` - """ - if (hasattr(eventsource, 'metadata') and - eventsource.metadata['is_simulation']): - return HESSIOR1Calibrator(**kwargs) - elif eventsource.__class__.__name__ == "TargetIOEventSource": - from ctapipe_io_targetio import TargetIOR1Calibrator - return TargetIOR1Calibrator(**kwargs) - - return NullR1Calibrator(**kwargs) - - -class NullR1Calibrator(CameraR1Calibrator): - """ - A dummy R1 calibrator that simply fills the r1 container with the samples - from the r0 container. - - Parameters - ---------- - config : traitlets.loader.Config - Configuration specified by config file or cmdline arguments. - Used to set traitlet values. - Set to None if no configuration to pass. - tool : ctapipe.core.Tool or None - Tool executable that is calling this component. - Passes the correct logger to the component. - Set to None if no Tool to pass. - kwargs - """ - - def __init__(self, config=None, parent=None, **kwargs): - super().__init__(config, parent, **kwargs) - self.log.info("Using NullR1Calibrator, if event source is at " - "the R0 level, then r1 samples will equal r0 samples") - - def calibrate(self, event): - for telid in event.r0.tels_with_data: - if self.check_r0_exists(event, telid): - samples = event.r0.tel[telid].waveform - event.r1.tel[telid].waveform = samples.astype('float32') - - -class HESSIOR1Calibrator(CameraR1Calibrator): - """ - The R1 calibrator for hessio files. Fills the r1 container. - - This calibrator correctly applies the pedestal subtraction and conversion - from counts to photoelectrons for the Monte-Carlo data. - - Parameters - ---------- - config : traitlets.loader.Config - Configuration specified by config file or cmdline arguments. - Used to set traitlet values. - Set to None if no configuration to pass. - tool : ctapipe.core.Tool or None - Tool executable that is calling this component. - Passes the correct logger to the component. - Set to None if no Tool to pass. - kwargs - """ - - calib_scale = 1.05 - """ - CALIB_SCALE is only relevant for MC calibration. - - CALIB_SCALE is the factor needed to transform from mean p.e. units to - units of the single-p.e. peak: Depends on the collection efficiency, - the asymmetry of the single p.e. amplitude distribution and the - electronic noise added to the signals. Default value is for GCT. - - To correctly calibrate to number of photoelectron, a fresh SPE calibration - should be applied using a SPE sim_telarray run with an - artificial light source. - """ - # TODO: Handle calib_scale differently per simlated telescope - - def calibrate(self, event): - if event.meta['origin'] != 'hessio': - raise ValueError('Using HESSIOR1Calibrator to calibrate a ' - 'non-hessio event.') - - for telid in event.r0.tels_with_data: - if self.check_r0_exists(event, telid): - samples = event.r0.tel[telid].waveform - n_samples = samples.shape[2] - ped = event.mc.tel[telid].pedestal / n_samples - gain = event.mc.tel[telid].dc_to_pe * self.calib_scale - calibrated = (samples - ped[..., None]) * gain[..., None] - event.r1.tel[telid].waveform = calibrated diff --git a/ctapipe/calib/camera/tests/test_calibrator.py b/ctapipe/calib/camera/tests/test_calibrator.py index 9cd92c3bf29..11f63298085 100644 --- a/ctapipe/calib/camera/tests/test_calibrator.py +++ b/ctapipe/calib/camera/tests/test_calibrator.py @@ -1,53 +1,25 @@ -from numpy.testing import assert_allclose - from ctapipe.calib.camera import ( CameraCalibrator, - HESSIOR1Calibrator, - NullR1Calibrator ) from ctapipe.image.extractor import LocalPeakWindowSum -from ctapipe.io import SimTelEventSource -from ctapipe.utils import get_dataset_path from traitlets.config.configurable import Config def test_camera_calibrator(example_event): telid = list(example_event.r0.tel)[0] - calibrator = CameraCalibrator(r1_product="HESSIOR1Calibrator") + calibrator = CameraCalibrator() calibrator.calibrate(example_event) image = example_event.dl1.tel[telid].image assert image is not None -def test_manual_r1(): - calibrator = CameraCalibrator(r1_product="HESSIOR1Calibrator") - assert isinstance(calibrator.r1, HESSIOR1Calibrator) - - def test_manual_extractor(): calibrator = CameraCalibrator(extractor_name="LocalPeakWindowSum") assert isinstance(calibrator.dl1.extractor, LocalPeakWindowSum) -def test_eventsource_r1(): - dataset = get_dataset_path("gamma_test_large.simtel.gz") - eventsource = SimTelEventSource(input_url=dataset) - calibrator = CameraCalibrator(eventsource=eventsource) - assert isinstance(calibrator.r1, HESSIOR1Calibrator) - - -def test_eventsource_override_r1(): - dataset = get_dataset_path("gamma_test_large.simtel.gz") - eventsource = SimTelEventSource(input_url=dataset) - calibrator = CameraCalibrator( - eventsource=eventsource, - r1_product="NullR1Calibrator" - ) - assert isinstance(calibrator.r1, NullR1Calibrator) - - def test_config(): window_shift = 3 window_width = 9 @@ -56,7 +28,6 @@ def test_config(): "window_width": window_width, }}) calibrator = CameraCalibrator( - r1_product='HESSIOR1Calibrator', extractor_name='LocalPeakWindowSum', config=config ) diff --git a/ctapipe/calib/camera/tests/test_dl0.py b/ctapipe/calib/camera/tests/test_dl0.py index 2183d4298dd..f351e62dfc1 100644 --- a/ctapipe/calib/camera/tests/test_dl0.py +++ b/ctapipe/calib/camera/tests/test_dl0.py @@ -1,19 +1,8 @@ -from numpy.testing import assert_almost_equal - from ctapipe.calib.camera.dl0 import CameraDL0Reducer -from ctapipe.calib.camera.r1 import HESSIOR1Calibrator - - -def previous_calibration(event): - r1 = HESSIOR1Calibrator() - r1.calibrate(event) def test_camera_dl0_reducer(example_event): - previous_calibration(example_event) - - telid = list(example_event.r0.tel)[0] - + telid = list(example_event.r1.tel)[0] reducer = CameraDL0Reducer() reducer.reduce(example_event) waveforms = example_event.dl0.tel[telid].waveform @@ -21,9 +10,7 @@ def test_camera_dl0_reducer(example_event): def test_check_r1_exists(example_event): - telid = list(example_event.r0.tel)[0] - - previous_calibration(example_event) + telid = list(example_event.r1.tel)[0] reducer = CameraDL0Reducer() assert (reducer.check_r1_exists(example_event, telid) is True) example_event.r1.tel[telid].waveform = None diff --git a/ctapipe/calib/camera/tests/test_dl1.py b/ctapipe/calib/camera/tests/test_dl1.py index 9ab1534a009..9d607111248 100644 --- a/ctapipe/calib/camera/tests/test_dl1.py +++ b/ctapipe/calib/camera/tests/test_dl1.py @@ -1,14 +1,9 @@ -from numpy.testing import assert_allclose - from ctapipe.calib.camera.dl0 import CameraDL0Reducer from ctapipe.calib.camera.dl1 import integration_correction, \ CameraDL1Calibrator -from ctapipe.calib.camera.r1 import HESSIOR1Calibrator def previous_calibration(event): - r1 = HESSIOR1Calibrator() - r1.calibrate(event) dl0 = CameraDL0Reducer() dl0.reduce(event) diff --git a/ctapipe/calib/camera/tests/test_r1.py b/ctapipe/calib/camera/tests/test_r1.py deleted file mode 100644 index af2d6e1a8ab..00000000000 --- a/ctapipe/calib/camera/tests/test_r1.py +++ /dev/null @@ -1,72 +0,0 @@ -from numpy.testing import assert_array_equal - -from ctapipe.calib.camera.r1 import ( - CameraR1Calibrator, - HESSIOR1Calibrator, - NullR1Calibrator, -) -from ctapipe.io.eventsource import EventSource -from ctapipe.io.simteleventsource import SimTelEventSource -from ctapipe.utils import get_dataset_path - - -dataset = get_dataset_path("gamma_test_large.simtel.gz") - - -def test_hessio_r1_calibrator(example_event): - telid = list(example_event.r0.tel)[0] - - calibrator = HESSIOR1Calibrator() - calibrator.calibrate(example_event) - assert example_event.r1.tel[telid].waveform is not None - - -def test_null_r1_calibrator(example_event): - telid = list(example_event.r0.tel)[0] - - calibrator = NullR1Calibrator() - calibrator.calibrate(example_event) - r0 = example_event.r0.tel[telid].waveform - r1 = example_event.r1.tel[telid].waveform - assert_array_equal(r0, r1) - - -def test_check_r0_exists(example_event): - telid = list(example_event.r0.tel)[0] - - calibrator = HESSIOR1Calibrator() - assert (calibrator.check_r0_exists(example_event, telid) is True) - example_event.r0.tel[telid].waveform = None - assert (calibrator.check_r0_exists(example_event, telid) is False) - - -def test_factory_from_product(): - calibrator = CameraR1Calibrator.from_name("NullR1Calibrator") - assert isinstance(calibrator, NullR1Calibrator) - calibrator = CameraR1Calibrator.from_name("HESSIOR1Calibrator") - assert isinstance(calibrator, HESSIOR1Calibrator) - - -def test_factory_for_eventsource(): - eventsource = SimTelEventSource(input_url=dataset) - calibrator = CameraR1Calibrator.from_eventsource(eventsource=eventsource) - assert isinstance(calibrator, HESSIOR1Calibrator) - - -class UnknownEventSource(EventSource): - """ - Simple working EventSource - """ - - def _generator(self): - return range(len(self.input_url)) - - @staticmethod - def is_compatible(file_path): - return False - - -def test_factory_from_unknown_eventsource(): - eventsource = UnknownEventSource(input_url=dataset) - calibrator = CameraR1Calibrator.from_eventsource(eventsource=eventsource) - assert isinstance(calibrator, NullR1Calibrator) diff --git a/ctapipe/io/containers.py b/ctapipe/io/containers.py index c4d664b4873..a5594b2aa41 100644 --- a/ctapipe/io/containers.py +++ b/ctapipe/io/containers.py @@ -124,15 +124,10 @@ class R0CameraContainer(Container): trigger_type = Field(0o0, "camera's event trigger type if applicable") num_trig_pix = Field(0, "Number of trigger groups (sectors) listed") trig_pix_id = Field(None, "pixels involved in the camera trigger") - image = Field(None, ( - "numpy array containing integrated ADC data " - "(n_channels x n_pixels) DEPRECATED" - )) # to be removed, since this doesn't exist in real data and useless in mc waveform = Field(None, ( "numpy array containing ADC samples" "(n_channels x n_pixels, n_samples)" )) - num_samples = Field(None, "number of time samples for telescope") class R0Container(Container): diff --git a/ctapipe/io/hessioeventsource.py b/ctapipe/io/hessioeventsource.py index 2af2d8d020a..2fa44eaf267 100644 --- a/ctapipe/io/hessioeventsource.py +++ b/ctapipe/io/hessioeventsource.py @@ -132,25 +132,24 @@ def _generator(self): # event.mc.tel[tel_id] = MCCameraContainer() - data.mc.tel[tel_id].dc_to_pe = file.get_calibration(tel_id) - data.mc.tel[tel_id].pedestal = file.get_pedestal(tel_id) - data.r0.tel[tel_id].waveform = (file. - get_adc_sample(tel_id)) - if data.r0.tel[tel_id].waveform.size == 0: - # To handle ASTRI and dst files - data.r0.tel[tel_id].waveform = (file. - get_adc_sum(tel_id)[..., None]) - data.r0.tel[tel_id].image = file.get_adc_sum(tel_id) + adc_samples = file.get_adc_sample(tel_id) + if adc_samples.size == 0: + adc_samples = file.get_adc_sum(tel_id)[..., None] + dc_to_pe = file.get_calibration(tel_id) + pedestal = file.get_pedestal(tel_id) + data.r0.tel[tel_id].waveform = adc_samples + data.r1.tel[tel_id].waveform = ( + (adc_samples - pedestal[..., np.newaxis]) + * dc_to_pe[..., np.newaxis] + ) + + data.mc.tel[tel_id].dc_to_pe = dc_to_pe + data.mc.tel[tel_id].pedestal = pedestal data.r0.tel[tel_id].num_trig_pix = file.get_num_trig_pixels(tel_id) data.r0.tel[tel_id].trig_pix_id = file.get_trig_pixels(tel_id) data.mc.tel[tel_id].reference_pulse_shape = (file. get_ref_shapes(tel_id)) - nsamples = file.get_event_num_samples(tel_id) - if nsamples <= 0: - nsamples = 1 - data.r0.tel[tel_id].num_samples = nsamples - # load the data per telescope/pixel hessio_mc_npe = file.get_mc_number_photon_electron(tel_id) data.mc.tel[tel_id].photo_electron_image = hessio_mc_npe diff --git a/ctapipe/io/simteleventsource.py b/ctapipe/io/simteleventsource.py index 1981836fb16..7a4b6b642aa 100644 --- a/ctapipe/io/simteleventsource.py +++ b/ctapipe/io/simteleventsource.py @@ -213,21 +213,8 @@ def __generator(self): adc_samples = telescope_event.get('adc_samples') if adc_samples is None: adc_samples = telescope_event['adc_sums'][:, :, np.newaxis] - - r0 = data.r0.tel[tel_id] - r0.waveform = adc_samples - r0.num_samples = adc_samples.shape[-1] - # We should not calculate stuff in an event source - # if this is not needed, we calculate it for nothing - r0.image = adc_samples.sum(axis=-1) - - pixel_lists = telescope_event['pixel_lists'] - r0.num_trig_pix = pixel_lists.get(0, {'pixels': 0})['pixels'] - if r0.num_trig_pix > 0: - r0.trig_pix_id = pixel_lists[0]['pixel_list'] - + _, n_pixels, n_samples = adc_samples.shape pixel_settings = telescope_description['pixel_settings'] - n_pixel = r0.waveform.shape[-2] mc = data.mc.tel[tel_id] mc.dc_to_pe = array_event['laser_calibrations'][tel_id]['calib'] @@ -239,7 +226,7 @@ def __generator(self): array_event .get('photoelectrons', {}) .get(tel_index, {}) - .get('photoelectrons', np.zeros(n_pixel, dtype='float32')) + .get('photoelectrons', np.zeros(n_pixels, dtype='float32')) ) tracking_position = tracking_positions[tel_id] @@ -247,6 +234,19 @@ def __generator(self): mc.altitude_raw = tracking_position['altitude_raw'] mc.azimuth_cor = tracking_position.get('azimuth_cor', 0) mc.altitude_cor = tracking_position.get('altitude_cor', 0) + + r0 = data.r0.tel[tel_id] + r1 = data.r1.tel[tel_id] + r0.waveform = adc_samples + ped = mc.pedestal[..., np.newaxis] / n_samples + gain = mc.dc_to_pe[..., np.newaxis] + r1.waveform = (adc_samples - ped) * gain + + pixel_lists = telescope_event['pixel_lists'] + r0.num_trig_pix = pixel_lists.get(0, {'pixels': 0})['pixels'] + if r0.num_trig_pix > 0: + r0.trig_pix_id = pixel_lists[0]['pixel_list'] + yield data def fill_mc_information(self, data, array_event): diff --git a/ctapipe/io/tests/test_hdf5.py b/ctapipe/io/tests/test_hdf5.py index 33a2b1128aa..0c3303ef162 100644 --- a/ctapipe/io/tests/test_hdf5.py +++ b/ctapipe/io/tests/test_hdf5.py @@ -28,8 +28,6 @@ def test_write_container(temp_h5_file): mc = MCEventContainer() mc.reset() r0tel.waveform = np.random.uniform(size=(50, 10)) - r0tel.image = np.random.uniform(size=50) - r0tel.num_samples = 10 r0tel.meta['test_attribute'] = 3.14159 r0tel.meta['date'] = "2020-10-10" @@ -42,8 +40,6 @@ def test_write_container(temp_h5_file): for ii in range(100): r0tel.waveform[:] = np.random.uniform(size=(50, 10)) - r0tel.image[:] = np.random.uniform(size=50) - r0tel.num_samples = 10 mc.energy = 10**np.random.uniform(1, 2) * u.TeV mc.core_x = np.random.uniform(-1, 1) * u.m mc.core_y = np.random.uniform(-1, 1) * u.m @@ -119,8 +115,8 @@ def test_read_container(temp_h5_file): r0_2 = next(r0tab2) print("MC:", m) - print("t0:", r0_1.image) - print("t1:", r0_2.image) + print("t0:", r0_1.waveform) + print("t1:", r0_2.waveform) print("---------------------------") assert 'test_attribute' in r0_1.meta diff --git a/ctapipe/io/tests/test_simteleventsource.py b/ctapipe/io/tests/test_simteleventsource.py index 541049bb499..6fd9f9c66bd 100644 --- a/ctapipe/io/tests/test_simteleventsource.py +++ b/ctapipe/io/tests/test_simteleventsource.py @@ -51,9 +51,8 @@ def compare_sources(input_url): assert (h.mc.tel[tel_id].dc_to_pe == s.mc.tel[tel_id].dc_to_pe).all() assert (h.mc.tel[tel_id].pedestal == s.mc.tel[tel_id].pedestal).all() assert h.r0.tel[tel_id].waveform.shape == s.r0.tel[tel_id].waveform.shape + assert h.r1.tel[tel_id].waveform.shape == s.r1.tel[tel_id].waveform.shape assert np.allclose(h.r0.tel[tel_id].waveform, s.r0.tel[tel_id].waveform) - assert (h.r0.tel[tel_id].num_samples == s.r0.tel[tel_id].num_samples) - assert (h.r0.tel[tel_id].image == s.r0.tel[tel_id].image).all() assert h.r0.tel[tel_id].num_trig_pix == s.r0.tel[tel_id].num_trig_pix assert (h.r0.tel[tel_id].trig_pix_id == s.r0.tel[tel_id].trig_pix_id).all() diff --git a/ctapipe/reco/tests/test_HillasReconstructor.py b/ctapipe/reco/tests/test_HillasReconstructor.py index 2bffb4f4f00..32688990836 100644 --- a/ctapipe/reco/tests/test_HillasReconstructor.py +++ b/ctapipe/reco/tests/test_HillasReconstructor.py @@ -109,7 +109,7 @@ def test_reconstruction(): tel_azimuth[tel_id] = event.mc.tel[tel_id].azimuth_raw * u.rad tel_altitude[tel_id] = event.mc.tel[tel_id].altitude_raw * u.rad - pmt_signal = event.r0.tel[tel_id].image[0] + pmt_signal = event.r0.tel[tel_id].waveform[0].sum(axis=1) mask = tailcuts_clean(geom, pmt_signal, picture_thresh=10., boundary_thresh=5.) diff --git a/ctapipe/tools/bokeh/file_viewer.py b/ctapipe/tools/bokeh/file_viewer.py index 20819b8a084..0a83f4ab4f0 100644 --- a/ctapipe/tools/bokeh/file_viewer.py +++ b/ctapipe/tools/bokeh/file_viewer.py @@ -7,7 +7,6 @@ from traitlets import Dict, List, Int, Bool from ctapipe.calib.camera.dl0 import CameraDL0Reducer from ctapipe.calib.camera.dl1 import CameraDL1Calibrator -from ctapipe.calib.camera.r1 import CameraR1Calibrator from ctapipe.core import Tool from ctapipe.image.extractor import ImageExtractor from ctapipe.io import EventSource @@ -47,7 +46,6 @@ class BokehFileViewer(Tool): EventSource, CameraDL1Calibrator, ] + tool_utils.classes_with_traits(ImageExtractor) - + tool_utils.classes_with_traits(CameraR1Calibrator) ) def __init__(self, **kwargs): @@ -73,7 +71,6 @@ def __init__(self, **kwargs): self.reader = None self.seeker = None self.extractor = None - self.r1 = None self.dl0 = None self.dl1 = None self.viewer = None @@ -90,10 +87,6 @@ def setup(self): self.extractor_product, parent=self ) - self.r1 = CameraR1Calibrator.from_eventsource( - eventsource=self.reader, - parent=self - ) self.dl0 = CameraDL0Reducer(parent=self) self.dl1 = CameraDL1Calibrator( extractor=self.extractor, @@ -209,7 +202,6 @@ def event(self): def event(self, val): # Calibrate - self.r1.calibrate(val) self.dl0.reduce(val) self.dl1.calibrate(val) diff --git a/ctapipe/tools/display_dl1.py b/ctapipe/tools/display_dl1.py index 99df19c4758..a00cca11a27 100644 --- a/ctapipe/tools/display_dl1.py +++ b/ctapipe/tools/display_dl1.py @@ -187,10 +187,7 @@ def setup(self): parent=self, ) - self.calibrator = CameraCalibrator( - eventsource=self.eventsource, - parent=self, - ) + self.calibrator = CameraCalibrator(parent=self) self.plotter = ImagePlotter(parent=self) diff --git a/ctapipe/tools/display_events_single_tel.py b/ctapipe/tools/display_events_single_tel.py index b159e66a4f9..b46e1d9dd1c 100755 --- a/ctapipe/tools/display_events_single_tel.py +++ b/ctapipe/tools/display_events_single_tel.py @@ -76,9 +76,7 @@ def setup(self): self.event_source = EventSource.from_url(self.infile, parent=self) self.event_source.allowed_tels = {self.tel, } - self.calibrator = CameraCalibrator( - parent=self, eventsource=self.event_source - ) + self.calibrator = CameraCalibrator(parent=self) self.log.info(f'SELECTING EVENTS FROM TELESCOPE {self.tel}') diff --git a/ctapipe/tools/display_integrator.py b/ctapipe/tools/display_integrator.py index 42429364ce8..02d2a285814 100644 --- a/ctapipe/tools/display_integrator.py +++ b/ctapipe/tools/display_integrator.py @@ -8,8 +8,7 @@ from traitlets import Dict, List, Int, Bool, Enum import ctapipe.utils.tools as tool_utils -from ctapipe.calib.camera import CameraR1Calibrator, CameraDL0Reducer, \ - CameraDL1Calibrator +from ctapipe.calib.camera import CameraDL0Reducer, CameraDL1Calibrator from ctapipe.core import Tool from ctapipe.image.extractor import ImageExtractor from ctapipe.io.eventseeker import EventSeeker @@ -262,7 +261,6 @@ class DisplayIntegrator(Tool): def __init__(self, **kwargs): super().__init__(**kwargs) self.eventseeker = None - self.r1 = None self.dl0 = None self.extractor = None self.dl1 = None @@ -276,11 +274,6 @@ def setup(self): self.extractor_product, parent=self, ) - self.r1 = CameraR1Calibrator.from_eventsource( - eventsource=event_source, - parent=self, - ) - self.dl0 = CameraDL0Reducer(parent=self) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, parent=self) @@ -291,7 +284,6 @@ def start(self): event = self.eventseeker[event_num] # Calibrate - self.r1.calibrate(event) self.dl0.reduce(event) self.dl1.calibrate(event) diff --git a/ctapipe/tools/display_summed_images.py b/ctapipe/tools/display_summed_images.py index f945e74dfd0..758978391e9 100644 --- a/ctapipe/tools/display_summed_images.py +++ b/ctapipe/tools/display_summed_images.py @@ -71,9 +71,7 @@ def setup(self): ) self.log.info(f"SELECTED TELESCOPES:{self._selected_tels}") - self.calibrator = CameraCalibrator( - parent=self, eventsource=self.reader - ) + self.calibrator = CameraCalibrator(parent=self,) self.reader.allowed_tels = self._selected_tels diff --git a/ctapipe/tools/extract_charge_resolution.py b/ctapipe/tools/extract_charge_resolution.py index 1117558eae3..1bac365fb41 100644 --- a/ctapipe/tools/extract_charge_resolution.py +++ b/ctapipe/tools/extract_charge_resolution.py @@ -16,7 +16,6 @@ ChargeResolutionCalculator from ctapipe.calib.camera.dl0 import CameraDL0Reducer from ctapipe.calib.camera.dl1 import CameraDL1Calibrator -from ctapipe.calib.camera.r1 import HESSIOR1Calibrator from ctapipe.core import Tool, Provenance from ctapipe.image.extractor import ImageExtractor @@ -58,7 +57,6 @@ class ChargeResolutionGenerator(Tool): def __init__(self, **kwargs): super().__init__(**kwargs) self.eventsource = None - self.r1 = None self.dl0 = None self.dl1 = None self.calculator = None @@ -73,8 +71,6 @@ def setup(self): parent=self ) - self.r1 = HESSIOR1Calibrator(parent=self) - self.dl0 = CameraDL0Reducer(parent=self) self.dl1 = CameraDL1Calibrator(extractor=extractor, parent=self) @@ -84,7 +80,6 @@ def setup(self): def start(self): desc = "Extracting Charge Resolution" for event in tqdm(self.eventsource, desc=desc): - self.r1.calibrate(event) self.dl0.reduce(event) self.dl1.calibrate(event) diff --git a/ctapipe/tools/tests/test_tools.py b/ctapipe/tools/tests/test_tools.py index 5f6d888e908..4266098342c 100644 --- a/ctapipe/tools/tests/test_tools.py +++ b/ctapipe/tools/tests/test_tools.py @@ -23,7 +23,7 @@ def test_muon_reconstruction(tmpdir): tool.run(['--help-all']) -def test_display_summed_imaged(tmpdir): +def test_display_summed_images(tmpdir): from ctapipe.tools.display_summed_images import ImageSumDisplayerTool mpl.use('Agg') tool = ImageSumDisplayerTool() diff --git a/docs/ctapipe_api/calib/index_camera.rst b/docs/ctapipe_api/calib/index_camera.rst index a3ace2be651..eb061790f5c 100644 --- a/docs/ctapipe_api/calib/index_camera.rst +++ b/docs/ctapipe_api/calib/index_camera.rst @@ -35,10 +35,6 @@ Reference/API ------------------------------ -.. automodapi:: ctapipe.calib.camera.r1 - ------------------------------- - .. automodapi:: ctapipe.calib.camera.dl0 :no-inheritance-diagram: diff --git a/docs/examples/convert_hex_to_square.ipynb b/docs/examples/convert_hex_to_square.ipynb index 462a26ace79..87b769684d9 100644 --- a/docs/examples/convert_hex_to_square.ipynb +++ b/docs/examples/convert_hex_to_square.ipynb @@ -71,7 +71,7 @@ "outputs": [], "source": [ "camera = event.inst.subarray.tel[1].camera\n", - "image = event.r0.tel[1].image[0]\n", + "image = event.r0.tel[1].waveform[0].sum(axis=1)\n", "CameraDisplay(camera, image)" ] }, diff --git a/docs/tutorials/calibrated_data_exploration.ipynb b/docs/tutorials/calibrated_data_exploration.ipynb index 1d51f520895..27f8af30317 100644 --- a/docs/tutorials/calibrated_data_exploration.ipynb +++ b/docs/tutorials/calibrated_data_exploration.ipynb @@ -113,7 +113,7 @@ "source": [ "from ctapipe.calib import CameraCalibrator\n", "\n", - "calib = CameraCalibrator(r1_product=\"HESSIOR1Calibrator\")\n", + "calib = CameraCalibrator()\n", "calib.calibrate(event)" ] }, @@ -375,7 +375,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.7.2" } }, "nbformat": 4, diff --git a/docs/tutorials/ctapipe_handson.ipynb b/docs/tutorials/ctapipe_handson.ipynb index a162ec42a1c..a11e01eba49 100644 --- a/docs/tutorials/ctapipe_handson.ipynb +++ b/docs/tutorials/ctapipe_handson.ipynb @@ -343,7 +343,7 @@ "metadata": {}, "outputs": [], "source": [ - "calib = CameraCalibrator(eventsource=source)" + "calib = CameraCalibrator()" ] }, { diff --git a/docs/tutorials/lst_analysis_bootcamp_2018.ipynb b/docs/tutorials/lst_analysis_bootcamp_2018.ipynb index 0165fd6ef85..517030b66b4 100644 --- a/docs/tutorials/lst_analysis_bootcamp_2018.ipynb +++ b/docs/tutorials/lst_analysis_bootcamp_2018.ipynb @@ -288,9 +288,7 @@ "source": [ "### Data calibration\n", "\n", - "As we saw, the data container only contains raw data (only the `r0` containers are filled)\n", - "\n", - "So we use the `CameraCalibrator` factory to calibrate the event." + "The `CameraCalibrator` calibrates the event (obtaining the `dl1` images)." ] }, { @@ -301,16 +299,7 @@ "source": [ "from ctapipe.calib import CameraCalibrator\n", "\n", - "calibrator = CameraCalibrator(eventsource=source)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "calibrator.r1" + "calibrator = CameraCalibrator()" ] }, { @@ -611,7 +600,7 @@ "input_url = get_dataset_path('gamma_test_large.simtel.gz')\n", "source = event_source(input_url)\n", "\n", - "calibrator = CameraCalibrator(eventsource=source)\n", + "calibrator = CameraCalibrator()\n", "\n", "reco = HillasReconstructor()\n", "\n", @@ -788,7 +777,7 @@ " allowed_tels=[1, 2, 3, 4], # only use the first LST\n", ")\n", "\n", - "calibrator = CameraCalibrator(eventsource=source)\n", + "calibrator = CameraCalibrator()\n", "\n", "class EventInfo(Container):\n", " event_id = Field('event_id')\n", diff --git a/docs/tutorials/raw_data_exploration.ipynb b/docs/tutorials/raw_data_exploration.ipynb index b857f8de93f..3573171970f 100644 --- a/docs/tutorials/raw_data_exploration.ipynb +++ b/docs/tutorials/raw_data_exploration.ipynb @@ -434,7 +434,7 @@ " camgeom = event.inst.subarray.tel[tel].camera\n", " title=\"CT{}, run {} event {}\".format(tel,event.r0.obs_id,event.r0.event_id)\n", " disp = CameraDisplay(camgeom,title=title)\n", - " disp.image = event.r0.tel[tel].image[0]\n", + " disp.image = event.r0.tel[tel].waveform[0].sum(axis=1)\n", " disp.cmap = plt.cm.RdBu_r\n", " disp.add_colorbar()\n", " disp.set_limits_percent(95)" diff --git a/docs/tutorials/theta_square.ipynb b/docs/tutorials/theta_square.ipynb index 3fec0aa9eaa..20eabfc82f6 100644 --- a/docs/tutorials/theta_square.ipynb +++ b/docs/tutorials/theta_square.ipynb @@ -77,7 +77,7 @@ "filename = datasets.get_dataset_path(\"gamma_test_large.simtel.gz\")\n", "source = event_source(filename, allowed_tels={1, 2, 3, 4}, max_events=10)\n", "reco = HillasReconstructor()\n", - "calib = CameraCalibrator(eventsource=source)" + "calib = CameraCalibrator()" ] }, { diff --git a/examples/load_one_event.py b/examples/load_one_event.py index 6e28623d466..31d32f7d7fd 100644 --- a/examples/load_one_event.py +++ b/examples/load_one_event.py @@ -10,7 +10,7 @@ if __name__ == '__main__': - calib = CameraCalibrator(r1_product="HESSIOR1Calibrator") + calib = CameraCalibrator() if len(sys.argv) >= 2: filename = sys.argv[1] diff --git a/examples/plot_theta_square.py b/examples/plot_theta_square.py index a3216a651f0..229017d3ea8 100644 --- a/examples/plot_theta_square.py +++ b/examples/plot_theta_square.py @@ -28,7 +28,7 @@ source = event_source(filename, allowed_tels={1, 2, 3, 4}) reco = HillasReconstructor() -calib = CameraCalibrator(r1_product="HESSIOR1Calibrator") +calib = CameraCalibrator() off_angles = [] for event in source: diff --git a/examples/simple_pipeline.py b/examples/simple_pipeline.py index 3a15bab7bb1..fdd6a880ece 100644 --- a/examples/simple_pipeline.py +++ b/examples/simple_pipeline.py @@ -14,7 +14,7 @@ source = event_source(filename, max_events=None) - cal = CameraCalibrator(r1_product="HESSIOR1Calibrator") + cal = CameraCalibrator() for ii, event in enumerate(source):