Coverage for pesummary/gw/conversions/mass.py: 98.3%

59 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:42 +0000

1# Licensed under an MIT style license -- see LICENSE.md 

2 

3from pesummary.utils.decorators import array_input 

4 

5__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"] 

6 

7 

8@array_input() 

9def mass2_from_m1_q(mass1, q): 

10 """Return the secondary mass given samples for mass1 and mass ratio 

11 """ 

12 return mass1 * q 

13 

14 

15@array_input() 

16def m_total_from_m1_m2(mass1, mass2): 

17 """Return the total mass given the samples for mass1 and mass2 

18 """ 

19 return mass1 + mass2 

20 

21 

22@array_input() 

23def component_mass_product(mass1, mass2): 

24 """Return the product of mass1 and mass2 

25 """ 

26 return mass1 * mass2 

27 

28 

29@array_input() 

30def mchirp_from_m1_m2(mass1, mass2): 

31 """Return the chirp mass given the samples for mass1 and mass2 

32 

33 Parameters 

34 ---------- 

35 """ 

36 total_mass = m_total_from_m1_m2(mass1, mass2) 

37 return component_mass_product(mass1, mass2)**0.6 / total_mass**0.2 

38 

39 

40@array_input() 

41def component_masses_from_mtotal_q(mtotal, q): 

42 """Return the primary and secondary masses given samples for the total mass 

43 and mass ratio 

44 """ 

45 m1 = mtotal / (1. + q) 

46 return m1, mass2_from_m1_q(m1, q) 

47 

48 

49@array_input() 

50def component_masses_from_mchirp_q(mchirp, q): 

51 """Return the primary and secondary masses given samples for the chirp mass 

52 and mass ratio 

53 """ 

54 m1 = ((1. / q)**(2. / 5.)) * ((1.0 + (1. / q))**(1. / 5.)) * mchirp 

55 return m1, mass2_from_m1_q(m1, q) 

56 

57 

58@array_input() 

59def m1_from_mchirp_q(mchirp, q): 

60 """Return the mass of the larger component given the chirp mass and 

61 mass ratio 

62 """ 

63 return component_masses_from_mchirp_q(mchirp, q)[0] 

64 

65 

66@array_input() 

67def m2_from_mchirp_q(mchirp, q): 

68 """Return the mass of the smaller component given the chirp mass and 

69 mass ratio 

70 """ 

71 return component_masses_from_mchirp_q(mchirp, q)[1] 

72 

73 

74@array_input() 

75def m1_from_mtotal_q(mtotal, q): 

76 """Return the mass of the larger component given the total mass and 

77 mass ratio 

78 """ 

79 return component_masses_from_mtotal_q(mtotal, q)[0] 

80 

81 

82@array_input() 

83def m2_from_mtotal_q(mtotal, q): 

84 """Return the mass of the smaller component given the total mass and 

85 mass ratio 

86 """ 

87 return component_masses_from_mtotal_q(mtotal, q)[1] 

88 

89 

90@array_input() 

91def eta_from_m1_m2(mass1, mass2): 

92 """Return the symmetric mass ratio given the samples for mass1 and mass2 

93 """ 

94 total_mass = m_total_from_m1_m2(mass1, mass2) 

95 return component_mass_product(mass1, mass2) / total_mass**2 

96 

97 

98@array_input() 

99def eta_from_mtotal_q(total_mass, mass_ratio): 

100 """Return the symmetric mass ratio given samples for the total mass and 

101 mass ratio 

102 """ 

103 mass1, mass2 = component_masses_from_mtotal_q(total_mass, mass_ratio) 

104 return eta_from_m1_m2(mass1, mass2) 

105 

106 

107@array_input() 

108def q_from_m1_m2(mass1, mass2): 

109 """Return the mass ratio given the samples for mass1 and mass2 

110 """ 

111 return mass2 / mass1 

112 

113 

114@array_input() 

115def invq_from_m1_m2(mass1, mass2): 

116 """Return the inverted mass ratio (mass1/mass2 for mass1 > mass2) 

117 given the samples for mass1 and mass2 

118 """ 

119 return 1. / q_from_m1_m2(mass1, mass2) 

120 

121 

122@array_input() 

123def invq_from_q(mass_ratio): 

124 """Return the inverted mass ratio (mass1/mass2 for mass1 > mass2) 

125 given the samples for mass ratio (mass2/mass1) 

126 """ 

127 return 1. / mass_ratio 

128 

129 

130@array_input() 

131def q_from_eta(symmetric_mass_ratio): 

132 """Return the mass ratio given samples for symmetric mass ratio 

133 """ 

134 temp = (1 / symmetric_mass_ratio / 2 - 1) 

135 return (temp - (temp ** 2 - 1) ** 0.5) 

136 

137 

138@array_input() 

139def mchirp_from_mtotal_q(total_mass, mass_ratio): 

140 """Return the chirp mass given samples for total mass and mass ratio 

141 """ 

142 return eta_from_mtotal_q(total_mass, mass_ratio)**(3. / 5) * total_mass