-
Notifications
You must be signed in to change notification settings - Fork 9
Quantities (pint)
One aim of weldx is to be as specific about describing the physics of welding data as possible.
An important aspect of this task is the use of (physical) quantities, i.e. the combination of numeric values with a unit.
The weldx packages relies heavily on pint to work with quantities.
One advantage of pint besides it's ease of use is the ongoing effort to further integrate it with other popular packages like numpy, sympy, pandas and xarray that are also used in weldx.
Read more about pint here.
If you only want to start working with units inside weldx, here is what you need to know:
First, import the weldx base quantity constructor Q_
from weldx import Q_Now use Q_ to create quantities or add a unit to existing numpy-like arrays.
Here are some examples:
import numpy as np
a = Q_(5, "meter")
print(a)
t = Q_(2, "minute")
print(t)
I = Q_(np.arange(20),"A")
print(I)5 meter
2 minute
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19] ampere
That's it, simply use the quantity objects like you would with other numpy-like numerical objects.
If you are worried about unit syntax, don't be: pint has very powerful string parsing for units (including prefixes), so in most cases it should be sufficient to provide units in a "natural" engineering notation even for complex cases:
Q_(200,"kVA / (nsecond * dl)")200kilovolt_ampere/(deciliter nanosecond)
When importing the weldx package two things happen:
- A default
pint.UnitRegistryis created and imported asweldx.constants.WELDX_UNIT_REGISTRY. Since allpintquantities must have the same baseUnitRegistryit is important to work with theUnitRegistryeverywhere inweldx. All changes and modifications to the unit system are based and stored in this Registry (example: enabling use of"%"for units). - Based on the above
UnitRegistrytheQ_object gets created. This should be the default method when creating new quantities throughoutweldx.
Check equal dimensionality
from weldx.constants import WELDX_UNIT_REGISTRY as ureg
ureg.is_compatible_with("m*s","inch*min")