WEM.postWRF.postWRF package

Submodules

WEM.postWRF.postWRF.axes module

class WEM.postWRF.postWRF.axes.Axes(config)

Bases: object

setup(config)

WEM.postWRF.postWRF.birdseye module

Top-down 2D plots, which are so common in meteorology that they get their own file here.

Subclass of Figure.

class WEM.postWRF.postWRF.birdseye.BirdsEye(nc=False, ax=0, fig=0)

Bases: WEM.postWRF.postWRF.figure.Figure

axes_of_dilatation(xdata, ydata, fname, outdir, lats=False, lons=False, smooth=False, locations=False, x=False, y=False, m=False, Nlim=False, Elim=False, Slim=False, Wlim=False)
get_plot_arguments(cmap=False, clvs=False, color=False)

Returns colourmap and contouring levels

Options keyword arguments: clvs : manually override contour levels

make_subplot_label(ax, label)
plot2D(data, fname, outdir, plottype='contourf', save=True, smooth=1, lats=False, lons=False, clvs=False, cmap=False, title=False, cb=True, locations=False, m=False, x=False, y=False, Nlim=False, Elim=False, Slim=False, Wlim=False, color='k', inline=False, lw=False, extend=False, cblabel=False, ideal=False)

Generic method that plots any matrix of data on a map

Inputs: data : 2D matrix of data outdir : path to plots outf : filename for output (with or without .png)

Optional: plottype : matplotlib function for plotting smooth : Gaussian smooth by this many grid spaces clvs : scale for contours title : title on plot save : whether to save to file

Parameters:locations (dict) – Locations to plot on the basemap. Format: locations = {‘label’:(lat,lon),etc}
plot_streamlines(U, V, outdir, fname, lats=False, lons=False, smooth=1, title=False, lw_speed=False, density=1.8, ideal=False)

Plot streamlines.

U : U-component of wind (nx x ny) V : V-component of wind (same dimensions)

lw_speed : linewidth is proportional to wind speed

spaghetti(t, lv, va, contour, wrfouts, outpath, da=0, dom=0)

wrfouts : list of wrfout files

Only change dom if there are multiple domains.

WEM.postWRF.postWRF.clicker module

class WEM.postWRF.postWRF.clicker.Clicker(wrfout, data=0, fig=0, ax=0, clvs=False, cmap=False)

Bases: WEM.postWRF.postWRF.figure.Figure

click_x_y(plotpoint=0)

plotpoint : boolean. If yes, plot point.

draw_box()
draw_line()
on_press(event)
on_release_box(event)
on_release_line(event)
on_release_point(event)
onpick(event)
overlay_data(data, clvs=False, cmap=False)
set_box_width(X)

Ask user to specify a width that is normal to the cross-section X. The plot will show with the box displayed. If the user is not happy, they can try again.

WEM.postWRF.postWRF.colourtables module

Colour tables for plotting.

Adapted from code by Luke Madaus and David-John Gagne II

WEM.postWRF.postWRF.colourtables.PkBlfloat(datarange)
WEM.postWRF.postWRF.colourtables.PuRdBlfloat(datarange)
WEM.postWRF.postWRF.colourtables.RdBuWH()
WEM.postWRF.postWRF.colourtables.RdBufloat(*args)
WEM.postWRF.postWRF.colourtables.bw_irsat(*args)
WEM.postWRF.postWRF.colourtables.dewpoint1(*args)
WEM.postWRF.postWRF.colourtables.grays(*args)
WEM.postWRF.postWRF.colourtables.irsat(*args)
WEM.postWRF.postWRF.colourtables.mixprecip1(*args)
WEM.postWRF.postWRF.colourtables.ncdc_modified_ISU(nlvs)
WEM.postWRF.postWRF.colourtables.precip1(*args)
WEM.postWRF.postWRF.colourtables.rain1(*args)
WEM.postWRF.postWRF.colourtables.reflect(*args)
WEM.postWRF.postWRF.colourtables.reflect_ncdc(*args)
WEM.postWRF.postWRF.colourtables.sftemp(*args)
WEM.postWRF.postWRF.colourtables.snow1(*args)
WEM.postWRF.postWRF.colourtables.snow2(*args)
WEM.postWRF.postWRF.colourtables.thetae(*args)
WEM.postWRF.postWRF.colourtables.universal_reflect()

Map a number to a colour.

WEM.postWRF.postWRF.constants module

WEM.postWRF.postWRF.defaults module

Default settings that are used when the user does not specify their own.

class WEM.postWRF.postWRF.defaults.Defaults

Bases: object

WEM.postWRF.postWRF.ecmwf module

class WEM.postWRF.postWRF.ecmwf.ECMWF(fpath, config)

Bases: object

basemap_setup(**kwargs)
ecmwf_times()
find_level_idx(lv)
find_time_idx(t)
get(va, lv, t)
get_key(va)
plot(va, lv, times, **kwargs)

WEM.postWRF.postWRF.figure module

All matplotlib figures are subclasses of Figure.

class WEM.postWRF.postWRF.figure.Figure(nc=False, ax=0, fig=0, plotn=(1, 1), layout='normal')

Bases: object

C : configuration settings W : data

basemap_setup(smooth=1, lats=False, lons=False, proj='merc', Nlim=False, Elim=False, Slim=False, Wlim=False)

Needs rewriting to include limited domains based on lats/lons. Currently, assuming whole domain is plotted.

create_colorbar(fpath, fname, cf, label='', tix=False)

Create colorbar.

Inputs: fpath : path to file fname : filename cf : contour filling for legend label : colorbar label

create_fname(*naming)

Default naming should be: Variable + time + level

figsize(defwidth, defheight, fig)
just_one_colorbar(fpath, fname, cf, label=False, tix=False)
save(outpath, fname, tight=True)
title_time()

WEM.postWRF.postWRF.lookuptable module

class WEM.postWRF.postWRF.lookuptable.LookUpTable

Bases: object

WEM.postWRF.postWRF.main module

This handles user requests and controls computations and plotting.

This script is API and should not be doing any hard work of importing matplotlib etc!

Useful/utility scripts are in WEM.utils.

TODO: move all DKE stuff to stats and figure/birdseye.

TODO: move more utilities to utils.

TODO: generalise plotting so the mountain of arguments can be easily changed and documented. Right now a small change to general plotting API takes a lot of time, and the documentation is a bit crazy.

TODO: make boring methods private, e.g. _create_fname(). Then hide it from documentation if it is revealed to the user at the top level.

class WEM.postWRF.postWRF.main.WRFEnviron

Bases: object

Main environment API.

This currently only loads default settings.

all_error_growth(outdir, infodict, ylim=False, f_prefix=False, f_suffix=False, energy='total')

