pyatoa.visuals.wave_maker

Waveform plotting functionality

Produces waveform plots from stream objects and plots misfit windows outputted by Pyflex as well as adjoint sources from Pyadjoint. Flexible to allow for only waveform plots, or for the addition of objects based on inputs.

Module Contents

Classes

WaveMaker

Standardized waveform figures featuring observed and synthetic traces,

Functions

align_yaxes(ax1, ax2)

Plotting tool to adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1

pretty_grids(input_ax[, twax, grid, fontsize, ...])

Standard plot skeleton formatting, thick lines and internal tick marks etc.

format_axis(input_ax[, percent_over])

Ensure that the upper and lower y-bounds are the same value

Attributes

rejected_window_colors

pyatoa.visuals.wave_maker.rejected_window_colors[source]
class pyatoa.visuals.wave_maker.WaveMaker(mgmt, **kwargs)[source]

Standardized waveform figures featuring observed and synthetic traces, STA/LTA waveforms, misfit windows, rejected windows, adjoint sources and auxiliary information collected within the workflow.

WAVEFORM KEYWORD ARGUMENTS:

FIGURE: figsize (tuple): size of the figure, defaults (800, 200) pixels

per channel

dpi (float): dots per inch of the figure, defaults 100 legend_fontsize (int): size linewidth (float): line width for all lines on plot, default 1.6 axes_linewidth (float): line width for axis spines, default 1 xlim_s (list): time-axis bounds of the plot in seconds, def full trace figure (pyplot.Figure): an existing figure object to plot to, rather

than generating a new figure

subplot_spec (gridspec.GridSpec): an overlying grid that waveforms

will be plotted into. Useful for combining waveform plots

FONTSIZE: fontsize (int): font size of the title, axis labels, def 8 axes_fontsize (int): font size of the tick labels, def 8 rejected_window_fontsize (int): fontsize for the annotations that

describe the rejected windows, default 6

window_anno_fontsize (str): fontsize for window annotation, def 7

COLORS: obs_color (str): color for observed waveform, defaults ‘k’ syn_color (str): color for synthetic waveform, defaults ‘r stalta_color (str): color of stalta waveform, default ‘gray’ window_color (str): color for misfit windows, default ‘orange’ adj_src_color (str): color for adjoint sources, default ‘g’

ADJOINT SOURCE adj_src_linestyle (str, tuple): adjoint souce style, default tight dash adj_src_alpha (float): opacity of adjoint source, default 0.4

WINDOW ANNOTATIONS: window_anno (str): a custom string which can contain the optional

format arguemnts: [max_cc, cc_shift, dlnA, left, length]. None, defaults to formatting all arguments

window_anno_alternate (str): custom string for all windows that

aren’t the first window, useful for dropping the labels for parameters, allows for cleaner annotations without compromising readability

window_anno_height (float): annotation height, percentage of y axis,

default 0.7

alternate_anno_height (float): optional, shift the annotation height

each window to prevent overlapping annotations

window_anno_rotation (float): rotation of annotation (deg), def 0 window_anno_fontcolor (str): color of annotation text, def ‘k’ window_anno_fontweight (str): weight of font, default ‘normal’ window_anno_bbox (dict): bbox dict for window annotations, None means

no bounding box

TOGGLES: plot_xaxis (bool): toggle the labels and ticks on the x axis, def True plot_yaxis (bool): toggle the labels and ticks on the y axis, def True plot_windows (bool): toggle window plotting, default True plot_rejected_windows (bool): toggle rejected window plot, default T plot_window_annos (bool): toggle window annotations, default True plot_staltas (bool): toggle stalta plotting, default True plot_adjsrcs (bool): toggle adjoint source plotting, default True plot_waterlevel (bool): toggle stalta waterlevel plotting, def True plot_arrivals (bool): toggle phase arrival plotting, default True plot_legend (bool): toggle legend, default True

MISC: normalize (bool): normalize waveform data before plotting set_title (bool or str): create a default title using workflow

parameters, if str given, overwrites all title

append_title(str): User appended string to the end of the title.

useful to get extra information on top of the default title

setup_plot(dpi, figsize, twax_off=False)[source]

Dynamically set up plots according to number_of given

Calculate the figure size based on DPI, (800, 250) pixels per channel

Parameters:
  • dpi (float) – dots per inch, to be set by plot()

  • figsize (tuple) – size of the figure, set by plot()

  • twax_off (bool) – if True, dont instantiate a twin-x axis

Rtype (tw)axes:

matplotlib axes

Return (tw)axes:

axis objects

plot_waveforms(ax, obs, syn, normalize=False)[source]

Plot observed and synthetic data on the same axis, label them according to their trace ID

