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 1 commit
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
29 changes: 13 additions & 16 deletions ctapipe/tools/display_dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


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."
Expand Down Expand Up @@ -136,22 +136,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": "DisplayDL1Calib.telescope",
nbiederbeck marked this conversation as resolved.
Show resolved Hide resolved
("o", "output"): "ImagePlotter.output_path",
}
flags = {
"D": (
{"ImagePlotter": {"display": True}},
"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)

def __init__(self, **kwargs):
Expand Down
29 changes: 12 additions & 17 deletions ctapipe/tools/display_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,19 @@ 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": "DisplayIntegrator.event_index",
nbiederbeck marked this conversation as resolved.
Show resolved Hide resolved
"T": "DisplayIntegrator.telescope",
"C": "DisplayIntegrator.channel",
}
flags = {
"id": (
{"DisplayDL1Calib": {"use_event_index": True}},
nbiederbeck marked this conversation as resolved.
Show resolved Hide resolved
"event_index will obtain an event using event_id instead of 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)
}

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
77 changes: 44 additions & 33 deletions ctapipe/tools/dl1_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from ..io import metadata as meta, DL1EventSource
from ..io import HDF5TableWriter
from ..core import Provenance, Tool, traits
from ..core import Provenance, Tool
from ..core.traits import Path, Bool, Set, Unicode, flag, CInt
from ..instrument import SubarrayDescription

import warnings
Expand Down Expand Up @@ -90,37 +91,35 @@ class MergeTool(Tool):

If no pattern is given, all .h5 files of the given directory will be taken as input.
"""
input_dir = traits.Path(
input_dir = Path(
help="Input dl1-directory", exists=True, directory_ok=True, file_ok=False
).tag(config=True)
input_files = List(default_value=[], help="Input dl1-files").tag(config=True)
output_path = traits.Path(
help="Merged-DL1 output filename", directory_ok=False
).tag(config=True)
skip_images = traits.Bool(
output_path = Path(help="Merged-DL1 output filename", directory_ok=False).tag(
config=True
)
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,23 +140,7 @@ class MergeTool(Tool):
}

flags = {
"skip-images": (
{"MergeTool": {"skip_images": True}},
"Skip DL1/Event/Telescope and Simulation/Event/Telescope images in output",
),
"skip-simu-images": (
{"MergeTool": {"skip_simu_images": True}},
"Skip Simulation/Event/Telescope images in output",
),
"skip-parameters": (
{"MergeTool": {"skip_parameters": True}},
"Skip DL1/Event/Telescope and Simulation/Event/Telescope parameters in output",
),
"skip-broken-files": (
{"MergeTool": {"skip_broken_files": True}},
"Skip broken files instead of raising an error",
),
"overwrite": (
("f", "overwrite"): (
{"MergeTool": {"overwrite": True}},
"Overwrite output file if it exists",
),
Expand All @@ -166,6 +149,34 @@ class MergeTool(Tool):
"Show a progress bar for all given input files",
),
}
_flags = [
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",
),
flag(
"skip-simu-images",
"MergeTool.skip_simu_images",
"Skip Simulation/Event/Telescope images in output",
"Don't skip Simulation/Event/Telescope images in output",
),
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",
),
flag(
"skip-broken-files",
"MergeTool.skip_broken_files",
"Skip broken files instead of raising an error",
"Don't skip broken files instead of raising an error",
),
]
for f in _flags:
nbiederbeck marked this conversation as resolved.
Show resolved Hide resolved
flags.update(f)

def setup(self):
# prepare output path:
Expand Down
14 changes: 6 additions & 8 deletions ctapipe/tools/dump_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ class DumpTriggersTool(Tool):
{"infile": "DumpTriggersTool.infile", "outfile": "DumpTriggersTool.outfile"}
)

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

examples = (
"ctapipe-dump-triggers --infile gamma.simtel.gz "
Expand Down
15 changes: 8 additions & 7 deletions ctapipe/tools/muon_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ 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", "overwrite"): (
{"MuonAnalysis": {"overwrite": True}},
"overwrite output file",
)
}

def setup(self):
Expand Down
40 changes: 25 additions & 15 deletions ctapipe/tools/stage1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..calib.camera import CameraCalibrator, GainSelector
from ..core import Tool
from ..core.traits import Bool, classes_with_traits
from ..core.traits import Bool, classes_with_traits, flag
from ..image import ImageCleaner, ImageProcessor
from ..image.extractor import ImageExtractor
from ..io import DataLevel, DataWriter, EventSource, SimTelEventSource
Expand Down Expand Up @@ -44,18 +44,6 @@ class Stage1Tool(Tool):
}

flags = {
"write-images": (
{"DataWriter": {"write_images": True}},
"store DL1/Event/Telescope images in output",
),
"write-parameters": (
{"DataWriter": {"write_parameters": True}},
"store DL1/Event/Telescope parameters in output",
),
"write-index-tables": (
{"DataWriter": {"write_index_tables": True}},
"generate PyTables index tables for the parameter and image datasets",
),
("f", "overwrite"): (
{"DataWriter": {"overwrite": True}},
"Overwrite output file if it exists",
Expand All @@ -65,6 +53,28 @@ class Stage1Tool(Tool):
"show a progress bar during event processing",
),
}
_flags = [
flag(
"write-images",
"DataWriter.write_images",
"store DL1/Event/Telescope images in output",
"don't store DL1/Event/Telescope images in output",
),
flag(
"write-parameters",
"DataWriter.write_parameters",
"store DL1/Event/Telescope parameters in output",
"don't store DL1/Event/Telescope parameters in output",
),
flag(
"write-index-tables",
"DataWriter.write_index_tables",
"generate PyTables index tables for the parameter and image datasets",
"don't generate PyTables index tables for the parameter and image datasets",
),
]
for f in _flags:
flags.update(f)

classes = (
[CameraCalibrator, DataWriter, ImageProcessor]
Expand Down Expand Up @@ -110,7 +120,7 @@ def setup(self):
)

def _write_processing_statistics(self):
""" write out the event selection stats, etc. """
"""write out the event selection stats, etc."""
# NOTE: don't remove this, not part of DataWriter
image_stats = self.process_images.check_image.to_table(functions=True)
image_stats.write(
Expand Down Expand Up @@ -143,7 +153,7 @@ def finish(self):


def main():
""" run the tool"""
"""run the tool"""
tool = Stage1Tool()
tool.run()

Expand Down