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

.. only:: html

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

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

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

.. _sphx_glr_examples_plotting_plot_cross_section.py:


=================================
Plot a Cross Section from a Grid
=================================

This is an example of how to plot a cross section
of your radar grid using the GridMapDisplay

.. GENERATED FROM PYTHON SOURCE LINES 10-78



.. image-sg:: /examples/plotting/images/sphx_glr_plot_cross_section_001.png
   :alt: xsapr-sg 0.5 km 2011-05-20T06:41:22Z  Equivalent reflectivity factor, xsapr-sg cross-section slice 2011-05-20T06:41:22Z Equivalent reflectivity factor
   :srcset: /examples/plotting/images/sphx_glr_plot_cross_section_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    print(__doc__)

    # Author: Max Grover (mgrover@anl.gov)
    # License: BSD 3 clause

    import cartopy.crs as ccrs
    import matplotlib.pyplot as plt

    import pyart
    from pyart.testing import get_test_data

    # Read in the data from two XSAPR radars
    xsapr_sw_file = get_test_data("swx_20120520_0641.nc")
    xsapr_se_file = get_test_data("sex_20120520_0641.nc")
    radar_sw = pyart.io.read_cfradial(xsapr_sw_file)
    radar_se = pyart.io.read_cfradial(xsapr_se_file)

    # Filter out gates with reflectivity > 100 from both radars
    gatefilter_se = pyart.filters.GateFilter(radar_se)
    gatefilter_se.exclude_transition()
    gatefilter_se.exclude_above("corrected_reflectivity_horizontal", 100)
    gatefilter_sw = pyart.filters.GateFilter(radar_sw)
    gatefilter_sw.exclude_transition()
    gatefilter_sw.exclude_above("corrected_reflectivity_horizontal", 100)

    # perform Cartesian mapping, limit to the reflectivity field.
    grid = pyart.map.grid_from_radars(
        (radar_se, radar_sw),
        gatefilters=(gatefilter_se, gatefilter_sw),
        grid_shape=(20, 181, 181),
        grid_limits=((500, 10000), (-50000, 40000), (-60000, 40000)),
        grid_origin=(36.57861, -97.363611),
        fields=["corrected_reflectivity_horizontal"],
    )

    # Define some start and end points, using (longitude, latitude)
    start = (36.7, -97.7)
    end = (36.2, -97.8)

    # Setup the figure, and plot our x/y view of the radar
    fig = plt.figure(figsize=(18, 6))
    ax1 = plt.subplot(121, projection=ccrs.PlateCarree())
    display = pyart.graph.GridMapDisplay(grid)
    display.plot_grid(
        "corrected_reflectivity_horizontal",
        ax=ax1,
        cmap="pyart_HomeyerRainbow",
        vmin=-20,
        vmax=70,
    )

    # Plot our start and end points, as well as a line in between the two
    ax1.scatter(start[1], start[0], color="tab:blue", label="Start")
    ax1.scatter(end[1], end[0], color="black", label="End")
    ax1.plot([start[1], end[1]], [start[0], end[0]], color="k", linestyle=":")
    plt.legend(loc="upper right")

    # Add a cross section, using our start and end points, and set our x-axis as latitude (lat)
    ax2 = plt.subplot(122)
    display.plot_cross_section(
        "corrected_reflectivity_horizontal",
        start,
        end,
        cmap="pyart_HomeyerRainbow",
        vmin=-20,
        vmax=70,
    )


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

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


.. _sphx_glr_download_examples_plotting_plot_cross_section.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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