Skip to content

Commit 1b89ec0

Browse files
author
Uli Köhler
committed
Fix docstring linting errors in UliEngineering/Physics/ files
1 parent c73c667 commit 1b89ec0

7 files changed

Lines changed: 328 additions & 84 deletions

File tree

UliEngineering/Physics/Density.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
__all__ = ["Densities", "density_by_volume_and_weight", "normalize_density_kg_per_m3", "DensityKgPerM3"]
1212

1313
"""
14-
Pre-defined densities for various materials in kg/m³
14+
Pre-defined densities for various materials in kg/m³.
1515
"""
1616
Densities: dict[str, float] = {
1717
# Various (pure) metals

UliEngineering/Physics/HalfLife.py

Lines changed: 124 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6298
def 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

73124
def 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

84150
def 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

176255
def 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)

UliEngineering/Physics/Light.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ def lumen_to_candela_by_apex_angle(flux: LuminousFluxLumen, angle: AngleDegrees)
2828
assuming that the flux of <flux> is distributed equally around
2929
a cone with apex angle <angle>.
3030
31-
Keyword parameters
32-
------------------
33-
flux : value, engineer string or NumPy array
34-
The luminous flux in Lux.
35-
angle : value, engineer string or NumPy array
36-
The apex angle of the emission cone, in degrees
37-
For many LEDs, this is
38-
31+
Parameters
32+
----------
33+
flux : LuminousFluxLumen
34+
The luminous flux in lumens.
35+
angle : AngleDegrees
36+
The apex angle of the emission cone, in degrees.
37+
38+
Returns
39+
-------
40+
float
41+
Luminous intensity in candela.
42+
43+
Examples
44+
--------
3945
>>> autoFormat(lumen_to_candela_by_apex_angle, "25 lm", "120°")
4046
'7.96 cd'
4147
"""

UliEngineering/Physics/MagneticResonance.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ def larmor_frequency(b0: MagneticFieldTesla, nucleus_larmor_frequency=NucleusLar
3636
3737
Parameters
3838
----------
39-
b0 : float or str
40-
Magnetic field strength in Tesla
39+
b0 : MagneticFieldTesla
40+
Magnetic field strength in Tesla.
4141
nucleus_larmor_frequency : float, optional
42-
Larmor frequency of the nucleus in MHz/T
42+
Larmor frequency of the nucleus in MHz/T.
43+
44+
Returns
45+
-------
46+
float
47+
Larmor frequency in Hz.
4348
"""
4449
b0 = normalize_magnetic_field(b0)
4550
return b0 * (nucleus_larmor_frequency * 1e6) # MHz/T -> Hz/T

UliEngineering/Physics/NTC.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ def normalize_resistance(resistance: NormalizableArgument) -> NormalizedComputab
2727
@returns_unit("Ω")
2828
def ntc_resistance(r25: ResistanceOhm, b25, t: TemperatureKelvin):
2929
"""
30-
Compute the NTC resistance by temperature and NTC parameters
30+
Compute the NTC resistance by temperature and NTC parameters.
3131
3232
Parameters
3333
----------
34-
r25 : float or EngineerIO string
35-
The NTC resistance at 25°C, sometimes also called "nominal resistance"
36-
b25: float or EngineerIO string
37-
The NTC b-constant (e.g. b25/50, b25/85 or b25/100)
38-
t : temperature
39-
The temperature. Will be interpreted using normalize_temperature()
34+
r25 : ResistanceOhm
35+
The NTC resistance at 25°C, sometimes also called "nominal resistance".
36+
b25 : float or EngineerIO string
37+
The NTC b-constant (e.g. b25/50, b25/85 or b25/100).
38+
t : TemperatureKelvin
39+
The temperature. Will be interpreted using normalize_temperature().
40+
41+
Returns
42+
-------
43+
float
44+
NTC resistance in Ohms.
4045
"""
4146
r25 = normalize_resistance(r25)
4247
b25 = normalize_numeric(b25)
@@ -51,20 +56,21 @@ def ntc_resistances(r25: ResistanceOhm, b25, t0=-40, t1=85, resolution=0.1):
5156
5257
Parameters
5358
----------
54-
r25 : float or EngineerIO string
55-
The NTC resistance at 25°C, sometimes also called "nominal resistance"
56-
b25: float or EngineerIO string
57-
The NTC b-constant (e.g. b25/50, b25/85 or b25/100)
59+
r25 : ResistanceOhm
60+
The NTC resistance at 25°C, sometimes also called "nominal resistance".
61+
b25 : float or EngineerIO string
62+
The NTC b-constant (e.g. b25/50, b25/85 or b25/100).
5863
t0 : temperature
59-
The start temperature
64+
The start temperature.
6065
t1 : temperature
61-
The end temperature
66+
The end temperature.
6267
resolution : temperature
63-
The resolution of the temperature range
68+
The resolution of the temperature range.
6469
6570
Returns
66-
=======
67-
A (temperatures, values) tuple
71+
-------
72+
tuple
73+
A (temperatures, values) tuple.
6874
"""
6975
r25 = normalize_resistance(r25)
7076
b25 = normalize_numeric(b25)

0 commit comments

Comments
 (0)