Compare many ensembles’ DKE and DTE spreads on one plot. The times don’t need to be identical.

cold_pool_strength(utc, ncdir=False, outdir=False, ncf=False, nct=False, f_prefix=False, f_suffix=False, swath_width=100, bounding=False, dom=1, twoplot=False, fig=0, axes=0, dz=0)

Pick A, B points on sim ref overlay This sets the angle between north and line AB Also sets the length in along-line direction For every gridpt along line AB:

  • Locate gust front via shear
  • Starting at front, do 3-grid-pt-average in line-normal direction
Parameters:
  • swath_width (int) – length in gridpoint in cross-section-normal direction.
  • bounding (dict) – bounding box for domain. Dictionary contains four keys (Nlim, Elim, Slim, Wlim) with float values (northern latitude limit, eastern longitude limit, southern latitude limit, western latitude limit, respectively).
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • twoplot (bool) – If true, return two figures: cold pool strength and the cref/cross-section
  • dz (bool) – plot height of cold pool only.
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto. If tuple/list of length two, this is the first and second axis, if twoplot is True.
composite_profile(vrbl, utc, enspaths, latlon=False, dom=1, mean=True, std=True, xlim=False, ylim=False)

Plot multiple vertical profiles of atmospheric variables including optional mean and standard deviation.

Superceded by twopanel_profile()?

Parameters:
  • vrbl (str) – WRF variable or computed quantity
  • utc (int,list,tuple) – date/time
  • enspaths (list,tuple) – absolute paths to all netCDF files for each ensemble member.
  • latlon (bool,tuple,list) – (lat,lon) for plotting. If this is False, a pop-up window will allow user to choose location.
  • dom (int) – WRF domain to use
  • mean (bool) – plot ensemble mean of variable
  • std (bool) – plot ensemble standard deviate of variable (+/- 1 sigma)
  • xlim (bool,tuple,list) – x-axis limit. False is automatic.
  • ylim (bool,tuple,list) – y-axis limit, False is automatic.
compute_diff_energy(*args, **kwargs)
create_fname(vrbl, utc=False, level=False, other=False, f_prefix=False, f_suffix=False, extension='png')

Generate a filename (without extension) for saving a figure. Differentiate between similar plots for e.g. different domains by using the f_suffix/f_prefix options.

Parameters:
  • vrbl (str) – variable name as found in WRF, or one of the computed fields available in WEM.
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (time.gmtime).
  • level (str) – required level.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str

Returns:str – filename with extension.
delta_diff_energy(vrbl, utc0, utc1, energy, datadir, outdir, meanvrbl='Z', meanlevel=500, dataf=False, outprefix=False, outsuffix=False, clvs=0, title=False, fig=False, ax=False, ncdata=False)

Plot DKE/DTE growth with time: delta DKE/DTE (DDKE/DDTE). Filled contours of DDKE or DDTE is optionally plotted over the ensemble mean of a variable (contours). DDKE/DDTE is valid halfway between the first and second times specified.

Parameters:
  • vrbl (str) – Vertically integrated (‘sum_z’) or summated over all dimensions (‘sum_xyz’).
  • utc0 (tuple,list,int) – First date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • utc1 (tuple,list,int) – as for utc0, but for the second time.
  • energy (str) – DKE (‘kinetic’) or DTE (‘total’).
  • datadir (str) – directory holding computed data
  • outdir (str) – root directory for plots
  • dataf (str) – file name of data file, if ambiguous
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
  • f_suffix (bool,str) – custom filename suffix for output. Ignore if False.
  • clvs (bool,N.ndarray) – contour levels for DDKE/DDTE. Generate with numpy.arange().
  • meanclvs (bool,N.ndarray) – contour levels for ensemble mean. Generate with numpy.arange().
  • title (bool,str) – title for output
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto
  • meanvrbl (str) – variable of ensemble mean (WRF key or computed vrbl)
  • meanlevel (int,str) – level for the ensemble mean variable. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • ncdata – if meanvrbl is not False, list of absolute paths to all netcdf files of ensemble members
frontogenesis(utc, level, ncdir, outdir, ncf=False, nct=False, dom=1, smooth=0, clvs=0, title=0, cmap='bwr', fig=False, ax=False, cb=True, match_nc=False, Nlim=False, Elim=False, Slim=False, Wlim=False)

Compute and plot Miller frontogenesis as d/dt of theta gradient.

Use a centred-in-time derivative; hence, if time index is start or end of wrfout file, skip the plot.

