pip install git+https://github.com/sabarish-vm/unitconvert.gitAfter cloning or downloading the desired verion x.y.z do the following,
pip install numpy astropygit checkout old_versions
cd v0.x.y
pip install -e .The package contains modules which will convert the desired units given as astropy.units. Quantity object to physical units like natural units, geometrized units, and cgs gaussian units. Here, natural units refer to the unit system where ℏ = c = kB = ϵ0 = 1, geometrized units refer to c = G = 1, cgs gaussian refers to 4πϵ0 = 1
There are three key modules toNaturalunits(q) , fromNaturalunits(q,required_units), and factorNatural(q).
from unitconvert.natural import *
from astropy import units as au
height = 1*au.m # In S.I. units
height_natural = toNatural(height) # In natural units
We can revert back to S.I. units as follows,
height_si = fromNatural(height_natural,au.m) # We convert it back to SI
height_cgs = fromNatural(height_natural,au.cm) # We convert it to CGS
We can also find the factor that will the restore the constants which were set to 1 in a given analytic expression. This is illustrated with the example below,
Consider the equation E = m c-2, in natural units it becomes E = m, now to restore the units using the package follow the given recipe, find the factor of each variable in the equation using the function factorNatural(quantity), and divide the same variable with output. i.e. in our example we have for the rhs the quantity mass which has the units kg,
In : factorNatural(u.kg)
Out : {'hbar': 0.0, 'c': -2.0, 'k_B': 0, 'eps0': 0.0}
Thus you will divide m by c -2, to get m c 2. Similarly for LHS we get,
In : factorNatural(u.eV)
Out : {'hbar': 0.0, 'c': 0.0, 'k_B': 0, 'eps0': 0.0}
Here there factor is just 1, thus we get the equation with restored constants as E = m c2
These unit systems are defined inside unitconvert.geometrized, unitconvert.gaussian, unitconvert.planck and they have similar named modules to that of unitconvert.natural, that is they contain toGeometrized, toGaussian, toPlanck, factorGeometrized, factorGaussian,factorPlanck, fromGeometrized, fromGaussian, fromPlanck. They can be imported as follows,
from unitconvert.geometrized import *
from unitconvert.gaussian import *
from unitconvert.planck import *