Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwanted default columns in disp output #2440

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions ctapipe/reco/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions ctapipe/reco/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,21 +10,21 @@ 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
maxnoe marked this conversation as resolved.
Show resolved Hide resolved
"""
if prefix is None:
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
Expand Down
2 changes: 1 addition & 1 deletion ctapipe/tools/tests/test_apply_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/changes/2440.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix additional, unwanted columns being written into disp prediction output.