striqt.waveform.units¶
Unit strings for power, amplitude, and dB quantities, and their SI prefixes.
SIPrefix
dataclass
¶
Units
dataclass
¶
format_quantity
¶
format_quantity(
value: float,
units: Union[str, None],
*,
prefix: Union[SIPrefix, str, Literal['auto']] = 'auto',
places: Union[int, None] = None,
sep: str = ' ',
) -> str
return value in engineering notation with a prefixed units suffix.
Parameters:
-
value(float) –the value in
units; a numpy or cupy scalar is converted withfloat -
units(Union[str, None]) –the units string of
value,''for a bare prefix, or None to return the scaled mantissa alone -
prefix(Union[SIPrefix, str, Literal['auto']], default:'auto') –'auto'selectssi_prefixofvalue, a prefix symbol such as'M'or'u'forces that prefix, and anSIPrefixis applied as given -
places(Union[int, None], default:None) –the decimal places of the mantissa, or None for the shortest representation (
'g') -
sep(str, default:' ') –the text between the mantissa and the suffix
Returns:
-
str–the mantissa, then
sepand the prefix symbol andunitswhenunitsis not -
str–None;
'nan','∞', or'-∞'for a value that is not finite, with the -
str–unprefixed
unitssuffix
Raises:
-
ValueError–if
prefixis a symbol thatPREFIXESdoes not define
has_power_form
¶
return whether units carries a DB_POWER, POWER, or AMPLITUDE field.
is_prefixable
¶
return whether an SI prefix may scale the base unit of units.
A base that begins dB, the bases 'mW', 'FS', 'a.u.', and
'unitless' (with or without a leading √), and None are not prefixable.
The empty string is a bare number that takes a prefix.
power_family
¶
return the power unit that the dB, linear, or amplitude units string refers to.
'dBm', 'mW', and '√mW/Hz' give 'mW'; 'dBFS' gives 'FS';
'dB(a.u.)' gives 'a.u.'. A ratio ('dB') or a unit of another kind
gives None.
resolve_power_units
¶
return units with its power form fields filled by power_units.
DB_POWER becomes the dB unit of power_units ('dBm' for 'mW'), POWER
becomes power_units, and AMPLITUDE the square root form. A denominator such
as '{dB}/Hz' is kept. A string without a form field is returned unchanged.
si_prefix
¶
si_prefix(
values: Union[float, Iterable[float]],
units: Union[str, None] = None,
*,
places: Union[int, None] = None,
) -> SIPrefix
return one SI prefix for every value of values in units.
The prefix is that of the largest finite nonzero magnitude, with a mantissa that
rounds to 1000 under places carried to the next prefix. With two or more
distinct magnitudes, the prefix is lowered to that of the step between the
closest pair, by at most one prefix. Thus 3.7 and 3.75 GHz read as 3700 and
3750 MHz, and every mantissa stays below 10⁶. Units that are not is_prefixable,
and values with no finite nonzero magnitude, give the exponent 0.
Parameters:
-
values(Union[float, Iterable[float]]) –one value, or the values to share the prefix; zero, NaN, and infinite values are ignored
-
units(Union[str, None], default:None) –the units string of the values, or None for a bare number
-
places(Union[int, None], default:None) –the decimal places the mantissas are shown with, or None for the shortest representation
Returns:
-
SIPrefix–the
SIPrefixwith an exponent in the range ofPREFIXES
to_dB
¶
return the dB form of a linear power or amplitude units string.
'mW' and '√mW' give 'dBm', 'W/Hz' gives 'dBW/Hz', and
'unitless' gives 'dB'. A string without a known linear base is returned
unchanged.
to_linear
¶
return the linear power form of a dB or amplitude units string.
'dBm' and '√mW' give 'mW', 'dBW/Hz' gives 'W/Hz', and
'dB' gives 'unitless'. A string without a known base is returned
unchanged.
to_wave
¶
return the amplitude (square root of power) form of a units string.
'dBm' and 'mW' give '√mW', and 'dB' gives '√unitless'. A
string without a known base is returned unchanged.
with_power_units
¶
return units with its power unit replaced by power_units in the same form.
The dB, linear, or amplitude form and the denominator are kept: 'dBm/Hz' with
'FS' gives 'dBFS/Hz', and '√mW' with 'a.u.' gives '√a.u.'. A
string that power_family does not recognize is returned unchanged.