Skip to content

Commit

Permalink
Merge pull request #1945 from cta-observatory/ignore_containers
Browse files Browse the repository at this point in the history
Ignore containers and maps by default in HDF5Writer
  • Loading branch information
maxnoe authored Jun 30, 2022
2 parents 179feae + a6ea236 commit 5341875
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
10 changes: 0 additions & 10 deletions ctapipe/io/datawriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,6 @@ def _setup_writer(self):
transform=tr_tel_list_to_mask,
)

# avoid some warnings about unwritable columns (which here are just
# sub-containers)
writer.exclude("dl1/event/subarray/trigger", "tel")
writer.exclude("dl1/monitoring/subarray/pointing", "tel")
writer.exclude("/dl1/event/telescope/images/.*", "parameters")

# currently the trigger info is used for the event time, but we dont'
# want the other bits of the trigger container in the pointing or other
# montitoring containers
Expand All @@ -437,15 +431,11 @@ def _setup_writer(self):
writer.exclude("/dl1/event/telescope/images/.*", "image_mask")

if self._is_simulation:
writer.exclude("/simulation/event/telescope/images/.*", "true_parameters")
writer.exclude("/simulation/event/telescope/images/.*", "impact")
# no timing information yet for true images
writer.exclude("/simulation/event/telescope/parameters/.*", r"peak_time_.*")
writer.exclude("/simulation/event/telescope/parameters/.*", "timing_.*")
writer.exclude("/simulation/event/subarray/shower", "true_tel")

# Set up transforms

if self.transform_image:
transform = FixedPointColumnTransform(
scale=self.image_scale,
Expand Down
14 changes: 11 additions & 3 deletions ctapipe/io/hdf5tableio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
EnumColumnTransform,
QuantityColumnTransform,
)
from ..core import Container
from ..core import Container, Map

__all__ = ["HDF5TableWriter", "HDF5TableReader"]

Expand Down Expand Up @@ -141,12 +141,20 @@ def _add_column_to_schema(self, table_name, schema, meta, pos, field, name, valu
typename = ""
shape = 1

if isinstance(value, Container):
self.log.debug("Ignoring sub-container: %s/%s", table_name, name)
return

if isinstance(value, Map):
self.log.debug("Ignoring map-field: %s/%s", table_name, name)
return

if self._is_column_excluded(table_name, name):
self.log.debug(f"excluded column: {table_name}/{name}")
self.log.debug("excluded column: %s/%s", table_name, name)
return

if name in schema.columns:
self.log.warning(f"Found duplicated column {name}, skipping")
self.log.warning("Found duplicated column %s, skipping", name)
return

# apply any user-defined transforms first
Expand Down

0 comments on commit 5341875

Please sign in to comment.