Skip to content

Commit 05504a8

Browse files
authored
Merge pull request #272 from ctlearn-project/fix_predict_tool
Two minor bug fixes predict tool
2 parents 0925db7 + 37cd1b1 commit 05504a8

3 files changed

Lines changed: 25 additions & 20 deletions

File tree

.github/workflows/python-package-conda.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ jobs:
1616
os: [ubuntu-22.04]
1717
python-version: ['3.12', '3.13', '3.14']
1818
dl1dh-version: ['latest', 'nightly']
19+
tensorflow-version: ['latest', '2.16.*']
20+
exclude:
21+
- python-version: '3.13'
22+
tensorflow-version: '2.16.*'
23+
- python-version: '3.14'
24+
tensorflow-version: '2.16.*'
1925
max-parallel: 6
2026
runs-on: ${{ matrix.os }}
2127
continue-on-error: ${{ matrix.dl1dh-version == 'nightly' || matrix.python-version == '3.14' }}
@@ -50,6 +56,11 @@ jobs:
5056
else
5157
pip install dl1-data-handler
5258
fi
59+
if [ "${{ matrix.tensorflow-version }}" = "latest" ]; then
60+
pip install --upgrade tensorflow
61+
else
62+
pip install "tensorflow==${{ matrix.tensorflow-version }}"
63+
fi
5364
5465
- name: Add MKL_THREADING_LAYER variable
5566
run: echo "MKL_THREADING_LAYER=GNU" >> $GITHUB_ENV

ctlearn/tools/predict_model.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@
9090
from ctlearn.utils import validate_trait_dict
9191

9292
# Convienient constants for column names and table keys
93-
CONFIG_INSTRUMENT_SUBARRAY_LAYOUT = "/configuration/instrument/subarray/layout"
94-
CONFIG_INSTRUMENT_TEL = "/configuration/instrument/telescope"
95-
CONFIG_INSTRUMENT_TEL_CAMERA = "/configuration/instrument/telescope/camera"
9693
SUBARRAY_EVENT_KEYS = ["obs_id", "event_id"]
9794
TEL_EVENT_KEYS = ["obs_id", "event_id", "tel_id"]
9895
TEL_ITER_GROUPS = [
@@ -519,7 +516,13 @@ def _ensure_subarray_consistency(self):
519516
if input_subarray == self.dl1dh_reader.subarray:
520517
return
521518

522-
self.dl1dh_reader.subarray.to_hdf(self.output_path, overwrite=True)
519+
# From the merger tool a SubarrayDescription for the full array is already stored
520+
# in the output file. We need to remove it to avoid conflicts when storing
521+
# the new SubarrayDescription for the selected telescopes.
522+
with tables.open_file(self.output_path, mode="a") as h5file:
523+
h5file.remove_node("/configuration/instrument", recursive=True)
524+
selected_subarray = input_subarray.select_subarray(set(self.dl1dh_reader.tel_ids))
525+
selected_subarray.to_hdf(self.output_path)
523526
self.log.info("SubarrayDescription was stored in '%s'", self.output_path)
524527

525528
tel_trigger_table = read_table(
@@ -538,9 +541,12 @@ def _ensure_subarray_consistency(self):
538541
)
539542

540543
subarray_trigger_table = tel_trigger_table.copy()
541-
subarray_trigger_table.keep_columns(
542-
SUBARRAY_EVENT_KEYS + ["time", "event_type"]
543-
)
544+
subarray_columns = SUBARRAY_EVENT_KEYS + ["time"]
545+
# In older data formats the event type is not included in the trigger table, so we need to
546+
# check if it is present before keeping the column to be backwards compatible.
547+
if "event_type" in subarray_trigger_table.colnames:
548+
subarray_columns.append("event_type")
549+
subarray_trigger_table.keep_columns(subarray_columns)
544550
subarray_trigger_table = unique(
545551
subarray_trigger_table, keys=SUBARRAY_EVENT_KEYS
546552
)
@@ -611,19 +617,6 @@ def prune_group(group, valid_ids):
611617
if group is not None:
612618
prune_group(group, tel_ids)
613619

614-
# Camera configuration tables
615-
layout_node = getattr(h5_file.root, CONFIG_INSTRUMENT_SUBARRAY_LAYOUT, None)
616-
camera_group = getattr(h5_file.root, CONFIG_INSTRUMENT_TEL_CAMERA, None)
617-
if not (layout_node and camera_group):
618-
return
619-
# layout can be either a Table or a Group containing a Table
620-
layout_table = (
621-
layout_node
622-
if isinstance(layout_node, tables.Table)
623-
else next(layout_node._f_iter_nodes("Table"))
624-
)
625-
camera_indices = set(layout_table.col("camera_index"))
626-
prune_group(camera_group, camera_indices)
627620

628621
def _create_nan_table(self, nonexample_identifiers, columns, shapes, reco_task):
629622
"""

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies = [
3737
"scikit-learn",
3838
"numba",
3939
"tensorflow>=2.16",
40+
"tensorboard",
4041
"pydot",
4142
"setuptools",
4243
"ctapipe[all]>=0.29",

0 commit comments

Comments
 (0)