def test_generate_longitudinal_level_title(): grid_shape = (1, 1, 1) grid_limits = ((0, 1), (0, 1), (0, 1)) grid = pyart.testing.make_empty_grid(grid_shape, grid_limits) grid.metadata['instrument_name'] = 'bar' grid.fields['foo'] = {} title = common.generate_longitudinal_level_title(grid, 'foo', 0) assert title == ('bar 0.0 km east of origin 2000-01-01T00:00:00Z \nFoo') grid.x['data'][0] = -1000. title = common.generate_longitudinal_level_title(grid, 'foo', 0) assert title == ('bar 1.0 km west of origin 2000-01-01T00:00:00Z \nFoo')
def test_generate_longitudinal_level_title(): grid_shape = (1, 1, 1) grid_limits = ((0, 1), (0, 1), (0, 1)) grid = pyart.testing.make_empty_grid(grid_shape, grid_limits) grid.metadata['instrument_name'] = 'bar' grid.fields['foo'] = {} title = common.generate_longitudinal_level_title(grid, 'foo', 0) assert title == ( 'bar 0.0 km east of origin 2000-01-01T00:00:00Z \nFoo') grid.x['data'][0] = -1000. title = common.generate_longitudinal_level_title(grid, 'foo', 0) assert title == ( 'bar 1.0 km west of origin 2000-01-01T00:00:00Z \nFoo')
def generate_longitudinal_level_title(self, field, level): """ Generate a title for a plot. Parameters ---------- field : str Field plotted. level : int Longitudinal level plotted. Returns ------- title : str Plot title. """ return common.generate_longitudinal_level_title( self.grid, field, level)
def plot_longitudinal_level(self, field, x_index, vmin=None, vmax=None, norm=None, cmap=None, mask_outside=False, title=None, title_flag=True, axislabels=(None, None), axislabels_flag=True, colorbar_flag=True, colorbar_label=None, colorbar_orient='vertical', edges=True, ax=None, fig=None, ticks=None, ticklabs=None, **kwargs): """ Plot a slice along a given longitude. Additional arguments are passed to Basemaps's pcolormesh function. Parameters ---------- field : str Field to be plotted. x_index : float Index of the longitudinal level to plot. vmin, vmax : float Lower and upper range for the colormesh. If either parameter is None, a value will be determined from the field attributes (if available) or the default values of -8, 64 will be used. Parameters are ignored is norm is not None. norm : Normalize or None, optional matplotlib Normalize instance used to scale luminance data. If not None the vmax and vmin parameters are ignored. If None, vmin and vmax are used for luminance scaling. 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. mask_outside : bool True to mask data outside of vmin, vmax. False performs no masking. title : str Title to label plot with, None to use default title generated from the field and lat,lon 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. colorbar_orient : 'vertical' or 'horizontal' Colorbar orientation. edges : bool True will interpolate and extrapolate the gate edges from the range, azimuth and elevations in the radar, treating these as specifying the center of each gate. False treats these coordinates themselved as the gate edges, resulting in a plot in which the last gate in each ray and the entire last ray are not not plotted. 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. ticks : array Colorbar custom tick label locations. ticklabs : array Colorbar custom tick labels. """ # parse parameters ax, fig = common.parse_ax_fig(ax, fig) vmin, vmax = common.parse_vmin_vmax(self.grid, field, vmin, vmax) cmap = common.parse_cmap(cmap, field) data = self.grid.fields[field]['data'][:, :, x_index] # mask the data where outside the limits if mask_outside: data = np.ma.masked_invalid(data) data = np.ma.masked_outside(data, vmin, vmax) # plot the grid y_1d = self.grid.y['data'] / 1000 z_1d = self.grid.z['data'] / 1000 if edges: if len(y_1d) > 1: y_1d = _interpolate_axes_edges(y_1d) if len(z_1d) > 1: z_1d = _interpolate_axes_edges(z_1d) xd, yd = np.meshgrid(y_1d, z_1d) if norm is not None: # if norm is set do not override with vmin, vmax vmin = vmax = None pm = ax.pcolormesh(xd, yd, data, vmin=vmin, vmax=vmax, norm=norm, cmap=cmap, **kwargs) self.mappables.append(pm) self.fields.append(field) if title_flag: if title is None: ax.set_title( common.generate_longitudinal_level_title( self.grid, field, x_index)) else: ax.set_title(title) if axislabels_flag: self._label_axes_longitude(axislabels, ax) if colorbar_flag: self.plot_colorbar(mappable=pm, label=colorbar_label, orientation=colorbar_orient, field=field, ax=ax, fig=fig, ticks=ticks, ticklabs=ticklabs) return