Dewpoint and Mixing Ratio#

Use functions from metpy.calc as well as pint’s unit support to perform calculations.

The code below converts the mixing ratio value into a value for vapor pressure assuming both 1000mb and 850mb ambient air pressure values. It also demonstrates converting the resulting dewpoint temperature to degrees Fahrenheit.

import metpy.calc as mpcalc
from metpy.units import units

Create a test value of mixing ratio in grams per kilogram

mixing = 10 * units('g/kg')
10.0 gram / kilogram

Now throw that value with units into the function to calculate the corresponding vapor pressure, given a surface pressure of 1000 mb

15.823863685716976 millibar

Take the odd units and force them to millibars

15.823863685716976 millibar

Take the raw vapor pressure and throw into the dewpoint function

td = mpcalc.dewpoint(e)
13.854699858753747 degree_Celsius

Which can of course be converted to Fahrenheit

56.93845974575668 degree_Fahrenheit

Now do the same thing for 850 mb, approximately the pressure of Denver

13.450284132859428 millibar

And print the corresponding dewpoint

td = mpcalc.dewpoint(e)
11.3770989195134 degree_Celsius 52.47877805512405 degree_Fahrenheit

Total running time of the script: ( 0 minutes 0.008 seconds)

Gallery generated by Sphinx-Gallery