Skip to content

Commit

Permalink
Merge pull request #920 from AdamTheisen/master
Browse files Browse the repository at this point in the history
ADD: Corner Reflector Raster Scan Plotting
  • Loading branch information
zssherman authored Mar 31, 2020
2 parents 3fc9c63 + cbfb975 commit cebdb7e
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 2 deletions.
147 changes: 146 additions & 1 deletion pyart/graph/radardisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from matplotlib.dates import DateFormatter
import numpy as np
import netCDF4
from scipy.interpolate import griddata
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

Expand Down Expand Up @@ -804,6 +805,150 @@ def plot_azimuth_to_rhi(
mappable=pm, label=colorbar_label, orient=colorbar_orient,
field=field, ax=ax, fig=fig, ticks=ticks, ticklabs=ticklabs)

def plot_cr_raster(self, field='reflectivity', target_range=None, ax=None, fig=None,
delta_x=None, delta_y=None, az_limits=None, el_limits=None,
vmin=None, vmax=None, cmap=None, title=None, title_flag=True,
axislabels=[None, None], axislabels_flag=True,
colorbar_flag=True, colorbar_label=None,
colorbar_orient='vertical', ticks=None, ticklabs=None, raster=False):
"""
Plot a corner reflector raster scan
Parameters
----------
field : String
Field to plot if other than reflectivity
target_range : Float
Estimated range of the corner reflector
Other Parameters
----------------
ax : Axis
Axis to plot on. None will use the current axis.
fig : Figure
Figure to add the colorbar to. None will use the current figure.
delta_x : Float
Azimuth grid spacing for griddata
delta_y : Float
Elevation grid spacing for griddata
az_limits : list
Azimuth limits in form [min, max]
el_limits : list
Elevation limits in form [min, max]
vmin : float
Luminance minimum value, None for default value.
Parameter is ignored is norm is not None.
vmax : float
Luminance maximum value, None for default value.
Parameter is ignored is norm is not None.
cmap : str or None
Matplotlib colormap name. None will use the default colormap for
the field being plotted as specified by the Py-ART configuration.
title : str
Title to label plot with, None to use default title generated from
the field and sweep parameters. Parameter is ignored if title_flag
is False.
title_flag : bool
True to add a title to the plot, False does not add a title.
axislabels : (str, str)
2-tuple of x-axis, y-axis labels. None for either label will use
the default axis label. Parameter is ignored if axislabels_flag is
False.
axislabels_flag : bool
True to add label the axes, False does not label the axes.
colorbar_flag : bool
True to add a colorbar with label to the axis. False leaves off
the colorbar.
colorbar_label : str
Colorbar label, None will use a default label generated from the
field information.
ticks : array
Colorbar custom tick label locations.
ticklabs : array
Colorbar custom tick labels.
colorbar_orient : 'vertical' or 'horizontal'
Colorbar orientation.
raster : bool
False by default. Set to True to render the display as a raster
rather than a vector in call to pcolormesh. Saves time in plotting
high resolution data over large areas. Be sure to set the dpi
of the plot for your application if you save it as a vector format
(i.e., pdf, eps, svg).
"""

ax, fig = common.parse_ax_fig(ax, fig)

# Get data and coordinate information
az = self._radar.azimuth['data']
el = self._radar.elevation['data']
rng = self._radar.range['data']
data = self._radar.fields[field]['data']

# Calculate delta for x and y
if az_limits is None:
min_az = np.nanmin(az)
max_az = np.nanmax(az)
else:
min_az = az_limits[0]
max_az = az_limits[1]

if el_limits is None:
min_el = np.nanmin(el)
max_el = np.nanmax(el)
else:
min_el = el_limits[0]
max_el = el_limits[1]

if delta_x is None:
delta_x = max_az-min_az
if delta_y is None:
delta_y = max_el-min_el

# Get range closest to target_range
if target_range is None:
target_index = 0
else:
target_index = np.argmin(np.abs(np.array(rng) - target_range))

data = data[:, target_index]

# Geet azimuth and elevation onto a meshgrid
xi, yi = np.meshgrid(np.linspace(min_az, max_az, int(delta_x/0.01)),
np.linspace(min_el, max_el, int(delta_y/0.01)))

# Grid up the data for plotting
grid = griddata((az, el), data, (xi, yi), method='linear')

# Plot data using pcolormesh
pm = ax.pcolormesh(xi[0, :], yi[:, 0], grid, vmin=vmin, vmax=vmax, cmap=cmap)

