How to use the ctapipe.core.traits.Path 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
class ChargeResolutionGenerator(Tool):
    name = "ChargeResolutionGenerator"
    description = (
        "Calculate the Charge Resolution from a sim_telarray "
        "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",
        )
github cta-observatory / ctapipe / ctapipe / tools / muon_reconstruction.py View on Github external
)


class MuonAnalysis(Tool):
    """
    Detect and extract muon ring parameters, and write the muon ring and
    intensity parameters to an output table.

    The resulting output can be read e.g. using for example
    `pandas.read_hdf(filename, 'dl1/event/telescope/parameters/muon')`
    """

    name = "ctapipe-reconstruct-muons"
    description = traits.Unicode(__doc__)

    output = traits.Path(directory_ok=False, help="HDF5 output file name").tag(
        config=True
    )

    completeness_threshold = traits.FloatTelescopeParameter(
        default_value=30.0, help="Threshold for calculating the ``ring_completeness``",
    ).tag(config=True)

    ratio_width = traits.FloatTelescopeParameter(
        default_value=1.5,
        help=(
            "Ring width for intensity ratio"
            " computation as multiple of pixel diameter"
        ),
    ).tag(config=True)

    overwrite = traits.Bool(
github cta-observatory / ctapipe / ctapipe / tools / display_dl1.py View on Github external
from ctapipe.calib import CameraCalibrator
from ctapipe.core import Component, Tool
from ctapipe.core import traits
from ctapipe.image.extractor import ImageExtractor
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe.visualization import CameraDisplay


class ImagePlotter(Component):
    """ Plotter for camera images """

    display = Bool(
        True, help="Display the photoelectron images on-screen as they are produced."
    ).tag(config=True)
    output_path = traits.Path(
        directory_ok=False,
        help=(
            "Output path for the pdf containing all the images."
            " Set to None for no saved output."
        ),
    ).tag(config=True)

    def __init__(self, subarray, config=None, parent=None, **kwargs):
        """
        Plotter for camera images.

        Parameters
        ----------
        config : traitlets.loader.Config
            Configuration specified by config file or cmdline arguments.
            Used to set traitlet values.
github cta-observatory / ctapipe / ctapipe / tools / dump_triggers.py View on Github external
MAX_TELS = 1000


class DumpTriggersTool(Tool):
    description = Unicode(__doc__)
    name = "ctapipe-dump-triggers"

    # =============================================
    # configuration parameters:
    # =============================================

    infile = Path(exists=True, directory_ok=False, help="input simtelarray file").tag(
        config=True
    )

    outfile = Path(
        default_value="triggers.fits",
        directory_ok=False,
        help="output filename (*.fits, *.h5)",
    ).tag(config=True)

    overwrite = Bool(False, help="overwrite existing output file").tag(config=True)

    # =============================================
    # map low-level options to high-level command-line options
    # =============================================

    aliases = Dict(
        {"infile": "DumpTriggersTool.infile", "outfile": "DumpTriggersTool.outfile"}
    )

    flags = Dict(
github cta-observatory / ctapipe / ctapipe / tools / dump_instrument.py View on Github external
"""

    cam_types = defaultdict(list)

    for telid in subarray.tel:
        geom = subarray.tel[telid].camera.geometry
        cam_types[geom.camera_name].append(telid)

    return cam_types


class DumpInstrumentTool(Tool):
    description = Unicode(__doc__)
    name = "ctapipe-dump-instrument"

    infile = Path(exists=True, help="input simtelarray file").tag(config=True)
    format = Enum(
        ["fits", "ecsv", "hdf5"],
        default_value="fits",
        help="Format of output file",
        config=True,
    )

    aliases = Dict(
        dict(infile="DumpInstrumentTool.infile", format="DumpInstrumentTool.format")
    )

    def setup(self):
        with event_source(self.infile) as source:
            self.subarray = source.subarray

    def start(self):
github cta-observatory / ctapipe / examples / simple_event_writer.py View on Github external
from tqdm import tqdm

from ctapipe.core import Tool
from ctapipe.core.traits import Path, Unicode, List, Dict, Bool
from ctapipe.io import EventSource, HDF5TableWriter

from ctapipe.calib import CameraCalibrator
from ctapipe.utils import get_dataset_path
from ctapipe.image import hillas_parameters, tailcuts_clean


class SimpleEventWriter(Tool):
    name = "ctapipe-simple-event-writer"
    description = Unicode(__doc__)

    infile = Path(
        default_value=get_dataset_path(
            "lst_prod3_calibration_and_mcphotons.simtel.zst"
        ),
        help="input file to read",
        directory_ok=False,
        exists=True,
    ).tag(config=True)
    outfile = Path(
        help="output file name", directory_ok=False, default_value="output.h5"
    ).tag(config=True)
    progress = Bool(help="display progress bar", default_value=True).tag(config=True)

    aliases = Dict(
        {
            "infile": "EventSource.input_url",
            "outfile": "SimpleEventWriter.outfile",
github cta-observatory / ctapipe / ctapipe / io / eventsource.py View on Github external
**NOTE**: The "event" that is returned from the generator is a pointer.
    Any operation that progresses that instance of the generator further will
    change the data pointed to by "event". If you wish to ensure a particular
    event is kept, you should perform a `event_copy = copy.deepcopy(event)`.


    Attributes
    ----------
    input_url : str
        Path to the input event file.
    max_events : int
        Maximum number of events to loop through in generator
    """

    input_url = Path(
        directory_ok=False,
        exists=True,
        help="Path to the input file containing events.",
    ).tag(config=True)

    max_events = Int(
        None,
        allow_none=True,
        help="Maximum number of events that will be read from the file",
    ).tag(config=True)

    allowed_tels = Set(
        default_value=None,
        allow_none=True,
        help=(
            "list of allowed tel_ids, others will be ignored. "
github cta-observatory / ctapipe / ctapipe / tools / stage1.py View on Github external
class Stage1ProcessorTool(Tool):
    name = "ctapipe-stage1-process"
    description = __doc__ + f" This currently writes {DL1_DATA_MODEL_VERSION} DL1 data"
    examples = """
    To process data with all default values:
    > ctapipe-stage1-process --input events.simtel.gz --output events.dl1.h5 --progress

    Or use an external configuration file, where you can specify all options:
    > ctapipe-stage1-process --config stage1_config.json --progress

    The config file should be in JSON or python format (see traitlets docs). For an
    example, see ctapipe/examples/stage1_config.json in the main code repo.
    """

    output_path = Path(
        help="DL1 output filename", default_value=pathlib.Path("events.dl1.h5")
    ).tag(config=True)

    write_images = Bool(
        help="Store DL1/Event/Image data in output", default_value=False
    ).tag(config=True)

    write_parameters = Bool(
        help="Compute and store image parameters", default_value=True
    ).tag(config=True)

    compression_level = Int(
        help="compression level, 0=None, 9=maximum", default_value=5, min=0, max=9
    ).tag(config=True)

    split_datasets_by = CaselessStrEnum(
github cta-observatory / ctapipe / ctapipe / tools / display_summed_images.py View on Github external
import numpy as np
from matplotlib import pyplot as plt

from ctapipe.calib import CameraCalibrator
from ctapipe.core import Tool
from ctapipe.core.traits import Unicode, Integer, Dict, List, Path
from ctapipe.io import SimTelEventSource
from ctapipe.visualization import CameraDisplay
from ctapipe.utils import get_dataset_path


class ImageSumDisplayerTool(Tool):
    description = Unicode(__doc__)
    name = "ctapipe-display-imagesum"

    infile = Path(
        help="input simtelarray file",
        default_value=get_dataset_path("gamma_test_large.simtel.gz"),
        exists=True,
        directory_ok=False,
    ).tag(config=True)

    telgroup = Integer(help="telescope group number", default_value=1).tag(config=True)

    max_events = Integer(
        help="stop after this many events if non-zero", default_value=0, min=0
    ).tag(config=True)

    output_suffix = Unicode(
        help="suffix (file extension) of output "
        "filenames to write images "
        "to (no writing is done if blank). "