.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/hydrology/plot_12_mccarthy_muskingum_routing.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_hydrology_plot_12_mccarthy_muskingum_routing.py: McCarthy's Muskingum routing (1938) =================================== Gerald McCarthy, working on flood control in the Muskingum basin of Ohio, wrote the storage of a river reach as a weighted mix of its inflow and outflow, ``S = K (X I + (1 - X) O)``. Combined with continuity, the outflow becomes a fixed linear combination of the latest inflows and the previous outflow. Routing a flood through a reach delays it by about ``K`` and lowers its peak, more so when ``X`` is small, while conserving its volume. .. GENERATED FROM PYTHON SOURCE LINES 12-32 .. image-sg:: /api/gallery/hydrology/images/sphx_glr_plot_12_mccarthy_muskingum_routing_001.png :alt: Muskingum: the flood is delayed and flattened :srcset: /api/gallery/hydrology/images/sphx_glr_plot_12_mccarthy_muskingum_routing_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from earthsciencekit.hydrology import muskingum_coefficients, muskingum_routing step = 3600.0 hours = np.arange(96) inflow = 20 + 380 * (hours / 12) ** 2 * np.exp(2 * (1 - hours / 12)) # m^3/s fig, ax = plt.subplots() ax.plot(hours, inflow, "k", lw=2, label="inflow") for weighting in (0.0, 0.2, 0.4): assert np.isclose(muskingum_coefficients(6 * step, weighting, step).sum(), 1) outflow = muskingum_routing(inflow, 6 * step, weighting, step) assert np.isclose(outflow.sum(), inflow.sum(), rtol=1e-3) and outflow.max() < inflow.max() ax.plot(hours, outflow, label=f"outflow, K = 6 h, X = {weighting}") ax.set(xlabel="time [h]", ylabel="discharge [m^3/s]", title="Muskingum: the flood is delayed and flattened") ax.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.101 seconds) .. _sphx_glr_download_api_gallery_hydrology_plot_12_mccarthy_muskingum_routing.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/hydrology/plot_12_mccarthy_muskingum_routing.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_12_mccarthy_muskingum_routing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_12_mccarthy_muskingum_routing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_12_mccarthy_muskingum_routing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_