pyatoa.visuals.insp_plot
The plotting functionality of the Inspector class. Used to generate statistics and basemap like plots from the Inspector DataFrame objects.
Module Contents
Classes
A class of methods for plotting statistics from an Inspector. |
Functions
|
Ensure that all plots have the same default look. Should be more flexible |
|
Create a custom colormap and colorbar |
|
Allow for hover on a plot for custom annotated information |
|
Get mean, variance and standard deviation from a histogram |
|
Convenience function to annotate some information |
Attributes
- class pyatoa.visuals.insp_plot.InspectorPlotter[source]
A class of methods for plotting statistics from an Inspector. Should not be called on its own, these functions will be inherited by the Inspector class automatically.
- map(event=None, network=None, station=None, show=True, save=False, **kwargs)[source]
Plot source and receiver locations with map view. Optional arguments for only plotting certain stations or events.
- scatter(x, y, iteration=None, step_count=None, save=None, show=True, **kwargs)[source]
Create a scatter plot between two chosen keys in the windows attribute
- travel_times(iteration=None, step_count=None, component=None, constants=None, t_offset=0, hist=False, hist_max=None, plot_end=False, save=None, show=True, **kwargs)[source]
Plot relative window starttime (proxy for phase arrival) against source-receiver distance, to try to convey which phases are included in the measurement.
Similar to Figure 4.18 in Shearer’s Intro to Seismology.
- Parameters:
iteration (str) – the chosen iteration to plot for, if None will default to the latest iteration available
step_count (str) – chosen step count. If None, defaults to latest
component (str) – optional specify a measurement component to isolate only e.g., ‘Z’ components to look at Rayleigh waves
constants (list of floats) – plot lines of constant velocity to estimate the average wavespeed that leads to some of the linear trends
t_offset (float) – if the synthetic offset time in SPECFEM is set then the constant lines will need to be offset by the same amount to match the measurements.
hist (bool) – create a histogram binning the approximate seismic velocities
plot_end (bool) – if True, plots the beginning and end of the misfit window as a vertical line. If False, plots only the beginning of the misfit window
- event_depths(xaxis='longitude', show=True, save=None, **kwargs)[source]
Create a scatter plot of events at depth. Compresses all events onto a single slice, optional choice of showing the x-axis or the y-axis
- raypaths(iteration=None, step_count=None, color_by=None, show=True, save=False, vmin=None, vmax=None, **kwargs)[source]
Plot rays connecting sources and receivers based on the availability of measurements. Useful for getting an approximation of resolution.
- Parameters:
iteration (int) – iteration to retrieve data from
step_count (int) – step count to retrieve data from
color_by (str) – allow rays to be colored based on a normalized value. nwin: color rays by the number of windows available for that path misfit: color rays by total misfit
show (bool) – show the plot
save (str) – fid to save the figure
- raypath_density(iteration=None, step_count=None, point_spacing_km=0.5, bin_spacing_km=8, cmap='viridis', show=True, save=False, **kwargs)[source]
Create a raypath density plot to provide a more deatiled illustration of raypath gradients, which may be interpreted alongside tomographic inversion results as a preliminary resolution test.
The idea behind this is to partition each individual raypath line into discrete points and then create a 2D histogram with all points
- Parameters:
point_spacing_km (float) – approximate discretization interval for each raypath line. Smaller numbers will lead to higher resolution but also longer computation time.
bin_spacing_km (float) – the bin size in km of the 2d histogram. If the same as ‘point_spacing_km’ then you’ll probably just see the lines. Should be larger than ‘point_spacing_km’ for a more contour plot looking feel.
- measurement_hist(iteration=None, step_count=None, choice='event', show=True, save=False)[source]
Make histograms of measurements for stations or events to show the distribution of measurements.
- station_event_misfit_map(station, iteration, step_count, choice, show=True, save=False, **kwargs)[source]
Plot a single station and all events that it has measurements for. Events will be colored by choice of value: misfit or nwin (num windows)
- event_station_misfit_map(event, iteration, step_count, choice, show=True, save=False, **kwargs)[source]
Plot a single event and all stations with measurements. Stations are colored by choice of value: misfit or nwin (number of windows)
- event_misfit_map(choice=None, iteration=None, step_count=None, show=True, save=False, **kwargs)[source]
Plot all events on a map and their corresponding scaled misfit value
- hist(iteration=None, step_count=None, iteration_comp=None, step_count_comp=None, f=None, ax=None, event=None, station=None, choice='cc_shift_in_seconds', binsize=None, show=True, save=None, **kwargs)[source]
Create a histogram of misfit information for either time shift or amplitude differences. Option to compare against different iterations, and to look at different choices.
Choices are any column value in the Inspector.windows attribute
- Parameters:
iteration (str) – iteration to choose for misfit
step_count (str) – step count to query, e.g. ‘s00’
iteration_comp (str) – iteration to compare with, will be plotted in front of iteration
step_count_comp (str) – step to compare with
f (matplotlib.figure) – plot to an existing figure
ax (matplotlib.axes._subplots.AxesSubplot) – plot to an existing axis e.g. to string together histograms
event (str) – filter for measurements for a given event
station (str) – filter for measurements for a given station
choice (str) – choice of ‘cc_shift_s’ for time shift, or ‘dlnA’ as amplitude
binsize (float) – size of the histogram bins
show (bool) – show the plot
save (str) – fid to save the figure
- plot_windows(iteration=None, step_count=None, iteration_comp=None, step_count_comp=None, choice='cc_shift_in_seconds', event=None, network=None, station=None, component=None, no_overlap=True, distances=False, annotate=False, bounds=False, show=True, save=False, **kwargs)[source]
Show lengths of windows chosen based on source-receiver distance, akin to Tape’s Thesis or to the LASIF plots. These are useful for showing which phases are chosen, and window choosing behavior as distance increases and (probably) misfit increases.
- Parameters:
iteration (str) – iteration to analyze
step_count (str) – step count to query, e.g. ‘s00’
iteration_comp (str) – Optional, if provided, difference the ‘choice’ values with the chosen ‘iteration/step’. Useful for easily checking for improvement. Only works if the windows are the same.
step_count_comp (str) – associated step count for ‘iteration_comp’
event (str) – filter for measurements for a given event
network (str) – filter for measurements for a given network
station (str) – filter for measurements for a given station
component (str) – choose a specific component to analyze
choice (str) – choice of value to define the colorscale by. These relate to the keys of Inspector.windows. Default is ‘cc_shift_in_seconds’
no_overlap (bool) – If real distances are used, many src-rcv pairs are at the same or very similar distances, leading to overlapping rectangles. If this is set to True, to minimize overlap, the function will try to shift the distance to a value that hasn’t yet been plotted. It will alternate larger positive and negative values until something is found. Will lead to non-real distances.
distances (bool) – If set False, just plot one window atop the other, which makes for more concise, easier to view plots, but then real distance information is lost, only relative distance kept.
annotate (bool) – If True, will annotate event and station information for each window. May get messy if distances == True and no_overlap == False because you will get many overlapping annotations. Works ideally if distances == False.
bounds (bool or list of float) –
(bool) False: set default bounds based on the min and max of data
(bool) True: set default bounds equal, based on abs max of data
(list) Manually set the bounds of the colorbar
show (bool) – show the plot after generating
save (str) – save the plot to the given filename
- Keyword Arguments:
alpha (float) – The opacity of the rectangles, defaults to 0.25
cmap (str) – The colormap used to plot the values of choice
cbar_label (str) – The label for the colorbar
rectangle_height (float) – The vertical size of the rectangles, defaults to 1.
anno_shift (float) – The distance in seconds to shift the plot to accomodate annotations. This needs to be played as its based on the length of the strings that are used in the annotations.
- convergence(windows='length_s', trials=False, show=True, save=None, normalize=False, float_precision=3, annotate=False, restarts='default', restart_annos=None, xvalues='model', **kwargs)[source]
TO DO: Separate the sorting functionality from the plotting functionality, this function is too confusing.
Plot the convergence rate over the course of an inversion. Scatter plot of total misfit against iteration number, or by step count
Note
Because misfits are floats, they wont be exactly equal, so we need to set some small tolerance in which they can differ
- Parameters:
parameter to use for Inspector.measurements() to determine how to illustrate measurement number, either by:
length_s: cumulative window length in seconds
nwin: number of misfit windows
None: will not plot window information
trials (str) –
plot the discarded trial step function evaluations from the line searches. Useful for understanding optimization efficiency
marker: plot trial steps as red x’s at their respective misfit val
text: annotate the number of trial steps but not their misfit val
normalize (bool) – normalize the objective function values between [0, 1]
float_precision (int) – acceptable floating point precision for comparisons of misfits. Defaults to 3 values after decimal
restarts (list of int) – If the inversion was restarted, e.g. for parameter changes, then the convergence figure should separate two line plots. This list allows the User to tell the function where to separate the convergence plot. The integers should correspond to indices of the Inspector.models attribute.
annotate (bool) – annotate misfit values next to markers
restart_annos (list of str) – if restarts is not None, allow annotating text next to each restart. Useful for annotating e.g. parameter changes that accompany each restart
xvalues (str) –
How the x-axis should be labelled, available:
model: plot the model number under each point
eval: number sequentially from 1
show (bool) – show the plot after making it
save (str) – file id to save the figure to
- pyatoa.visuals.insp_plot.default_axes(ax, cbar=None, **kwargs)[source]
Ensure that all plots have the same default look. Should be more flexible than setting rcParams or having a style sheet. Also allows the same kwargs to be thrown by all functions so that the function calls have the same format.
- pyatoa.visuals.insp_plot.colormap_colorbar(cmap, vmin=0.0, vmax=1.0, dv=None, cbar_label='', extend='neither')[source]
Create a custom colormap and colorbar
- Parameters:
- Return type:
- Returns:
- pyatoa.visuals.insp_plot.hover_on_plot(f, ax, obj, values, dissapear=True)[source]
Allow for hover on a plot for custom annotated information
Note
This functionality is copied from StackOverflow: https://stackoverflow.com/questions/7908636/possible-to-make-labels-appear-when-hovering-over-a-point-in-matplotlib
- Parameters:
f (matplotlib.figure.Figure) – figure object for hover
ax (matplotlib.axes._subplot.AxesSubplot) – axis object for hover
obj (matplotlib.collections.PathCollection or matplotlib.lines.Line2D) – scatter plot, returned from plt.scatter() or plt.plot()
dissapear (bool) – annotations dissapear when mouse moves off
- Rtype hover:
function
- Return hover:
the hover function to be passed to matplotlib
- pyatoa.visuals.insp_plot.get_histogram_stats(n, bins)[source]
Get mean, variance and standard deviation from a histogram
- Parameters:
n (array or list of arrays) – values of histogram bins
bins (array) – edges of the bins