piel.units#
These functions contain relevant functionality for unit conversion and related.
Submodules#
Functions#
|
Converts power from dBm to Vpp (peak-to-peak voltage) in a specified impedance network. |
|
Converts power from dBm (decibel-milliwatts) to Watts. |
|
Converts power from dBm to Vrms (root mean square voltage) in a specified impedance network. |
|
Converts Vpp (peak-to-peak voltage) to dBm in a specified impedance network. |
|
Converts Vrms (root mean square voltage) to Vpp (peak-to-peak voltage). |
|
Converts Vpp (peak-to-peak voltage) to Vrms (root mean square voltage). |
|
Converts Vrms (root mean square voltage) to dBm in a specified impedance network. |
|
Converts Vrms (root mean square voltage) to power in Watts for a given impedance. |
|
Converts power in Watts to Vrms (root mean square voltage) for a given impedance. |
|
Converts power from Watts to dBm (decibel-milliwatts). |
|
Convert frequency in Hertz (Hz) to time period in seconds (s). |
|
Convert time period in seconds (s) to frequency in Hertz (Hz). |
|
Converts an AWG value to meters squared. |
|
Converts a string with a number and optional suffix into an integer. |
|
Matches a unit string to a predefined Unit instance. |
|
Retrieves a Unit instance based on the datum type. |
Package Contents#
- dBm2vpp(dBm: piel.types.NumericalTypes, impedance: piel.types.NumericalTypes = 50.0) piel.types.NumericalTypes[source]#
Converts power from dBm to Vpp (peak-to-peak voltage) in a specified impedance network.
The conversion is performed using the following steps:
Convert dBm to Watts: .. math:
P_{ ext{Watt}} = 10^{\left(
rac{P_{ ext{dBm}}}{10} ight)} imes 10^{-3}
Convert Watts to Vrms: .. math:
V_{ ext{rms}} = \sqrt{P_{ ext{Watt}} imes Z}
Convert Vrms to Vpp: .. math:
V_{ ext{pp}} = V_{ ext{rms}} imes \sqrt{2} imes 2
Args: - dBm (NumericalTypes): Power level in dBm (can be int, float, or numpy array). - impedance (float): The network impedance in ohms. Default is 50 ohms.
Returns: - NumericalTypes: Vpp value, in the same type as the input.
- dBm2watt(dBm: piel.types.NumericalTypes) piel.types.NumericalTypes[source]#
Converts power from dBm (decibel-milliwatts) to Watts.
The conversion is performed using the following equation:
\[P_{ ext{Watt}} = 10^{\left(\]rac{P_{ ext{dBm}}}{10} ight)} imes 10^{-3}
Args: - dBm (NumericalTypes): Power level in dBm (can be int, float, or numpy array).
Returns: - NumericalTypes: Power level in Watts, in the same type as the input.
- dBm2vrms(dBm: piel.types.NumericalTypes, impedance: piel.types.NumericalTypes = 50.0) piel.types.NumericalTypes[source]#
Converts power from dBm to Vrms (root mean square voltage) in a specified impedance network.
The conversion is performed using the following steps:
Convert dBm to Watts: .. math:
P_{ ext{Watt}} = 10^{\left(
rac{P_{ ext{dBm}}}{10} ight)} imes 10^{-3}
Convert Watts to Vrms: .. math:
V_{ ext{rms}} = \sqrt{P_{ ext{Watt}} imes Z}
Args: - dBm (NumericalTypes): Power level in dBm (can be int, float, or numpy array). - impedance (float): The network impedance in ohms. Default is 50 ohms.
Returns: - NumericalTypes: Vrms value, in the same type as the input.
- vpp2dBm(vpp: piel.types.NumericalTypes, impedance: piel.types.NumericalTypes = 50.0) piel.types.NumericalTypes[source]#
Converts Vpp (peak-to-peak voltage) to dBm in a specified impedance network.
The conversion is performed using the following steps:
Convert Vpp to Vrms: .. math:
V_{ ext{rms}} =
rac{V_{ ext{pp}}}{sqrt{2} imes 2}
Convert Vrms to Watts: .. math:
P_{ ext{Watt}} =
rac{V_{ ext{rms}}^2}{Z}
Convert Watts to dBm: .. math:
P_{ ext{dBm}} = 10 imes \log_{10}\left(
rac{P_{ ext{Watt}}}{10^{-3}} ight)
Args: - vpp (NumericalTypes): Vpp value. - impedance (float): The network impedance in ohms. Default is 50 ohms.
Returns: - NumericalTypes: Power level in dBm, in the same type as the input.
- vrms2vpp(vrms: piel.types.NumericalTypes) piel.types.NumericalTypes[source]#
Converts Vrms (root mean square voltage) to Vpp (peak-to-peak voltage).
The conversion is performed using the following equation:
\[V_{ ext{pp}} = V_{ ext{rms}} imes \sqrt{2} imes 2\]Args: - vrms (NumericalTypes): Vrms value.
Returns: - NumericalTypes: Vpp in the same type as the input.
- vpp2vrms(vpp: piel.types.NumericalTypes) piel.types.NumericalTypes[source]#
Converts Vpp (peak-to-peak voltage) to Vrms (root mean square voltage).
The conversion is performed using the following equation:
\[V_{ ext{rms}} =\]rac{V_{ ext{pp}}}{sqrt{2} imes 2}
Args: - vpp (NumericalTypes): Vpp value.
Returns: - NumericalTypes: Vrms value, in the same type as the input.
- vrms2dBm(vrms: piel.types.NumericalTypes, impedance: piel.types.NumericalTypes = 50.0) piel.types.NumericalTypes[source]#
Converts Vrms (root mean square voltage) to dBm in a specified impedance network.
The conversion is performed using the following steps:
Convert Vrms to Watts: .. math:
P_{ ext{Watt}} =
rac{V_{ ext{rms}}^2}{Z}
Convert Watts to dBm: .. math:
P_{ ext{dBm}} = 10 imes \log_{10}\left(
rac{P_{ ext{Watt}}}{10^{-3}} ight)
Args: - vrms (NumericalTypes): Vrms value. - impedance (float): The network impedance in ohms. Default is 50 ohms.
Returns: - NumericalTypes: Power level in dBm, in the same type as the input.
- vrms2watt(vrms: piel.types.NumericalTypes, impedance: piel.types.NumericalTypes = 50.0) piel.types.NumericalTypes[source]#
Converts Vrms (root mean square voltage) to power in Watts for a given impedance.
The conversion is performed using the following equation:
\[P_{ ext{Watt}} =\]rac{V_{ ext{rms}}^2}{Z}
Args: - vrms (NumericalTypes): Vrms value. - impedance (float): The network impedance in ohms.
Returns: - NumericalTypes: Power level in Watts, in the same type as the input.
- watt2vrms(watt: piel.types.NumericalTypes, impedance: piel.types.NumericalTypes = 50.0) piel.types.NumericalTypes[source]#
Converts power in Watts to Vrms (root mean square voltage) for a given impedance.
The conversion is performed using the following equation:
\[V_{ ext{rms}} = \sqrt{P_{ ext{Watt}} imes Z}\]Args: - watt (NumericalTypes): Power level in Watts. - impedance (float): The network impedance in ohms. Defaults to 50.0 Ohms.
Returns: - NumericalTypes: Vrms in the same type as the input.
- watt2dBm(watt: piel.types.NumericalTypes) piel.types.NumericalTypes[source]#
Converts power from Watts to dBm (decibel-milliwatts).
The conversion is performed using the following equation:
\[P_{ ext{dBm}} = 10 imes \log_{10}\left(\]rac{P_{ ext{Watt}}}{10^{-3}} ight)
Args: - watt (NumericalTypes): Power level in Watts (can be int, float, or numpy array).
Returns: - NumericalTypes: Power level in dBm, in the same type as the input.
- Hz2s(hz: piel.types.NumericalTypes) piel.types.NumericalTypes[source]#
Convert frequency in Hertz (Hz) to time period in seconds (s). :param hz: Frequency in Hz :return: Time period in seconds (s)
- s2Hz(s: piel.types.NumericalTypes) piel.types.NumericalTypes[source]#
Convert time period in seconds (s) to frequency in Hertz (Hz). :param s: Time period in seconds (s) :return: Frequency in Hertz (Hz)
- awg2m2(awg: int) float[source]#
Converts an AWG value to meters squared.
Reference: https://en.wikipedia.org/wiki/American_wire_gauge
- Parameters:
awg (ing) – AWG value.
- Returns:
Cross sectional area in meters squared.
- Return type:
float
- prefix2int(s: str) int[source]#
Converts a string with a number and optional suffix into an integer.
- Supported suffixes:
‘k’ or ‘K’ - Thousand ‘m’ or ‘M’ - Million ‘b’ or ‘B’ - Billion ‘t’ or ‘T’ - Trillion
Examples
‘17.03k’ -> 17030 ‘17K’ -> 17000 ‘2.5M’ -> 2500000 ‘500’ -> 500 ‘-3.2B’ -> -3200000000
- Parameters:
s (str) – The string to convert.
- Returns:
The integer representation of the input string.
- Return type:
int
- Raises:
ValueError – If the string format is invalid or contains unsupported suffixes.
- match_unit_abbreviation(unit_str: str) piel.types.units.Unit[source]#
Matches a unit string to a predefined Unit instance.
- Parameters:
unit_str (str) – The unit abbreviation extracted from a column name (e.g., “s”, “v”, “dB”).
- Returns:
The corresponding Unit instance.
- Return type:
- Raises:
ValueError – If the unit string does not match any predefined units.
- get_unit_by_datum(datum: str) piel.types.Unit | None[source]#
Retrieves a Unit instance based on the datum type.
- Parameters:
datum (str) – The datum type (e.g., ‘voltage’, ‘current’).
- Returns:
The corresponding Unit instance if found, else None.
- Return type:
Optional[Unit]