Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-flags, add short aliases, make aliases more consistent #1748

Merged
merged 6 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions ctapipe/tools/display_dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
from copy import copy
from matplotlib import pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from traitlets import Bool, Dict, Int

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.io.datalevels import DataLevel
from ctapipe.utils import get_dataset_path
from ctapipe.visualization import CameraDisplay
from ..calib import CameraCalibrator
from ..core import Component, Tool
from ..core.traits import Bool, Path, flag, Int, classes_with_traits
from ..image.extractor import ImageExtractor
from ..io import EventSource
from ..io.datalevels import DataLevel
from ..utils import get_dataset_path
from ..visualization import CameraDisplay


class ImagePlotter(Component):
""" Plotter for camera images """
"""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(
output_path = Path(
directory_ok=False,
help=(
"Output path for the pdf containing all the images."
Expand Down Expand Up @@ -136,23 +135,19 @@ class DisplayDL1Calib(Tool):
help="Telescope to view. Set to None to display all telescopes.",
).tag(config=True)

aliases = Dict(
dict(
input="EventSource.input_url",
max_events="EventSource.max_events",
T="DisplayDL1Calib.telescope",
O="ImagePlotter.output_path",
)
aliases = {
("i", "input"): "EventSource.input_url",
("m", "max-events"): "EventSource.max_events",
("t", "telescope"): "DisplayDL1Calib.telescope",
("o", "output"): "ImagePlotter.output_path",
}
flags = flag(
"display",
"ImagePlotter.display",
"Display the photo-electron images on-screen as they are produced.",
)
flags = Dict(
dict(
D=(
{"ImagePlotter": {"display": True}},
"Display the photo-electron images on-screen as they are produced.",
)
)
)
classes = [EventSource, ImagePlotter] + traits.classes_with_traits(ImageExtractor)

classes = [EventSource, ImagePlotter] + classes_with_traits(ImageExtractor)

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
44 changes: 19 additions & 25 deletions ctapipe/tools/display_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
"""
import numpy as np
from matplotlib import pyplot as plt
from traitlets import Dict, Int, Bool, Enum

from ctapipe.core import traits
from ctapipe.calib import CameraCalibrator
from ctapipe.core import Tool
from ctapipe.image.extractor import ImageExtractor
from ctapipe.io import EventSource
from ctapipe.io.eventseeker import EventSeeker
from ctapipe.visualization import CameraDisplay
from ..calib import CameraCalibrator
from ..core import Tool
from ..core.traits import Int, Bool, Enum, flag, classes_with_traits
from ..io import EventSource
from ..io.eventseeker import EventSeeker
from ..visualization import CameraDisplay


def plot(subarray, event, telid, chan, extractor_name):
Expand Down Expand Up @@ -226,24 +224,20 @@ class DisplayIntegrator(Tool):
).tag(config=True)
channel = Enum([0, 1], 0, help="Channel to view").tag(config=True)