Parameters:
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • level (int,str) – required level. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • ncdir (str) – directory of netcdf data file
  • outdir (str) – directory to save output figures
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
  • f_suffix (bool,str) – custom filename suffix for output. Ignore if False.
  • bounding (dict) – bounding box for domain. Dictionary contains four keys (Nlim, Elim, Slim, Wlim) with float values (northern latitude limit, eastern longitude limit, southern latitude limit, western latitude limit, respectively).
  • smooth (int) – pass data through a Gaussian filter. Value of 1 is essentially `off’. Integer greater than zero is the degree of smoothing, in grid spacing.
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto
  • clvs (bool,numpy.ndarray) – contour levels for plotting. Generate using numpy.arange. False is automatic.
  • cmap (str) – matplotlib.cmap name. Pick a nice one from http://matplotlib.org/examples/color/ colormaps_reference.html
generate_times(itime, ftime, interval)

Wrapper for utility method WEM.utils.GIS_tools.generate_times(), so user can access this at the top level to loop over times.

get_cmap_clvs(vrbl, level, clvs=False, cmap=False)
get_level_string(level)

Makes sure user’s level input is a string. Saves typing hPa for the common usage of pressure levels.

Parameters:level (str,int) – desired level.
Returns:str
get_list(dic, key, default)

Fetch value from dictionary.

If it doesn’t exist, use default. If the value is an integer, make a list of one.

get_netcdf(ncdir, ncf=False, nct=False, dom=1, path_only=False)

Returns the WRFOut, ECMWF, or RUC instance.

Parameters:
  • ncdir – absolute path to directory that contains the netCDF file.
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • path_only (bool) – if True, return only absolute path to file. This is useful to loop over ensemble members and generate a list of files.
list_ncfiles(ncdirs, nct=False, ncf=False, dom=0, path_only=1)

Create list of absolute paths or objects* to netCDF files, given the list/tuple of directories they are in. If ambiguous, user needs to specify domain, and either the filename (if all identical) or initialisation time of the run (this needs to be the same for all files).

Note * that the object will be a WRFOut instance if netCDF is a wrfout file, RUC instance for RUC, or EC instance for ECMWF.

Parameters:
  • ncdirs (tuple,list) – absolute paths to directories containing netCDF files.
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • path_only – if True, return only strings to the files. if False, return the instances (RUC,EC,WRFOut).
Returns:

either a list of absolute path strings, or a list of instances (RUC,EC,WRFOut).

TODO: Deal with ambiguous selections.

make_1D(data, output='list')

Ensure input data is a time series of 1D values, and numpy array.

List of arrays -> Numpy array or list

meteogram(vrbl, loc, ncfiles, outdir=False, ncf=False, nct=False, dom=1)
plot2D(vrbl, utc, level=False, ncdir=False, outdir=False, ncf=False, nct=False, f_prefix=0, f_suffix=False, dom=1, plottype='contourf', smooth=1, fig=False, ax=False, clvs=False, cmap=False, locations=False, cb=True, match_nc=False, Nlim=False, Elim=False, Slim=False, Wlim=False, other=False, color='k', inline=False, lw=False, extend=False, save=True, accum_hr=False, cblabel=False, ideal=False)

Basic birds-eye-view plotting.

This script is top-most and decides if the variables is built into WRF default output or needs computing. It unstaggers and slices data from the wrfout file appropriately.

Parameters:
  • vrbl (str) – variable name as found in WRF, or one of the computed fields available in WEM
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • level (int,str,bool) – required level. Can be False if variable has no level. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • ncdir (str,bool) – directory of netcdf data file. False uses home directory.
  • outdir (str,bool) – directory to save output figures False uses home directory.
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
  • f_suffix (bool,str) – custom filename suffix for output. Ignore if False.
  • smooth (int) – pass data through a Gaussian filter. Value of 1 is essentially `off’. Integer greater than zero is the degree of smoothing, in grid spacing.
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto
  • clvs (bool,numpy.ndarray) – contour levels for plotting. Generate using numpy.arange. False is automatic.
  • cmap (str) – matplotlib.cmap name. Pick a nice one from http://matplotlib.org/examples/color/ colormaps_reference.html
  • locations (dict) – Locations to plot on the basemap. Format: locations = {‘label’:(lat,lon),etc}
  • cb (bool) – plot a colorbar.
  • match_nc (str) – Use domain from other netCDF file. Absolute path to this netCDF file.
  • Nlim (float) – north limit (latitude) for plot
  • Elim (float) – east limit (longitude) for plot
  • Slim (float) – south limit (latitude) for plot
  • Wlim (float) – west limit (longitude) for plot
Params plottype:
 

matplotlib command for plotting data (contour or contourf).

Returns:

None.

plot_accum_rain(utc, accum_hr, ncdir, outdir, ncf=False, nct=False, f_prefix=0, f_suffix=False, dom=1, plottype='contourf', smooth=1, fig=False, ax=False, clvs=False, cmap=False, locations=False, Nlim=False, Elim=False, Slim=False, Wlim=False)

Needs to be expanded to include other forms of precip. Plot accumulated precip (RAIN!) valid at time utc for accum_hr hours.

plot_axes_of_dilatation(utc, level=False, ncdir=False, outdir=False, ncf=False, nct=False, f_prefix=0, f_suffix=False, dom=1, plottype='contourf', smooth=1, fig=False, ax=False, clvs=False, cmap=False, locations=False, cb=True, match_nc=False, Nlim=False, Elim=False, Slim=False, Wlim=False, other=False)
plot_delta(vrbl, utc, level=False, ncdir1=False, ncdir2=False, outdir=False, ncf1=False, ncf2=False, nct=False, f_prefix=0, f_suffix=False, dom=1, plottype='contourf', smooth=1, fig=False, ax=False, clvs=False, cmap=False, locations=False, cb=True, match_nc=False, Nlim=False, Elim=False, Slim=False, Wlim=False, other=False)
plot_diff_energy(vrbl, energy, datadir, outdir, utc=False, dataf=False, outprefix=False, outsuffix=False, clvs=False, title=False, fig=False, ax=False, cb=False)

This function requires data already generated by WEM.postWRF.postWRF.stats.compute_diff_energy().

Parameters:
  • vrbl (str) – Vertically integrated (‘2D’) or summated over all dimensions (‘3D’).
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime). If false, loop over all times
  • energy (str) – DKE or DTE.
  • datadir (str) – directory holding computed data
  • outdir (str) – root directory for plots
  • dataf (str) – file name of data file, if ambiguous
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
  • f_suffix (bool,str) – custom filename suffix for output. Ignore if False.
  • clvs (bool,N.ndarray) – contour levels for plot. Generate with numpy.arange().
  • title (bool,str) – title for output
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto
plot_diff_energy_spectrum(energy, ncfiles, utc=False, outdir=False)

Compute total KE/TE and the power spectrum of DKE/DTE for a time.

plot_domains(ncdirs, labels, outdir, fname, Nlim, Elim, Slim, Wlim, colours='black', nct=False, ncf=False, fill_land=False, labpos=False, fill_water=False)

Plot only the domains for each netCDF file specified.

Parameters:
  • ncdirs (str,tuple,list) – Absolute paths to all netCDF directories, or one single absolute path if only one domain is to be plotted.
  • labels (str,tuple,list) – labels for each domain.
  • outdir (str) – directory to save output figures
  • Nlim (float) – north limit (latitude) for plot
  • Elim (float) – east limit (longitude) for plot
  • Slim (float) – south limit (latitude) for plot
  • Wlim (float) – west limit (longitude) for plot
  • colours (str,list,tuple) – colours for each domain box, in the same order as the ncdirs sequence (if more than one)
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
plot_error_growth(outdir, datadir, dataf=False, sensitivity=False, ylim=0, f_prefix=False, f_suffix=False)

Plots line graphs of DKE/DTE error growth varying by a sensitivity - e.g. error growth involving all members that use a certain parameterisation.

Requires data file in pickle format already produced by [method here].

Parameters:
  • datadir (str) – folder with pickle data
  • dataf (str) – data (pickle) filename if ambiguous
  • ensnames (list,tuple) – names of each ensemble member, e.g. the parameterisation scheme, the initial conditions used. This is used as the label for the plot legend.
  • ylim (list,tuple) – [min,max] for y axis range
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str

TODO: is sensitivity/ensnames variable OK to be optional?

plot_radar(utc, datadir, outdir=False, Nlim=False, Elim=False, Slim=False, Wlim=False, ncdir=False, nct=False, ncf=False, dom=1, composite=False, locations=False, fig=False, ax=False, cb=True, compthresh=False)

Plot verification radar.

composite allows plotting max reflectivity for a number of times over a given domain. This can show the evolution of a system.

Need to rewrite so plotting is done in birdseye.

plot_skewT(utc, ncdir=False, outdir=False, ncf=False, nct=False, f_prefix=False, f_suffix=False, latlon=False, dom=1, save_output=False, composite=0, ax=False, fig=False)

