Beam Block

Creating beamblock functions that use wradlib to retrieve PBB and CBB. beamblock flags are then created and the PBB, CBB and flags are converted into fields in an empty radar object.


In [1]:
import matplotlib.pyplot as plt
from IPython.display import Image, display
get_ipython().magic(
    'install_ext https://raw.github.com/cpcloud/ipython-\
autotime/master/autotime.py')
get_ipython().magic('load_ext autotime')


ERROR:root:Line magic function `%install_ext` not found.

In [2]:
"""
pyart.retrieve.beam_block_calc
=======================================

Calculates partial beam block(PBB) and cumulative beam block(CBB)
by using wradlib's beamblock and geotiff functions. PBB and CBB
are then used to created flags when a certain beam block fraction
is passed. Empty radar object is created using Py-ART and then
is filled with beam block data.

.. autosummary::
    :toctreeL generated/
    :template: dev_template.rst

    beam_block
    empty_radar_beam_block
    beam_block_flag
    _arrays_to_dict
    _flags_to_dict

"""

import pyart
import numpy as np
import wradlib as wrl


def beam_block(radar, tif_name,
               beam_width=1.0):
    """
    Beam Block Calculation

    Parameters
    ----------
    radar : Radar
        Radar object used.
    tif_name : string
        Name of geotiff file to use for the
        calculation

    Other Parameters
    ----------------
    beam_width : float
        Radar's beam width for calculation.
        Default value is 1.0.

    Returns
    -------
    pbb : array
        Array of partial beam block fractions for each
        gate in each ray.
    cbb: array
        Array of cumulative beam block fractions for
        each gate in each ray.

    References
    ----------
    Bech, J., B. Codina, J. Lorente, and D. Bebbington,
    2003: The sensitivity of single polarization weather
    radar beam blockage correction to variability in the
    vertical refractivity gradient. J. Atmos. Oceanic
    Technol., 20, 845–855

    Heistermann, M., Jacobi, S., and Pfaff, T., 2013:
    Technical Note: An open source library for processing
    weather radar data (wradlib), Hydrol. Earth Syst.
    Sci., 17, 863-871, doi:10.5194/hess-17-863-2013

    """

    _range = radar.range['data']
    beamradius = wrl.util.half_power_radius(_range, beam_width)

    rasterfile = tif_name
    data_raster = wrl.io.open_raster(rasterfile)
    proj_raster = wrl.georef.wkt_to_osr(data_raster.GetProjection())
    rastercoords, rastervalues = wrl.io.read_raster_data(rasterfile)
    sitecoords = (np.float(radar.longitude['data']),
                  np.float(radar.latitude['data']),
                  np.float(radar.altitude['data']))

    pbb_arrays = []
    cbb_arrays = []

    for i in range(len(radar.sweep_start_ray_index['data'])):
        index_start = radar.sweep_start_ray_index['data'][i]
        index_end = radar.sweep_end_ray_index['data'][i]

        nrays = index_end - index_start + 1
        nbins = radar.ngates
        range_res = (np.max(_range) - np.min(_range)) / (nbins - 1)
        elev = radar.fixed_angle['data'][i]

        coord = wrl.georef.sweep_centroids(nrays, range_res,
                                           nbins, elev)
        lon, lat, alt = wrl.georef.polar2lonlatalt_n(
            coord[..., 0], np.degrees(coord[..., 1]),
            coord[..., 2], sitecoords)

        x_pol, y_pol = wrl.georef.reproject(
            lon, lat, projection_target=proj_raster)
        polcoords = np.dstack((x_pol, y_pol))

        rlimits = (x_pol.min(), y_pol.min(), x_pol.max(), y_pol.max())
        # Clip the region inside our bounding box
        ind = wrl.util.find_bbox_indices(rastercoords, rlimits)
        rastercoords = rastercoords[ind[1]:ind[3], ind[0]:ind[2], ...]
        rastervalues = rastervalues[ind[1]:ind[3], ind[0]:ind[2]]

        # Map rastervalues to polar grid points
        polarvalues = wrl.ipol.cart2irregular_spline(
            rastercoords, rastervalues, polcoords)

        pbb = wrl.qual.beam_block_frac(polarvalues, alt, beamradius)
        pbb = np.ma.masked_invalid(pbb)
        pbb_arrays.append(pbb)

        maxindex = np.nanargmax(pbb, axis=1)
        cbb = np.copy(pbb)
        # Iterate over all beams
        for ii, index in enumerate(maxindex):
            premax = 0.
            for jj in range(index):
                # Only iterate to max index to make this faster
                if pbb[ii, jj] > premax:
                    cbb[ii, jj] = pbb[ii, jj]
                    premax = cbb[ii, jj]
                else:
                    cbb[ii, jj] = premax
            # beyond max index, everything is max anyway
            cbb[ii, index:] = pbb[ii, index]
        cbb_arrays.append(cbb)

    pbb_all = np.ma.concatenate(pbb_arrays)
    cbb_all = np.ma.concatenate(cbb_arrays)
    return pbb_all, cbb_all

