Skip to content

Commit

Permalink
Fix Optics.__hash__ for case of nan effective focal length
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jun 2, 2022
1 parent 8ca3d3e commit b31fdec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ctapipe/instrument/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ def __init__(

def __hash__(self):
"""Make this hashable, so it can be used as dict keys or in sets"""
effective_focal_length = self.effective_focal_length.to_value(u.m)
# nan hash is objet id in python >= 3.10, we want a fixed hash for all
# nans
if np.isnan(effective_focal_length):
effective_focal_length = -1

return hash(
(
self.equivalent_focal_length.to_value(u.m),
self.effective_focal_length.to_value(u.m),
effective_focal_length,
self.mirror_area,
self.num_mirrors,
self.num_mirror_tiles,
Expand Down Expand Up @@ -180,6 +186,7 @@ def __repr__(self):
f"{self.__class__.__name__}"
f"(name={self.name}"
f", equivalent_focal_length={self.equivalent_focal_length:.2f}"
f", effective_focal_length={self.effective_focal_length:.2f}"
f", num_mirrors={self.num_mirrors}"
f", mirror_area={self.mirror_area:.2f}"
")"
Expand Down

0 comments on commit b31fdec

Please sign in to comment.