Exemplo n.º 1
0
def test_neighbor_peak_window_sum(camera_waveforms):
    waveforms, subarray = camera_waveforms
    extractor = NeighborPeakWindowSum(subarray=subarray)
    charge, pulse_time = extractor(waveforms, telid=1)
    assert_allclose(charge[0], 94.671, rtol=1e-3)
    assert_allclose(pulse_time[0], 54.116092, rtol=1e-3)

    extractor.lwt = 4
    charge, pulse_time = extractor(waveforms, telid=1)
    assert_allclose(charge[0], 220.418657, rtol=1e-3)
    assert_allclose(pulse_time[0], 48.717848, rtol=1e-3)
Exemplo n.º 2
0
def test_neighbor_peak_window_sum(camera_waveforms):
    waveforms, camera = camera_waveforms
    nei = camera.neighbor_matrix_where
    extractor = NeighborPeakWindowSum()
    extractor.neighbors = nei
    charge, pulse_time = extractor(waveforms)
    assert_allclose(charge[0], 94.671, rtol=1e-3)
    assert_allclose(pulse_time[0], 54.116092, rtol=1e-3)

    extractor.lwt = 4
    charge, pulse_time = extractor(waveforms)
    assert_allclose(charge[0], 220.418657, rtol=1e-3)
    assert_allclose(pulse_time[0], 48.717848, rtol=1e-3)
Exemplo n.º 3
0
    def __init__(self,
                 config=None,
                 parent=None,
                 subarray=None,
                 image_extractor=None,
                 **kwargs):
        """
        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.
        subarray: ctapipe.instrument.SubarrayDescription
            Description of the subarray
        image_extractor: ctapipe.image.extractor.ImageExtractor
            The ImageExtractor to use for 'TailCutsDataVolumeReducer'.
            If None, then NeighborPeakWindowSum will be used by default.
        kwargs
        """

        self.subarray = subarray
        super().__init__(config=config,
                         parent=parent,
                         subarray=subarray,
                         **kwargs)

        if image_extractor is None:
            image_extractor = NeighborPeakWindowSum(parent=self,
                                                    subarray=subarray)
        self.image_extractor = image_extractor

        self.cleaner = TailcutsImageCleaner(parent=self, subarray=subarray)
Exemplo n.º 4
0
    def __init__(self, n_pixels, n_samples, mapping=None, **kwargs):
        super().__init__(n_pixels, n_samples, **kwargs)

        if mapping is None:
            raise ValueError("A mapping must be passed "
                             "to CtapipeNeighbourPeakIntegrator")

        try:
            from ctapipe.image.extractor import NeighborPeakWindowSum
        except ImportError:
            msg = ("ctapipe not found. Please either install ctapipe or "
                   "disable the columns from WaveformReducer {} ({})".format(
                       self.__class__.__name__, self.columns))
            raise ImportError(msg)

        camera = get_ctapipe_camera_geometry(mapping)

        self.window_size = self.kwargs.get("window_size", 6)
        self.window_shift = self.kwargs.get("window_shift", 3)
        self.integrator = NeighborPeakWindowSum(
            window_shift=self.window_shift,
            window_width=self.window_size,
            lwt=0,
        )
        self.integrator.neighbors = camera.neighbor_matrix_where
Exemplo n.º 5
0
def test_neighbor_peak_window_sum_lwt(toymodel):
    waveforms, subarray, telid, selected_gain_channel, true_charge, true_time = toymodel
    extractor = NeighborPeakWindowSum(subarray=subarray, lwt=4)
    assert extractor.lwt.tel[telid] == 4
    charge, pulse_time = extractor(waveforms, telid, selected_gain_channel)
    assert_allclose(charge, true_charge, rtol=0.1)
    assert_allclose(pulse_time, true_time, rtol=0.1)
Exemplo n.º 6
0
def test_neighbor_peak_window_sum(camera_waveforms):
    waveforms, camera = camera_waveforms
    nei = camera.neighbor_matrix_where
    extractor = NeighborPeakWindowSum()
    extractor.neighbors = nei
    charge, pulse_time = extractor(waveforms)

    assert_allclose(charge[0][0], 94.671, rtol=1e-3)
    assert_allclose(charge[1][0], 426.887, rtol=1e-3)
    assert_allclose(pulse_time[0][0], 54.116092, rtol=1e-3)
    assert_allclose(pulse_time[1][0], 62.038344, rtol=1e-3)

    extractor.lwt = 4
    charge, pulse_time = extractor(waveforms)

    assert_allclose(charge[0][0], 220.418657, rtol=1e-3)
    assert_allclose(charge[1][0], 426.887, rtol=1e-3)
    assert_allclose(pulse_time[0][0], 48.717848, rtol=1e-3)
    assert_allclose(pulse_time[1][0], 62.038344, rtol=1e-3)