def empty_radar_beam_block(ngates, rays_per_sweep, nsweeps,
                            lon, lat, alt, range_start,
                            gate_space, elevations):
    """ Creates a radar object with no fields based on
    user inputed dimensions. The empty radar is to then
    be used to add PBB, CBB and the flags for both. """
    radar = pyart.testing.make_empty_ppi_radar(
        ngates, rays_per_sweep, nsweeps)

    radar.longitude['data'] = np.array([lon])
    radar.latitude['data'] = np.array([lat])
    radar.altitude['data'] = np.array([alt])
    # radar.azimuth['data'] = np.linspace(0, 360, rays_per_sweep)
    radar.range['data'] = np.linspace(
        range_start, (ngates - 1)*gate_space + range_start, ngates)
    radar.fixed_angle['data'] = elevations
    radar.metadata['instrument_name'] = 'beam_block_radar_object'
    return radar

def beam_block_flag(pbb_all, cbb_all, pbb_threshold,
                    cbb_threshold):
    """ Takes PBB and CBB arrays created from the
    beam_block function and user chosen thresholds
    to create and array of 1s and 0s, 1 is a flagged gate
    where the fraction value is past the threshold. """
    pbb_flags = np.empty_like(pbb_all)
    pbb_flags[pbb_all > pbb_threshold] = True
    pbb_flags[pbb_all < pbb_threshold] = False

    cbb_flags = np.empty_like(cbb_all)
    cbb_flags[cbb_all > cbb_threshold] = True
    cbb_flags[cbb_all < cbb_threshold] = False
    return pbb_flags, cbb_flags

def _arrays_to_dict(pbb_all, cbb_all):
    """ Function that takes the PBB and CBB arrays
    and turns them into dictionaries to be used and added
    to the pyart radar object. """
    pbb_dict = {}
    pbb_dict['coordinates'] = 'elevation, azimuth, range'
    pbb_dict['units'] = 'unitless'
    pbb_dict['data'] = pbb_all
    pbb_dict['standard_name'] = 'partial_beam_block'
    pbb_dict['long_name'] = 'Partial Beam Block Fraction'
    pbb_dict['comment'] = 'Partial beam block fraction due to terrain'

    cbb_dict = {}
    cbb_dict['coordinates'] = 'elevation, azimuth, range'
    cbb_dict['units'] = 'unitless'
    cbb_dict['data'] = cbb_all
    cbb_dict['standard_name'] = 'cumulative_beam_block'
    cbb_dict['long_name'] = 'Cumulative Beam Block Fraction'
    cbb_dict['comment'] = 'Cumulative beam block fraction due to terrain'
    return pbb_dict, cbb_dict

def _flags_to_dict(pbb_flags, cbb_flags):
    """ Function that takes the PBB_flag and CBB_flag
    arrays and turns them into dictionaries to be used
    and added to the pyart radar object. """
    pbb_flag_dict = {}
    pbb_flag_dict['units'] = 'unitless'
    pbb_flag_dict['data'] = pbb_flags
    pbb_flag_dict['standard_name'] = 'partial_beam_block_flag'
    pbb_flag_dict['long_name'] = 'Partial Beam Block Flag'
    pbb_flag_dict['comment'] = 'Partial beam block fraction flag, ' \
                            '1 for flagged values, 0 for non-flagged.'

    cbb_flag_dict = {}
    cbb_flag_dict['units'] = 'unitless'
    cbb_flag_dict['data'] = cbb_flags
    cbb_flag_dict['standard_name'] = 'cumulative_beam_block_flag'
    cbb_flag_dict['long_name'] = 'Cumulative Beam Block Flag'
    cbb_flag_dict['comment'] = 'Cumulative beam block fraction flag, ' \
                            '1 for flagged values, 0 for non-flagged.'
    return pbb_flag_dict, cbb_flag_dict