aliases = Dict(
dict(
f="EventSource.input_url",
max_events="EventSource.max_events",
E="DisplayIntegrator.event_index",
T="DisplayIntegrator.telescope",
C="DisplayIntegrator.channel",
)
aliases = {
("i", "input"): "EventSource.input_url",
("m", "max-events"): "EventSource.max_events",
("e", "event-index"): "DisplayIntegrator.event_index",
("t", "telescope"): "DisplayIntegrator.telescope",
("C", "channel"): "DisplayIntegrator.channel",
}
flags = flag(
"id",
"DisplayDL1Calib.use_event_index",
"event_index will obtain an event using event_id instead of index.",
"event_index will obtain an event using index.",
)
flags = Dict(
dict(
id=(
{"DisplayDL1Calib": {"use_event_index": True}},
"event_index will obtain an event using event_id instead of index.",
)
)
)
classes = [EventSource] + traits.classes_with_traits(ImageExtractor)
classes = classes_with_traits(EventSource)

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
64 changes: 37 additions & 27 deletions ctapipe/tools/dl1_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ..io import metadata as meta, DL1EventSource
from ..io import HDF5TableWriter
from ..core import Provenance, Tool, traits
from ..core.traits import Bool, Set, Unicode, flag, CInt
from ..instrument import SubarrayDescription

import warnings
Expand Down Expand Up @@ -97,30 +98,28 @@ class MergeTool(Tool):
output_path = traits.Path(
help="Merged-DL1 output filename", directory_ok=False
).tag(config=True)
skip_images = traits.Bool(
skip_images = Bool(
help="Skip DL1/Event/Telescope and Simulation/Event/Telescope images in output",
default_value=False,
).tag(config=True)
skip_simu_images = traits.Bool(
skip_simu_images = Bool(
help="Skip Simulation/Event/Telescope images in output", default_value=False
).tag(config=True)
skip_parameters = traits.Bool(
skip_parameters = Bool(
help="Skip DL1/Event/Telescope and Simulation/Event/Telescope parameters"
"in output",
default_value=False,
).tag(config=True)
skip_broken_files = traits.Bool(
skip_broken_files = Bool(
help="Skip broken files instead of raising an error", default_value=False
).tag(config=True)
overwrite = traits.Bool(help="Overwrite output file if it exists").tag(config=True)
progress_bar = traits.Bool(help="Show progress bar during processing").tag(
config=True
)
file_pattern = traits.Unicode(
overwrite = Bool(help="Overwrite output file if it exists").tag(config=True)
progress_bar = Bool(help="Show progress bar during processing").tag(config=True)
file_pattern = Unicode(
default_value="*.h5", help="Give a specific file pattern for the input files"
).tag(config=True)
allowed_tels = traits.Set(
trait=traits.CInt(),
allowed_tels = Set(
trait=CInt(),
default_value=None,
allow_none=True,
help=(
Expand All @@ -141,29 +140,40 @@ class MergeTool(Tool):
}

flags = {
"skip-images": (
{"MergeTool": {"skip_images": True}},
"f": ({"MergeTool": {"overwrite": True}}, "Overwrite output file if it exists"),
**flag(
"overwrite",
"MergeTool.overwrite",
"Overwrite output file if it exists",
"Don't overwrite output file if it exists",
),
"progress": (
{"MergeTool": {"progress_bar": True}},
"Show a progress bar for all given input files",
),
**flag(
"skip-images",
"MergeTool.skip_images",
"Skip DL1/Event/Telescope and Simulation/Event/Telescope images in output",
"Don't skip DL1/Event/Telescope and Simulation/Event/Telescope images in output",
),
"skip-simu-images": (
{"MergeTool": {"skip_simu_images": True}},
**flag(
"skip-simu-images",
"MergeTool.skip_simu_images",
"Skip Simulation/Event/Telescope images in output",
"Don't skip Simulation/Event/Telescope images in output",
),
"skip-parameters": (
{"MergeTool": {"skip_parameters": True}},
**flag(
"skip-parameters",
"MergeTool.skip_parameters",
"Skip DL1/Event/Telescope and Simulation/Event/Telescope parameters in output",
"Don't skip DL1/Event/Telescope and Simulation/Event/Telescope parameters in output",
),
"skip-broken-files": (
{"MergeTool": {"skip_broken_files": True}},
**flag(
"skip-broken-files",
"MergeTool.skip_broken_files",
"Skip broken files instead of raising an error",
),
"overwrite": (
{"MergeTool": {"overwrite": True}},
"Overwrite output file if it exists",
),
"progress": (
{"MergeTool": {"progress_bar": True}},
"Show a progress bar for all given input files",
"Don't skip broken files instead of raising an error",
),
}

Expand Down
26 changes: 15 additions & 11 deletions ctapipe/tools/dump_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from astropy import units as u
from astropy.table import Table

from ctapipe.io import EventSource
from ctapipe.core import Provenance, ToolConfigurationError
from ctapipe.core.traits import Unicode, Dict, Bool, Path
from ..io import EventSource
from ..core import Provenance, ToolConfigurationError
from ..core.traits import Unicode, Dict, Bool, Path, flag
from ..core import Tool

MAX_TELS = 1000
Expand Down Expand Up @@ -43,14 +43,18 @@ class DumpTriggersTool(Tool):
{"infile": "DumpTriggersTool.infile", "outfile": "DumpTriggersTool.outfile"}
)

flags = Dict(
{
"overwrite": (
{"DumpTriggersTool": {"overwrite": True}},
"Enable overwriting of output file",
)
}
)
flags = {
"f": (
{"DumpTriggersTool": {"overwrite": True}},
"Enable overwriting of output file",
),
**flag(
"overwrite"
"DumpTriggersTool.overwrite"
"Enable overwriting of output file.",
"Disable overwriting of output file.",
),
}

examples = (
"ctapipe-dump-triggers --infile gamma.simtel.gz "
Expand Down
43 changes: 24 additions & 19 deletions ctapipe/tools/muon_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from tqdm.auto import tqdm
import numpy as np
from astropy.coordinates import SkyCoord
from ctapipe.containers import TelEventIndexContainer

from ctapipe.calib import CameraCalibrator
from ctapipe.core import Provenance
from ctapipe.core import Tool, ToolConfigurationError
from ctapipe.core import traits
from ctapipe.io import EventSource
from ctapipe.io import HDF5TableWriter
from ctapipe.image.cleaning import TailcutsImageCleaner
from ctapipe.coordinates import TelescopeFrame, CameraFrame
from ctapipe.containers import MuonParametersContainer
from ctapipe.instrument import CameraGeometry

from ..containers import TelEventIndexContainer
from ..calib import CameraCalibrator
from ..core import Provenance
from ..core import Tool, ToolConfigurationError
from ..core import traits
from ..core.traits import flag
from ..io import EventSource
from ..io import HDF5TableWriter
from ..image.cleaning import TailcutsImageCleaner
from ..coordinates import TelescopeFrame, CameraFrame
from ..containers import MuonParametersContainer
from ..instrument import CameraGeometry

from ctapipe.image.muon import (
MuonRingFitter,
Expand Down Expand Up @@ -77,16 +78,20 @@ class MuonAnalysis(Tool):
]

aliases = {
"i": "EventSource.input_url",
"input": "EventSource.input_url",
"o": "MuonAnalysis.output",
"output": "MuonAnalysis.output",
"max-events": "EventSource.max_events",
"allowed-tels": "EventSource.allowed_tels",
("i", "input"): "EventSource.input_url",
("o", "output"): "MuonAnalysis.output",
("m", "max-events"): "EventSource.max_events",
("t", "allowed-tels"): "EventSource.allowed_tels",
}

flags = {
"overwrite": ({"MuonAnalysis": {"overwrite": True}}, "overwrite output file")
"f": ({"MuonAnalysis": {"overwrite": True}}, "Overwrite output file"),
**flag(
"overwrite",
"MuonAnalysis.overwrite",
"Overwrite output file",
"Don't overwrite output file",
),
}

def setup(self):
Expand Down
Loading