Exemplo n.º 7
0
    def __init__(
        self,
        subarray,
        config=None,
        parent=None,
        data_volume_reducer=None,
        image_extractor=None,
        **kwargs,
    ):
        """
        Parameters
        ----------
        subarray: ctapipe.instrument.SubarrayDescription
            Description of the subarray. Provides information about the
            camera which are useful in calibration. Also required for
            configuring the TelescopeParameter traitlets.
        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.
        data_volume_reducer : ctapipe.image.reducer.DataVolumeReducer
            The DataVolumeReducer to use. If None, then
            NullDataVolumeReducer will be used by default, and waveforms
            will not be reduced.
        image_extractor : ctapipe.image.extractor.ImageExtractor
            The ImageExtractor to use. If None, then NeighborPeakWindowSum
            will be used by default.
        subarray: ctapipe.instrument.SubarrayDescription
            Description of the subarray
        kwargs
        """
        super().__init__(config=config, parent=parent, **kwargs)
        self.subarray = subarray

        self._r1_empty_warn = False
        self._dl0_empty_warn = False

        if image_extractor is None:
            image_extractor = NeighborPeakWindowSum(parent=self, subarray=subarray)
        self.image_extractor = image_extractor

        if data_volume_reducer is None:
            data_volume_reducer = NullDataVolumeReducer(
                parent=self, image_extractor=self.image_extractor
            )
        self.data_volume_reducer = data_volume_reducer
Exemplo n.º 8
0
    def __init__(self,
                 config=None,
                 parent=None,
                 gain_selector=None,
                 data_volume_reducer=None,
                 image_extractor=None,
                 **kwargs):
        """
        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.
        gain_selector : ctapipe.calib.camera.gainselection.GainSelector
            The GainSelector to use. If None, then ManualGainSelector will be
            used, which by default selects the high/first gain channel.
        data_volume_reducer : ctapipe.image.reducer.DataVolumeReducer
            The DataVolumeReducer to use. If None, then
            NullDataVolumeReducer will be used by default, and waveforms
            will not be reduced.
        image_extractor : ctapipe.image.extractor.ImageExtractor
            The ImageExtractor to use. If None, then NeighborPeakWindowSum
            will be used by default.
        kwargs
        """
        super().__init__(config=config, parent=parent, **kwargs)

        self._r1_empty_warn = False
        self._dl0_empty_warn = False

        if gain_selector is None:
            gain_selector = ManualGainSelector(parent=self)
        self.gain_selector = gain_selector

        if data_volume_reducer is None:
            data_volume_reducer = NullDataVolumeReducer(parent=self)
        self.data_volume_reducer = data_volume_reducer

        if image_extractor is None:
            image_extractor = NeighborPeakWindowSum(parent=self)
        self.image_extractor = image_extractor