## You are using the Python ARM Radar Toolkit (Py-ART), an open source
## library for working with weather radar data.
##
## If you use this software to prepare a publication, please cite:
##
##     JJ Helmus and SM Collis, JORS 2016, doi: 10.5334/jors.119 
time: 552 ms

In [3]:
# Examples
# --------
# >>> import pyart
# >>> radar = pyart.io.read('radar_file.nc')
# >>> gatefilter = pyart.correct.GateFilter(radar)
# >>> beam_block = radar.fields['partial_beam_block_flag']['data']
# >>> gatefilter.exclude_beam_block(beam_block)

def exclude_beam_block(self, beam_block, exclude_masked=True, op='or'):
    """
    Exclude gates where a beam block is equal to True.

    Parameters
    ----------
    beam_block : numpy array
        Boolean numpy array with same shape as a field array.
    exclude_masked : bool, optional
        True to filter masked values in the specified mask if it is
        a masked array, False to include any masked values.
    op : {'and', 'or', 'new'}
        Operation to perform when merging the existing set of excluded
        gates with the excluded gates from the current operation.
        'and' will perform a logical AND operation, 'or' a logical OR,
        and 'new' will replace the existing excluded gates with the one
        generated here. 'or', the default for exclude methods, is
        typically desired when building up a set of conditions for
        excluding gates where the desired effect is to exclude gates which
        meet any of the conditions. 'and', the default for include
        methods, is typically desired when building up a set of conditions
        where the desired effect is to include gates which meet any of the
        conditions.  Note that the 'and' method MAY results in including
        gates which have previously been excluded because they were masked
        or invalid.

    """

    fdata = next(iter(self._radar.fields.values()))['data']
    if beam_block.shape != fdata.shape:
        raise ValueError("beam_block array must be the same size as a field.")
    marked = np.array(beam_block, dtype='bool')
    return self._merge(marked, op, exclude_masked)


time: 3.91 ms

In [4]:
# sitecoords = (-28.0257, 39.0916, 40.0)
elevations = np.array([0.5, 1.0, 2.0, 3.0, 4.0, 10.0, 11.0, 15.0,
                          20.0, 30.0, 40.0])
radar = empty_radar_beam_block(1073, 990, 11, -28.0257,
                                39.0916, 40.0, 0, 100,
                                elevations=elevations)
tif_name = '/home/zsherman/beam_block/data/dtm_gra.tif'


time: 4.02 ms

In [5]:
pbb_all, cbb_all = beam_block(
    radar, tif_name, 1.0)


/home/zsherman/anaconda3/envs/gdal_jupyter/lib/python3.5/site-packages/wradlib/qual.py:205: RuntimeWarning: invalid value encountered in sqrt
  (a ** 2 * np.arcsin(y / a)) + (np.pi * a ** 2 / 2.)
/home/zsherman/anaconda3/envs/gdal_jupyter/lib/python3.5/site-packages/wradlib/qual.py:205: RuntimeWarning: divide by zero encountered in true_divide
  (a ** 2 * np.arcsin(y / a)) + (np.pi * a ** 2 / 2.)
/home/zsherman/anaconda3/envs/gdal_jupyter/lib/python3.5/site-packages/wradlib/qual.py:205: RuntimeWarning: invalid value encountered in arcsin
  (a ** 2 * np.arcsin(y / a)) + (np.pi * a ** 2 / 2.)
time: 17.5 s

In [6]:
print(pbb_all.max())
print(cbb_all.max())


0.999999904642
0.999999904642
time: 50.3 ms

In [7]:
pbb_flags, cbb_flags = beam_block_flag(
    pbb_all, cbb_all, 0.2, 0.2)


time: 107 ms
/home/zsherman/anaconda3/envs/gdal_jupyter/lib/python3.5/site-packages/ipykernel/__main__.py:164: RuntimeWarning: invalid value encountered in greater
/home/zsherman/anaconda3/envs/gdal_jupyter/lib/python3.5/site-packages/ipykernel/__main__.py:165: RuntimeWarning: invalid value encountered in less

In [8]:
pbb_dict, cbb_dict = _arrays_to_dict(
    pbb_all, cbb_all)
pbb_flag_dict, cbb_flag_dict = _flags_to_dict(
    pbb_flags, cbb_flags)


time: 873 µs

In [9]:
radar.add_field('partial_beam_block',
                pbb_dict, replace_existing=True)
