How to use the ctapipe.image.extractor.ImageExtractor function in ctapipe

To help you get started, we’ve selected a few ctapipe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cta-observatory / ctapipe / ctapipe / tools / extract_charge_resolution.py View on Github external
"simulation and store within a HDF5 file."
    )

    telescopes = List(
        Int(),
        None,
        allow_none=True,
        help="Telescopes to include from the event file. Default = All telescopes",
    ).tag(config=True)
    output_path = Path(
        default_value="charge_resolution.h5",
        directory_ok=False,
        help="Path to store the output HDF5 file",
    ).tag(config=True)
    extractor_product = traits.create_class_enum_trait(
        ImageExtractor, default_value="NeighborPeakWindowSum"
    )

    aliases = Dict(
        dict(
            f="SimTelEventSource.input_url",
            max_events="SimTelEventSource.max_events",
            T="SimTelEventSource.allowed_tels",
            extractor="ChargeResolutionGenerator.extractor_product",
            O="ChargeResolutionGenerator.output_path",
        )
    )

    classes = List([SimTelEventSource] + traits.classes_with_traits(ImageExtractor))

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
github cta-observatory / ctapipe / ctapipe / tools / stage1.py View on Github external
).tag(config=True)

    split_datasets_by = CaselessStrEnum(
        values=["tel_id", "tel_type"],
        default_value="tel_id",
        help="Splitting level for the parameters and images datasets",
    ).tag(config=True)

    compression_type = CaselessStrEnum(
        values=["blosc:zstd", "zlib"],
        help="compressor algorithm to use. ",
        default_value="blosc:zstd",
    ).tag(config=True)

    image_extractor_type = create_class_enum_trait(
        base_class=ImageExtractor,
        default_value="NeighborPeakWindowSum",
        help="Method to use to turn a waveform into a single charge value",
    ).tag(config=True)

    gain_selector_type = create_class_enum_trait(
        base_class=GainSelector, default_value="ThresholdGainSelector"
    ).tag(config=True)

    image_cleaner_type = create_class_enum_trait(
        base_class=ImageCleaner, default_value="TailcutsImageCleaner"
    )

    write_index_tables = Bool(
        help=(
            "Generate PyTables index datasets for all tables that contain an "
            "event_id or tel_id. These speed up in-kernal pytables operations,"
github cta-observatory / ctapipe / ctapipe / tools / display_integrator.py View on Github external
description = __doc__

    event_index = Int(0, help="Event index to view.").tag(config=True)
    use_event_id = Bool(
        False, help="event_index will obtain an event using event_id instead of index.",
    ).tag(config=True)
    telescope = Int(
        None,
        allow_none=True,
        help="Telescope to view. Set to None to display the first"
        "telescope with data.",
    ).tag(config=True)
    channel = Enum([0, 1], 0, help="Channel to view").tag(config=True)

    extractor_product = traits.create_class_enum_trait(
        ImageExtractor, default_value="NeighborPeakWindowSum"
    )

    aliases = Dict(
        dict(
            f="EventSource.input_url",
            max_events="EventSource.max_events",
            extractor="DisplayIntegrator.extractor_product",
            E="DisplayIntegrator.event_index",
            T="DisplayIntegrator.telescope",
            C="DisplayIntegrator.channel",
        )
    )
    flags = Dict(
        dict(
            id=(
                {"DisplayDL1Calib": {"use_event_index": True}},
github cta-observatory / ctapipe / ctapipe / tools / bokeh / file_viewer.py View on Github external
class BokehFileViewer(Tool):
    name = "BokehFileViewer"
    description = (
        "Interactively explore an event file using the bokeh " "visualisation package"
    )

    port = Int(5006, help="Port to open bokeh server onto").tag(config=True)
    disable_server = Bool(
        False, help="Do not start the bokeh server " "(useful for testing)"
    ).tag(config=True)

    default_url = get_dataset_path("gamma_test_large.simtel.gz")
    EventSource.input_url.default_value = default_url

    extractor_product = traits.create_class_enum_trait(
        ImageExtractor, default_value="NeighborPeakWindowSum"
    )

    aliases = Dict(
        dict(
            port="BokehFileViewer.port",
            disable_server="BokehFileViewer.disable_server",
            f="EventSource.input_url",
            max_events="EventSource.max_events",
            extractor="BokehFileViewer.extractor_product",
        )
    )

    classes = List([EventSource,] + traits.classes_with_traits(ImageExtractor))

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
github cta-observatory / ctapipe / ctapipe / tools / display_dl1.py View on Github external
self.log.info("Closing PDF")
            self.pdf.close()


class DisplayDL1Calib(Tool):
    name = "ctapipe-display-dl1"
    description = __doc__

    telescope = Int(
        None,
        allow_none=True,
        help="Telescope to view. Set to None to display all telescopes.",
    ).tag(config=True)

    extractor_product = traits.create_class_enum_trait(
        ImageExtractor, default_value="NeighborPeakWindowSum"
    )

    aliases = Dict(
        dict(
            input="EventSource.input_url",
            max_events="EventSource.max_events",
            extractor="DisplayDL1Calib.extractor_product",
            T="DisplayDL1Calib.telescope",
            O="ImagePlotter.output_path",
        )
    )
    flags = Dict(
        dict(
            D=(
                {"ImagePlotter": {"display": True}},
                "Display the photo-electron images on-screen as they are produced.",
github cta-observatory / ctapipe / ctapipe / tools / display_dl1.py View on Github external
max_events="EventSource.max_events",
            extractor="DisplayDL1Calib.extractor_product",
            T="DisplayDL1Calib.telescope",
            O="ImagePlotter.output_path",
        )
    )
    flags = Dict(
        dict(
            D=(
                {"ImagePlotter": {"display": True}},
                "Display the photo-electron images on-screen as they are produced.",
            )
        )
    )
    classes = List(
        [EventSource, ImagePlotter] + traits.classes_with_traits(ImageExtractor)
    )

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.config.EventSource.input_url = get_dataset_path(
            "gamma_test_large.simtel.gz"
        )
        self.eventsource = None
        self.calibrator = None
        self.plotter = None

    def setup(self):
        self.eventsource = self.add_component(EventSource.from_config(parent=self))

        self.calibrator = self.add_component(
            CameraCalibrator(parent=self, subarray=self.eventsource.subarray)
github cta-observatory / ctapipe / ctapipe / calib / camera / pedestals.py View on Github external
number of waveform channel to be considered
        charge_product : str
            Name of the charge extractor to be used
        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.

        kwargs

    """

        super().__init__(**kwargs)

        # load the waveform charge extractor
        self.extractor = ImageExtractor.from_name(
            self.charge_product, config=self.config, subarray=subarray,
        )
        self.log.info(f"extractor {self.extractor}")
github cta-observatory / ctapipe / ctapipe / tools / display_integrator.py View on Github external
def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        event_source = self.add_component(EventSource.from_config(parent=self))
        self.subarray = event_source.subarray
        self.eventseeker = self.add_component(EventSeeker(event_source, parent=self))
        self.extractor = self.add_component(
            ImageExtractor.from_name(
                self.extractor_product, parent=self, subarray=self.subarray
            )
        )
        self.calibrate = self.add_component(
            CameraCalibrator(
                parent=self, image_extractor=self.extractor, subarray=self.subarray
            )
github cta-observatory / ctapipe / ctapipe / image / extractor.py View on Github external
"""


class FullWaveformSum(ImageExtractor):
    """
    Extractor that sums the entire waveform.
    """

    def __call__(self, waveforms, telid, selected_gain_channel):
        charge, peak_time = extract_around_peak(
            waveforms, 0, waveforms.shape[-1], 0, self.sampling_rate[telid]
        )
        return charge, peak_time


class FixedWindowSum(ImageExtractor):
    """
    Extractor that sums within a fixed window defined by the user.
    """

    peak_index = IntTelescopeParameter(
        default_value=0, help="Manually select index where the peak is located"
    ).tag(config=True)
    window_width = IntTelescopeParameter(
        default_value=7, help="Define the width of the integration window"
    ).tag(config=True)
    window_shift = IntTelescopeParameter(
        default_value=0,
        help="Define the shift of the integration window from the peak_index "
        "(peak_index - shift)",
    ).tag(config=True)
github cta-observatory / ctapipe / ctapipe / image / extractor.py View on Github external
)

    def __call__(self, waveforms, telid, selected_gain_channel):
        peak_index = waveforms.argmax(axis=-1).astype(np.int)
        charge, peak_time = extract_around_peak(
            waveforms,
            peak_index,
            self.window_width.tel[telid],
            self.window_shift.tel[telid],
            self.sampling_rate[telid],
        )
        charge *= self._calculate_correction(telid=telid)[selected_gain_channel]
        return charge, peak_time


class NeighborPeakWindowSum(ImageExtractor):
    """
    Extractor which sums in a window about the
    peak defined by the wavefroms in neighboring pixels.
    """

    window_width = IntTelescopeParameter(
        default_value=7, help="Define the width of the integration window"
    ).tag(config=True)
    window_shift = IntTelescopeParameter(
        default_value=3,
        help="Define the shift of the integration window "
        "from the peak_index (peak_index - shift)",
    ).tag(config=True)
    lwt = IntTelescopeParameter(
        default_value=0,
        help="Weight of the local pixel (0: peak from neighbors only, "