EQcorrscan_plotting

Utility code for most of the plots used as part of the EQcorrscan package.

Copyright 2015 Calum Chamberlain

This file is part of EQcorrscan.

EQcorrscan is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

EQcorrscan is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with EQcorrscan. If not, see <http://www.gnu.org/licenses/>.

EQcorrscan_plotting.NR_plot(stream, NR_stream, detections, false_detections=False, size=(18.5, 10), save=False, title=False)[source]

Function to plot the Network response alongside the streams used - highlights detection times in the network response

Parameters:
  • stream – Stream to plot
  • NR_stream – Stream for the network response
  • detections (List of datetime objects) – List of the detections
  • false_detections (List of datetime) – Either False (default) or list of false detection times
  • size (tuple) – Size of figure, default is (18.5,10)
  • save (bool) – Save figure or plot to screen, if not False, must be string of save path
  • title (str) – String for the title of the plot, set to False
EQcorrscan_plotting.Noise_plotting(station, channel, PAZ, datasource)[source]

Function to make use of obspy’s PPSD functionality to read in data from a single station and the poles-and-zeros for that station before plotting the PPSD for this station. See McNamara(2004) for more details.

Parameters:
  • station (String) – Station name as it is in the filenames in the database
  • channel (String) – Channel name as it is in the filenames in the database
  • PAZ (Dict) – Must contain, Poles, Zeros, Sensitivity, Gain :type Poles: List of Complex :type Zeros: List of Complex :type Sensitivity: Float :type Gain: Float
  • datasource (String) – The directory in which data can be found, can contain wildcards.
Returns:

PPSD object

EQcorrscan_plotting.SVD_plot(SVStreams, SValues, stachans, title=False)[source]

Function to plot the singular vectors from the clustering routines, one plot for each stachan

Parameters:
  • SVStreams (List of :class:Obspy.Stream) – See clustering.SVD_2_Stream - will assume these are ordered by power, e.g. first singular vector in the first stream
  • SValues (List of float) – List of the singular values corresponding to the SVStreams
  • stachans (List) – List of station.channel
EQcorrscan_plotting.chunk_data(tr, samp_rate, state='mean')[source]

Function to downsample data for plotting by computing the maximum of data within chunks, usefil for plotting waveforms or cccsums, large datasets that ould otherwise exceed the complexity allowed, and overflow.

Parameters:
  • tr – Trace to be chunked
  • samp_rate (float) – Desired sampling rate in Hz
  • state (str) – Either ‘Min’, ‘Max’, ‘Mean’ or ‘Maxabs’ to return one of these for the chunks. Maxabs will return the largest (positive or negative) for that chunk.
Returns:

class:obspy.Trace

EQcorrscan_plotting.cumulative_detections(dates, template_names, save=False, savefile='')[source]

Simple plotting function to take a list of datetime objects and plot a cumulative detections list. Can take dates as a list of lists and will plot each list seperately, e.g. if you have dates from more than one template it will overlay them in different colours.

Parameters:
  • dates (list of lists of datetime.datetime) – Must be a list of lists of datetime.datetime objects
  • template_names (list of strings) – List of the template names in order of the dates
  • save (Boolean, optional) – Save figure or show to screen
  • savefile (String, optional) – String to save to.
EQcorrscan_plotting.detection_multiplot(stream, template, times, streamcolour='k', templatecolour='r')[source]

Function to plot the stream of data that has been detected in, with the template on top of it timed according to a list of given times, just a pretty way to show a detection!

Parameters:
  • stream (obspy.Stream) – Stream of data to be plotted as the base (black)
  • template (obspy.Stream) – Template to be plotted on top of the base stream (red)
  • times (List of datetime.datetime) – list of times of detections in the order of the channels in template.
  • streamcolour (str) – String of matplotlib colour types for the stream
  • templatecolour (str) – Colour to plot the template in.
EQcorrscan_plotting.interev_mag(times, mags)[source]

Function to plot interevent times against magnitude for given times and magnitudes.

Parameters:
  • times (list of datetime) – list of the detection times, must be sorted the same as mags
  • mags (list of float) – list of magnitudes
EQcorrscan_plotting.interev_mag_sfiles(sfiles)[source]