radar.add_field('cumulative_beam_block',
                cbb_dict, replace_existing=True)
radar.add_field('partial_beam_block_flag',
                pbb_flag_dict, replace_existing=True)
radar.add_field('cumulative_beam_block_flag',
                cbb_flag_dict, replace_existing=True)


time: 2.5 ms

In [10]:
pyart.io.write_cfradial(
    '/home/zsherman/beam_block/data/radar_object_pbb_cbb_all_sweeps', radar)


time: 1.81 s

In [11]:
bb_radar = pyart.io.read(
    '/home/zsherman/beam_block/data/radar_object_pbb_cbb_all_sweeps')


time: 1.16 s

In [12]:
bb_radar.fields.keys()


Out[12]:
dict_keys(['cumulative_beam_block', 'partial_beam_block_flag', 'partial_beam_block', 'cumulative_beam_block_flag'])
time: 2.83 ms

In [13]:
bb_radar.fields['partial_beam_block']['data']


Out[13]:
masked_array(data =
 [[-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 ..., 
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]],
             mask =
 [[ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 ..., 
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]],
       fill_value = 9.96920996839e+36)
time: 8.14 ms

In [14]:
np.argwhere(bb_radar.fields[
    'partial_beam_block_flag']['data'] == 1).shape


Out[14]:
(16095, 2)
time: 75 ms

In [15]:
bb_radar.fields[
    'partial_beam_block_flag']['data']


Out[15]:
masked_array(data =
 [[-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 ..., 
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]],
             mask =
 [[ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 ..., 
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]],
       fill_value = 9.96920996839e+36)
time: 2.59 ms

In [16]:
np.argwhere(bb_radar.fields['partial_beam_block']['data'] > 0.25).shape


Out[16]:
(14656, 2)
time: 56.9 ms

In [17]:
first_sweep = bb_radar.extract_sweeps([0])


time: 15.8 ms

In [18]:
third_sweep = bb_radar.extract_sweeps([2])


time: 23.6 ms

In [19]:
third_sweep.azimuth['data'] = np.linspace(0, 360, 990)


time: 714 µs

In [20]:
third_sweep.azimuth['data']


