.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Dewpoint_and_Mixing_Ratio.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_calculations_Dewpoint_and_Mixing_Ratio.py: ========================= 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. .. GENERATED FROM PYTHON SOURCE LINES 16-19 .. code-block:: Python import metpy.calc as mpcalc from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 20-21 Create a test value of mixing ratio in grams per kilogram .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python mixing = 10 * units('g/kg') print(mixing) .. rst-class:: sphx-glr-script-out .. code-block:: none 10.0 gram / kilogram .. GENERATED FROM PYTHON SOURCE LINES 25-27 Now throw that value with units into the function to calculate the corresponding vapor pressure, given a surface pressure of 1000 mb .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python e = mpcalc.vapor_pressure(1000. * units.mbar, mixing) print(e) .. rst-class:: sphx-glr-script-out .. code-block:: none 15.823863685716976 millibar .. GENERATED FROM PYTHON SOURCE LINES 31-32 Take the odd units and force them to millibars .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python print(e.to(units.mbar)) .. rst-class:: sphx-glr-script-out .. code-block:: none 15.823863685716976 millibar .. GENERATED FROM PYTHON SOURCE LINES 35-36 Take the raw vapor pressure and throw into the dewpoint function .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python td = mpcalc.dewpoint(e) print(td) .. rst-class:: sphx-glr-script-out .. code-block:: none 13.854699858753747 degree_Celsius .. GENERATED FROM PYTHON SOURCE LINES 40-41 Which can of course be converted to Fahrenheit .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python print(td.to('degF')) .. rst-class:: sphx-glr-script-out .. code-block:: none 56.93845974575668 degree_Fahrenheit .. GENERATED FROM PYTHON SOURCE LINES 44-45 Now do the same thing for 850 mb, approximately the pressure of Denver .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python e = mpcalc.vapor_pressure(850. * units.mbar, mixing) print(e.to(units.mbar)) .. rst-class:: sphx-glr-script-out .. code-block:: none 13.450284132859428 millibar .. GENERATED FROM PYTHON SOURCE LINES 49-50 And print the corresponding dewpoint .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python td = mpcalc.dewpoint(e) print(td, td.to('degF')) .. rst-class:: sphx-glr-script-out .. code-block:: none 11.3770989195134 degree_Celsius 52.47877805512405 degree_Fahrenheit .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.005 seconds) .. _sphx_glr_download_examples_calculations_Dewpoint_and_Mixing_Ratio.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Dewpoint_and_Mixing_Ratio.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Dewpoint_and_Mixing_Ratio.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_