From 3ba1f4b49c26876cf4f7cd82710e11c5ac9ee574 Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Thu, 9 Jan 2025 13:35:15 +0100 Subject: [PATCH] Fix SubarrayDescription.info for non-unique telescope description strings --- docs/changes/2673.bugfix.rst | 2 ++ src/ctapipe/instrument/subarray.py | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 docs/changes/2673.bugfix.rst diff --git a/docs/changes/2673.bugfix.rst b/docs/changes/2673.bugfix.rst new file mode 100644 index 00000000000..bed51120dc6 --- /dev/null +++ b/docs/changes/2673.bugfix.rst @@ -0,0 +1,2 @@ +Fix ``SubarrayDescription.info()`` in cases +of different ``TelescopeDescription`` with the same string representation. diff --git a/src/ctapipe/instrument/subarray.py b/src/ctapipe/instrument/subarray.py index d2500ab6f33..f66bce99702 100644 --- a/src/ctapipe/instrument/subarray.py +++ b/src/ctapipe/instrument/subarray.py @@ -2,6 +2,7 @@ Description of Arrays or Subarrays of telescopes """ import warnings +from collections import defaultdict from collections.abc import Iterable from contextlib import ExitStack from copy import copy @@ -135,19 +136,19 @@ def info(self, printer=print): printer("") # print the per-telescope-type informatino: - n_tels = {} - tel_ids = {} - + tel_ids = defaultdict(list) for tel_type in self.telescope_types: ids = self.get_tel_ids_for_type(tel_type) - tel_ids[str(tel_type)] = _range_extraction(ids) - n_tels[str(tel_type)] = len(ids) + tel_ids[str(tel_type)].extend(ids) + + n_tels = {tel_type: len(ids) for tel_type, ids in tel_ids.items()} + id_ranges = [_range_extraction(ids) for ids in tel_ids.values()] out_table = Table( { "Type": list(n_tels.keys()), "Count": list(n_tels.values()), - "Tel IDs": list(tel_ids.values()), + "Tel IDs": id_ranges, } ) out_table["Tel IDs"].format = "