@@ -26,10 +26,22 @@ def half_lifes_passed(timespan: TimespanSeconds, half_life: TimespanSeconds) ->
2626 Compute the number of half-lifes that have passed within a certain
2727 timespan. The timespan can be a string or a number (in seconds).
2828
29+ Parameters
30+ ----------
31+ timespan : TimespanSeconds
32+ The timespan in seconds or a string like "1h".
33+ half_life : TimespanSeconds
34+ The half-life in seconds or a string like "1min".
35+
36+ Returns
37+ -------
38+ float
39+ Number of half-lifes that have passed.
40+
2941 Examples
3042 --------
31- half_lifes_passed("1h", half_life="1min") => 1/60
32-
43+ >>> half_lifes_passed("1h", half_life="1min")
44+ 60.0
3345 """
3446 timespan = normalize_timespan (timespan )
3547 half_life = normalize_timespan (half_life )
@@ -40,10 +52,22 @@ def fraction_remaining(timespan: TimespanSeconds, half_life: TimespanSeconds) ->
4052 Compute the fraction of the original quantity that remains after
4153 a certain timespan and half-life.
4254
55+ Parameters
56+ ----------
57+ timespan : TimespanSeconds
58+ The timespan in seconds or a string like "1h".
59+ half_life : TimespanSeconds
60+ The half-life in seconds or a string like "1min".
61+
62+ Returns
63+ -------
64+ float
65+ Fraction of the original quantity that remains.
66+
4367 Examples
4468 --------
45- fraction_remaining("1h", half_life="1min") => 0.5
46-
69+ >>> fraction_remaining("1h", half_life="1min")
70+ 0.0
4771 """
4872 return 0.5 ** half_lifes_passed (timespan , half_life )
4973
@@ -52,54 +76,98 @@ def fraction_decayed(timespan: TimespanSeconds, half_life: TimespanSeconds) -> f
5276 Compute the fraction of the original quantity that has decayed
5377 after a certain timespan and half-life.
5478
79+ Parameters
80+ ----------
81+ timespan : TimespanSeconds
82+ The timespan in seconds or a string like "1h".
83+ half_life : TimespanSeconds
84+ The half-life in seconds or a string like "1min".
85+
86+ Returns
87+ -------
88+ float
89+ Fraction of the original quantity that has decayed.
90+
5591 Examples
5692 --------
57- fraction_decayed("1h", half_life="1min") => 0.5
58-
93+ >>> fraction_decayed("1h", half_life="1min")
94+ 1.0
5995 """
6096 return 1.0 - fraction_remaining (timespan , half_life )
6197
6298def remaining_quantity (timespan : TimespanSeconds , half_life : TimespanSeconds , initial_quantity ) -> float :
6399 """
64100 Compute the quantity that remains after a certain timespan and half-life.
65101
102+ Parameters
103+ ----------
104+ timespan : TimespanSeconds
105+ The timespan in seconds or a string like "1h".
106+ half_life : TimespanSeconds
107+ The half-life in seconds or a string like "1min".
108+ initial_quantity : float
109+ The initial quantity.
110+
111+ Returns
112+ -------
113+ float
114+ Quantity that remains.
115+
66116 Examples
67117 --------
68- remaining_quantity("1h", half_life="1min", initial_quantity=100) => ...
118+ >>> remaining_quantity("1h", half_life="1min", initial_quantity=100)
119+ 0.0
69120 """
70121 initial_quantity = normalize_numeric (initial_quantity )
71122 return fraction_remaining (timespan , half_life ) * initial_quantity
72123
73124def decayed_quantity (timespan : TimespanSeconds , half_life : TimespanSeconds , initial_quantity ) -> float :
74125 """
75- Compute the quantity that remains after a certain timespan and half-life.
126+ Compute the quantity that has decayed after a certain timespan and half-life.
76127
128+ Parameters
129+ ----------
130+ timespan : TimespanSeconds
131+ The timespan in seconds or a string like "1h".
132+ half_life : TimespanSeconds
133+ The half-life in seconds or a string like "1min".
134+ initial_quantity : float
135+ The initial quantity.
136+
137+ Returns
138+ -------
139+ float
140+ Quantity that has decayed.
141+
142+ Examples
77143 --------
78- Examples:
79- decayed_quantity("1h", half_life="1min", initial_quantity= 100) => 40/60
144+ >>> decayed_quantity("1h", half_life="1min", initial_quantity=100)
145+ 100.0
80146 """
81147 initial_quantity = normalize_numeric (initial_quantity )
82148 return fraction_decayed (timespan , half_life ) * initial_quantity
83149
84150def half_life_from_decay_constant (decay_constant ) -> float :
85151 """
86- Compute the half-life from a decay constant using the formula: T₁/₂ = ln(2) / λ
152+ Compute the half-life from a decay constant using the formula: T₁/₂ = ln(2) / λ.
87153
88154 The half-life is the time required for a quantity to reduce to half of its initial value.
89- This is co
90- ----------monly used in radioactive decay, drug elimination, and chemical kinetics.
155+ This is commonly used in radioactive decay, drug elimination, and chemical kinetics.
91156
92- Parameters:
93- decay_constant (float): The decay constant λ (lambda) in s⁻¹
157+ Parameters
158+ ----------
159+ decay_constant : float
160+ The decay constant λ (lambda) in s⁻¹.
94161
95162 Returns
96163 -------
97- float: The half-life in the same time units as the decay constant (typically seconds)
164+ float
165+ The half-life in the same time units as the decay constant (typically seconds).
98166
99167 Examples
100168 --------
101- >>> half_life_from_decay_constant(0.1) # For λ = 0.1 s⁻¹
102- 6.9314718056
169+ >>> half_life_from_decay_constant(0.1) # For λ = 0.1 s⁻¹
170+ 6.9314718056
103171 """
104172 decay_constant = normalize_numeric (decay_constant )
105173 return _ln2 / decay_constant
@@ -110,18 +178,22 @@ def half_life_from_remaining_quantity(timespan: TimespanSeconds, remaining_quant
110178
111179 Parameters
112180 ----------
113- timespan (str or float): The timespan in seconds or a string like "1h"
114- remaining_quantity (float): The quantity that remains after the timespan
115- initial_quantity (float): The initial quantity
181+ timespan : TimespanSeconds
182+ The timespan in seconds or a string like "1h".
183+ remaining_quantity : float
184+ The quantity that remains after the timespan.
185+ initial_quantity : float
186+ The initial quantity.
116187
117188 Returns
118189 -------
119- float: The half-life in the same time units as the timespan
190+ float
191+ The half-life in the same time units as the timespan.
120192
121193 Examples
122194 --------
123- >>> half_life_from_remaining_quantity("1h", 50, 100)
124- 3600.0
195+ >>> half_life_from_remaining_quantity("1h", 50, 100)
196+ 3600.0
125197 """
126198 timespan = normalize_timespan (timespan )
127199 remaining_quantity = normalize_numeric (remaining_quantity )
@@ -134,18 +206,22 @@ def half_life_from_decayed_quantity(timespan: TimespanSeconds, decayed_quantity,
134206
135207 Parameters
136208 ----------
137- timespan (str or float): The timespan in seconds or a string like "1h"
138- decayed_quantity (float): The quantity that has decayed after the timespan
139- initial_quantity (float): The initial quantity
209+ timespan : TimespanSeconds
210+ The timespan in seconds or a string like "1h".
211+ decayed_quantity : float
212+ The quantity that has decayed after the timespan.
213+ initial_quantity : float
214+ The initial quantity.
140215
141216 Returns
142217 -------
143- float: The half-life in the same time units as the timespan
218+ float
219+ The half-life in the same time units as the timespan.
144220
145221 Examples
146222 --------
147- >>> half_life_from_decayed_quantity("1h", 50, 100)
148- 3600.0
223+ >>> half_life_from_decayed_quantity("1h", 50, 100)
224+ 3600.0
149225 """
150226 timespan = normalize_timespan (timespan )
151227 decayed_quantity = normalize_numeric (decayed_quantity )
@@ -159,35 +235,42 @@ def half_life_from_fraction_remaining(timespan: TimespanSeconds, fraction_remain
159235
160236 Parameters
161237 ----------
162- timespan (str or float): The timespan in seconds or a string like "1h"
163- fraction_remaining (float): The fraction of the initial quantity that remains
238+ timespan : TimespanSeconds
239+ The timespan in seconds or a string like "1h".
240+ fraction_remaining : float
241+ The fraction of the initial quantity that remains.
164242
165243 Returns
166244 -------
167- float: The half-life in the same time units as the timespan
245+ float
246+ The half-life in the same time units as the timespan.
168247
169248 Examples
170249 --------
171- >>> half_life_from_fraction_remaining("1h", 0.5)
172- 3600.0
250+ >>> half_life_from_fraction_remaining("1h", 0.5)
251+ 3600.0
173252 """
174253 return half_life_from_remaining_quantity (timespan , fraction_remaining , 1.0 )
175254
176255def half_life_from_fraction_decayed (timespan : TimespanSeconds , fraction_decayed ) -> float :
177256 """
178257 Compute the half-life from a decayed fraction after a certain timespan.
179258
180- Parameters:
181- timespan (str or float): The timespan in seconds or a string like "1h"
182- fraction_decayed (float): The fraction of the initial quantity that has decayed
259+ Parameters
260+ ----------
261+ timespan : TimespanSeconds
262+ The timespan in seconds or a string like "1h".
263+ fraction_decayed : float
264+ The fraction of the initial quantity that has decayed.
183265
184266 Returns
185267 -------
186- float: The half-life in the same time units as the timespan
268+ float
269+ The half-life in the same time units as the timespan.
187270
188271 Examples
189272 --------
190- >>> half_life_from_fraction_decayed("1h", 0.5)
191- 3600.0
273+ >>> half_life_from_fraction_decayed("1h", 0.5)
274+ 3600.0
192275 """
193276 return half_life_from_decayed_quantity (timespan , fraction_decayed , 1.0 )
0 commit comments