Function to plot interevent-time versus magnitude for series of events. Wrapper for interev_mag.

Parameters:sfiles (List) – List of sfiles to read from
EQcorrscan_plotting.multi_event_singlechan(streams, picks, clip=10.0, pre_pick=2.0, freqmin=False, freqmax=False, realign=False, cut=(-3.0, 5.0), PWS=False, title=False)[source]

Function to plot data from a single channel at a single station for multiple events - data will be alligned by their pick-time given in the picks

Parameters:
  • streams (List of :class:obspy.stream) – List of the streams to use, can contain more traces than you plan on plotting
  • picks (List of :class:PICK) – List of picks, one for each stream
  • clip (float) – Length in seconds to plot, defaults to 10.0
  • pre_pick (Float) – Length in seconds to extract and plot before the pick, defaults to 2.0
  • freqmin (float) – Low cut for bandpass in Hz
  • freqmax (float) – High cut for bandpass in Hz
  • realign (Bool) – To compute best alignement based on correlation or not.
  • cut (tuple:) – tuple of start and end times for cut in seconds from the pick
  • PWS (bool) – compute Phase Weighted Stack, if False, will compute linear stack
  • title (str) – Plot title.
Returns:

Alligned and cut traces, and new picks

EQcorrscan_plotting.peaks_plot(data, starttime, samp_rate, save=False, peaks=[(0, 0)], savefile='')[source]

Simple utility code to plot the correlation peaks to check that the peak finding routine is running correctly, used in debugging for the EQcorrscan module.

Parameters:
  • data (numpy.array) – Numpy array of the data within which peaks have been found
  • starttime (obspy.UTCDateTime) – Start time for the data
  • samp_rate (float) – Sampling rate of data in Hz
  • save (Boolean, optional) – Save figure or plot to screen (False)
  • peaks (List of Tuple, optional) – List of peak locations and amplitudes (loc, amp)
  • savefile (String, optional) – Path to save to, only used if save=True
EQcorrscan_plotting.plot_synth_real(real_template, synthetic, channels=False)[source]

Plot multiple channels of data for real data and synthetic

Parameters:
  • real_template (obspy.Stream) – Stream of the real template
  • synthetic (obspy.Stream) – Stream of synthetic template
  • channels (List of str) – List of tuples of (station, channel) to plot, default is False, which plots all.
EQcorrscan_plotting.pretty_template_plot(template, size=(18.5, 10.5), save=False, title=False, background=False)[source]

Function to make a pretty plot of a single template, designed to work better than the default obspy plotting routine for short data lengths.

Parameters:
  • template – Template stream to plot
  • size (tuple) – tuple of plot size
  • save (Boolean) – if False will plot to screen, if True will save
  • title (Boolean) – String if set will be the plot title
  • background – Stream to plot the template within.
EQcorrscan_plotting.threeD_gridplot(nodes, save=False, savefile='')[source]

Function to plot in 3D a series of grid points.

Parameters:
  • nodes (List of tuples) – List of tuples of the form (lat, long, depth)
  • save (bool) – if True will save without plotting to screen, if False (default) will plot to screen but not save
  • savefile (str) – required if save=True, path to save figure to.
EQcorrscan_plotting.threeD_seismplot(stations, nodes)[source]

Function to plot seismicity and stations in a 3D, movable, zoomable space using matplotlibs Axes3D package.

Parameters:
  • stations (list of tuple) – list of one tuple per station of (lat, long, elevation), with up positive
  • nodes (list of tuple) – list of one tuple per event of (lat, long, depth) with down positive
EQcorrscan_plotting.triple_plot(cccsum, cccsum_hist, trace, threshold, save=False, savefile='')[source]

Main function to make a triple plot with a day-long seismogram, day-long correlation sum trace and histogram of the correlation sum to show normality

Parameters:
  • cccsum (numpy.ndarray) – Array of the cross-channel cross-correlation sum
  • ccsum_hist – cccsum for histogram plotting, can be the same as cccsum but included if cccsum is just an envelope.
  • trace (obspy.Trace) – A sample trace from the same time as cccsum
  • threshold (float) – Detection threshold within cccsum
  • save (Bool, optional) – If True will svae and not plot to screen, vice-versa if False
  • savefile (String, optional) – Path to save figure to, only required if save=True