From 3587d9c4eedfff29b222450970178492c3791130 Mon Sep 17 00:00:00 2001 From: Collin Capano Date: Wed, 26 Aug 2020 14:52:19 +0200 Subject: [PATCH 1/2] register the new function --- pycbc/conversions.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pycbc/conversions.py b/pycbc/conversions.py index 83799976fa2..2476c2b179e 100644 --- a/pycbc/conversions.py +++ b/pycbc/conversions.py @@ -643,6 +643,27 @@ def dquadmon_from_lambda(lambdav): ln_quad_moment = ai + bi*ll + ci*ll**2.0 + di*ll**3.0 + ei*ll**4.0 return numpy.exp(ln_quad_moment) - 1 + +def spin_from_pulsar_freq(mass, radius, freq): + """Returns the dimensionless spin of a pulsar. + + Assumes the pulsar is a solid sphere when computing the moment of inertia. + + Parameters + ---------- + mass : float + The mass of the pulsar, in solar masses. + radius : float + The assumed radius of the pulsar, in kilometers. + freq : float + The spin frequency of the pulsar, in Hz. + """ + omega = 2 * numpy.pi * freq + mt = mass * lal.MTSUN_SI + I = (2/3.) * mt * (radius * 1000 / lal.C_SI)**2 + return I * omega / mt**2 + + # # ============================================================================= # @@ -1512,5 +1533,5 @@ def nltides_gw_phase_diff_isco(f_low, f0, amplitude, n, m1, m2): 'final_mass_from_initial', 'final_spin_from_initial', 'optimal_dec_from_detector', 'optimal_ra_from_detector', 'chi_eff_from_spherical', 'chi_p_from_spherical', - 'nltides_gw_phase_diff_isco', + 'nltides_gw_phase_diff_isco', 'spin_from_pulsar_freq', ] From 6bd1bcec6d8bc3478f7c55c4cc0c9a39a84999a8 Mon Sep 17 00:00:00 2001 From: Collin Capano Date: Wed, 26 Aug 2020 15:20:59 +0200 Subject: [PATCH 2/2] code climate --- pycbc/conversions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pycbc/conversions.py b/pycbc/conversions.py index 2476c2b179e..b7507df7c74 100644 --- a/pycbc/conversions.py +++ b/pycbc/conversions.py @@ -658,10 +658,10 @@ def spin_from_pulsar_freq(mass, radius, freq): freq : float The spin frequency of the pulsar, in Hz. """ - omega = 2 * numpy.pi * freq - mt = mass * lal.MTSUN_SI - I = (2/3.) * mt * (radius * 1000 / lal.C_SI)**2 - return I * omega / mt**2 + omega = 2 * numpy.pi * freq + mt = mass * lal.MTSUN_SI + mominert = (2/3.) * mt * (radius * 1000 / lal.C_SI)**2 + return mominert * omega / mt**2 #