@@ -232,19 +232,24 @@ def convert_to_lal_binary_black_hole_parameters(parameters):
232232 key = 'chi_{}' .format (idx )
233233 if key in original_keys :
234234 if "chi_{}_in_plane" .format (idx ) in original_keys :
235- converted_parameters ["a_{}" .format (idx )] = (
236- converted_parameters [f"chi_{ idx } " ] ** 2
237- + converted_parameters [f"chi_{ idx } _in_plane" ] ** 2
238- ) ** 0.5
239- converted_parameters [f"cos_tilt_{ idx } " ] = (
240- converted_parameters [f"chi_{ idx } " ]
241- / converted_parameters [f"a_{ idx } " ]
242- )
235+ a = (converted_parameters [f"chi_{ idx } " ] ** 2
236+ + converted_parameters [f"chi_{ idx } _in_plane" ] ** 2 ) ** 0.5
237+ converted_parameters [f"a_{ idx } " ] = a
238+ with np .errstate (invalid = "raise" ):
239+ try :
240+ converted_parameters [f"cos_tilt_{ idx } " ] = (
241+ converted_parameters [f"chi_{ idx } " ] / a
242+ )
243+ except (FloatingPointError , ZeroDivisionError ):
244+ logger .debug (
245+ "Error in conversion to spherical spin tilt. "
246+ "This is often due to the spin parameters being zero. "
247+ f"Setting cos_tilt_{ idx } = 1."
248+ )
249+ converted_parameters [f"cos_tilt_{ idx } " ] = 1.0
243250 elif "a_{}" .format (idx ) not in original_keys :
244- converted_parameters ['a_{}' .format (idx )] = abs (
245- converted_parameters [key ])
246- converted_parameters ['cos_tilt_{}' .format (idx )] = \
247- np .sign (converted_parameters [key ])
251+ converted_parameters ['a_{}' .format (idx )] = abs (converted_parameters [key ])
252+ converted_parameters ['cos_tilt_{}' .format (idx )] = np .sign (converted_parameters [key ])
248253 else :
249254 with np .errstate (invalid = "raise" ):
250255 try :
0 commit comments