TODO: use Clicker instance if latlon is False.

Parameters:
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • ncdir (str) – directory of netcdf data file
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
Outdir:

directory to save output figures

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str :param latlon: (lat,lon) for plotting. If False, choose from

pop-up.
Parameters:
  • dom (int) – WRF domain to plot from.
  • save_output (bool) – not sure why this here? TODO
  • composite (list,tuple,bool) – If not False, plot numerous Skew-Ts on the same graph. List is absolute paths to netCDF files.
plot_streamlines(utc, level, ncdir, outdir, ncf=False, nct=False, f_prefix=False, f_suffix=False, dom=1, smooth=1, fig=False, ax=False, bounding=False, density=1.8, ideal=False)

Plot streamlines of wind at a level.

Parameters:
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • level (int,str) – required level. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • ncdir (str) – directory of netcdf data file
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
Outdir:

directory to save output figures

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str :param bounding: bounding box for domain.

Dictionary contains four keys (Nlim, Elim, Slim, Wlim) with float values (northern latitude limit, eastern longitude limit, southern latitude limit, western latitude limit, respectively).
Parameters:
  • smooth (int) – pass data through a Gaussian filter. Value of 1 is essentially `off’. Integer greater than zero is the degree of smoothing, in grid spacing.
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto

TODO: extra kwargs to account for arrow size, density, etc.

plot_strongest_wind(itime, ftime, level=2000, ncdir=False, outdir=False, ncf=False, nct=False, f_prefix=False, f_suffix=False, bounding=False, dom=1, clvs=False, fig=False, ax=False, cb=True, extend='max', cmap='jet', save=True)

Plot strongest wind at level between itime and ftime.

Parameters:
  • itime (tuple,list,int) – initial time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • ftime (tuple,list,int) – final time. Same format as itime.
  • level (int,str) – required level. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • ncdir (str) – directory of netcdf data file
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.
Outdir:

directory to save output figures

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str :param bounding: bounding box for domain.

Dictionary contains four keys (Nlim, Elim, Slim, Wlim) with float values (northern latitude limit, eastern longitude limit, southern latitude limit, western latitude limit, respectively).
Parameters:dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
plot_xs(vrbl, utc, ncdir, outdir, latA=0, lonA=0, latB=0, lonB=0, ncf=False, nct=False, f_prefix=0, f_suffix=0, dom=1, clvs=False, ylim=False, ztop=8, cmap='jet', contour_vrbl='skip', contour_clvs=False, avepts=False, shiftpts=False, cftix=False, cflabel=False)

Plot cross-section.

If no lat/lon transect is indicated, a popup appears for the user to pick points. The popup can have an overlaid field such as reflectivity to help with the process.

Parameters:
  • vrbl (str) – variable name as found in WRF, or one of the computed fields available in WEM
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • ncdir (str) – directory of netcdf data file
  • outdir (str) – directory to save output figures
  • latA (bool,float) – latitude of transect start point. False triggers a pop-up box.
  • lonA – longitude of transect start point. False triggers a pop-up box.
  • latB (bool,float) – latitude of transect end point. False triggers a pop-up box.
  • lonB (bool,float) – longitude of transect end point. False triggers a pop-up box.
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str :param dom: domain for plotting (for WRF data).

If zero, the only netCDF file present will be plotted.
Parameters:
  • clvs (numpy.ndarray,bool) – contouring for the variable plotted. False is automatic. Generate the numpy.ndarray with numpy.arange().
  • ylim (list,tuple,bool) – [min,max] (in km) altitude to plot. False is automatic (all model levels)
probability_threshold(ensemble, vrbl, overunder, threshold, itime, ftime, smooth=False, level=2000, outdir=False, f_prefix=False, f_suffix=False, bounding=False, dom=1, clvs=False, fig=False, ax=False, cb=True)

Create threshold contour plots.

spaghetti(vrbl, utc, level, contour, ncdirs, outdir, bounding=False, dom=1)

Do a multi-member spaghetti plot, contouring a value of a given variable.

Parameters:
  • vrbl (str) – variable name as found in WRF, or one of the computed fields available in WEM
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • level (int,str) – required level. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • contour (float,int) – contour to draw for data
  • ncdirs (list,tuple) – directories of netcdf data file
  • outdir (str) – directory to save output figures
  • bounding (dict) – bounding box for domain. Dictionary contains four keys (Nlim, Elim, Slim, Wlim) with float values (northern latitude limit, eastern longitude limit, southern latitude limit, western latitude limit, respectively).
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
std(vrbl, utc, level, ncdirs, outdir, ncf=False, nct=False, f_prefix=False, f_suffix=False, bounding=False, smooth=1, dom=1, plottype='contourf', fig=False, ax=False, clvs=False, cmap='jet')

Plot standard deviation of all members for given variable.

Parameters:
  • vrbl (str) – variable name as found in WRF, or one of the computed fields available in WEM
  • utc (tuple,list,int) – one date/time. The tuple/list format is YYYY,MM,DD,HH,MM,SS (ready for calendar.timegm). Integer format is epoch/datenum (ready for time.gmtime).
  • level (int,str) – required level. Lowest model level is integer 2000. Pressure level is integer in hPa, e.g. 850. Isentropic surface is a string + K, e.g. ‘320K’. Geometric height is a string + m, e.g. ‘4000m’.
  • ncdirs – directories of netcdf data files for all ensemble members. If not ambiguous, user needs to specify either ncf (if all data files have the same name) or nct (they need to have the same start time).
  • outdir (str) – directory to save output figures
  • ncf (bool,str) – filename of netcdf data file if ambiguous within ncdir. If no wrfout file is explicitly specified, the netCDF file in that folder is chosen if unambiguous.
  • nct (bool,str) – initialisation time of netcdf data file, if ambiguous within ncdir.
  • f_prefix (bool,str) – custom filename prefix for output. Ignore if False.

:param f_suffix custom filename suffix for output. Ignore if False. :type f_suffix bool,str :param bounding: bounding box for domain.

Dictionary contains four keys (Nlim, Elim, Slim, Wlim) with float values (northern latitude limit, eastern longitude limit, southern latitude limit, western latitude limit, respectively).
Parameters:
  • smooth (int) – pass data through a Gaussian filter. Value of 1 is essentially `off’. Integer greater than zero is the degree of smoothing, in grid spacing.
  • dom (int) – domain for plotting (for WRF data). If zero, the only netCDF file present will be plotted.
  • fig (bool,matplotlib.figure) – value of False will create new figure. A value of matplotlib.figure object will plot data onto this figure (similarly for axis, below).
  • ax (bool,matplotlib.axis) – matplotlib.axis object to plot onto
  • clvs (bool,numpy.ndarray) – contour levels for plotting. Generate using numpy.arange. False is automatic.
  • cmap (str) – matplotlib.cmap name. Pick a nice one from http://matplotlib.org/examples/color/ colormaps_reference.html
