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

.. only:: html

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

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

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

.. _sphx_glr_examples_retrieve_plot_column_subset.py:


====================================
Extract a radar column above a point
====================================

Given a radar and a point, extract the column of radar data values above
a point

.. GENERATED FROM PYTHON SOURCE LINES 9-24

.. code-block:: Python


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

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

    import pyart
    from pyart.testing import get_test_data

    # Read in some test data
    filename = get_test_data("swx_20120520_0641.nc")
    radar = pyart.io.read(filename)








.. GENERATED FROM PYTHON SOURCE LINES 25-31

**Plot the first sweep and our desired point**

Let's visualize our radar data from a single sweep, and plot
the location of our desired point on a map.
This will provide some context as to where we are extracting our
column of values.

.. GENERATED FROM PYTHON SOURCE LINES 31-54

.. code-block:: Python


    site_lon = -97.73  # longitude in degrees
    site_lat = 36.41  # latitdue in degrees

    # Setup the RadarMapDisplay and add our projection
    display = pyart.graph.RadarMapDisplay(radar)
    ax = plt.subplot(111, projection=ccrs.PlateCarree())

    # Visualize the reflectivity field, using the lowest sweep with
    # latitude and longitude lines
    display.plot_ppi_map(
        "reflectivity_horizontal",
        0,
        ax=ax,
        vmin=-32,
        vmax=64.0,
        lon_lines=np.arange(-98, -97, 0.2),
        lat_lines=np.arange(36, 37, 0.2),
    )

    # Plot our site location on top of the radar image
    ax.scatter(site_lon, site_lat, color="black")




.. image-sg:: /examples/retrieve/images/sphx_glr_plot_column_subset_001.png
   :alt: xsapr-sg 0.5 Deg. 2011-05-20T06:42:11Z  Equivalent reflectivity factor
   :srcset: /examples/retrieve/images/sphx_glr_plot_column_subset_001.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.PathCollection object at 0x2b624b4ec5f0>



.. GENERATED FROM PYTHON SOURCE LINES 55-57

Now that we have our point defined, and our radar object, we can use the following
utility function in Py-ART to subset a column

.. GENERATED FROM PYTHON SOURCE LINES 57-59

.. code-block:: Python

    ds = pyart.util.columnsect.get_field_location(radar, site_lat, site_lon)








.. GENERATED FROM PYTHON SOURCE LINES 60-61

This function returns an xarray dataset, with all of our data fields!

.. GENERATED FROM PYTHON SOURCE LINES 61-63

.. code-block:: Python

    print(ds)





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

 .. code-block:: none

    <xarray.Dataset> Size: 2kB
    Dimensions:                            (height: 22)
    Coordinates:
      * height                             (height) float64 176B 351.4 ... 1.818e+04
    Data variables: (12/15)
        corrected_reflectivity_horizontal  (height) float64 176B 39.2 37.52 ... nan
        reflectivity_horizontal            (height) float64 176B 32.88 31.46 ... nan
        recalculated_diff_phase            (height) float64 176B 1.555 1.32 ... -0.0
        specific_attenuation               (height) float64 176B 0.2778 ... 0.0
        unf_dp_phase_shift                 (height) float32 88B 58.05 ... 36.27
        mean_doppler_velocity              (height) float32 88B -9.133 ... 5.688
        ...                                 ...
        dp_phase_shift                     (height) float64 176B 145.5 144.0 ... nan
        diff_reflectivity                  (height) float32 88B 0.0 0.0 ... 0.0 0.0
        proc_dp_phase_shift                (height) float32 88B 51.8 50.25 ... 36.27
        copol_coeff                        (height) float64 176B 0.95 0.92 ... nan
        base_time                          datetime64[ns] 8B 2011-05-20T06:42:11
        time_offset                        (height) datetime64[ns] 176B 2011-05-2...
    Attributes:
        distance_from_radar:    15.113 km
        azimuth:                233.545 degrees
        latitude_of_location:   36.41 degrees
        longitude_of_location:  -97.73 degrees




.. GENERATED FROM PYTHON SOURCE LINES 64-68

**Visualize the Reflectivity Values in the Column**

Let's visualize the reflectivity values in the column
above our point, which is stored in our new dataset

.. GENERATED FROM PYTHON SOURCE LINES 68-69

.. code-block:: Python

    ds.corrected_reflectivity_horizontal.plot(y="height")



.. image-sg:: /examples/retrieve/images/sphx_glr_plot_column_subset_002.png
   :alt: plot column subset
   :srcset: /examples/retrieve/images/sphx_glr_plot_column_subset_002.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    [<matplotlib.lines.Line2D object at 0x2b624b47f920>]




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

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


.. _sphx_glr_download_examples_retrieve_plot_column_subset.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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