%load_ext autoreload
%autoreload 2

Convert quantities

Quantities can be converted into other form and units with PyUnitWizard.

To facilitate the conversion of units between different forms, PyUnitWizard includes the method pyunitwizard.convert(). This way quantities and units can be converted between different forms and units:

import pyunitwizard as puw
q = puw.quantity(value=3.0, unit='joules', form='openmm.unit')
q2 = puw.convert(q, to_unit='kilocalories', to_form='pint')
q2
0.0007170172084130018 kilocalorie

If the output form is not specified with the argument to_form, a quantity with the same form is obtained:

q = puw.quantity(value=1000.0, unit='kN/m**2', form='pint')
q2 = puw.convert(q, to_unit='atmospheres')
q2
9.869232667160128 standard_atmosphere
puw.get_form(q2)
'pint'