Params plottype:
 

matplotlib command for plotting data (contour or contourf).

twopanel_profile(vrbl, utc, enspaths, outdir, two_panel=1, dom=1, mean=1, std=1, xlim=False, ylim=False, latlon=False, locname=False, overlay=False, ml=-2)

Create two-panel figure with profile location on map, with profile of all ensemble members in comparison.

Parameters:
  • vrbl (str) – WRF variable or computed quantity
  • utc (int,list,tuple) – date/time
  • enspaths (list,tuple) – absolute paths to all netCDF files for each ensemble member.
  • outdir (str) – directory for plot output
  • two_panel (bool) – Add extra panel of location if True.
  • dom (int) – WRF domain to use
  • mean (bool) – plot ensemble mean of variable
  • std (bool) – plot ensemble standard deviate of variable (+/- 1 sigma)
  • xlim (bool,tuple,list) – x-axis limit. False is automatic.
  • ylim (bool,tuple,list) – y-axis limit, False is automatic.
  • latlon (bool,tuple,list) – (lat,lon) for plotting. If this is False, a pop-up window will allow user to choose location.
  • locname (str) – this is passed to the filename of output figure when saved, to differentiate similar plots of different locations.
  • overlay (str) – data from the same time to overlay on inset basemap. E.g. radar reflectivity. TODO: this is only cref right now (bool)
  • ml (int) – member level. Negative number that corresponds to the folder in the absolute path string, for naming purposes. Useful for file naming, labelling.

WEM.postWRF.postWRF.map module

class WEM.postWRF.postWRF.map.Map(nc=False, ax=0, fig=0, plotn=(1, 1), layout='normal')

Bases: WEM.postWRF.postWRF.figure.Figure

C : configuration settings W : data

plot_domains(wrfouts, labels, latlons, colour=0)

wrfouts : list of wrfout file paths latlons : dictionary of Nlim,Elim,Slim,Wlim

for plot

WEM.postWRF.postWRF.maps module

WEM.postWRF.postWRF.maps.plot_domains(wrfouts, labels, outpath, Nlim, Elim, Slim, Wlim, colours='k', fname=False, fill_land=False, labpos=False, fill_water=False)

wrfouts : list of wrfout file paths

WEM.postWRF.postWRF.obs module

Scripts related to plotting of observed data, such as surface observations, radar reflectivity, severe weather reports.

class WEM.postWRF.postWRF.obs.Obs(fpath)

Bases: object

An instance represents a data set.

class WEM.postWRF.postWRF.obs.Radar(utc, datapath)

Bases: WEM.postWRF.postWRF.obs.Obs

Composite radar archive data from mesonet.agron.iastate.edu.

Parameters:
  • datapath (str) – Absolute path to folder or .png file
  • wldpath (str) – Absolute path to .wld file
  • fmt (str) – format of data - N0Q or N0R
generate_basemap(fig, ax, Nlim=False, Elim=False, Slim=False, Wlim=False)

Generate basemap.

Parameters:ax (matplotlib.basemap?) – The axis on which to create the basemap
get_dBZ(data)
get_radar_fname()
get_radar_url()
get_subdomain(Nlim, Elim, Slim, Wlim, overwrite=False)

Return data array between bounds

If overwrite is True, replace class data with new subdomain

plot_radar(outdir, fig=False, ax=False, fname=False, Nlim=False, Elim=False, Slim=False, Wlim=False, cb=True)

Plot radar data.

class WEM.postWRF.postWRF.obs.SPCReports(utc, datadir, wind=True, hail=True, torn=True)

Bases: WEM.postWRF.postWRF.obs.Obs

plot_reports(fig=False, ax=False)
report_datenum(timestamp)

convert timestamp to datenum format.

class WEM.postWRF.postWRF.obs.StormReports(fpath)

Bases: WEM.postWRF.postWRF.obs.Obs

convert_times()
plot(reports, itime, ftime, fname, outdir, Nlim=False, Elim=False, Slim=False, Wlim=False, annotate=True, fig=False, ax=False, ss=50, color='blue')

WEM.postWRF.postWRF.ruc module

class WEM.postWRF.postWRF.ruc.RUC(fpath, wrfdir=False)

Bases: WEM.postWRF.postWRF.wrfout.WRFOut

config : configuration settings t : time, datenum format

optional key-word arguments: wrfdir : if picked, domain is cut down

basemap_setup(**kwargs)
check_compute(vrbl)

OVERRIDE WRFOUT VERSION

colocate_WRF_map(wrfdir)
compute_shear_old(nc, **kwargs)

top and bottom in km. kwargs[‘top’] kwargs[‘bottom’]

compute_wind10_2(nc)

Version ‘3’ for RAP has U10 and V10

cut_2D_array(data_in)

Return a smaller array of data depending of specified limits

cut_lat_lon()

Return a smaller array of data depending of specified limits

get_MAYBE(vrbl, utc=False, level=False, lats=False, lons=False, smooth=1, other=False)

Overwrite WRFOut method here.

get_OLD(va, **kwargs)
get_fname()
get_grid_spacing()
get_key(vrbl)

Returns the netcdf key for the desired variable

get_latlon()
get_p(vrbl, tidx, level, lonidx, latidx)
get_time_seq()

Makes sure time is time sequence (YYYY,MM,DD,HH,MM,SS)

get_utc_time(rawtime, fmt='datenum')
get_version()
load(vrbl, tidx, lvidx, lonidx, latidx)

OVERRIDE WRFOUT VERSION

plot(variables, lv, **kwargs)
plot_streamlines(va, lv, **kwargs)
plot_variable(va, lv, **kwargs)

WEM.postWRF.postWRF.rucplot module

WEM.postWRF.postWRF.sal module

class WEM.postWRF.postWRF.sal.SAL(Wctrl_fpath, Wmod_fpath, vrbl, utc, lv=False, accum_hr=False, radar_datadir=False, thresh=False, footprint=500, ctrl_fmt='obs', mod_fmt='WRF', dx=False, dy=False, f=0.06666666666666667, datafmt=False)

Bases: object

active_px(data='ctrl', fmt='pc')

Return number of pixels included in chosen dataset’s objects. data is set to ‘ctrl’ or ‘mod’. Expressed as percentage.

compute_L1()
compute_L2()
compute_V(dic)
compute_amplitude()
compute_d()
compute_location()
compute_r(dic)
compute_structure()
get_radar_verif(utc, datapath)
identify_objects()
object_operators(dic, typ=False)
vector_diff_km(v1, v2)
vrbl = None

