The goal of this notebook is to show an example using the units support in MetPy. In this example, we calculate the dewpoint, corresponding to a fixed value of mixing ratio, at two different surface pressure values.


In [1]:
# First import our calculation functions, as well as unit support
import metpy.calc as mcalc
from metpy.units import units

In [2]:
# Create a test value of mixing ratio in grams per kilogram
mixing = 10 * units('g/kg')
print(mixing)


10.0 gram / kilogram

In [3]:
# Now throw that value with units into the function to calculate
# the corresponding vapor pressure, given a surface pressure of 1000 mb
e = mcalc.vapor_pressure(1000. * units.mbar, mixing)
print(e)


15825.67178529092 gram * millibar / kilogram

In [4]:
# Take the odd units and force them to millibars
print(e.to(units.mbar))


15.82567178529092 millibar

In [5]:
# Take the raw vapor pressure and throw into the dewpoint function
td = mcalc.dewpoint(e)
print(td)


13.856458659577921 degC

In [6]:
# Which can of course be converted to Farenheit
print(td.to('degF'))


56.94162598724023 degF

In [7]:
# Now do the same thing for 850 mb, approximately the pressure of Denver
e = mcalc.vapor_pressure(850. * units.mbar, mixing)
print(e.to(units.mbar))


13.451821017497283 millibar

In [8]:
# And print the corresponding dewpoint
td = mcalc.dewpoint(e)
print(td, td.to('degF'))


11.378824018637602 degC 52.48188363354765 degF