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: UnitRegistry = <pint.registry.UnitRegistry object>#

pint unit registry

fibomat.units.Q_#

Quantity constructor.

fibomat.units.U_#

Unit constructor

fibomat.units.UnitType#

Generic pint unit type used for typing annotation. Objects constructed with U_ hae this type.

fibomat.units.QuantityType#

pint quantity type used for typing annotation

fibomat.units.has_length_dim(quant_or_unit: Unit | 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: Unit | 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: Unit | Quantity, other_unit: Unit | 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: Unit | Quantity, 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