fibomat.units module

This submodule implements (physical) unit support for the package (units = physical units).

It uses the python module pint. For usage, see the example below or the documentation at https://pint.readthedocs.io/en/0.10.1/

from fibomat.units import Q_, U_

# factor of 1. exists implicitly
a = 1. * Q_('µm') = Q_('1. µm') = 1. * U_('µm')

a_in_m = a.to('m')

a_raw = a.magnitude
a_unit = a.units

dose = 12 * Q('ions / nm**2')
dose_in_c_per_um2 = dose.to('coulomb / µm**2')
fibomat.units.ureg: pint.registry.UnitRegistry = <pint.registry.UnitRegistry object>

pint unit registry

fibomat.units.Q_

alias of pint.quantity.build_quantity_class.<locals>.Quantity

fibomat.units.U_

alias of pint.unit.build_unit_class.<locals>.Unit

fibomat.units.UnitType

alias of pint.unit.Unit

fibomat.units.QuantityType

alias of pint.quantity.Quantity

fibomat.units.has_length_dim(quant_or_unit: Union[pint.unit.Unit, pint.quantity.Quantity]) bool[source]

Check if quant_or_unit has dimension [length].

Args:

quant_or_unit (UnitType, QuantityType): unit or quantity to be checked.

Returns:

bool

fibomat.units.has_time_dim(quant_or_unit: Union[pint.unit.Unit, pint.quantity.Quantity]) bool[source]

Check if quant_or_unit has dimension [time].

Args:

quant_or_unit (UnitType, QuantityType): unit or quantity to be checked.

Returns:

bool

fibomat.units.scale_factor(base_unit: Union[pint.unit.Unit, pint.quantity.Quantity], other_unit: Union[pint.unit.Unit, pint.quantity.Quantity]) float[source]

Calculates the scaling factor needed to convert other_unit to base_untit.

Warning

If base_unit or other_unit are quantities, the magnitude is ignored.

Args:

base_unit (Union[UnitType, QuantityType]): base unit other_unit (Union[UnitType, QuantityType]): other unit

Returns:

float: scaling factor

fibomat.units.scale_to(base_unit: Union[pint.unit.Unit, pint.quantity.Quantity], quantity: pint.quantity.Quantity) float[source]

Scales quantity quantity to base_unit and returns the result as float.

Args:

base_unit (Union[UnitType, QuantityType]): base unit quantity (QuantityType): quantity to be scaled

Returns:

float: scaled quantity