Using the pint in code below I somehow end up with both units: meter and kilometer:
107661.59454231549 meter ** 1.5 / kilometer ** 0.5 / second
import math
import pint
u = pint.UnitRegistry()
Q_ = u.Quantity
R_mars = 3396 * u.km
m_mars = 6.419 * 10 ** 23 * u.kg
G = 6.674 * 10 ** (-11) * u.m ** 3 / u.kg / u.s ** 2
R = 300 * u.km + R_mars
def calc_orbital_v(M, R):
return (G * M / R) ** (1/2)
print(calc_orbital_v(m_mars, R))
Why does pint not automatically convert to a unified unit, either meter or kilometer?
I didn't find an automatic (implicit), but programmatic (explicit) conversion.
Base Units & Explicit Conversion
You could force conversion to base-units of the configured default system by optionally setting
ureg.default_systemand using.to_base_units():Note:
ureg(instead your givenu)mks(which will usemeters andseconds)Then resulting output is:
The concept of default systems and base units seem to exist since version 0.7.