Out[20]:
array([   0.        ,    0.36400404,    0.72800809,    1.09201213,
          1.45601618,    1.82002022,    2.18402427,    2.54802831,
          2.91203236,    3.2760364 ,    3.64004044,    4.00404449,
          4.36804853,    4.73205258,    5.09605662,    5.46006067,
          5.82406471,    6.18806876,    6.5520728 ,    6.91607685,
          7.28008089,    7.64408493,    8.00808898,    8.37209302,
          8.73609707,    9.10010111,    9.46410516,    9.8281092 ,
         10.19211325,   10.55611729,   10.92012133,   11.28412538,
         11.64812942,   12.01213347,   12.37613751,   12.74014156,
         13.1041456 ,   13.46814965,   13.83215369,   14.19615774,
         14.56016178,   14.92416582,   15.28816987,   15.65217391,
         16.01617796,   16.380182  ,   16.74418605,   17.10819009,
         17.47219414,   17.83619818,   18.20020222,   18.56420627,
         18.92821031,   19.29221436,   19.6562184 ,   20.02022245,
         20.38422649,   20.74823054,   21.11223458,   21.47623862,
         21.84024267,   22.20424671,   22.56825076,   22.9322548 ,
         23.29625885,   23.66026289,   24.02426694,   24.38827098,
         24.75227503,   25.11627907,   25.48028311,   25.84428716,
         26.2082912 ,   26.57229525,   26.93629929,   27.30030334,
         27.66430738,   28.02831143,   28.39231547,   28.75631951,
         29.12032356,   29.4843276 ,   29.84833165,   30.21233569,
         30.57633974,   30.94034378,   31.30434783,   31.66835187,
         32.03235592,   32.39635996,   32.760364  ,   33.12436805,
         33.48837209,   33.85237614,   34.21638018,   34.58038423,
         34.94438827,   35.30839232,   35.67239636,   36.0364004 ,
         36.40040445,   36.76440849,   37.12841254,   37.49241658,
         37.85642063,   38.22042467,   38.58442872,   38.94843276,
         39.3124368 ,   39.67644085,   40.04044489,   40.40444894,
         40.76845298,   41.13245703,   41.49646107,   41.86046512,
         42.22446916,   42.58847321,   42.95247725,   43.31648129,
         43.68048534,   44.04448938,   44.40849343,   44.77249747,
         45.13650152,   45.50050556,   45.86450961,   46.22851365,
         46.59251769,   46.95652174,   47.32052578,   47.68452983,
         48.04853387,   48.41253792,   48.77654196,   49.14054601,
         49.50455005,   49.8685541 ,   50.23255814,   50.59656218,
         50.96056623,   51.32457027,   51.68857432,   52.05257836,
         52.41658241,   52.78058645,   53.1445905 ,   53.50859454,
         53.87259858,   54.23660263,   54.60060667,   54.96461072,
         55.32861476,   55.69261881,   56.05662285,   56.4206269 ,
         56.78463094,   57.14863498,   57.51263903,   57.87664307,
         58.24064712,   58.60465116,   58.96865521,   59.33265925,
         59.6966633 ,   60.06066734,   60.42467139,   60.78867543,
         61.15267947,   61.51668352,   61.88068756,   62.24469161,
         62.60869565,   62.9726997 ,   63.33670374,   63.70070779,
         64.06471183,   64.42871587,   64.79271992,   65.15672396,
         65.52072801,   65.88473205,   66.2487361 ,   66.61274014,
         66.97674419,   67.34074823,   67.70475228,   68.06875632,
         68.43276036,   68.79676441,   69.16076845,   69.5247725 ,
         69.88877654,   70.25278059,   70.61678463,   70.98078868,
         71.34479272,   71.70879676,   72.07280081,   72.43680485,
         72.8008089 ,   73.16481294,   73.52881699,   73.89282103,
         74.25682508,   74.62082912,   74.98483316,   75.34883721,
         75.71284125,   76.0768453 ,   76.44084934,   76.80485339,
         77.16885743,   77.53286148,   77.89686552,   78.26086957,
         78.62487361,   78.98887765,   79.3528817 ,   79.71688574,
         80.08088979,   80.44489383,   80.80889788,   81.17290192,
         81.53690597,   81.90091001,   82.26491405,   82.6289181 ,
         82.99292214,   83.35692619,   83.72093023,   84.08493428,
         84.44893832,   84.81294237,   85.17694641,   85.54095046,
         85.9049545 ,   86.26895854,   86.63296259,   86.99696663,
         87.36097068,   87.72497472,   88.08897877,   88.45298281,
         88.81698686,   89.1809909 ,   89.54499494,   89.90899899,
         90.27300303,   90.63700708,   91.00101112,   91.36501517,
         91.72901921,   92.09302326,   92.4570273 ,   92.82103134,
         93.18503539,   93.54903943,   93.91304348,   94.27704752,
         94.64105157,   95.00505561,   95.36905966,   95.7330637 ,
         96.09706775,   96.46107179,   96.82507583,   97.18907988,
         97.55308392,   97.91708797,   98.28109201,   98.64509606,
         99.0091001 ,   99.37310415,   99.73710819,  100.10111223,
        100.46511628,  100.82912032,  101.19312437,  101.55712841,
        101.92113246,  102.2851365 ,  102.64914055,  103.01314459,
        103.37714863,  103.74115268,  104.10515672,  104.46916077,
        104.83316481,  105.19716886,  105.5611729 ,  105.92517695,
        106.28918099,  106.65318504,  107.01718908,  107.38119312,
        107.74519717,  108.10920121,  108.47320526,  108.8372093 ,
        109.20121335,  109.56521739,  109.92922144,  110.29322548,
        110.65722952,  111.02123357,  111.38523761,  111.74924166,
        112.1132457 ,  112.47724975,  112.84125379,  113.20525784,
        113.56926188,  113.93326593,  114.29726997,  114.66127401,
        115.02527806,  115.3892821 ,  115.75328615,  116.11729019,
        116.48129424,  116.84529828,  117.20930233,  117.57330637,
        117.93731041,  118.30131446,  118.6653185 ,  119.02932255,
        119.39332659,  119.75733064,  120.12133468,  120.48533873,
        120.84934277,  121.21334681,  121.57735086,  121.9413549 ,
        122.30535895,  122.66936299,  123.03336704,  123.39737108,
        123.76137513,  124.12537917,  124.48938322,  124.85338726,
        125.2173913 ,  125.58139535,  125.94539939,  126.30940344,
        126.67340748,  127.03741153,  127.40141557,  127.76541962,
        128.12942366,  128.4934277 ,  128.85743175,  129.22143579,
        129.58543984,  129.94944388,  130.31344793,  130.67745197,
        131.04145602,  131.40546006,  131.76946411,  132.13346815,
        132.49747219,  132.86147624,  133.22548028,  133.58948433,
        133.95348837,  134.31749242,  134.68149646,  135.04550051,
        135.40950455,  135.77350859,  136.13751264,  136.50151668,
        136.86552073,  137.22952477,  137.59352882,  137.95753286,
        138.32153691,  138.68554095,  139.04954499,  139.41354904,
        139.77755308,  140.14155713,  140.50556117,  140.86956522,
        141.23356926,  141.59757331,  141.96157735,  142.3255814 ,
        142.68958544,  143.05358948,  143.41759353,  143.78159757,
        144.14560162,  144.50960566,  144.87360971,  145.23761375,
        145.6016178 ,  145.96562184,  146.32962588,  146.69362993,
        147.05763397,  147.42163802,  147.78564206,  148.14964611,
        148.51365015,  148.8776542 ,  149.24165824,  149.60566229,
        149.96966633,  150.33367037,  150.69767442,  151.06167846,
        151.42568251,  151.78968655,  152.1536906 ,  152.51769464,
        152.88169869,  153.24570273,  153.60970677,  153.97371082,
        154.33771486,  154.70171891,  155.06572295,  155.429727  ,
        155.79373104,  156.15773509,  156.52173913,  156.88574317,
        157.24974722,  157.61375126,  157.97775531,  158.34175935,
        158.7057634 ,  159.06976744,  159.43377149,  159.79777553,
        160.16177958,  160.52578362,  160.88978766,  161.25379171,
        161.61779575,  161.9817998 ,  162.34580384,  162.70980789,
        163.07381193,  163.43781598,  163.80182002,  164.16582406,
        164.52982811,  164.89383215,  165.2578362 ,  165.62184024,
        165.98584429,  166.34984833,  166.71385238,  167.07785642,
        167.44186047,  167.80586451,  168.16986855,  168.5338726 ,
        168.89787664,  169.26188069,  169.62588473,  169.98988878,
        170.35389282,  170.71789687,  171.08190091,  171.44590495,
        171.809909  ,  172.17391304,  172.53791709,  172.90192113,
        173.26592518,  173.62992922,  173.99393327,  174.35793731,
        174.72194135,  175.0859454 ,  175.44994944,  175.81395349,
        176.17795753,  176.54196158,  176.90596562,  177.26996967,
        177.63397371,  177.99797776,  178.3619818 ,  178.72598584,
        179.08998989,  179.45399393,  179.81799798,  180.18200202,
        180.54600607,  180.91001011,  181.27401416,  181.6380182 ,
        182.00202224,  182.36602629,  182.73003033,  183.09403438,
        183.45803842,  183.82204247,  184.18604651,  184.55005056,
        184.9140546 ,  185.27805865,  185.64206269,  186.00606673,
        186.37007078,  186.73407482,  187.09807887,  187.46208291,
        187.82608696,  188.190091  ,  188.55409505,  188.91809909,
        189.28210313,  189.64610718,  190.01011122,  190.37411527,
        190.73811931,  191.10212336,  191.4661274 ,  191.83013145,
        192.19413549,  192.55813953,  192.92214358,  193.28614762,
        193.65015167,  194.01415571,  194.37815976,  194.7421638 ,
        195.10616785,  195.47017189,  195.83417594,  196.19817998,
        196.56218402,  196.92618807,  197.29019211,  197.65419616,
        198.0182002 ,  198.38220425,  198.74620829,  199.11021234,
        199.47421638,  199.83822042,  200.20222447,  200.56622851,
        200.93023256,  201.2942366 ,  201.65824065,  202.02224469,
        202.38624874,  202.75025278,  203.11425683,  203.47826087,
        203.84226491,  204.20626896,  204.570273  ,  204.93427705,
        205.29828109,  205.66228514,  206.02628918,  206.39029323,
        206.75429727,  207.11830131,  207.48230536,  207.8463094 ,
        208.21031345,  208.57431749,  208.93832154,  209.30232558,
        209.66632963,  210.03033367,  210.39433771,  210.75834176,
        211.1223458 ,  211.48634985,  211.85035389,  212.21435794,
        212.57836198,  212.94236603,  213.30637007,  213.67037412,
        214.03437816,  214.3983822 ,  214.76238625,  215.12639029,
        215.49039434,  215.85439838,  216.21840243,  216.58240647,
        216.94641052,  217.31041456,  217.6744186 ,  218.03842265,
        218.40242669,  218.76643074,  219.13043478,  219.49443883,
        219.85844287,  220.22244692,  220.58645096,  220.95045501,
        221.31445905,  221.67846309,  222.04246714,  222.40647118,
        222.77047523,  223.13447927,  223.49848332,  223.86248736,
        224.22649141,  224.59049545,  224.95449949,  225.31850354,
        225.68250758,  226.04651163,  226.41051567,  226.77451972,
        227.13852376,  227.50252781,  227.86653185,  228.23053589,
        228.59453994,  228.95854398,  229.32254803,  229.68655207,
        230.05055612,  230.41456016,  230.77856421,  231.14256825,
        231.5065723 ,  231.87057634,  232.23458038,  232.59858443,
        232.96258847,  233.32659252,  233.69059656,  234.05460061,
        234.41860465,  234.7826087 ,  235.14661274,  235.51061678,
        235.87462083,  236.23862487,  236.60262892,  236.96663296,
        237.33063701,  237.69464105,  238.0586451 ,  238.42264914,
        238.78665319,  239.15065723,  239.51466127,  239.87866532,
        240.24266936,  240.60667341,  240.97067745,  241.3346815 ,
        241.69868554,  242.06268959,  242.42669363,  242.79069767,
        243.15470172,  243.51870576,  243.88270981,  244.24671385,
        244.6107179 ,  244.97472194,  245.33872599,  245.70273003,
        246.06673407,  246.43073812,  246.79474216,  247.15874621,
        247.52275025,  247.8867543 ,  248.25075834,  248.61476239,
        248.97876643,  249.34277048,  249.70677452,  250.07077856,
        250.43478261,  250.79878665,  251.1627907 ,  251.52679474,
        251.89079879,  252.25480283,  252.61880688,  252.98281092,
        253.34681496,  253.71081901,  254.07482305,  254.4388271 ,
        254.80283114,  255.16683519,  255.53083923,  255.89484328,
        256.25884732,  256.62285137,  256.98685541,  257.35085945,
        257.7148635 ,  258.07886754,  258.44287159,  258.80687563,
        259.17087968,  259.53488372,  259.89888777,  260.26289181,
        260.62689585,  260.9908999 ,  261.35490394,  261.71890799,
        262.08291203,  262.44691608,  262.81092012,  263.17492417,
        263.53892821,  263.90293225,  264.2669363 ,  264.63094034,
        264.99494439,  265.35894843,  265.72295248,  266.08695652,
        266.45096057,  266.81496461,  267.17896866,  267.5429727 ,
        267.90697674,  268.27098079,  268.63498483,  268.99898888,
        269.36299292,  269.72699697,  270.09100101,  270.45500506,
        270.8190091 ,  271.18301314,  271.54701719,  271.91102123,
        272.27502528,  272.63902932,  273.00303337,  273.36703741,
        273.73104146,  274.0950455 ,  274.45904954,  274.82305359,
        275.18705763,  275.55106168,  275.91506572,  276.27906977,
        276.64307381,  277.00707786,  277.3710819 ,  277.73508595,
        278.09908999,  278.46309403,  278.82709808,  279.19110212,
        279.55510617,  279.91911021,  280.28311426,  280.6471183 ,
        281.01112235,  281.37512639,  281.73913043,  282.10313448,
        282.46713852,  282.83114257,  283.19514661,  283.55915066,
        283.9231547 ,  284.28715875,  284.65116279,  285.01516684,
        285.37917088,  285.74317492,  286.10717897,  286.47118301,
        286.83518706,  287.1991911 ,  287.56319515,  287.92719919,
        288.29120324,  288.65520728,  289.01921132,  289.38321537,
        289.74721941,  290.11122346,  290.4752275 ,  290.83923155,
        291.20323559,  291.56723964,  291.93124368,  292.29524772,
        292.65925177,  293.02325581,  293.38725986,  293.7512639 ,
        294.11526795,  294.47927199,  294.84327604,  295.20728008,
        295.57128413,  295.93528817,  296.29929221,  296.66329626,
        297.0273003 ,  297.39130435,  297.75530839,  298.11931244,
        298.48331648,  298.84732053,  299.21132457,  299.57532861,
        299.93933266,  300.3033367 ,  300.66734075,  301.03134479,
        301.39534884,  301.75935288,  302.12335693,  302.48736097,
        302.85136502,  303.21536906,  303.5793731 ,  303.94337715,
        304.30738119,  304.67138524,  305.03538928,  305.39939333,
        305.76339737,  306.12740142,  306.49140546,  306.8554095 ,
        307.21941355,  307.58341759,  307.94742164,  308.31142568,
        308.67542973,  309.03943377,  309.40343782,  309.76744186,
        310.1314459 ,  310.49544995,  310.85945399,  311.22345804,
        311.58746208,  311.95146613,  312.31547017,  312.67947422,
        313.04347826,  313.40748231,  313.77148635,  314.13549039,
        314.49949444,  314.86349848,  315.22750253,  315.59150657,
        315.95551062,  316.31951466,  316.68351871,  317.04752275,
        317.41152679,  317.77553084,  318.13953488,  318.50353893,
        318.86754297,  319.23154702,  319.59555106,  319.95955511,
        320.32355915,  320.6875632 ,  321.05156724,  321.41557128,
        321.77957533,  322.14357937,  322.50758342,  322.87158746,
        323.23559151,  323.59959555,  323.9635996 ,  324.32760364,
        324.69160768,  325.05561173,  325.41961577,  325.78361982,
        326.14762386,  326.51162791,  326.87563195,  327.239636  ,
        327.60364004,  327.96764408,  328.33164813,  328.69565217,
        329.05965622,  329.42366026,  329.78766431,  330.15166835,
        330.5156724 ,  330.87967644,  331.24368049,  331.60768453,
        331.97168857,  332.33569262,  332.69969666,  333.06370071,
        333.42770475,  333.7917088 ,  334.15571284,  334.51971689,
        334.88372093,  335.24772497,  335.61172902,  335.97573306,
        336.33973711,  336.70374115,  337.0677452 ,  337.43174924,
        337.79575329,  338.15975733,  338.52376138,  338.88776542,
        339.25176946,  339.61577351,  339.97977755,  340.3437816 ,
        340.70778564,  341.07178969,  341.43579373,  341.79979778,
        342.16380182,  342.52780586,  342.89180991,  343.25581395,
        343.619818  ,  343.98382204,  344.34782609,  344.71183013,
        345.07583418,  345.43983822,  345.80384226,  346.16784631,
        346.53185035,  346.8958544 ,  347.25985844,  347.62386249,
        347.98786653,  348.35187058,  348.71587462,  349.07987867,
        349.44388271,  349.80788675,  350.1718908 ,  350.53589484,
        350.89989889,  351.26390293,  351.62790698,  351.99191102,
        352.35591507,  352.71991911,  353.08392315,  353.4479272 ,
        353.81193124,  354.17593529,  354.53993933,  354.90394338,
        355.26794742,  355.63195147,  355.99595551,  356.35995956,
        356.7239636 ,  357.08796764,  357.45197169,  357.81597573,
        358.17997978,  358.54398382,  358.90798787,  359.27199191,
        359.63599596,  360.        ])
