SourceSpec API
SourceSpec has a modular structure. Each module corresponds to a specific function or class of functions.
Main modules
SourceSpec main modules are presented below, following the logical order on which
they’re used within source_spec.py
.
source_spec.py
Earthquake source parameters from inversion of P- or S-wave spectra.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>, Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_parse_arguments
Argument parser for sourcespec.
- copyright
2021-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_setup
Setup functions for sourcespec.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>, Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- ssp_setup.configure(options, progname, config_overrides=None)[source]
Parse command line arguments and read config file.
- ssp_setup.move_outdir(config)[source]
Move outdir to a new dir named from evid (and optional run_id).
- ssp_setup.setup_logging(config, basename=None, progname='source_spec')[source]
Set up the logging infrastructure.
This function is typically called twice: the first time without basename and a second time with a basename (typically the eventid). When called the second time, the previous logfile is renamed using the given basename.
ssp_read_traces
Read traces in multiple formats of data and metadata.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>
- 2015-2023 Claudio Satriano <satriano@ipgp.fr>,
Sophie Lambotte <sophie.lambotte@unistra.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_process_traces
Trace processing for sourcespec.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_build_spectra
Build spectral objects.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>, Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_plot_traces
Trace plotting routine.
- copyright
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_inversion
Spectral inversion routines for sourcespec.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>, Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_radiated_energy
Compute radiated energy from spectral integration.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>, Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_local_magnitude
Local magnitude calculation for sourcespec.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_summary_statistics
Post processing of station source parameters.
- copyright
2012-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_output
Output functions for source_spec.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_residuals
Spectral residual routine for sourcespec.
- copyright
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_plot_spectra
Spectral plotting routine.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_plot_params_stats
Plot parameter statistics.
- copyright
2022-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_plot_stations
Station plotting routine.
- copyright
2018-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_html_report
Generate an HTML report for source_spec.
- copyright
2021-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
Other modules
These modules, in alphabetical order, are used by the main modules.
ssp_correction
Spectral station correction calculated from ssp_residuals.
- copyright
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_data_types
Classes for spectral inversion routines.
- copyright
2017-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- class ssp_data_types.Bounds(config, spec, initial_values)[source]
Bounds for bounded spectral inversion.
- property bounds
Get bounds for minimize() as sequence of (min, max) pairs.
- class ssp_data_types.InitialValues(Mw_0=None, fc_0=None, t_star_0=None)[source]
Initial values for spectral inversion.
- class ssp_data_types.OrderedAttribDict[source]
An ordered dictionary whose values can be accessed as classattributes.
- class ssp_data_types.SourceSpecOutput[source]
The output of SourceSpec.
- find_outliers(key, n)[source]
Find outliers using the IQR method.
Q1-n*IQR Q1 median Q3 Q3+n*IQR |-----:-----| o |--------| : |--------| o o |-----:-----| outlier <-----------> outliers IQR
If
n
isNone
, then the above check is skipped.Nan
andinf
values are also marked as outliers.
- class ssp_data_types.SpectralParameter(id, name=None, units=None, value=None, uncertainty=None, lower_uncertainty=None, upper_uncertainty=None, confidence_level=None, format=None)[source]
A spectral parameter measured at one station.
- class ssp_data_types.StationParameters(id, instrument_type=None, latitude=None, longitude=None, hypo_dist_in_km=None, epi_dist_in_km=None, azimuth=None)[source]
The parameters describing a given station (e.g., its id and location) and the spectral parameters measured at that station.
Spectral parameters are provided as attributes, using SpectralParameter() objects.
- class ssp_data_types.SummarySpectralParameter(id, name=None, units=None, format=None)[source]
A summary spectral parameter comprising one ore more summary statistics.
- class ssp_data_types.SummaryStatistics(type, value=None, uncertainty=None, lower_uncertainty=None, upper_uncertainty=None, confidence_level=None, lower_percentage=None, mid_percentage=None, upper_percentage=None, nobs=None, message=None, format=None)[source]
A summary statistics (e.g., mean, weighted_mean, percentile), along with its uncertainty.
ssp_grid_sampling
A class for sampling a parameter space over a grid.
Sampling can be performed by several approaches. The class provides optimal solutions, uncertainties and plotting methods.
- copyright
2022-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- class ssp_grid_sampling.GridSampling(misfit_func, bounds, nsteps, sampling_mode, params_name, params_unit)[source]
A class for sampling a parameter space over a grid.
Sampling can be performed by several approaches. The class provides optimal solutions, uncertainties and plotting methods.
- property conditional_misfit
Compute conditional misfit along each dimension.
Conditional misfit is computed by fixing the other parameters to their optimal value.
- property conditional_peak_widths
Find width of conditional misfit around its minimum.
- property values_1d
Extract a 1D array of parameter values along one dimension.
ssp_spectral_model
Spectral model and objective function.
- copyright
2012 Claudio Satriano <satriano@ipgp.fr>
- 2013-2014 Claudio Satriano <satriano@ipgp.fr>,
Emanuela Matrullo <matrullo@geologie.ens.fr>, Agnes Chounet <chounet@ipgp.fr>
2015-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- ssp_spectral_model.objective_func(xdata, ydata, weight)[source]
Objective function generator for bounded inversion.
- ssp_spectral_model.spectral_model(freq, Mw, fc, t_star, alpha=1.0)[source]
Spectral model.
\[Y_{data} = M_w + \frac{2}{3} \left[ - \log_{10} \left( 1+\left(\frac{f}{f_c}\right)^2 \right) - \pi \, f t^* \log_{10} e \right]\]see Theoretical Background for a detailed derivation of this model.
ssp_qml_output
QuakeML output for source_spec.
- copyright
2016-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement, Version 2.1 (http://www.cecill.info/index.en.html)
ssp_radiation_pattern
Compute radiation pattern.
- copyright
2021-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_sqlite_output
SQLite output for source_spec.
- copyright
2013-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
ssp_util
Utility functions for sourcespec.
- copyright
2012-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- ssp_util.bsd(Mo_in_N_m, ra_in_m)[source]
Compute Brune stress drop in MPa.
Madariaga (2009), doi:10.1007/978-1-4419-7695-6_22, eq. 27
- ssp_util.get_vel(lon, lat, depth_in_km, wave, config)[source]
Get velocity at a given point from NLL grid, config or taup model.
- ssp_util.quality_factor(travel_time_in_s, t_star_in_s)[source]
Compute quality factor from travel time and t_star.
- ssp_util.remove_instr_response(trace, pre_filt=(0.5, 0.6, 40.0, 45.0))[source]
Remove instrument response from a trace.
Trace is converted to the sensor units (m for a displacement sensor, m/s for a short period or broadband velocity sensor, m/s**2 for a strong motion sensor).
ssp_wave_arrival
Arrival time calculation for sourcespec.
- copyright
2012-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
config
Config class for sourcespec.
- copyright
2013-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
kdtree
Grid importance sampling using a k-d tree.
- copyright
2022-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
savefig
Save Matplotlib figure. Optimize PNG format using PIL.
- copyright
2022-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
spectrum
A Spectrum() class defined as a modification of the ObsPy class Trace().
Provides the high-level function do_spectrum() and the low-level function do_fft().
- copyright
2012-2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
clipping_detection
Check trace for clipping using kernel density estimation of the trace= amplitude values.
- Two methods are available:
clipping_score()
: compute a trace clipping score based on the shape of the kernel density estimation.clipping_peaks()
: check if trace is clipped, based on the number of peaks in the kernel density estimation;
- copyright
- 2023 Claudio Satriano <satriano@ipgp.fr>,
Kris Vanneste <kris.vanneste@oma.be>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- clipping_detection.clipping_peaks(trace, sensitivity=3, clipping_percentile=10, debug=False)[source]
Check if a trace is clipped, based on the number of peaks in the kernel density estimation of the trace amplitude values.
The algorithm is based on the following steps:
The trace is demeaned.
A kernel density estimation is computed on the trace amplitude values.
The kernel density estimation is weighted by the distance from the zero mean amplitude value, using a parabolic function, between 1 and 5.
Peaks are detected in the weighted kernel density estimation. The sensitivity of the peak detection algorithm is controlled by the
sensitivity
parameter, based on which a minimum prominence threshold is set.The trace is considered clipped if there is at least one peak in the amplitude range corresponding to the
clipping_percentile
parameter.
- Parameters
trace (
obspy.core.trace.Trace
) – Trace to check.sensitivity (
int
) – Sensitivity level, from 1 (least sensitive) to 5 (most sensitive). (default: 3). The sensitivity level controls the minimum prominence threshold used for peak detection in the kernel density estimation. See thescipy.signal.find_peaks()
documentation for more details.clipping_percentile (
float
,between 0
and100
) – Percentile of trace amplitude range (expressed as percentage) to check for clipping. Default is 10, which means that the 10% highest and lowest values of the trace amplitude will be checked for clipping. A value of 0 means that no clipping check will be performed.debug (
bool
) – If True, plot trace, samples histogram and kernel density.
- Returns
trace_clipped (
bool
) – True if trace is clipped, False otherwise.properties (
dict
) – Dictionary with the properties used for the clipping detection. The dictionary contains the following keys:npeaks (
int
): number of peaks found in the kernel densitynpeaks_clipped (
int
): number of peaks found in the kernel density that are considered clippedpeaks (
numpy.ndarray
): list of peaks found in the kernel densityprominences (
numpy.ndarray
): list of prominences of the peaks found in the kernel density
- clipping_detection.clipping_score(trace, remove_baseline=False, debug=False)[source]
Compute a trace clipping score based on the shape of the kernel density estimation of the trace amplitude values.
The algorithm is based on the following steps:
The trace is detrended and demeaned. Optionally, the trace baseline can be removed.
A kernel density estimation is computed on the trace amplitude values.
Two weighted kernel density functions are computed:
a full weighted kernel density, where the kernel density is weighted by the distance from the zero mean amplitude value, using a 8th order power function between 1 and 100.
a weighted kernel density without the central peak, where the kernel density is weighted by the distance from the zero mean amplitude value, using a 8th order power function between 0 and 100.
In both cases, the weight gives more importance to samples far from the zero mean value. In the second case, the central peak is ignored.
The score, ranging from 0 to 100, is the sum of the squared weighted kernel density without the central peak, normalized by the sum of the squared full weighted kernel density. The score is 0 if there is no additional peak beyond the central peak.
- Parameters
trace (
Trace
) – Trace to check for clipping.remove_baseline (
bool
, optional) – If set, remove the trace baseline before computing the score.debug (
bool
, optional) – If set, plot the trace, the samples histogram, the kernel density (unweighted and weighted), the kernel baseline model, and the misfit. Default is False.
- Returns
clipping_score – Clipping score, in percentage.
- Return type
Note
Distorted traces (e.g., signals with strong baselines) can also get a high clipping score. To avoid this, the trace baseline can be removed.
A debug mode is available to plot the trace, the samples histogram, the kernel density (unweighted and weighted), the kernel baseline model, and the misfit.
plot_sourcepars
plot_sourcepars.py
1D or 2D plot of source parameters from a sqlite parameter file.
- copyright
2023 Claudio Satriano <satriano@ipgp.fr>
- license
CeCILL Free Software License Agreement v2.1 (http://www.cecill.info/licences.en.html)
- plot_sourcepars.stress_drop_curve_Er_mw(delta_sigma, vs, rho, mw)[source]
Constant stress drop curve in Er vs Mw.
Madariaga (2009), doi:10.1007/978-1-4419-7695-6_22, eq. 33., page 374.
- plot_sourcepars.stress_drop_curve_fc_mw(delta_sigma, vs, mw, b=-0.5)[source]
Constant stress drop curve in fc vs Mw.
Chounet et al. (2013), https://hal.science/hal-03965701, eq. 9, page 9.