pyprobe.units#
A module for unit conversion of PyProBE data.
Module Attributes
A dictionary of valid units and their corresponding quantities. |
|
A dictionary of SI prefixes and their corresponding factors. |
|
A dictionary of valid time units and their corresponding factors. |
|
A set of all valid units, including prefixed combinations. |
Functions
|
Return the default unit and prefix of a given unit. |
|
Split a column name into quantity and unit. |
Classes
|
A polars namespace for unit conversion of columns. |
- unit_dict: dict[str, str] = {'%': 'Percentage', 'A': 'Current', 'A.h': 'Capacity', 'Ah': 'Capacity', 'C': 'Temperature', 'K': 'Temperature', 'Ohms': 'Resistance', 'Seconds': 'Time', 'V': 'Voltage', 's': 'Time', '°C': 'Temperature'}#
A dictionary of valid units and their corresponding quantities.
- prefix_dict: dict[str, float] = {'M': 1000000.0, 'k': 1000.0, 'm': 0.001, 'n': 1e-09, 'p': 1e-12, 'µ': 1e-06}#
A dictionary of SI prefixes and their corresponding factors.
- time_unit_dict: dict[str, float] = {'Seconds': 1, 'h': 3600, 'hr': 3600, 'min': 60, 's': 1}#
A dictionary of valid time units and their corresponding factors.
- valid_units = {'%', 'A', 'A.h', 'Ah', 'C', 'K', 'M%', 'MA', 'MA.h', 'MAh', 'MC', 'MK', 'MOhms', 'MSeconds', 'MV', 'Ms', 'M°C', 'Ohms', 'Seconds', 'V', 'h', 'hr', 'k%', 'kA', 'kA.h', 'kAh', 'kC', 'kK', 'kOhms', 'kSeconds', 'kV', 'ks', 'k°C', 'm%', 'mA', 'mA.h', 'mAh', 'mC', 'mK', 'mOhms', 'mSeconds', 'mV', 'min', 'ms', 'm°C', 'n%', 'nA', 'nA.h', 'nAh', 'nC', 'nK', 'nOhms', 'nSeconds', 'nV', 'ns', 'n°C', 'p%', 'pA', 'pA.h', 'pAh', 'pC', 'pK', 'pOhms', 'pSeconds', 'pV', 'ps', 'p°C', 's', '°C', 'µ%', 'µA', 'µA.h', 'µAh', 'µC', 'µK', 'µOhms', 'µSeconds', 'µV', 'µs', 'µ°C'}#
A set of all valid units, including prefixed combinations.
- split_quantity_unit(name, regular_expression='^(.*?)(?:\\s*\\[([^\\]]+)\\])?$')#
Split a column name into quantity and unit.
- Parameters:
name (str) – The column name (e.g. “Current [A]” or “Temperature”)
regular_expression (str) – The pattern to match the column name.
- Returns:
The quantity and unit.
- Return type:
tuple[str, str]
- get_unit_scaling(unit)#
Return the default unit and prefix of a given unit.
- Parameters:
unit (str) – The unit to convert.
- Returns:
The prefix and default unit.
- Return type:
Tuple[Optional[str], str]
- class UnitsExpr(expr)#
Bases:
objectA polars namespace for unit conversion of columns.
- Parameters:
expr (Expr)
- to_base_unit(unit)#
Convert a from a given unit to its base unit.
- Parameters:
unit (str) – The unit to convert.
- Return type:
Expr
- from_base_unit(unit)#
Convert a column from its base unit to a given unit.
- Parameters:
unit (str) – The unit to convert.
- Return type:
Expr
- to_unit(unit)#
Convert a column to a given unit.
- Parameters:
unit (str) – The unit to convert to.
- Return type:
Expr