convert.py
Unit conversions and physical constants used throughout the package.
Powers flow through a budget as linear quantities (watts, or whatever
consistent unit you choose); these helpers move between that linear domain
and decibels, and scale a frequency for display.
BOLTZMANN_CONSTANT
module-attribute
BOLTZMANN_CONSTANT: float = 1.380649e-23
SPEED_OF_LIGHT
module-attribute
SPEED_OF_LIGHT: float = 299792458.0
REFERENCE_NOISE_TEMP_K
module-attribute
REFERENCE_NOISE_TEMP_K: float = 290.0
linear_to_db
linear_to_db(val: float) -> float
Convert a linear power ratio to decibels (10*log10(val)).
A val of exactly zero returns -inf rather than raising.
Source code in linkbudget/convert.py
| def linear_to_db(val: float) -> float:
"""Convert a linear power ratio to decibels (``10*log10(val)``).
A ``val`` of exactly zero returns ``-inf`` rather than raising.
"""
if val == 0.0:
return -np.inf
return 10.0 * np.log10(val)
|
db_to_linear
db_to_linear(val: float) -> float
Convert a decibel value to a linear power ratio (10**(val/10)).
Source code in linkbudget/convert.py
| def db_to_linear(val: float) -> float:
"""Convert a decibel value to a linear power ratio (``10**(val/10)``)."""
return 10.0**(val / 10.0)
|
scale_hertz
scale_hertz(freq: float) -> tuple[float, str]
Scale a frequency in Hz to the most readable unit for display.
Returns (value, unit) where unit is one of "Hz", "kHz",
"MHz" or "GHz".
Source code in linkbudget/convert.py
| def scale_hertz(freq: float) -> tuple[float, str]:
"""Scale a frequency in Hz to the most readable unit for display.
Returns ``(value, unit)`` where ``unit`` is one of ``"Hz"``, ``"kHz"``,
``"MHz"`` or ``"GHz"``.
"""
if freq > 1e3 and freq < 1e6:
return freq / 1e3, 'kHz'
if freq > 1e6 and freq < 1e9:
return freq / 1e6, 'MHz'
if freq > 1e9:
return freq / 1e9, 'GHz'
return freq, 'Hz'
|