fig, ax = plt.subplots(1) ax.pcolor(self.C[‘data’]) fig.savefig(‘/home/jrlawson/public_html/bowecho/SALtests/obs_pcolor.png’) plt.close(fig) fig, ax = plt.subplots(1) ax.pcolor(self.M[‘data’]) fig.savefig(‘/home/jrlawson/public_html/bowecho/SALtests/mod_pcolor.png’) plt.close(fig) import pdb; pdb.set_trace()

WEM.postWRF.postWRF.scales module

This file contains colorbar scales for plotting.

INPUTS

va : variable to be plotted lv : level to be plotted

OUTPUTS

cm : colour map clvs : contour levels

Level = 2000 indicates surface.

Default settings are listed at the bottom. These can be overwritten in user’s config file... somehow

class WEM.postWRF.postWRF.scales.Scales(vrbl, lv, clvs=0)

Bases: object

find_nearest_level(lv)
get_dict_of_levels()
get_multiplier(vrbl, lv)

WEM.postWRF.postWRF.skewt module

class WEM.postWRF.postWRF.skewt.Profile(nc=0)

Bases: WEM.postWRF.postWRF.figure.Figure

composite_profile(va, plot_time, plot_latlon, wrfouts, outpath, dom=1, mean=True, std=True, xlim=False, ylim=False, fig=False, ax=False, locname=0, ml=-2)

Loop over wrfout files. Get profile of variable Plot all members

Optional standard deviation Optional mean

If ax, save image to that axis

ml : member level. negative number that corresponds to the
folder in absolute string for naming purposes.
class WEM.postWRF.postWRF.skewt.SkewT(nc=False)

Bases: WEM.postWRF.postWRF.figure.Figure

dewpoint(nc, time, y, x, P, linestyle='dashed', color='black')
dewpoint_real(td, P, color='red', linestyle='dashed')
dry_adiabats()
e(w, p)

Returns vapor pressure (Pa) at mixing ratio w (kg/kg) and pressure p (Pa) Formula 2.18 in Rogers&Yau

es(T)

Returns saturation vapor pressure (Pascal) at temperature T (Celsius) Formula 2.17 in Rogers&Yau

gamma_s(T, p)

Calculates moist adiabatic lapse rate for T (Celsius) and p (Pa) Note: We calculate dT/dp, not dT/dz See formula 3.16 in Rogers&Yau for dT/dz, but this must be combined with the dry adiabatic lapse rate (gamma = g/cp) and the inverse of the hydrostatic equation (dz/dp = -RT/pg)

gettime()
isobars()
isotherms()
moist_adiabats()
plot_skewT(plot_time, plot_latlon, dom, outpath, save_output=0, save_plot=1)
return_data(whichdata, nc, time, y, x, thin_locs, P=None)
skewT_composite()

Open pickle files from multiple soundings Find mean Td/T

skewnessTerm(P)
td(e)

Returns dew point temperature (C) at vapor pressure e (Pa) Insert Td in 2.17 in Rogers&Yau and solve for Td

temperature(nc, time, y, x, P, linestyle='solid', color='black')
temperature_real(T, P, color='red', linestyle='dashed')
windbarbs(nc, time, y, x, P, thin_locs, n=45.0, color='black')
windbarbs_real(uwind, vwind, P, delta=3, color='red', n=37.5)

WEM.postWRF.postWRF.stats module

Scripts involving statistics or data manipulation here.

WEM.postWRF.postWRF.stats.DE_xyz(nc0, nc1, t_idx, energy, *args)

Computation for difference kinetic energy (DKE). Sums DKE over the 3D space, returns a time series.

Destaggering is not enabled as it introduces computational cost that is of miniscule value considering the magnitudes of output values.

Inputs:

nc0 : netCDF file nc1 : netCDF file t_idx : times indices to difference energy : kinetic or total *args : to catch lower/upper boundary which isn’t relevant here

Outputs:

data : time series.

WEM.postWRF.postWRF.stats.DE_z(nc0, nc1, t, energy, lower, upper)

Computation for difference kinetic energy (DKE). Sums DKE over all levels between lower and upper, for each grid point, and returns a 2D array.

Destaggering is not enabled as it introduces computational cost that is of miniscule value considering the magnitudes of output values.

Method finds levels nearest lower/upper hPa and sums between them inclusively.

Inputs:

nc0 : netCDF file nc1 : netCDF file t : times index to difference energy : kinetic or total lower : lowest level, hPa upper : highest level, hPa

Outputs:

data : 2D array.

WEM.postWRF.postWRF.stats.DKE_power_spectrum(data, dx)

Return power spectrum of DKE/DTE at time(s) for wavelengths.

WEM.postWRF.postWRF.stats.compute_diff_energy(ptype, energy, files, times, upper=None, lower=None, d_save=True, d_return=True, d_fname='diff_energy_data')

This method computes difference kinetic energy (DKE) or different total energy (DTE, including temp) between WRFout files for a given depth of the atmosphere, at given time intervals

Parameters:
  • ptype – ‘2D’ or ‘3D’. ‘2D’ integrates vertically between lower and upper hPa and creates a time series. ‘3D’ integrates over the 3D space (again between the upper and lower bounds) and creates 2D arrays.
  • energy – ‘DKE’ or ‘DTE’
  • upper – upper limit of vertical integration
  • lower – lower limit of vertical integration
  • files – abs paths to all wrfout files
  • times – times for computations - tuple format
  • d_save – save dictionary to folder (path to folder)
  • d_return – return dictionary (True or False)
  • d_fname – custom filename
Returns:

N.ndarray – time series or list of 2D arrays

WEM.postWRF.postWRF.stats.gauss_kern(size, sizey=None)

Taken from scipy cookbook online. Returns a normalized 2D gauss kernel array for convolutions

WEM.postWRF.postWRF.stats.gauss_smooth(data, n, ny=None, pad=1, pad_values=0)

Taken from scipy cookbook online. Blur the data by convolving with a gaussian kernel of typical size n. The optional keyword argument ny allows for a different size in the y direction.

Parameters:
  • data (N.ndarray) – data (2D only?)
  • pad (bool) – put zeros on edge of length n so that output array equals input array size.
  • pad_values (int,float) – if pad, then use this value to fill edges.
WEM.postWRF.postWRF.stats.max_filter(data, size=11, shape='circle')

blah

WEM.postWRF.postWRF.stats.std(ncfiles, vrbl, utc=False, level=False, other=False, axis=0)

Find standard deviation in along axis of ensemble members. Returns matrix x-y for plotting

WEM.postWRF.postWRF.stats.std_ttest(ncfiles1, ncfiles2, vrbl, utc=False, level=False, other=False, th=0)

