PUQ Python API

Unit-aware quantities, measurements, and unit systems.

class scinumtools3.puq.Quantity

A numerical value with physical units and optional measurement uncertainty.

convert(*args, **kwargs)

Overloaded function.

  1. convert(self: scinumtools3._snt.puq.Quantity, expression: str, system: scinumtools3._snt.puq.systems.SystemType = <SystemType.NONE: 12>, quantity: str = ‘’) -> scinumtools3._snt.puq.Quantity

Convert to target units or a target unit-system expression.

  1. convert(self: scinumtools3._snt.puq.Quantity, dformat: scinumtools3._snt.puq.formats.Dformat, system: scinumtools3._snt.puq.systems.SystemType = <SystemType.NONE: 12>) -> scinumtools3._snt.puq.Quantity

Convert using a base-dimension format and optional unit system.

info(self: scinumtools3._snt.puq.Quantity) → None

Print detailed information about the quantity.

rebase_dimensions(self: scinumtools3._snt.puq.Quantity) → scinumtools3._snt.puq.Quantity

Rebase the quantity dimensions.

rebase_prefixes(self: scinumtools3._snt.puq.Quantity) → scinumtools3._snt.puq.Quantity

Rebase units using the selected prefixes.

shape(self: scinumtools3._snt.puq.Quantity) → list[int]

Return the shape of the stored value.

size(self: scinumtools3._snt.puq.Quantity) → int

Return the number of stored values.

to_numpy(self: scinumtools3._snt.puq.Quantity) → numpy.typing.NDArray[numpy.float64]

Return the quantity value as a NumPy array.

to_string(self: scinumtools3._snt.puq.Quantity, format: scinumtools3._snt.puq.UnitFormat = <scinumtools3._snt.puq.UnitFormat object at 0x7fc462cde4f0>) → str

Format the quantity as text.

uncertainty(self: scinumtools3._snt.puq.Quantity, numpy: bool = False) → float | list[float] | numpy.typing.NDArray[numpy.float64]

Return uncertainty as a scalar, list, or NumPy array.

unit_system(self: scinumtools3._snt.puq.Quantity) → str

Return the quantity’s unit system.

property units

Return the quantity’s units as text.

value(self: scinumtools3._snt.puq.Quantity, numpy: bool = False) → float | list[float] | numpy.typing.NDArray[numpy.float64]

Return the value as a scalar, list, or NumPy array.

class scinumtools3.puq.UnitSystem

Context manager for changing the active unit system.

enter(self: scinumtools3._snt.puq.UnitSystem) → scinumtools3._snt.puq.UnitSystem

Enter the unit-system context.

exit(self: scinumtools3._snt.puq.UnitSystem, arg0: object, arg1: object, arg2: object) → None

Leave the unit-system context and restore the previous system.

to_string(self: scinumtools3._snt.puq.UnitSystem) → str

Return a textual description of the active unit system.