Parameters:
  • ax (matplotlib.axes.Axes) – axis object on which to plot

  • obs (obspy.core.trace.Trace) – observed waveform data to plot

  • syn (obspy.core.trace.Trace) – synthetic waveform data to plot

  • normalize (bool) – option to normalize the data traces between [-1, 1], defaults to False, do not normalize

plot_stalta(ax, stalta, plot_waterlevel=True)[source]

Plot the Short-term-average/long-term-average waveform to help visually identify the peaks/troughs used to determine windows

Parameters:
  • ax (matplotlib.axes.Axes) – axis object on which to plot

  • stalta (numpy.ndarray) – data array containing the sta/lta waveform

  • plot_waterlevel (bool) – plot a horizontal line showing the relative waterlevel of the sta/lta which is used in determining windows

Return type:

list of matplotlib.lines.Lines2D objects

Returns:

list containing the lines plotted on the axis

plot_windows(ax, windows, plot_window_annos=True, plot_phase_arrivals=True)[source]

Plot misfit windows, add annotations to each window related to information contained in the Window object.

Note

The keyword argument ‘window_anno_height’ should be given as a percentage of visible y-axis, e.g. 0.25 means 25% of the y-axis

Parameters:
  • ax (matplotlib.axes.Axes) – axis object on which to plot

  • windows (list of pyflex.Window objects) – list of windows to plot

  • plot_window_annos (bool) – annotate window information onto windows

  • plot_phase_arrivals (bool) – make small tick mark if P or S phase arrival within the window

plot_rejected_windows(ax, rejwin, windows=None, skip_tags=None)[source]

Plot rejected windows as transparent lines at the bottom of the axis. Hardcoded color dictionary (defined at top) used as a way to visually identify why certain windows were rejected

The function performs some array manipulation to exclude rejected windows that fall within already chosen time windows to avoid redundant plotting.

Parameters:
  • ax (matplotlib.axes.Axes) – axis object on which to plot

  • rejwin (list of pyflex.Window objects) – list of rejected windows to plot

  • windows (list of pyflex.Window objects) – list of windows to use for exclusion

  • skip_tags (list of str) – an optional list of tags that can be used to skip specific rejected window tags

plot_adjsrcs(ax, adjsrc)[source]

Plot adjoint sources behind streams, time reverse the adjoint source that is provided by Pyadjoint so that it lines up with waveforms and windows.

Note

The unit of adjoint source is based on Eq. 57 of Tromp et al. 2005, which is a traveltime adjoint source, and includes the units of the volumentric delta function since it’s assumed this is happening in a 3D volume.

Parameters:
  • ax (matplotlib.axes.Axes) – axis object on which to plot

  • adjsrc (pyadjoint.adjoint_source.AdjointSource objects) – adjsrc object containing data to plot

Return type:

list of matplotlib.lines.Lines2D objects

Returns:

list containing the lines plotted on the axis

plot_amplitude_threshold(ax, obs)[source]

Plot a line to show the amplitude threshold criteria used by Pyatoa

Parameters:
  • ax (matplotlib.axes.Axes) – axis object on which to plot

  • obs (obspy.core.trace.Trace) – observed trace plotted on the current axis, used to determine the peak amplitude value

create_title(normalized=False, append_title=None)[source]

Create the title based on information provided to the class

Parameters:
  • normalized (bool) – whether or not the data was normalized

  • append_title (str) – append extra information to title

Return type:

str

Returns:

title string composed of configuration parameters and source receiver information

plot(show=True, save=False, **kwargs)[source]

High level plotting function that plots all parts of the class and formats the axes nicely

pyatoa.visuals.wave_maker.align_yaxes(ax1, ax2)[source]

Plotting tool to adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1

Parameters:
  • ax1 (matplotlib axis) – axes to adjust

  • ax2 (matplotlib axis) – axes to adjust

pyatoa.visuals.wave_maker.pretty_grids(input_ax, twax=False, grid=False, fontsize=8, linewidth=1, sci_format=True)[source]

Standard plot skeleton formatting, thick lines and internal tick marks etc.

Parameters:
  • input_ax (matplotlib axis) – axis to prettify

  • twax (bool) – If twax (twin axis), do not set grids

  • grid (bool) – turn on grids of the axes, default grids off

  • fontsize (float) – fontsize of the axis tick labels

  • linewidth (float) – line width of the axis spines or boundign box

  • sci_format (bool) – turn on/off scientific formatting of tick labels default scientific format on/True.

pyatoa.visuals.wave_maker.format_axis(input_ax, percent_over=0.125)[source]

Ensure that the upper and lower y-bounds are the same value

Parameters:
  • input_ax (matplotlib axis) – axis to prettify

  • percent_over (float) – the percentage above the peak value that the bounds of the axis will be set