Find standard deviation in along axis of ensemble members. Returns matrix x-y for plotting. Returns sig test

WEM.postWRF.postWRF.ts module

Create time series of variable(s) for certain period at location.

Can use .TS files (?) Can use model output.

class WEM.postWRF.postWRF.ts.TimeSeries(ensemble, latlon, locname)

Bases: object

meteogram(vrbl, utc=False, outdir=False, ncf=False, nct=False, dom=1)

WEM.postWRF.postWRF.wrfout module

Compute or load data from netCDF file.

Dimensions of 4D variable X are X.dimensions: (Time,bottom_top,south_north,west_east_stag) Time, levels, latitude, longitude

class WEM.postWRF.postWRF.wrfout.WRFOut(fpath)

Bases: object

An instance of WRFOut contains all the methods that are used to access and process netCDF data.

Initialisation fetches and computes basic user-friendly variables that are most oftenly accessed.

Parameters:fpath (str) – absolute path to netCDF4 (wrfout) file
check_compute(vrbl)

This method returns the required variables that need to be loaded from the netCDF file.

Parameters:vrbl (str) – WRF variable desired
Returns:bool – True if variable exists in wrfout file. False if the variable needs computing.
check_destagger(var)

Looks up dimensions of netCDF file without loading data.

Returns dimension number that requires destaggering

check_vcs(z1, z2, exception=1)

Check the vertical coordinate systems

If identical, return the system If not, raise an exception.

cold_pool_depth(dpt, heights, dpt_env)
cold_pool_strength(X, time, swath_width=100, env=0, dz=0)

Returns array the same shape as WRF domain.

X : cross-section object with given path
This path goes front-to-back through a bow

km : width in the line-normal direction env : (x,y) for location to sample environmental dpt

compute(vrbl, tidx, lvidx, lonidx, latidx, other, lookup=0)

Look up method needed to return array of data for required variable.

Keyword arguments include settings for computation e.g. top and bottom of shear computation

Parameters:
  • vrbl (str) – variable name
  • tidx (int,list,tuple,numpy.ndarray) – time index/indices
lookup : enables a check to see if something can be
computed. Returns true or false.
compute_C2(x, y, dpt, heights, dpt_env)

C^2 as found in James et al. 2006 MWR

x : x location in domain y : y location in domain dpt : density potential temperature slice heights : height AGL slice dpt_env : environmental dpt, column

compute_CAPE(tidx, lvidx, lonidx, latidx, other)

INCOMPLETE!

CAPE method based on GEMPAK’s pdsuml.f function

Inputs:

tidx,lvidx,lonidx,latidx : dictionary of level/time/lat/lon

Outputs: CAPE : convective available potential energy CIN : convective inhibition

compute_DCAPE()
compute_DCP()

Derecho Composite Parameter (Evans and Doswell, 2001, WAF) And info from SPC Mesoanalyses

compute_PMSL_gradient(tidx, lvidx, lonidx, latidx, other)
compute_Q_pert(tidx, lvidx, lonidx, latidx, other)
compute_REFL_comp(tidx, lvidx, lonidx, latidx, other)
compute_RH(tidx, lvidx, lonidx, latidx, other)
compute_T2_gradient(tidx, lvidx, lonidx, latidx, other)
compute_T2_pertub(tidx, lvidx, lonidx, latidx, other)
compute_Td(tidx, lvidx, lonidx, latidx, other)

Using HootPy equation

compute_Td_2(tidx, lvidx, lonidx, latidx, other='C')

Another version of Td From p70 Djuric Weather Analysis

compute_accum_rain(utc, accum_hr)

Needs to be expanded to include other precip

compute_ave(va, z1, z2)

Compute average values for variable in layer

Inputs: va : variable z1 : height at bottom z2 : height at top

Output: data : the averaged variable

compute_buoyancy(tidx, lvidx, lonidx, latidx, other=False)

Method from Adams-Selin et al., 2013, WAF

compute_comp_ref(tidx, lvidx, lonidx, latidx, other)

Amend this so variables obtain at start fetch only correct date, lats, lons All levels need to be fetched as this is composite reflectivity

compute_cpdz(x, y, dpt, heights, dpt_env)

Cold pool depth

x : x location in domain y : y location in domain dpt : density potential temperature slice heights : height AGL slice dpt_env : environmental dpt, column

compute_density(tidx, lvidx, lonidx, latidx, other)
compute_derivatives(U, V)
compute_divergence(U, V)
compute_dpt(tidx, lvidx, lonidx, latidx, other)

Potential: if surface level is requested, choose sigma level just about the surface. I don’t think this affects any other dictionaries around...

compute_dptp(tidx, lvidx, lonidx, latidx, other)
compute_dryairmass(tidx, lvidx, lonidx, latidx, other)
compute_drybulb(tidx, lvidx, lonidx, latidx, other='K')
compute_fluid_trapping_diagnostic(tidx, lvidx, lonidx, latidx, other)
compute_frontogenesis(time, level)

Note that all variables fetched with self.get have been destaggered and are at the same location.

Output: Front : Frontgenesis in Kelvin per second.

compute_geopotential(tidx, lvidx, lonidx, latidx, other)
compute_geopotential_height(tidx, lvidx, lonidx, latidx, other)
compute_instantaneous_local_Lyapunov(tidx, lvidx, lonidx, latidx, other)
compute_mixing_ratios(tidx, lvidx, lonidx, latidx, other=False)
compute_olr(tidx, lvidx, lonidx, latidx, other)
compute_omega(tidx, lvidx, lonidx, latidx, other)
compute_pmsl(tidx, lvidx, lonidx, latidx, other)
compute_pressure(tidx, lvidx, lonidx, latidx, other)
compute_qtotal(tidx, lvidx, lonidx, latidx, other)
compute_satvappres(tidx, lvidx, lonidx, latidx, other)
compute_shear(tidx, lvidx, lonidx, latidx, other=False)
Params other:dictionary of ‘top’ and ‘bottom’ levels, km

Could make this faster with numpy.digitize()?

compute_shear_deformation(U, V)
compute_simref_atlevel(level=1)
compute_spechum(tidx, lvidx, lonidx, latidx, other)
compute_stretch_deformation(U, V)
compute_strongest_wind(tidx, lvidx, lonidx, latidx, other)

Pass the array of time indices and it will find the max along that axis.

compute_temp_advection(tidx, lvidx, lonidx, latidx, other)
compute_theta(tidx, lvidx, lonidx, latidx, other)
compute_thetae(tidx, lvidx, lonidx, latidx, other)
compute_total_deformation(U, V)
compute_vappres(tidx, lvidx, lonidx, latidx, other)
compute_vorticity(U, V)
compute_wind(tidx, lvidx, lonidx, latidx, other)
compute_wind10(tidx, lvidx, lonidx, latidx, other)
create_slice(vrbl, tidx, lvidx, lonidx, latidx, dim_names)

