
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/interp/plot_profile_altitudes.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_interp_plot_profile_altitudes.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_interp_plot_profile_altitudes.py:


Profile interpolation
=====================

Demonstrate interpolating two-dimensional model output onto a one-dimensional
profile defined by x and y coordinates inside a shapefile.

.. GENERATED FROM PYTHON SOURCE LINES 12-50



.. image-sg:: /examples/interp/images/sphx_glr_plot_profile_altitudes_001.png
   :alt: map view, profile view
   :srcset: /examples/interp/images/sphx_glr_plot_profile_altitudes_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /home/docs/checkouts/readthedocs.org/user_builds/hyoga/envs/stable/lib/python3.12/site-packages/hyoga/open/example.py:29: FutureWarning: In a future version, xarray will not decode timedelta values based on the presence of a timedelta-like units attribute by default. Instead it will rely on the presence of a timedelta64 dtype attribute, which is now xarray's default way of encoding timedelta64 values. To continue decoding timedeltas based on the presence of a timedelta-like units attribute, users will need to explicitly opt-in by passing True or CFTimedeltaCoder(decode_via_units=True) to decode_timedelta. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
      return xr.open_dataset(path)
    downloading https://raw.githubusercontent.com/juseg/hyoga-data/main/shp/profile.rhine.zip...






|

.. code-block:: Python


    import matplotlib.pyplot as plt
    import hyoga

    # initialize figure
    fig, (ax, pfax) = plt.subplots(ncols=2, gridspec_kw=dict(width_ratios=(1, 2)))

    # open demo data
    with hyoga.open.example('pism.alps.out.2d.nc') as ds:

        # plot 2D model output
        ds.hyoga.plot.bedrock_altitude(ax=ax, center=False)
        ds.hyoga.plot.ice_margin(ax=ax, edgecolor='tab:blue', linewidths=1)
        ds.hyoga.plot.ice_margin(ax=ax, facecolor='tab:blue')

        # interpolate along profile
        ds = ds.hyoga.profile(hyoga.open.example('profile.rhine.shp'))

        # plot profile line in map view
        ax.plot(ds.x, ds.y, color='w', dashes=(2, 1))
        ax.plot(ds.x[0], ds.y[0], 'wo')

        # plot bedrock and surface profiles
        ds.hyoga.getvar('bedrock_altitude').plot(ax=pfax, color='0.25')
        ds.hyoga.getvar('surface_altitude').plot(ax=pfax, color='tab:blue')

    # set map axes properties
    ax.set_xlim(425e3, 575e3)
    ax.set_ylim(5000e3, 5400e3)
    ax.set_title('map view')

    # set profile axes properties
    pfax.set_title('profile view')
    pfax.yaxis.set_label_position("right")
    pfax.yaxis.tick_right()

    # show
    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.373 seconds)


.. _sphx_glr_download_examples_interp_plot_profile_altitudes.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_profile_altitudes.ipynb <plot_profile_altitudes.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_profile_altitudes.py <plot_profile_altitudes.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_profile_altitudes.zip <plot_profile_altitudes.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
