.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/atmosphere/plot_05_dalton_partial_pressures.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_atmosphere_plot_05_dalton_partial_pressures.py: Dalton's partial pressures (1802) ================================= John Dalton found that each gas in a mixture exerts the pressure it would exert alone, and that the total is the sum. Water vapour in air is then an ideal gas with its own partial pressure ``e``. The mixing ratio is the ratio of the two partial densities, ``epsilon e / (p - e)``, and the specific humidity is the vapour fraction of the total mass. .. GENERATED FROM PYTHON SOURCE LINES 11-34 .. image-sg:: /api/gallery/atmosphere/images/sphx_glr_plot_05_dalton_partial_pressures_001.png :alt: Moisture at 1013 hPa total pressure :srcset: /api/gallery/atmosphere/images/sphx_glr_plot_05_dalton_partial_pressures_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from earthsciencekit.atmosphere import mixing_ratio, specific_humidity from earthsciencekit.constants import R_DRY_AIR, R_VAPOR pressure, temperature = 101325.0, 293.15 vapor = np.linspace(0, 4000, 201) w = mixing_ratio(vapor, pressure) q = specific_humidity(w) vapor_density = vapor / (R_VAPOR * temperature) dry_density = (pressure - vapor) / (R_DRY_AIR * temperature) np.testing.assert_allclose(w, vapor_density / dry_density) np.testing.assert_allclose(q, vapor_density / (vapor_density + dry_density)) fig, ax = plt.subplots() ax.plot(vapor / 100, w * 1000, label="mixing ratio (per kg dry air)") ax.plot(vapor / 100, q * 1000, ls="--", label="specific humidity (per kg moist air)") ax.set(xlabel="vapour partial pressure [hPa]", ylabel="water vapour [g/kg]", title=f"Moisture at {pressure / 100:.0f} hPa total pressure") ax.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.087 seconds) .. _sphx_glr_download_api_gallery_atmosphere_plot_05_dalton_partial_pressures.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../lite/lab/index.html?path=api/gallery/atmosphere/plot_05_dalton_partial_pressures.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_dalton_partial_pressures.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_dalton_partial_pressures.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_dalton_partial_pressures.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_