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, quantity_2, rtol=1e-05, atol=1e-08)[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.
quantity_1 (QuantityLike)
quantity_2 (QuantityLike)
rtol (float)
atol (float)
- Returns:
Whether the quantities or units are similar.
- Return type:
bool
- pyunitwizard.main.are_compatible(quantity_or_unit_1, quantity_or_unit_2)[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, quantity_or_unit_2, same_form=False)[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, value)[source]#
- Parameters:
quantity (QuantityLike)
value (ndarray | float | int)
- Return type:
QuantityLike
- pyunitwizard.main.check(quantity_or_unit, dimensionality=None, value_type=None, shape=None, unit=None, dtype_name=None)[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, quantity_or_unit_2)[source]#
- Parameters:
quantity_or_unit_1 (QuantityOrUnit)
quantity_or_unit_2 (QuantityOrUnit)
- Return type:
bool
- pyunitwizard.main.convert(quantity_or_unit, to_unit=None, to_form=None, parser=None, to_type='quantity')[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.
quantity_or_unit (Any)
- 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)[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
- Parameters:
quantity_or_unit (QuantityOrUnit)
- Return type:
Dict[str, int]
- pyunitwizard.main.get_form(quantity_or_unit)[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=None, dimensionality=None, form=None, parser=None)[source]#
Returns standard unit of the quantity or unit passed.
- Parameters:
quantity_or_unit (Any) – A quantity or unit
dimensionality (dict | None)
form (str | None)
parser (str | None)
- Returns:
The standard unit.
- Return type:
str
- Raises:
NoStandardsError – If no standard units were defined.
- pyunitwizard.main.get_unit(quantity, to_form=None, parser=None, standardized=False)[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.
quantity (QuantityLike)
to_form (str | None)
standardized (bool | None)
- Returns:
The unit.
- Return type:
UnitLike
- pyunitwizard.main.get_value(quantity, to_unit=None, parser=None, standardized=False)[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.
quantity (QuantityLike)
standardized (bool | None)
- 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, to_unit=None, to_form=None, parser=None, standardized=False)[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.
quantity (QuantityLike)
to_form (str | None)
standardized (str | None)
- Returns:
np.ndarray or float or int
UnitLike – The value and unit of the input quantity.
- Return type:
Tuple[ndarray | float | int, UnitLike]
- pyunitwizard.main.is_dimensionless(quantity_or_unit)[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, parser=None)[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, parser=None)[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, unit=None, form=None, parser=None, standardized=False)[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, quantity_or_unit_2, relative_tolerance=1e-08)[source]#
- Parameters:
quantity_or_unit_1 (QuantityOrUnit)
quantity_or_unit_2 (QuantityOrUnit)
relative_tolerance (float)
- Return type:
bool
- pyunitwizard.main.standardize(quantity_or_unit, to_form=None)[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.to_string(quantity_or_unit, to_unit=None, parser=None)[source]#
- Parameters:
quantity_or_unit (Any)
to_unit (str | None)
parser (str | None)
- Return type:
str
- pyunitwizard.main.unit(unit, form=None, parser=None)[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, parser=None, to_form=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.
to_form (str | None)
- Returns:
A quantity.
- Return type:
QuantityLike
Module contents#
PyUnitWizard Quantities and units assistant