pyunitwizard package
Subpackages
- pyunitwizard.configure package
- pyunitwizard.constants package
- pyunitwizard.forms package
- pyunitwizard.utils package
Submodules
pyunitwizard.kernel module
pyunitwizard.main module
- pyunitwizard.main.are_close(quantity_1: QuantityLike, quantity_2: QuantityLike, rtol: float = 1e-05, atol: float = 1e-08) bool [source]
Compares whether two quantities are similiar within a specified tolerance.
- Parameters:
quantity_or_unit_1 (QuantityOrUnit) – A quantity or a unit
quantity_or_unit_2 (QuantityOrUnit) – A quantity or a unit
relative_tolerance (float) – The relative tolerance to compare the quantities.
- Returns:
Whether the quantities or units are similar.
- Return type:
bool
- pyunitwizard.main.are_compatible(quantity_or_unit_1: QuantityOrUnit, quantity_or_unit_2: QuantityOrUnit) bool [source]
Check whether two quantities or units are compatible. This means that they have the same dimensionalities.
- Parameters:
quantity_or_unit_1 (QuantityOrUnit) – A quantity or a unit
quantity_or_unit_2 (QuantityOrUnit) – A quantity or a unit
- Returns:
Whether the quantities or units are compatible.
- Return type:
bool
- pyunitwizard.main.are_equal(quantity_or_unit_1: QuantityOrUnit, quantity_or_unit_2: QuantityOrUnit, same_form=False) bool [source]
Compares whether two quantities are similiar within a specified tolerance.
- Parameters:
quantity_or_unit_1 (QuantityOrUnit) – A quantity or a unit
quantity_or_unit_2 (QuantityOrUnit) – A quantity or a unit
relative_tolerance (float) – The relative tolerance to compare the quantities.
- Returns:
Whether the quantities or units are similar.
- Return type:
bool
- pyunitwizard.main.change_value(quantity: QuantityLike, value: ndarray | float | int) QuantityLike [source]
- pyunitwizard.main.check(quantity_or_unit: Any, dimensionality: Dict[str, int] | None = None, value_type: Any | None = None, shape: tuple | None = None, unit: str | None = None, dtype_name: str | None = None) bool [source]
Check if a quantity or unit has the specified dimensionality, value_type, shape, unit or data type.
- Parameters:
quantity_or_unit (Any) – A quantity or unit object. If any other object is passed False will be returned.
dimensionality (dict) – A dictionary specifying the dimensionality of the quantity or unit.
value_type (Any) – The type of the quantity. Can be int, float, np.ndarray.
shape (tuple of int) – For non scalar quantities. A tuple with the shape of the array.
unit (str) – Name of the unit.
dtype_name (str) – For non scalar quantities. The dtype of the array (i.e float64).
- Returns:
True if the quantity or unit has the specified parameters.
- Return type:
bool
- pyunitwizard.main.compatibility(quantity_or_unit_1: QuantityOrUnit, quantity_or_unit_2: QuantityOrUnit) bool [source]
- pyunitwizard.main.convert(quantity_or_unit: Any, to_unit: str | None = None, to_form: str | None = None, parser: str | None = None, to_type: str | None = 'quantity') QuantityOrUnit | float | ndarray [source]
Converts a quantity or unit to a different unit and/or to a different form and/or type.
- Parameters:
to_unit (str, optional) – The unit to convert to.
to_form ({"unyt", "pint", "openmm.unit", "string"}, optional) – The form to convert to.
parser ({"pint", "openmm.unit"}, optional) – The parser to use if a string is passed.
to_type ({"quantity", "unit", "value"}, optional) – The type to convert to.
- Returns:
The converted quantity or unit. If to_type is passed the return value can be a float or a numpy array.
- Return type:
QuantityOrUnit or ArrayLike or float
- pyunitwizard.main.get_dimensionality(quantity_or_unit: QuantityOrUnit) Dict[str, int] [source]
Returns the dimensionality of the quantity or unit.
Parmeters
- quantity_or_unitQuantityOrUnit
A quantity or a unit
- returns:
A dictionary with the dimensionality of the unit.
- rtype:
dict
- pyunitwizard.main.get_form(quantity_or_unit: QuantityOrUnit) str [source]
Returns the form of a quantity as a string.
- Parameters:
quantity_or_unit (QuantityOrUnit) – A quanitity or a unit
- Returns:
The form of the quantity
- Return type:
{“string”, “pint”, “openmm.unit”, “unyt”}
- pyunitwizard.main.get_standard_units(quantity_or_unit: QuantityOrUnit | None = None, dimensionality: dict | None = None, form: str | None = None, parser: str | None = None) UnitLike [source]
Returns standard unit of the quantity or unit passed.
- Parameters:
quantity_or_unit (Any) – A quantity or unit
- Returns:
The standard unit.
- Return type:
str
- Raises:
NoStandardsError – If no standard units were defined.
- pyunitwizard.main.get_unit(quantity: QuantityLike, to_form: str | None = None, parser: str | None = None, standardized: bool | None = False) UnitLike [source]
Returns the unit of a quantity.
- Parameters:
to_unit (str, optional) –
Name of the unit to which the quantity will be converted (i.e kcal/mol).
- form{“unyt”, “pint”, “openmm.unit”, “string”}, optional
If passed the unit will be converted to that form. This is the type that will be returned
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser to use.
- Returns:
The unit.
- Return type:
UnitLike
- pyunitwizard.main.get_value(quantity: QuantityLike, to_unit: str | None = None, parser: str | None = None, standardized: bool | None = False) ndarray | float | int [source]
Returns the value of a quantity.
- Parameters:
to_unit (str, optional) – Name of the unit to which the quantity will be converted (i.e kcal/mol).
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser to use.
- Returns:
An array with the quantity value or a a float or an int if it’s a scalar.
- Return type:
np.ndarray or float or int
- pyunitwizard.main.get_value_and_unit(quantity: QuantityLike, to_unit: str | None = None, to_form: str | None = None, parser: str | None = None, standardized: str | None = False) Tuple[ndarray | float | int, UnitLike] [source]
Returns the value and unit of a quantity.
- Parameters:
to_unit (str, optional) – Name of the unit to which the quantity will be converted (i.e kcal/mol).
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser to use.
- Returns:
np.ndarray or float or int
UnitLike – The value and unit of the input quantity.
- pyunitwizard.main.is_dimensionless(quantity_or_unit: QuantityOrUnit) bool [source]
Check wheter a quantity or unit is dimensionless.
- Parameters:
quantity_or_unit (QuantityOrUnit) – A quantity or a unit
- Returns:
Whether the quantity or unit is dimensionless.
- Return type:
bool
- pyunitwizard.main.is_quantity(quantity_or_unit: QuantityOrUnit, parser: str | None = None) bool [source]
Check whether an object is a quantity
- Parameters:
quantity_or_unit (QuantityOrUnit) – A quanitity or a unit
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser for string quantities
- Returns:
False if it’s not a quantity
- Return type:
bool
- pyunitwizard.main.is_unit(quantity_or_unit: QuantityOrUnit, parser: str | None = None) bool [source]
Check whether an object is a unit
- Parameters:
quantity_or_unit (QuantityOrUnit) – A quantity or a unit
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser for string quantities
- Returns:
False if it’s not a unit
- Return type:
bool
- pyunitwizard.main.quantity(value: int | float | ArrayLike, unit: UnitLike | None = None, form: str | None = None, parser: str | None = None, standardized: bool | None = False) QuantityLike [source]
Returns a quantity.
- Parameters:
value (int, float or arraylike) – The value of the quantity. Can be a scalar or an array like type.
unit (UnitLike) – Unit in of the quantity in any of the accepted form.
form ({"unyt", "pint", "openmm.unit", "string"}, optional) – Output form of the quantity.
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser to use.
standardized (bool, optional) – Return a standardized quantity, default=False.
- Returns:
The quantity.
- Return type:
QuantityLike
- pyunitwizard.main.similarity(quantity_or_unit_1: QuantityOrUnit, quantity_or_unit_2: QuantityOrUnit, relative_tolerance: float = 1e-08) bool [source]
- pyunitwizard.main.standardize(quantity_or_unit: QuantityOrUnit, to_form: str | None = None) QuantityOrUnit [source]
Concert a quantity or unit to standard units.
- Parameters:
quantity_or_unit (QuantityOrUnit) – The quantity or a unit that will be converted.
to_form (str, optional.) – The form to transform to
- Returns:
The quantity ot unit converted to standard units.
- Return type:
QuantityOrUnit
- Raises:
NoStandardsError – If no standard units were defined.
- pyunitwizard.main.unit(unit: str, form: str | None = None, parser: str | None = None) UnitLike [source]
Returns a unit.
- Parameters:
unit (str) – Name of the unit (i.e kcal/mol).
form ({"unyt", "pint", "openmm.unit", "string"}, optional) – The form of the unit. This is the type that will be returned
parser ({"unyt", "pint", "openmm.unit"}, optional) – The parser to use.
- Returns:
The unit.
- Return type:
Unitlike
pyunitwizard.parse module
- pyunitwizard.parse.parse(string: str, parser: str | None = None, to_form: str | None = None)[source]
Parses a string and returns a quantity.
- Parameters:
string (str) – A string quantity.
parser (str) – The parser that will be used.
str (to_form;) – The form of the quantity. Can be pint, openmm.unit or string.
optional – The form of the quantity. Can be pint, openmm.unit or string.
- Returns:
A quantity.
- Return type:
QuantityLike
Module contents
PyUnitWizard Quantities and units assistant