pycaps.plot package

Submodules

pycaps.plot.colormap_setup module

from_levels_and_colors(levels, colors, extend='neither')[source]

A helper routine to generate a cmap and a norm instance which behave similar to contourf’s levels and colors arguments. The contents of this code are identical to the from_levels_and_colors in more recent versions of matplotlib (which are not available in the python2.7 installation on the CAPS servers as of 21 Oct. 2015)

Parameters:
  • levels – sequence of numbers – The quantization levels used to construct the BoundaryNorm. Values v are quantizized to level i if lev[i] <= v < lev[i+1].
  • colors – sequence of colors – The fill color to use for each level. If extend is “neither” there must be n_level - 1 colors. For an extend of “min” or “max” add one extra color, and for an extend of “both” add two colors.
  • extend – {‘neither’, ‘min’, ‘max’, ‘both’}, optional. The behaviour when a value falls out of range of the given levels. See contourf() for details.
Returns:

tuple containing a Colormap and a Normalize instance

Return type:

(cmap, norm)

thresh_setup(var, max=100.0, min=-100.0, tornado=False)[source]

A function to define default thresholds and colorbar for plotting various fields.

For unknown fields, passing in a max and min value will generate a generic 20-gradation colorbar. If max and min data are missing, -100 to 100 will be assumed as a last resort.

NOTE: “max” and “min” are only used when “var” is not found in the presets.

Parameters:
  • var – the name of the variable, passed as a string
  • max – OPTIONAL – the maximum value you’d want to plot (default: -100.0)
  • min – OPTIONAL – the minimum value you’d want to plot (default: 100.0)
  • tornado – OPTIONAL – A flag to set True if you’re plotting fields for a tornado and thus need to use otherwise extreme values for some fields (default: False)
Returns:

a list of threshold values for contouring using contourf colormap: the name of a colormap to use from ns_colormaps.py cb_ticks: which ticks to show in the colorbar for this field no_proportional: A flag to set to select equal spacing in the colorbar

Return type:

thresholds

pycaps.plot.nexrad_color_tables module

remap(x)

pycaps.plot.ns_colormap module

pycaps.plot.plot_arps_xy module

xyplot(data, field, source, level, format='hdf', **kwargs)[source]

Plots a single HDF or NetCDF variable field (or field derived from history data) in the x-y plane, with options for various overlays. Grid data, such as that stored in an ARPS grdbas file, are required. Lambert conformal map projection will be used.

Parameters:
  • data – The 2D x-y slice to be plotted (e.g. u, v, pt, qr). Can be generated quickly using read_xy_slice.
  • field – The variable name (e.g. ‘u’, ‘v’, ‘pt’, ‘qr’). Needed to properly format your plot. Enclose it in single quotes.
  • source – The FULL PATH to the file containing the data for plotting.
  • level – The vertical (k) model layer on which to plot an x-y slice.
  • format – OPTIONAL – The file format for your input (currently, valid choices are “hdf” (default) and “netcdf”)
  • **kwargs – grdbas: The history file from which to read grid information (if different from ‘source’) h2: A second source file containing other data needed for plotting, if you have one. (example: Read reflectivity from one file, and wind data from another). name: A name to identify the data (may be used in plot title and output filename) truref: If reading from an ARPS file processed using ossedata (affects variable name and filename) this should be set to the full path to the truref file. addshape: Specify a shapefile to overlay data from. Requires the shapefile (and options) to be included in the shapefiles block in plot_arps_xy.py within the pycaps package. colormap: Used to specify a colormap from ns_colormap.py for use with this plot. If not provided, a default colormap choice appropriate to the variable will be used. pixels: A flag to set to True if you want a pixel (colormesh) plot instead of a contour plot. tornado: A flag to set to True if you are plotting values from a high-resolution tornadic dataset. Will choose appropriate values for relevant variables (e.g. wspd, p) imin: The i-coordinate of the west edge of your plot. If not given, default = 0 imax: The i-coordinate of the east edge of your plot. If not given, default = nx jmin: The j-coordinate of the south edge of your plot. If not given, default = 0 jmax: The j-coordinate of the north edge of your plot. If not given, default = ny qcbelow: If given, values below this threshold will be marked as missing/bad data. qcabove: If given, values above this threshold will be marked as missing/bad data. urban: A flag to set to True if you want to plot urban data (if not given, False by default). counties: A flag to set to False if you don’t want to plot counties (if not given, True by default). states: A flag to set to False if you don’t want to plot states (if not given, True by default). coastlines: A flag to set to False if you don’t want to plot coastlines (if not given, True by default). lat: If given, will plot lines of latitude at the given interval (in degrees). lon: If given, will plot lines of longitude at the given interval (in degrees). decompress: A flag to set to True if you’re using ARPS data with 32 bit integers mapped to 16 bit integers. Will call the decompression function if set to True.
