.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/oceanography/plot_04_stokes_deep_water_waves.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_oceanography_plot_04_stokes_deep_water_waves.py: Stokes's deep-water waves (1847) ================================ George Gabriel Stokes worked out oscillatory waves of small and finite height. The dispersion relation ``omega**2 = g k tanh(k h)`` makes long waves travel faster than short ones. In deep water the energy travels at the group speed, half the speed of the crests, which is why the swell from a distant storm arrives longest waves first. .. GENERATED FROM PYTHON SOURCE LINES 11-37 .. image-sg:: /api/gallery/oceanography/images/sphx_glr_plot_04_stokes_deep_water_waves_001.png :alt: Dispersion in water 50 m deep :srcset: /api/gallery/oceanography/images/sphx_glr_plot_04_stokes_deep_water_waves_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from earthsciencekit.constants import GRAVITY from earthsciencekit.oceanography import deep_group_speed, deep_wave_speed, shallow_wave_speed, wave_angular_frequency depth = 50.0 wavelength = np.logspace(0, 4, 2001) k = 2 * np.pi / wavelength omega = wave_angular_frequency(k, depth, GRAVITY) group = np.gradient(omega, k) deep = wavelength < depth np.testing.assert_allclose(group[deep][5:-5], deep_group_speed(wavelength[deep][5:-5], GRAVITY), rtol=1e-3) np.testing.assert_allclose(deep_group_speed(wavelength, GRAVITY), 0.5 * deep_wave_speed(wavelength, GRAVITY)) fig, ax = plt.subplots() ax.loglog(wavelength, omega / k, label="phase speed") ax.loglog(wavelength, group, label="group speed") ax.loglog(wavelength, deep_wave_speed(wavelength, GRAVITY), "k--", lw=0.8, label="deep-water limits") ax.loglog(wavelength, deep_group_speed(wavelength, GRAVITY), "k--", lw=0.8) ax.axhline(shallow_wave_speed(depth, GRAVITY), color="0.5", ls=":", label="shallow-water limit") ax.set(xlabel="wavelength [m]", ylabel="speed [m/s]", title=f"Dispersion in water {depth:.0f} m deep") ax.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.175 seconds) .. _sphx_glr_download_api_gallery_oceanography_plot_04_stokes_deep_water_waves.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/oceanography/plot_04_stokes_deep_water_waves.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_stokes_deep_water_waves.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_stokes_deep_water_waves.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_stokes_deep_water_waves.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_