pytac.units
#
Classes for use in unit conversion.
Members
Returns input value without performing any conversions. |
|
Piecewise Cubic Hermite Interpolating Polynomial unit conversion. |
|
Linear interpolation for converting between physics and engineering units. |
|
Class to convert between physics and engineering units. |
|
Default value for the pre and post functions used in unit conversion. |
- pytac.units.unit_function(value)[source]#
Default value for the pre and post functions used in unit conversion.
- class pytac.units.UnitConv(post_eng_to_phys=<function unit_function>, pre_phys_to_eng=<function unit_function>, engineering_units='', physics_units='', name=None)[source]#
Class to convert between physics and engineering units.
This class does not do conversion but does return values if the target units are the same as the provided units. Subclasses should implement _raw_eng_to_phys() and _raw_phys_to_eng() in order to provide complete unit conversion.
The two arguments to this function represent functions that are applied to the result of the initial conversion. One happens after the conversion, the other happens before the conversion back.
Attributes:
- Parameters:
post_eng_to_phys (function) – Function to be applied after the initial conversion.
pre_phys_to_eng (function) – Function to be applied before the initial conversion.
engineering_units (str) – The unit type of the post conversion engineering value.
physics_units (str) – The unit type of the post conversion physics value.
name (str) – An identifier for the unit conversion object.
Methods:
- set_post_eng_to_phys(post_eng_to_phys)[source]#
Set the function to be applied after the initial conversion.
- Parameters:
post_eng_to_phys (function) – Function to be applied after the initial conversion.
- set_pre_phys_to_eng(pre_phys_to_eng)[source]#
Set the function to be applied before the initial conversion.
- Parameters:
pre_phys_to_eng (function) – Function to be applied before the initial conversion.
- eng_to_phys(value)[source]#
Function that does the unit conversion.
Conversion from engineering to physics units. An additional function may be cast on the initial conversion.
- Parameters:
value (float) – Value to be converted from engineering to physics units.
- Returns:
The result value.
- Return type:
- Raises:
UnitsException – If the conversion is invalid; i.e. if there are no solutions, or multiple, within conversion limits.
- phys_to_eng(value)[source]#
Function that does the unit conversion.
Conversion from physics to engineering units. An additional function may be cast on the initial conversion.
- Parameters:
value (float) – Value to be converted from physics to engineering units.
- Returns:
The result value.
- Return type:
- Raises:
UnitsException – If the conversion is invalid; i.e. if there are no solutions, or multiple, within conversion limits.
- convert(value, origin, target)[source]#
Convert between two different unit types and check the validity of the result.
- Parameters:
- Returns:
The resulting value.
- Return type:
- Raises:
UnitsException – If the conversion is invalid; i.e. if there are no solutions, or multiple, within conversion limits.
- class pytac.units.PolyUnitConv(coef, post_eng_to_phys=<function unit_function>, pre_phys_to_eng=<function unit_function>, engineering_units='', physics_units='', name=None)[source]#
Linear interpolation for converting between physics and engineering units.
Attributes:
- p#
A one-dimensional polynomial of coefficients.
- Type:
poly1d
- Parameters:
coef (array-like) – The polynomial’s coefficients, in decreasing powers.
post_eng_to_phys (float) – The value after conversion between ENG and PHYS.
pre_eng_to_phys (float) – The value before conversion.
engineering_units (str) – The unit type of the post conversion engineering value.
physics_units (str) – The unit type of the post conversion physics value.
name (str) – An identifier for the unit conversion object.
- class pytac.units.PchipUnitConv(x, y, post_eng_to_phys=<function unit_function>, pre_phys_to_eng=<function unit_function>, engineering_units='', physics_units='', name=None)[source]#
Piecewise Cubic Hermite Interpolating Polynomial unit conversion.
Attributes:
- x#
A list of points on the x axis. These must be in increasing order for the interpolation to work. Otherwise, a ValueError is raised.
- Type:
- y#
A list of points on the y axis. These must be in increasing or decreasing order. Otherwise, a ValueError is raised.
- Type:
- pp#
A pchip one-dimensional monotonic cubic interpolation of points on both x and y axes.
- Type:
PchipInterpolator
- Parameters:
x (list) – A list of points on the x axis. These must be in increasing order for the interpolation to work. Otherwise, a ValueError is raised.
y (list) – A list of points on the y axis. These must be in increasing or decreasing order. Otherwise, a ValueError is raised.
engineering_units (str) – The unit type of the post conversion engineering value.
physics_units (str) – The unit type of the post conversion physics value.
name (str) – An identifier for the unit conversion object.
- Raises:
ValueError – if coefficients are not appropriately monotonic.