if title_flag is True:
if title is None:
time_str = common.generate_radar_time_begin(self._radar)
title = ' '.join(['Corner Reflector', field.title(), time_str.strftime('%m/%d/%Y %H:%M:%S')])
ax.set_title(title)

if axislabels_flag is True:
if axislabels[0] is None:
axislabels[0] = 'Azimuth (deg)'
if axislabels[1] is None:
axislabels[1] = 'Elevation (deg)'
ax.set_xlabel(axislabels[0])
ax.set_ylabel(axislabels[1])

if raster:
pm.set_rasterized(True)

# add plot and field to lists
self.plots.append(pm)
self.plot_vars.append(field)

if colorbar_flag:
self.plot_colorbar(
mappable=pm, label=colorbar_label, orient=colorbar_orient,
field=field, ax=ax, fig=fig, ticks=ticks, ticklabs=ticklabs)

def plot_range_rings(self, range_rings, ax=None, col='k', ls='-', lw=2):
"""
Plot a series of range rings.
Expand Down Expand Up @@ -1333,7 +1478,7 @@ def _get_vpt_data(self, field, mask_tuple, filter_transitions,
if gatefilter is not None:
mask_filter = gatefilter.gate_excluded
data = np.ma.masked_array(data, mask_filter)

# filter out antenna transitions
if filter_transitions and self.antenna_transition is not None:
in_trans = self.antenna_transition
Expand Down
12 changes: 12 additions & 0 deletions pyart/graph/tests/test_radardisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ def test_radardisplay_vpt(outfile=None):
plt.close()


def test_radardisplay_cr_raster(outfile=None):
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_CR_RASTER_FILE)
display = pyart.graph.RadarDisplay(radar)
fig = plt.figure()
ax = fig.add_subplot(111)
display.plot_cr_raster(target_range=478., el_limits=[-0.5, 2.5])
if outfile:
fig.savefig(outfile)
plt.close()


def test_radardisplay_vpt_time(outfile=None):
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
pyart.util.to_vpt(radar) # hack to make the data a VPT
Expand Down Expand Up @@ -289,3 +300,4 @@ def test_radardisplay_get_colorbar_label():
test_radardisplay_ppi('figure_radar_display_ppi.png')
test_radardisplay_ray('figure_radar_display_ray.png')
test_radardisplay_vpt('figure_radar_display_vpt.png')
test_radardisplay_cr_raster('figure_radar_display_cr_raster.png')
2 changes: 1 addition & 1 deletion pyart/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from .sample_files import MDV_PPI_FILE, MDV_RHI_FILE, MDV_GRID_FILE
from .sample_files import CFRADIAL_PPI_FILE, CFRADIAL_RHI_FILE
from .sample_files import CFRADIAL_PPI_FILE, CFRADIAL_RHI_FILE, CFRADIAL_CR_RASTER_FILE
from .sample_files import CHL_RHI_FILE, UF_FILE
from .sample_files import SIGMET_PPI_FILE, SIGMET_RHI_FILE
from .sample_files import INTERP_SOUNDE_FILE, SONDE_FILE
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyart/testing/data/example_cfradial_cr_raster.nc
Binary file not shown.
2 changes: 2 additions & 0 deletions pyart/testing/sample_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MDV_RHI_FILE
CFRADIAL_PPI_FILE
CFRADIAL_RHI_FILE
CFRADIAL_CR_RASTER_FILE
CHL_RHI_FILE
SIGMET_PPI_FILE
SIGMET_RHI_FILE
Expand All @@ -29,6 +30,7 @@
MDV_GRID_FILE = os.path.join(DATA_PATH, 'example_mdv_grid.mdv')
CFRADIAL_PPI_FILE = os.path.join(DATA_PATH, 'example_cfradial_ppi.nc')
CFRADIAL_RHI_FILE = os.path.join(DATA_PATH, 'example_cfradial_rhi.nc')
CFRADIAL_CR_RASTER_FILE = os.path.join(DATA_PATH, 'example_cfradial_cr_raster.nc')
CHL_RHI_FILE = os.path.join(DATA_PATH, 'example_chl_rhi.chl')
SIGMET_PPI_FILE = os.path.join(DATA_PATH, 'example_sigmet_ppi.sigmet')
SIGMET_RHI_FILE = os.path.join(DATA_PATH, 'example_sigmet_rhi.sigmet')
Expand Down

0 comments on commit cebdb7e

Please sign in to comment.