From 80351bfac00eb46a868d0c65d5ede43a6980aec1 Mon Sep 17 00:00:00 2001 From: James Chiang Date: Thu, 13 Jun 2024 13:37:24 -0700 Subject: [PATCH] handle nans from bad arguments to np.arccos --- skycatalogs/objects/sso_object.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/skycatalogs/objects/sso_object.py b/skycatalogs/objects/sso_object.py index b889f3cd..3171db26 100644 --- a/skycatalogs/objects/sso_object.py +++ b/skycatalogs/objects/sso_object.py @@ -69,7 +69,17 @@ def get_gsobject_components(self, gsparams=None, rng=None, init_v = UnitVector3d(LonLat.fromDegrees(ra, dec)) final_v = UnitVector3d(LonLat.fromDegrees(ra_final, dec_final)) - length = np.degrees(np.arccos(init_v.dot(final_v))) * 3600.0 + cos_sep = init_v.dot(final_v) + if cos_sep > 1.0: + # Handle values like cos_sep = 1.0000000000000002 + length = 0.0 + else: + length = np.degrees(np.arccos(cos_sep)) * 3600.0 + if np.isnan(length): + # This will raise if cos_sep < -1.0. A value of cos_sep = -1.0 + # is almost certainly unphysical, so we want to catch these cases. + raise ValueError("SSO streak length is nan") + if length * trail_width == 0: # Treat as a point source. return {'this_object': galsim.DeltaFunction(gsparams=gsparams)}