@@ -379,6 +379,51 @@ def test_bbh_cos_angle_to_angle_conversion(self):
379379 self .bbh_convert ()
380380 self .assertEqual (self .parameters ["tilt_1" ], t1 )
381381
382+ def test_bbh_chi_in_plane_zero_spin_both_components (self ):
383+ """
384+ When chi_1 = chi_1_in_plane = 0 the magnitude a_1 = 0,
385+ and the bare division chi_1 / a_1 = 0/0 would produce a NaN.
386+ This tests whether the wrapped np.errstate(invalid="raise")
387+ correctly catches the resulting error, and sets cos_tilt_1 = 1.0 instead.
388+ Same for component labeled 2.
389+ """
390+ self .parameters ["chi_1" ] = 0.0
391+ self .parameters ["chi_1_in_plane" ] = 0.0
392+ self .parameters ["chi_2" ] = 0.0
393+ self .parameters ["chi_2_in_plane" ] = 0.0
394+ self .bbh_convert ()
395+ for idx in ["1" , "2" ]:
396+ self .assertFalse (
397+ np .isnan (self .parameters [f"cos_tilt_{ idx } " ]),
398+ f"cos_tilt_{ idx } must not be NaN for zero spins" ,
399+ )
400+ self .assertEqual (self .parameters [f"a_{ idx } " ], 0.0 )
401+ self .assertEqual (self .parameters [f"cos_tilt_{ idx } " ], 1.0 )
402+
403+ def test_bbh_double_conversion_zero_spin_no_nan (self ):
404+ """
405+ Verify that, when calling convert_to_lal_binary_black_hole_parameters
406+ twice on a parameters dict that has chi_1 = chi_2 = 0, the np.errstate
407+ is correctly triggered and avoids NaNs.
408+ """
409+ self .parameters ["chi_1" ] = 0.0
410+ self .parameters ["chi_2" ] = 0.0
411+ # First conversion
412+ self .bbh_convert ()
413+ first_pass = self .parameters .copy ()
414+ self .assertFalse (np .isnan (first_pass .get ("cos_tilt_1" , 0.0 )))
415+
416+ # Second conversion on the already-converted parameters (the crash scenario)
417+ (second_pass , _ ) = conversion .convert_to_lal_binary_black_hole_parameters (first_pass )
418+ self .assertFalse (
419+ np .isnan (second_pass ["cos_tilt_1" ]),
420+ "cos_tilt_1 must not be NaN after a second conversion of zero-spin parameters" ,
421+ )
422+ self .assertFalse (
423+ np .isnan (second_pass ["cos_tilt_2" ]),
424+ "cos_tilt_2 must not be NaN after a second conversion of zero-spin parameters" ,
425+ )
426+
382427 def _conversion_to_component_tidal (self , keys ):
383428 for key in keys :
384429 self .parameters [key ] = self .tidal_parameters [key ]
0 commit comments