.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/atmosphere/plot_03_halley_barometric_altitude.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_03_halley_barometric_altitude.py: Halley's barometric altitude (1686) =================================== Edmond Halley combined Boyle's law with the weight of the air and found that height grows with the logarithm of pressure: equal ratios of pressure mark equal steps of height. The step for a factor e is the scale height ``R T / g``, about 8 km. Inverting the barometric law turns a barometer into an altimeter. .. GENERATED FROM PYTHON SOURCE LINES 11-30 .. image-sg:: /api/gallery/atmosphere/images/sphx_glr_plot_03_halley_barometric_altitude_001.png :alt: Height is linear in log pressure :srcset: /api/gallery/atmosphere/images/sphx_glr_plot_03_halley_barometric_altitude_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from earthsciencekit.atmosphere import barometric_pressure, scale_height from earthsciencekit.constants import GRAVITY height = np.linspace(0, 30e3, 301) fig, ax = plt.subplots() for temperature in [230, 260, 290]: H = float(scale_height(temperature, GRAVITY)) pressure = barometric_pressure(101325, height, temperature, GRAVITY) np.testing.assert_allclose(H * np.log(101325 / pressure), height, atol=1e-9) assert np.isclose(barometric_pressure(101325, H, temperature, GRAVITY), 101325 / np.e) ax.semilogx(pressure / 100, height / 1000, label=f"{temperature} K, H = {H / 1000:.2f} km") ax.set(xlabel="pressure [hPa, log scale]", ylabel="height [km]", title="Height is linear in log pressure") ax.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.120 seconds) .. _sphx_glr_download_api_gallery_atmosphere_plot_03_halley_barometric_altitude.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_03_halley_barometric_altitude.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_halley_barometric_altitude.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_halley_barometric_altitude.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_halley_barometric_altitude.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_