time: 16 ms

In [21]:
PBB = third_sweep.fields['partial_beam_block']['data']
r = third_sweep.range['data']
az = third_sweep.azimuth['data']

fig = plt.figure(figsize=(10, 7))
ax, dem = wrl.vis.plot_ppi(PBB, r=r,
                           az=az,
                           cmap=plt.cm.PuRd)
ax.set_xlim(-5000, 8000)
ax.set_ylim(-10000, 2000)
ax.plot(r[0], az[1], 'ro', )
ax.grid(True)
ax.annotate('  ARM ENA Site', (r[0], az[1]))
ticks = (ax.get_xticks()/1000).astype(np.int)
ax.set_xticklabels(ticks)
ticks = (ax.get_yticks()/1000).astype(np.int)
ax.set_yticklabels(ticks)
ax.set_title('Partial Beam Block 2.0 Degrees')
ax.set_xlabel("Kilometers")
ax.set_ylabel("Kilometers")
ax.set_axis_bgcolor('#E0E0E0')
plt.colorbar(dem, ax=ax)
plt.show()


time: 884 ms

In [22]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_ylim(-9, 2)
ax.set_xlim(-3, 6)
ax.set_axis_bgcolor('#E0E0E0')
display2 = pyart.graph.RadarMapDisplay(third_sweep)
display2.plot('partial_beam_block', vmin=0, vmax=1,
             cmap=plt.cm.PuRd)
plt.show()


time: 872 ms