seispy package¶
seispy.bootstrap module¶
-
exception
seispy.bootstrap.
InstabilityWarning
[source]¶ Bases:
UserWarning
Issued when results may be unstable.
-
seispy.bootstrap.
bootstrap_indexes
(data, n_samples=10000)[source]¶ Given data points data, where axis 0 is considered to delineate points, return an generator for sets of bootstrap indexes. This can be used as a list of bootstrap indexes (with list(bootstrap_indexes(data))) as well.
-
seispy.bootstrap.
bootstrap_indexes_moving_block
(data, n_samples=10000, block_length=3, wrap=False)[source]¶ Generate moving-block bootstrap samples.
Given data points data, where axis 0 is considered to delineate points, return a generator for sets of bootstrap indexes. This can be used as a list of bootstrap indexes (with list(bootstrap_indexes_moving_block(data))) as well.
n_samples [default 10000]: the number of subsamples to generate.
block_length [default 3]: the length of block.
wrap [default False]: if false, choose only blocks within the data, making the last block for data of length L start at L-block_length. If true, choose blocks starting anywhere, and if they extend past the end of the data, wrap around to the beginning of the data again.
-
seispy.bootstrap.
ci
(data, statfunction=<function average>, alpha=0.05, n_samples=10000, method='bca', output='lowhigh', epsilon=0.001, multi=None, _iter=True)[source]¶ Given a set of data
data
, and a statistics functionstatfunction
that applies to that data, computes the bootstrap confidence interval forstatfunction
on that data. Data points are assumed to be delineated by axis 0.- data: array_like, shape (N, …) OR tuple of array_like all with shape (N, …)
Input data. Data points are assumed to be delineated by axis 0. Beyond this, the shape doesn’t matter, so long as
statfunction
can be applied to the array. If a tuple of array_likes is passed, then samples from each array (along axis 0) are passed in order as separate parameters to the statfunction. The type of data (single array or tuple of arrays) can be explicitly specified by the multi parameter.- statfunction: function (data, weights=(weights, optional)) -> value
This function should accept samples of data from
data
. It is applied to these samples individually.If using the ABC method, the function _must_ accept a named
weights
parameter which will be an array_like with weights for each sample, and must return a _weighted_ result. Otherwise this parameter is not used or required. Note that numpy’s np.average accepts this. (default=np.average)- alpha: float or iterable, optional
The percentiles to use for the confidence interval (default=0.05). If this is a float, the returned values are (alpha/2, 1-alpha/2) percentile confidence intervals. If it is an iterable, alpha is assumed to be an iterable of each desired percentile.
- n_samples: float, optional
The number of bootstrap samples to use (default=10000)
- method: string, optional
The method to use: one of ‘pi’, ‘bca’, or ‘abc’ (default=’bca’)
- output: string, optional
The format of the output. ‘lowhigh’ gives low and high confidence interval values. ‘errorbar’ gives transposed abs(value-confidence interval value) values that are suitable for use with matplotlib’s errorbar function. (default=’lowhigh’)
- epsilon: float, optional (only for ABC method)
The step size for finite difference calculations in the ABC method. Ignored for all other methods. (default=0.001)
- multi: boolean, optional
If False, assume data is a single array. If True, assume data is a tuple/other iterable of arrays of the same length that should be sampled together. If None, decide based on whether the data is an actual tuple. (default=None)
- confidences: tuple of floats
The confidence percentiles specified by alpha
- ‘pi’: Percentile Interval (Efron 13.3)
The percentile interval method simply returns the 100*alphath bootstrap sample’s values for the statistic. This is an extremely simple method of confidence interval calculation. However, it has several disadvantages compared to the bias-corrected accelerated method, which is the default.
- ‘bca’: Bias-Corrected Accelerated (BCa) Non-Parametric (Efron 14.3) (default)
This method is much more complex to explain. However, it gives considerably better results, and is generally recommended for normal situations. Note that in cases where the statistic is smooth, and can be expressed with weights, the ABC method will give approximated results much, much faster. Note that in a case where the statfunction results in equal output for every bootstrap sample, the BCa confidence interval is technically undefined, as the acceleration value is undefined. To match the percentile interval method and give reasonable output, the implementation of this method returns a confidence interval of zero width using the 0th bootstrap sample in this case, and warns the user.
- ‘abc’: Approximate Bootstrap Confidence (Efron 14.4, 22.6)
This method provides approximated bootstrap confidence intervals without actually taking bootstrap samples. This requires that the statistic be smooth, and allow for weighting of individual points with a weights= parameter (note that np.average allows this). This is _much_ faster than all other methods for situations where it can be used.
To calculate the confidence intervals for the mean of some numbers:
>> boot.ci( np.randn(100), np.average )
Given some data points in arrays x and y calculate the confidence intervals for all linear regression coefficients simultaneously:
>> boot.ci( (x,y), scipy.stats.linregress )
Efron, An Introduction to the Bootstrap. Chapman & Hall 1993
-
seispy.bootstrap.
jackknife_indexes
(data)[source]¶ Given data points data, where axis 0 is considered to delineate points, return a list of arrays where each array is a set of jackknife indexes.
For a given set of data Y, the jackknife sample J[i] is defined as the data set Y with the ith data point deleted.
-
seispy.bootstrap.
randint
(low, high=None, size=None, dtype=int)¶ Return random integers from low (inclusive) to high (exclusive).
Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low).
Note
New code should use the
integers
method of adefault_rng()
instance instead; see random-quick-start.- lowint or array-like of ints
Lowest (signed) integers to be drawn from the distribution (unless
high=None
, in which case this parameter is one above the highest such integer).- highint or array-like of ints, optional
If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if
high=None
). If array-like, must contain integer values- sizeint or tuple of ints, optional
Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn. Default is None, in which case a single value is returned.- dtypedtype, optional
Desired dtype of the result. Byteorder must be native. The default value is int.
New in version 1.11.0.
- outint or ndarray of ints
size-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.
- random_integerssimilar to randint, only for the closed
interval [low, high], and 1 is the lowest value if high is omitted.
Generator.integers: which should be used for new code.
>>> np.random.randint(2, size=10) array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random >>> np.random.randint(1, size=10) array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Generate a 2 x 4 array of ints between 0 and 4, inclusive:
>>> np.random.randint(5, size=(2, 4)) array([[4, 0, 2, 1], # random [3, 2, 2, 0]])
Generate a 1 x 3 array with 3 different upper bounds
>>> np.random.randint(1, [3, 5, 10]) array([2, 2, 9]) # random
Generate a 1 by 3 array with 3 different lower bounds
>>> np.random.randint([1, 5, 7], 10) array([9, 8, 7]) # random
Generate a 2 by 4 array using broadcasting with dtype of uint8
>>> np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8) array([[ 8, 6, 9, 7], # random [ 1, 16, 9, 12]], dtype=uint8)
-
seispy.bootstrap.
subsample_indexes
(data, n_samples=1000, size=0.5)[source]¶ Given data points data, where axis 0 is considered to delineate points, return a list of arrays where each array is indexes a subsample of the data of size
size
. If size is >= 1, then it will be taken to be an absolute size. If size < 1, it will be taken to be a fraction of the data size. If size == -1, it will be taken to mean subsamples the same size as the sample (ie, permuted samples)
seispy.ccp module¶
-
seispy.ccp.
search_pierce
(rfdep, bin_loca, profile_range, stack_range, dep_axis, log, bin_radius=None, isci=False, domperiod=5)[source]¶
seispy.ccppara module¶
seispy.decov module¶
-
seispy.decov.
decovit
(uin, win, dt, nt=None, tshift=10, f0=2.0, itmax=400, minderr=0.001, info=False)[source]¶ Created on Wed Sep 10 14:21:38 2014 [RFI, rms, it]=makeRFitdecon(uin,win,dt,nt,tshift,f0,itmax,minderr)
In: uin = numerator (radial for PdS) win = denominator (vertical component for PdS) dt = sample interval (s) nt = number of samples tshift = Time until beginning of receiver function (s) f0 = width of gaussian filter itmax = max # iterations minderr = Min change in error required for stopping iterations
Out: RFI = receiver function rms = Root mean square error for predicting numerator after each iteration
@author: Mijian Xu @ NJU
seispy.distaz module¶
-
class
seispy.distaz.
distaz
(lat1, lon1, lat2, lon2)[source]¶ Bases:
object
c Subroutine to calculate the Great Circle Arc distance c between two sets of geographic coordinates c c Equations take from Bullen, pages 154, 155 c c T. Owens, September 19, 1991 c Sept. 25 – fixed az and baz calculations c P. Crotwell, Setember 27, 1995 Converted to c to fix annoying problem of fortran giving wrong answers if the input doesn’t contain a decimal point.
H. P. Crotwell, September 18, 1997 Java version for direct use in java programs. * * C. Groves, May 4, 2004 * Added enough convenience constructors to choke a horse and made public double * values use accessors so we can use this class as an immutable
H.P. Crotwell, May 31, 2006 Port to python, thus adding to the great list of languages to which distaz has been ported from the origin fortran: C, Tcl, Java and now python and I vaguely remember a perl port. Long live distaz!
-
az
¶ c c Make sure 0.0 is always 0.0, not 360. c
-
baz
¶ c c Bullen, Sec 10.2, eqn 7 / eqn 8 c c pt. 2 is unprimed, so this is technically the az c
-
delta
¶ c c Bullen, Sec 10.2, eqn 7 / eqn 8 c c pt. 1 is unprimed, so this is technically the baz c c Calculate baz this way to avoid quadrant problems c
-
evtlon
¶ - if (lat1 == lat2) and (lon1 == lon2):
self.delta = 0.0 self.az = 0.0 self.baz = 0.0 return
-
seispy.eq module¶
-
class
seispy.eq.
eq
(pathname, datestr, suffix, switchEN=False, reverseE=False, reverseN=False)[source]¶ Bases:
object
-
deconvolute
(shift, time_after, f0, phase='P', only_r=False, itmax=400, minderr=0.001, target_dt=None)[source]¶
-
seispy.geo module¶
seispy.hk module¶
-
seispy.hk.
ci
(allstack, h, kappa, ev_num)[source]¶ Search best H and kappa from stacked matrix. Calculate error for H and kappa :param allstack: stacked HK matrix :param h: 1-D array of H :param kappa: 1-D array of kappa :param ev_num: event number :return:
seispy.hkpara module¶
seispy.io module¶
-
seispy.io.
nc2npz
(ncdata, minlat=- 90, maxlat=90, minlon=- 180, maxlon=180, mindep=0, maxdep=6371, key='dvs')[source]¶
-
seispy.io.
wsfetch
(server, starttime=None, endtime=None, minlatitude=None, maxlatitude=None, minlongitude=None, maxlongitude=None, latitude=None, longitude=None, minradius=None, maxradius=None, mindepth=None, maxdepth=None, minmagnitude=None, maxmagnitude=None, magnitudetype=None, includeallorigins=None, includeallmagnitudes=None, includearrivals=None, eventid=None, limit=None, offset=None, orderby='time-asc', catalog=None, contributor=None)[source]¶
seispy.para module¶
seispy.pickfigure module¶
seispy.pickui module¶
seispy.plotR module¶
seispy.plotRT module¶
seispy.psrayp module¶
seispy.rf module¶
-
class
seispy.rf.
RF
(cfg_file=None, log=None)[source]¶ Bases:
object
-
property
date_begin
¶
-
property
date_end
¶
-
property
-
seispy.rf.
match_eq
(eq_lst, pathname, stla, stlo, ref_comp='Z', suffix='SAC', offset=None, tolerance=210, dateformat='%Y.%j.%H.%M.%S', switchEN=False, reverseE=False, reverseN=False)[source]¶
seispy.rf2depth_makedata module¶
-
seispy.rf2depth_makedata.
makedata
(cpara, velmod3d=None, log=<seispy.setuplog.setuplog object>)[source]¶
seispy.rfcorrect module¶
-
class
seispy.rfcorrect.
Mod3DPerturbation
(modpath, YAxisRange, velmod='iasp91')[source]¶ Bases:
object
-
seispy.rfcorrect.
moveoutcorrect_ref
(stadatar, raypref, YAxisRange, sampling, shift, velmod='iasp91')[source]¶ - Parameters
stadatar – data class of SACStation
raypref – referred ray parameter in rad
YAxisRange – Depth range in nd.array type
sampling – dt
shift – time before P
velmod – Path to velocity model
- Returns
Newdatar, EndIndex, x_s, x_p
-
seispy.rfcorrect.
psrf2depth
(stadatar, YAxisRange, sampling, shift, velmod='iasp91', velmod_3d=None, srayp=None)[source]¶ - Parameters
stadatar –
YAxisRange –
sampling –
shift –
velmod –
- Returns
-
seispy.rfcorrect.
psrf_3D_migration
(pplat_s, pplon_s, pplat_p, pplon_p, raylength_s, raylength_p, Tpds, YAxisRange, mod3d)[source]¶
-
seispy.rfcorrect.
psrf_3D_raytracing
(stadatar, YAxisRange, mod3d, srayp=None)[source]¶ Back ray trace the S wavs with a assumed ray parameter of P.
- stla: float
The latitude of the station
- stlo: float
The longitude of the station
- stadatar: object SACStation
The data class including PRFs and more parameters
- YAxisRange: array_like
The depth array with the same intervals
- mod3d: ‘Mod3DPerturbation’ object
The 3D velocity model with fields of
dep
,lat
,lon
,vp
andvs
.
seispy.setuplog module¶
seispy.signal module¶
-
seispy.signal.
smooth
(x, half_len=5, window='flat')[source]¶ smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.
- input:
x: the input signal helf_len: the half dimension of the smoothing window; should be an odd integer window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’
flat window will produce a moving average smoothing.
- output:
the smoothed signal
example:
t=linspace(-2,2,0.1) x=sin(t)+randn(len(t))*0.1 y=smooth(x)
see also:
numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string NOTE: length(output) != length(input), to correct this: return y[(window_len/2-1):-(window_len/2)] instead of just y.
-
seispy.signal.
whiten
(data, Nfft, delta, f1, f2, f3, f4)[source]¶ This function takes 1-dimensional data timeseries array, goes to frequency domain using fft, whitens the amplitude of the spectrum in frequency domain between freqmin and freqmax and returns the whitened fft.
- Parameters
data (
numpy.ndarray
) – Contains the 1D time series to whitenNfft (int) – The number of points to compute the FFT
delta (float) – The sampling frequency of the data
freqmin (float) – The lower frequency bound
freqmax (float) – The upper frequency bound
plot (bool) – Whether to show a raw plot of the action (default: False)
- Return type
numpy.ndarray
- Returns
The FFT of the input trace, whitened between the frequency bounds