From b31fdecfa071101673a987a72cc209239aaee5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20N=C3=B6the?= Date: Thu, 2 Jun 2022 16:36:17 +0200 Subject: [PATCH] Fix Optics.__hash__ for case of nan effective focal length --- ctapipe/instrument/optics.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ctapipe/instrument/optics.py b/ctapipe/instrument/optics.py index 0ba666d00d2..051f6dab4f0 100644 --- a/ctapipe/instrument/optics.py +++ b/ctapipe/instrument/optics.py @@ -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, @@ -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}" ")"