How to use the ctapipe.core.traits 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 / display_integrator.py View on Github external
name = "ctapipe-display-integration"
    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=(
github cta-observatory / ctapipe / ctapipe / tools / extract_charge_resolution.py View on Github external
).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)
        self.eventsource = None
        self.calibrator = None
        self.calculator = None

    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = self.add_component(SimTelEventSource(parent=self))

        extractor = self.add_component(
            ImageExtractor.from_name(
                self.extractor_product, parent=self, subarray=self.eventsource.subarray,
            )
github cta-observatory / ctapipe / ctapipe / reco / hillas_intersection.py View on Github external
reconstruction is performed by performing the same procedure in the
    tilted ground system.

    The height of maximum is reconstructed by the projection os the image
    centroid onto the shower axis, taking the weighted average of all images.

    Uncertainties on the positions are provided by taking the spread of the
    crossing points, however this means that no uncertainty can be provided
    for multiplicity 2 events.
    """

    atmosphere_profile_name = traits.CaselessStrEnum(
        ["paranal",], default_value="paranal", help="name of atmosphere profile to use"
    ).tag(config=True)

    weighting = traits.CaselessStrEnum(
        ["Konrad", "hess"], default_value="Konrad", help="Weighting Method name"
    ).tag(config=True)

    def __init__(self, config=None, parent=None, **kwargs):
        """
        Weighting must be a function similar to the weight_konrad already implemented
        """
        super().__init__(config=config, parent=parent, **kwargs)

        # We need a conversion function from height above ground to depth of maximum
        # To do this we need the conversion table from CORSIKA
        _ = get_atmosphere_profile_functions(self.atmosphere_profile_name)
        self.thickness_profile, self.altitude_profile = _

        # other weighting schemes can be implemented. just add them as additional methods
        if self.weighting == "Konrad":
github cta-observatory / ctapipe / ctapipe / io / toymodel.py View on Github external
from .eventsource import EventSource
from .datalevels import DataLevel

logger = logging.getLogger(__name__)


class ToyEventSource(EventSource, TelescopeComponent):

    trigger_probability = traits.FloatTelescopeParameter(
        default_value=0.5, help="Probability that the telescope has an event",
    ).tag(config=True)

    min_length_m = traits.FloatTelescopeParameter(
        default_value=0.05, help="Minimum length m",
    ).tag(config=True)
    max_length_m = traits.FloatTelescopeParameter(
        default_value=0.3, help="Maximum length in m",
    ).tag(config=True)
    min_eccentricity = traits.FloatTelescopeParameter(
        default_value=0.8, help="Minimum eccentricity = sqrt(1 - width**2/length**2)",
    ).tag(config=True)
    max_eccentricity = traits.FloatTelescopeParameter(
        default_value=0.98, help="Maximum eccentricity = sqrt(1 - width**2/length**2)",
    ).tag(config=True)
    min_skewness = traits.FloatTelescopeParameter(
        default_value=0.1, help="Minimum skewness",
    ).tag(config=True)
    max_skewness = traits.FloatTelescopeParameter(
        default_value=0.5, help="Maximum skewness",
    ).tag(config=True)

    def __init__(self, subarray, config=None, parent=None, **kwargs):
github cta-observatory / ctapipe / ctapipe / calib / camera / gainselection.py View on Github external
channel = traits.CaselessStrEnum(
        ["HIGH", "LOW"], default_value="HIGH", help="Which gain channel to retain"
    ).tag(config=True)

    def select_channel(self, waveforms):
        n_pixels = waveforms.shape[1]
        return np.full(n_pixels, GainChannel[self.channel])


class ThresholdGainSelector(GainSelector):
    """
    Select gain channel according to a maximum threshold value.
    """

    threshold = traits.Float(
        default_value=4000,
        help="Threshold value in waveform sample units. If a waveform "
        "contains a sample above this threshold, use the low gain "
        "channel for that pixel.",
    ).tag(config=True)

    def select_channel(self, waveforms):
        return (waveforms[0] > self.threshold).any(axis=1).astype(np.int8)
github cta-observatory / ctapipe / ctapipe / io / toymodel.py View on Github external
DataContainer,
    DL1CameraContainer,
    EventIndexContainer,
)
from ..core import traits
from ..core import TelescopeComponent
from ..image import toymodel
from .eventsource import EventSource
from .datalevels import DataLevel

logger = logging.getLogger(__name__)


class ToyEventSource(EventSource, TelescopeComponent):

    trigger_probability = traits.FloatTelescopeParameter(
        default_value=0.5, help="Probability that the telescope has an event",
    ).tag(config=True)

    min_length_m = traits.FloatTelescopeParameter(
        default_value=0.05, help="Minimum length m",
    ).tag(config=True)
    max_length_m = traits.FloatTelescopeParameter(
        default_value=0.3, help="Maximum length in m",
    ).tag(config=True)
    min_eccentricity = traits.FloatTelescopeParameter(
        default_value=0.8, help="Minimum eccentricity = sqrt(1 - width**2/length**2)",
    ).tag(config=True)
    max_eccentricity = traits.FloatTelescopeParameter(
        default_value=0.98, help="Maximum eccentricity = sqrt(1 - width**2/length**2)",
    ).tag(config=True)
    min_skewness = traits.FloatTelescopeParameter(
github cta-observatory / ctapipe / ctapipe / calib / camera / gainselection.py View on Github external
Returns
        -------
        selected_gain_channel : ndarray
            Gain channel to use for each pixel
            Shape: n_pix
            Dtype: int8
        """


class ManualGainSelector(GainSelector):
    """
    Manually choose a gain channel.
    """

    channel = traits.CaselessStrEnum(
        ["HIGH", "LOW"], default_value="HIGH", help="Which gain channel to retain"
    ).tag(config=True)

    def select_channel(self, waveforms):
        n_pixels = waveforms.shape[1]
        return np.full(n_pixels, GainChannel[self.channel])


class ThresholdGainSelector(GainSelector):
    """
    Select gain channel according to a maximum threshold value.
    """

    threshold = traits.Float(
        default_value=4000,
        help="Threshold value in waveform sample units. If a waveform "