Skip to content

Commit

Permalink
Allow only writing simulation info and trigger info in datawriter, re…
Browse files Browse the repository at this point in the history
…move obsolete dump-triggers
  • Loading branch information
maxnoe committed Jul 5, 2023
1 parent e3705aa commit ce1bc0c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 171 deletions.
34 changes: 19 additions & 15 deletions ctapipe/io/datawriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,11 @@ def __call__(self, event: ArrayEventContainer):
Write a single event to the output file.
"""
self._at_least_one_event = True
self.log.debug("WRITING EVENT %s", event.index)

# Write subarray event data
self._write_subarray_pointing(event, writer=self._writer)
self._write_trigger(self._writer, event)

self.log.debug("WRITING EVENT %s", event.index)
self._writer.write(
table_name="dl1/event/subarray/trigger",
containers=[event.index, event.trigger],
)
if event.simulation is not None and event.simulation.shower is not None:
self._writer.write(
table_name="simulation/event/subarray/shower",
Expand Down Expand Up @@ -415,8 +411,9 @@ def _setup_output_path(self):
self.write_muon_parameters,
]
if not any(writable_things):
raise ToolConfigurationError(
"DataWriter configured to write no information"
self.log.warning(
"No processing results were selected for writing"
", only writing trigger and simulation information"
)

def _setup_writer(self):
Expand Down Expand Up @@ -616,6 +613,20 @@ def table_name(self, tel_id):
"""construct dataset table names depending on chosen split method"""
return f"tel_{tel_id:03d}"

def _write_trigger(self, writer: TableWriter, event: ArrayEventContainer):
"""
Write trigger information
"""
self._writer.write(
table_name="dl1/event/subarray/trigger",
containers=[event.index, event.trigger],
)

for tel_id, trigger in event.trigger.tel.items():
writer.write(
"dl1/event/telescope/trigger", (_get_tel_index(event, tel_id), trigger)
)

def _write_r1_telescope_events(
self, writer: TableWriter, event: ArrayEventContainer
):
Expand Down Expand Up @@ -646,13 +657,6 @@ def _write_dl1_telescope_events(
event
"""

# write the telescope tables
# trigger info
for tel_id, trigger in event.trigger.tel.items():
writer.write(
"dl1/event/telescope/trigger", [_get_tel_index(event, tel_id), trigger]
)

# pointing info
for tel_id, pnt in event.pointing.tel.items():
current_pointing = (pnt.azimuth, pnt.altitude)
Expand Down
142 changes: 0 additions & 142 deletions ctapipe/tools/dump_triggers.py

This file was deleted.

1 change: 1 addition & 0 deletions ctapipe/tools/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def start(self):
"""
Process events
"""
self.log.info("applying calibration: %s", self.should_calibrate)
self.log.info("(re)compute DL1: %s", self.should_compute_dl1)
self.log.info("(re)compute DL2: %s", self.should_compute_dl2)
self.log.info(
Expand Down
22 changes: 22 additions & 0 deletions ctapipe/tools/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,25 @@ def test_plugin_help(capsys):
assert (
"PluginReconstructor.foo" in captured.out
), "Tool help is missing plugin classes, did you run `pip install -e ./test_plugin`?"


def test_only_trigger_and_simulation(tmp_path):
output = tmp_path / "only_trigger_and_simulation.h5"

run_tool(
ProcessorTool(),
argv=[
"--input=dataset://gamma_prod5.simtel.zst",
f"--output={output}",
"--no-write-parameters",
"--overwrite",
],
cwd=tmp_path,
raises=True,
)

with TableLoader(output, load_simulated=True) as loader:
events = loader.read_subarray_events()
assert len(events) == 7
assert "tels_with_trigger" in events.colnames
assert "true_energy" in events.colnames
13 changes: 0 additions & 13 deletions ctapipe/tools/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ def test_fileinfo(tmp_path, dl1_image_file):
assert "CTA ACTIVITY ID" in header[str(dl1_image_file)]


def test_dump_triggers(tmp_path):
from ctapipe.tools.dump_triggers import DumpTriggersTool

sys.argv = ["dump_triggers"]
output_path = tmp_path / "triggers.fits"
tool = DumpTriggersTool(input_path=PROD5B_PATH, output_path=str(output_path))

assert run_tool(tool, cwd=tmp_path) == 0

assert output_path.exists()
assert run_tool(tool, ["--help-all"]) == 0


def test_dump_instrument(tmp_path):
from ctapipe.tools.dump_instrument import DumpInstrumentTool

Expand Down
5 changes: 5 additions & 0 deletions docs/changes/2375.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The ``ctapipe-dump-triggers`` tool was removed, since it wrote a custom data format
not compatble with e.g. the output of the ``DataWriter`` and ``ctapipe-process``.
If you only want to store trigger and simulation information from simulated / DL0
input files into the ctapipe format HDF5 files, you can now use
``ctapipe-process -i <input> -o <output> --no-write-parameters``.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ exclude =
[options.entry_points]
console_scripts =
ctapipe-info = ctapipe.tools.info:main
ctapipe-dump-triggers = ctapipe.tools.dump_triggers:main
ctapipe-dump-instrument=ctapipe.tools.dump_instrument:main
ctapipe-display-dl1 = ctapipe.tools.display_dl1:main
ctapipe-process = ctapipe.tools.process:main
Expand Down

0 comments on commit ce1bc0c

Please sign in to comment.