Returns:

<<nothing>> (Generates and saves the requested plot to a .png file)

pycaps.plot.pubfig module

get_multiplier(fig=None)[source]

Get a multipler for the size of text objects, a function of the diagonal length on the figure.

Parameters:fig (matplotlib.figure.Figure) – The figure to use. Defaults to none, meaning to use the current figure.
Returns:The size multiplier for the figure.
get_subplot_position(gs)[source]

Get a subplot’s position in the figure layout.

Parameters:gs (gridspec) – A matplotlib gridspec object, perhaps obtained from the gs_parent keyword argument to your subpanel function.
Returns:A tuple containing the row and column of the subplot. Rows and columns are zero-based.
publication_figure(subfigures, layout, corner='ul', colorbar=None, hanging='bottom', dpi=300)[source]

Make publication figures out of many panels, automatically adding the subfigure letter and generating a figure colorbar.

Parameters:
  • subfigures (list) – A list of functions, each of which plots a panel of the figure. Each function should take **kwargs as arguments.
  • layout (tuple) – A tuple specifying how the panels are arranged (e.g. (2, 4) for a figure with 2 rows and 4 columns)
  • corner (str) – The corner in which to put the figure letter. Acceptable values are ‘ul’ for the upper-left corner, ‘lr’ for the lower-right corner, etc.
  • colorbar (dict) – A dictionary specifying how to create the figure colorbar.
  • hanging (str) – If the number of panels does not fit into the layout (e.g. 3 panels in a 2 \(\times\) 2 layout), this specifies where to have the incomplete row/column. Acceptable values are ‘left’, ‘bottom’, ‘right’, and ‘top’.
  • dpi (float) – Set the figure dpi to be at least this amount. If it’s already more than dpi, don’t mess with it.

pycaps.plot.skewTlib module

Skew-T Plotting Library

class SkewTPlotter[source]

Bases: object

Plot Skew-T log-p diagrams

p_lines

list

A list of the pressure lines (in hPa) to plot.

p_color

str

The color of the pressure lines

T_plot_min

float

Minimum isotherm on the plot in degrees C.

T_step

float

The temperature difference (in degrees C) between adjacent isotherms.

T_color_below_0

str

The color of isotherms below 0 C

T_color_0

str

The color of the 0 C isotherm

T_color_above_0

str

The color of isotherms above 0 C

th_min

float

Minimum dry adiabat on the plot in degrees C (references temperature at 1000 mb).

th_max

float

Maximum dry adiabat on the plot in degrees C (references temperature at 1000 mb).

th_step

float

Temperature difference (in degrees C) between adjacent dry adiabats.

th_color

str

The color of the dry adiabats.

the_min

float

Minimum moist adiabat on the plot in degrees C (references temperature at 1000 mb).

the_max

float

Maximum moist adiabat on the plot in degrees C (references temeprature at 1000 mb).

the_step

float

Temperature difference (in degrees C) between adjacent moist adiabats.

the_color

float

The color of the moist adiabats.

w_lines

list

A list of mixing ratio lines (in g/kg) to plot.

w_min_p

float

The starting pressure (in hPa) for mixing ratio lines.

w_max_p

float

The ending pressure (in hPa) for mixing ratio lines.

w_color

str

