diff --git a/ctapipe/reco/sklearn.py b/ctapipe/reco/sklearn.py index 976ecb6079e..1ae0bc78158 100644 --- a/ctapipe/reco/sklearn.py +++ b/ctapipe/reco/sklearn.py @@ -416,7 +416,7 @@ def predict_table(self, key, table: Table) -> Dict[ReconstructionProperty, Table result, ReconstructedEnergyContainer, prefix=self.prefix, - stereo=False, + add_tel_prefix=True, ) return {ReconstructionProperty.ENERGY: result} @@ -480,7 +480,10 @@ def predict_table(self, key, table: Table) -> Dict[ReconstructionProperty, Table } ) add_defaults_and_meta( - result, ParticleClassificationContainer, prefix=self.prefix, stereo=False + result, + ParticleClassificationContainer, + prefix=self.prefix, + add_tel_prefix=True, ) return {ReconstructionProperty.PARTICLE_TYPE: result} @@ -770,7 +773,8 @@ def predict_table(self, key, table: Table) -> Dict[ReconstructionProperty, Table disp_result, DispContainer, prefix=f"{self.prefix}_parameter", - stereo=False, + # disp is always per telescope, so no need to add the prefix + add_tel_prefix=False, ) psi = table["hillas_psi"].quantity.to_value(u.rad) @@ -797,7 +801,7 @@ def predict_table(self, key, table: Table) -> Dict[ReconstructionProperty, Table altaz_result, ReconstructedGeometryContainer, prefix=self.prefix, - stereo=False, + add_tel_prefix=True, ) return { diff --git a/ctapipe/reco/utils.py b/ctapipe/reco/utils.py index bf26d948074..66824292cea 100644 --- a/ctapipe/reco/utils.py +++ b/ctapipe/reco/utils.py @@ -1,4 +1,4 @@ -def add_defaults_and_meta(table, container, prefix=None, stereo=True): +def add_defaults_and_meta(table, container, prefix=None, add_tel_prefix=False): """ Fill column descriptions and default values into table for container @@ -10,7 +10,7 @@ def add_defaults_and_meta(table, container, prefix=None, stereo=True): the container class to add columns and descriptions to the table prefix : str prefix for the column names - stereo : bool + add_tel_prefix : bool If False, add a ``tel_`` prefix to the column names to signal it's telescope-wise quantity """ @@ -18,13 +18,13 @@ def add_defaults_and_meta(table, container, prefix=None, stereo=True): prefix = container.default_prefix for name, field in container.fields.items(): - if not stereo and name == "telescopes": + if add_tel_prefix and name == "telescopes": continue - if stereo: - colname = f"{prefix}_{name}" - else: + if add_tel_prefix: colname = f"{prefix}_tel_{name}" + else: + colname = f"{prefix}_{name}" if colname not in table.colnames and field.default is not None: table[colname] = field.default diff --git a/ctapipe/tools/tests/test_apply_models.py b/ctapipe/tools/tests/test_apply_models.py index 13f8edb805a..32b0e4bcc86 100644 --- a/ctapipe/tools/tests/test_apply_models.py +++ b/ctapipe/tools/tests/test_apply_models.py @@ -103,7 +103,6 @@ def test_apply_all( energy_regressor_path, particle_classifier_path, disp_reconstructor_path, - dl2_shower_geometry_file_lapalma, tmp_path, ): from ctapipe.tools.apply_models import ApplyModels @@ -211,6 +210,7 @@ def test_apply_all( assert f"{prefix_disp}_tel_is_valid" in tel_events.colnames assert f"{prefix_disp}_parameter_norm" in tel_events.colnames assert f"{prefix_disp}_parameter_is_valid" in tel_events.colnames + assert f"{prefix_disp}_parameter_tel_is_valid" not in tel_events.colnames # check that the "--no-dl1-parameters" option worked assert "hillas_intensity" not in tel_events.colnames diff --git a/docs/changes/2440.bugfix.rst b/docs/changes/2440.bugfix.rst new file mode 100644 index 00000000000..435d4288113 --- /dev/null +++ b/docs/changes/2440.bugfix.rst @@ -0,0 +1 @@ +Fix additional, unwanted columns being written into disp prediction output.