Exemplo n.º 9
0
def process_file(
        filename,
        max_events,
        site_altitude,
        telescopes,
        stereo,
        apply_quality_cuts):
    
    # Read source file
    try:
        source = event_source(
            filename,
            max_events=max_events,
            #back_seekable=True
            )
    except BaseException:
        print("Error: file " + filename + " could not be read", "\n")
        print(traceback.format_exc(), "\n")
        return None, None, None
    
    subarray = source.subarray

    # Exit if a telescope ID has been given that doesn't exist in the array
    if telescopes is not None:
        telescopes = [int(i) for i in telescopes.split(',')]
        for i in telescopes:
            if (i not in subarray.tel_ids):
                sys.exit('Error: tel_id ' + str(i) + ' is not in array ' + str(subarray.tel_ids))

    camera_name = source.subarray.tel[1].camera.camera_name

    if camera_name == 'CHEC':
        width = 23
        shift = 12
    elif camera_name == 'FlashCam':
        width = 4
        shift = 1
    else:
        sys.exit('Error: ' + camera_name + " camera not supported")
    
    image_extractor = NeighborPeakWindowSum(subarray=subarray, window_width=width, window_shift=shift)
    calib = CameraCalibrator(subarray=source.subarray, image_extractor=image_extractor)
    
    tested_altitude = False

    file_tel_data = []
    file_arr_data = []

    try:
        for event in source:
            if not tested_altitude:
                # Skip file if it's not at the given altitude
                tested_altitude = True
                if site_altitude is not None:
                    if event.mcheader.prod_site_alt.value != site_altitude:
                        raise ValueError

            # Process event
            tel_data, arr_data = process_event(
                event,
                telescopes,
                subarray,
                stereo,
                calib,
                apply_quality_cuts)

            if tel_data is not None:
                file_tel_data += tel_data
                file_arr_data.append(arr_data)
    # Skip file if it's at a different altitude than specified
    except ValueError:
        head, tail = os.path.split(filename)
        print(
            tail, "sims are not at an altitude of", str(site_altitude) + "m")
        return None, None, None

    # Skip file if it throws an unanticipated error on its own
    except BaseException:
        print(
            "Error: Something unanticipated went wrong\
            with processing an event in file ",
            filename)
        print(traceback.format_exc(), "\n")
        return None, None, None

    if len(file_tel_data) == 0:
        head, tail = os.path.split(filename)
        print(
            tail, "did not have any events output (maybe too low-energy?)")
        return None, None, None

    # Grab info for run data
    run_data = {
        'atmosphere': event.mcheader.atmosphere,
        'core_pos_mode': event.mcheader.core_pos_mode,
        'corsika_bunchsize': event.mcheader.corsika_bunchsize,
        'corsika_high_E_detail': event.mcheader.corsika_high_E_detail,
        'corsika_high_E_model': event.mcheader.corsika_high_E_model,
        'corsika_iact_options': event.mcheader.corsika_iact_options,
        'corsika_low_E_detail': event.mcheader.corsika_low_E_detail,
        'corsika_low_E_model': event.mcheader.corsika_low_E_model,
        'corsika_version': event.mcheader.corsika_version,
        'corsika_wlen_max': event.mcheader.corsika_wlen_max.value,
        'corsika_wlen_min': event.mcheader.corsika_wlen_min.value,
        'detector_prog_id': event.mcheader.detector_prog_id,
        'detector_prog_start': event.mcheader.detector_prog_start,
        'diffuse': event.mcheader.diffuse,
        'energy_range_max': event.mcheader.energy_range_max.value,
        'energy_range_min': event.mcheader.energy_range_min.value,
        'injection_height': event.mcheader.injection_height.value,
        'max_alt': event.mcheader.max_alt.value,
        'max_az': event.mcheader.max_az.value,
        'max_scatter_range': event.mcheader.max_scatter_range.value,
        'max_viewcone_radius': event.mcheader.max_viewcone_radius.value,
        'min_alt': event.mcheader.min_alt.value,
        'min_az': event.mcheader.min_az.value,
        'min_scatter_range': event.mcheader.min_scatter_range.value,
        'min_viewcone_radius': event.mcheader.min_viewcone_radius.value,
        'num_showers': event.mcheader.num_showers,
        'prod_site_alt': event.mcheader.prod_site_alt.value,
        #'prod_site_array': event.mcheader.prod_site_array,
        'prod_site_B_declination': event.mcheader.prod_site_B_declination.value,
        'prod_site_B_inclination': event.mcheader.prod_site_B_inclination.value,
        'prod_site_B_total': event.mcheader.prod_site_B_total.value,
        #'prod_site_coord': event.mcheader.prod_site_coord,
        #'prod_site_subarray': event.mcheader.prod_site_subarray,
        'run_id': event.index.obs_id,
        'shower_prog_id': event.mcheader.shower_prog_id,
        'shower_prog_start': event.mcheader.shower_prog_start,
        'shower_reuse': event.mcheader.shower_reuse,
        'simtel_version': event.mcheader.simtel_version,
        'spectral_index': event.mcheader.spectral_index,
    }

    return file_tel_data, file_arr_data, run_data
Exemplo n.º 10
0
    'r0_to_dl1',
    'get_events',
]

### PARAMETERS - TODO: use a yaml config file

allowed_tels = {1, 2, 3, 4}  # select LST1 only
max_events = None  # limit the number of events to analyse in files - None if no limit

threshold = 4094

# Add option to use custom calibration

custom = False

cal = CameraCalibrator(image_extractor=NeighborPeakWindowSum())

cleaning_method = tailcuts_clean
cleaning_parameters = {
    'boundary_thresh': 3,
    'picture_thresh': 6,
    'keep_isolated_pixels': False,
    'min_number_picture_neighbors': 1
}


def get_dl1(calibrated_event, telescope_id, dl1_container=None):
    """
    Return a DL1ParametersContainer of extracted features from a calibrated event.
    The DL1ParametersContainer can be passed to be filled if created outside the function
    (faster for multiple event processing)