The color of the mixing ratio lines.

T_max

float: The maximum temperature of the plot (at 1000 hPa) in degrees C.

T_min

float: The minimum temperature of the plot (at 1000 hPa) in degrees C.

p_max

float: The maximum pressure of the plot in hPa

p_min

float: The minimum pressure of the plot in hPa

plot_hodograph(u_snd, v_snd, p_snd, clip_p=200.0, bounds=(-20, -20, 40, 40), **kwargs)[source]

Plot a hodograph inset in the upper-right corner

Parameters:
  • u_snd (np.array) – A 1-dimensional array containing the u wind component
  • v_snd (np.array) – A 1-dimensional array containing the v wind component
  • p_snd (np.array) – A 1-dimensional array containing the pressure in hPa.
  • clip_p (float) – The pressure in hPa at which to cut off the line on the hodograph. The default is 200 hPa.
  • bounds (tuple) – The bounds for the hodograph as a tuple (u_min, v_min, u_max, v_max). The default is (-20, -20, 40, 40)
  • **kwargs – Any keywords that can be passed to matplotlib.pyplot.plot() (see http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot).
plot_profile(t_snd, p_snd, **kwargs)[source]

Plot a temperature or dewpoint profile on the skew-T

Parameters:
  • t_snd (np.array) – A 1-dimensional array containing the profile temperature in degrees C.
  • p_snd (np.array) – A 1-dimensional array containing the profile pressure in hPa.
  • **kwargs – Any keywords that can be passed to matplotlib.pyplot.plot() (see http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot; note that if you pass in a transform, it will be overwritten).
plot_skewt_background(staff=True, clip=False)[source]

Plots the background for the Skew-T diagram. Must be called first to initialize the plotting.

Parameters:
  • staff (bool) – If True, draw a line for the wind staff. Default is True.
  • clip (bool) – If True, clip the top right corner of the plot. Default is False.
plot_winds(u_snd, v_snd, p_snd, **kwargs)[source]

Plot a wind profile on the right side of the skew-T

Parameters:
  • u_snd (np.array) – A 1-dimensional array containing the u wind profile
  • v_snd (np.array) – A 1-dimensional array containing the v wind profile
  • p_snd (np.array) – A 1-dimenionsal array containing the pressure profile
  • **kwargs – Any keywords that can be passed to matplotlib.pyplot.barbs() (see http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.barbs; note that if you pass in clip_on or z_order, it will be overwritten)
trans

The skew-T log-p transform as a matplotlib transform object.

compute_parcel_trace(t_snd, td_snd, p_snd, prc_func=<function sb_parcel>)[source]

Compute the parcel temperature trace

Parameters:
  • t_snd (np.array) – A 1-dimensional float array containing the environmental temperature
  • td_snd (np.array) – A 1-dimensional float array containing the environmental dewpoint
  • p_snd (np.array) – A 1-dimensional float array containing the pressure
  • prc_func (function) – A function that returns the initial parcel temperature, pressure, and dewpoint (in that order) given the sounding temperature, pressure, and dewpoint (in that order). Some pre-defined functions are available in derived.parcel.
Returns:

A 1-dimensional array containing the parcel temperature trace.

plot_sounding(u, v, p, t, td, file_name, hodograph=False, hodo_bounds=(-20, -20, 40, 40))[source]

Plot a single sounding, optionally with a hodograph, and save to a file

Parameters:
  • u (np.array) – A 1-dimensional array containing the u wind component
  • v (np.array) – A 1-dimensional array containing the v wind component
  • p (np.array) – A 1-dimensional array containing the pressure in hPa
  • t (np.array) – A 1-dimensional array containing the temperature in degrees C
  • td (np.array) – A 1-dimensional array containing the dewpoint in degrees C
  • file_name (str) – The name of the file in which to save the image
  • hodograph (bool) – If True, plot a hodograph in the upper-right corner
  • hodo_bounds (tuple) – Bounds on the hodograph as a tuple (u_min, v_min, u_max, v_max), if one is plotted. The default is (-20, -20, 40, 40)

Module contents