Create slices from indices of level, time, lat, lon. False mean pick all indices.

destagger(data, ax)

Destagger data which needs it doing.

data : numpy array of data requiring destaggering ax : axis requiring destaggering

Theta always has unstaggered points in all three spatial dimensions (axes=1,2,3).

Data should be 4D but just the slice required to reduce unnecessary computation time.

Don’t destagger in x/y for columns

edit_namelist(fpath, old, new, incolumn=1, col=23)

col=23 is default for wps namelists.

find_gust_front(wind_slice, T2_slice, angle, method=3)

Find location of maximum shear in the horizontal wind along a 1D slice.

wind_slice : 1D numpy array T2_slice : temp 2m slice angle : angle of slice cross-section method : way to locate gust front

get(vrbl, utc=False, level=False, lats=False, lons=False, smooth=1, other=False)

Get data.

Will interpolate onto pressure, height coordinates if needed. Will smooth if needed.

Parameters:
  • vrbl (str) – WRF or computed variable required
  • utc – indices (<500): integer/N.ndarray of integers. time tuple: 6-item tuple or list/tuple of these. datenum: integer >500 or list of them.

Level: * indices: integer or N.ndarray of integers * pressure: string ending in ‘hPa’ * height: string ending in ‘m’ or ‘km’ * isentropic: string ending in ‘K’

Lats: * indices: integer or N.ndarray of integers * lats: float or N.ndarray of floats

Lons: * indices: integer or N.ndarray of integers * lons: float or N.ndarray of floats

get_XY(lat, lon)

Return grid indices for lat/lon pair.

get_dims(var)
get_lat_idx(lat)
get_limited_domain(da, skip=1, return_array='idx')

Return smaller array of lats, lons depending on input dictionary of N, E, S, W limits.

skip : for creating thinned domains return_type : if idx, return array of idx

if slice, return slice only if latlon, return lat/lon values
get_limits()
get_lon_idx(lon)
get_missing_axes(dims)
get_p(vrbl, tidx=False, level=False, lonidx=False, latidx=False)

Return an pressure level isosurface of given variable. Interpolation is linear so watch out.

Dimensions returns as (height,lat,lon) Or is it (height,lon, lat!?)

TODO: Need to include limited domain functionality

if vrbl==’pressure’,create constant grid.

get_time_idx(utc)
Parameters:utc (tuple,list,int) – time
Returns tidx:int – closest index to desired time
interp_to_p_fortran(config, nc_path, var, lv)

Uses p_interp fortran code to put data onto a pressure level specified.

Input: config : contains directory of p_interp files nc_path : path to original netCDF file data var : variable(s) to compute lv : pressure level(s) to compute

Returns: fpath : path to new netCDF file with p co-ords

load(vrbl, tidx, lvidx, lonidx, latidx)

Fetch netCDF data for a given variable, for given time, level, latitude, and longitude indices.

Parameters:
  • vrbl (str) – WRF variable
  • tidx (bool,int,numpy.ndarray) – time index. False fetches all.
  • lvidx (boot, int, numpy.ndarray) – level index. False fetches all

TODO: Get rid of integer arguments earlier in the method chain, and make them single-element numpy arrays.

make_4D(datain, vrbl=False, missing_axis=False)

If vrbl, look up the wrfout file’s variable dimensions and adjust accordingly to get into 4D structure. If not vrbl, for instance a computed variable, the user needs to specify which axes are missing in a tuple.

return_axis_of_dilatation_components(tidx, lvidx=False, lonidx=False, latidx=False, other=False)
return_tbl()

Returns a dictionary to look up method for computing a variable

return_tidx_range(utc0, utc1)

Give a start and end time. Returns an array of all indices. Useful for self.get() to return an array of data with all times between utc0 and utc1.

wrftime_to_datenum()

Convert wrf’s weird Times variable to datenum time.

WEM.postWRF.postWRF.xsection module

Create cross-sections through WRF data.

This can be time-height or distance-height. The height can be pressure, model, geometric, or geopotential

The output can be saved to a pickle file. This can be useful for creating composites

Input lat/lon can be either specified or from x,y co-ords calculated from manually clicking on a map with overlaid data (reflectivity, etc).

class WEM.postWRF.postWRF.xsection.CrossSection(wrfout, latA=0, lonA=0, latB=0, lonB=0)

Bases: WEM.postWRF.postWRF.figure.Figure

create_linenormal_xs(x, y, length_pts=3)

Return a cross-section that runs normal to the existing cross-section contained in self.

x,y : coordinates of intersection length_pts : length of normal line in grid points

draw_transect(outpath, fname, radar=True)
get_height(t, x, y, z, pts)

Return terrain heights along cross-section

TODO: What’s the diff between the outputs?

Inputs: t : time index as int x : x indices, as int y : y imdices, as int z : number of levels, as int pts : number of points along the x-sec

Outputs: terrain_z : ter0,rain height heighthalf : who knows?

Assuming t=0

get_latlon_from_xy(x, y)

Look up lat/lon in wrfout file from x and y coordinates.

get_wrfout_slice(vrbl, utc=False, level=False, x=False, y=False)
get_xs_slice()
get_xy_from_latlon(lat, lon)

Return x and y coordinates for given lat/lon.

exactlat, exactlon : exact coordinates of closest x/y

interp(geopot, pres, p)

Returns the interpolated geopotential at p using the values in pres. The geopotential for an element in pres must be given by the corresponding element in geopot. The length of the geopot and pres arrays must be the same.

mouseclick(event)
plot_average(vrbl, avepts, ttime, outpath, clvs=0, ztop=0, f_suffix=False, cmap='jet', contour_vrbl='skip', contour_clvs=False, cflabel=False, cftix=False)
plot_xs(vrbl, ttime, outpath, clvs=0, ztop=0, f_suffix=False, cmap='jet', contour_vrbl='skip', contour_clvs=False)

Inputs: vrbl : variable to plot, from this list:

parawind,perpwind,wind,U,V,W,T,RH,

ttime : time in ... format outpath : absolute path to directory to save output

popup_transect()

Pops up window for user to select start and end point for the cross-section.

Optional: this map can be overlaid with data to better guide the decision.

Optional: the transect can be saved as an image with/without the overlaid data, useful for publication.

translate_xs(sh)

Translate the cross-section up or down a certain number of points. For simplicity with grid spacing, the logic allows for 45 degree translation only.

sh : number of points to shift

Module contents

In main you will find the heart at the controls of the public API, which hides more complicated stuff from the user.