API¶
fio¶
File IO utilities.
hdf5¶
Provide custom functions to HDF5 file.
-
class
pymodule.hdf5.MyH5(name, mode=None, driver=None, libver=None, userblock_size=None, swmr=False, rdcc_nslots=None, rdcc_nbytes=None, rdcc_w0=None, track_order=None, fs_strategy=None, fs_persist=False, fs_threshold=1, **kwds)[source]¶
seis¶
Seismology related utilities.
-
pymodule.seis.dist_one2many(lon0, lat0, lons, lats)[source]¶ Distance between one point and many points.
-
pymodule.seis.geod_inv(lon1, lat1, lon2, lat2, radians=False, km=True)[source]¶ Can take array.
https://pyproj4.github.io/pyproj/html/api/geod.html#pyproj.Geod.inv
Return az: azimuth 1->2 Return baz: azimuth 2->1 (backazimuth)
-
pymodule.seis.get_spectrum(tr)[source]¶ Return frequencies, amplitude and phase of FFT.
Parameters: tr ( Trace) –
-
pymodule.seis.hdr_cor(reftime='2000-01-01', **kwargs)[source]¶ Create a new header for correlatoin.
Parameters: - kuser1 – rec network
- user1 – 1 for symmetric & 2 for double-sided
-
pymodule.seis.interp2d(x, y, z, xi, yi, **kwargs)[source]¶ Parameters: isgrid – Use RegularGridInterpolator if True otherwise griddata
-
pymodule.seis.interp_transect(lon1, lat1, lon2, lat2, x, y, z, kwargs_interp={}, **kwargs)[source]¶ Interpolate values along a transect.
-
pymodule.seis.sliced(tr, b=None, e=None, data_only=False)[source]¶ Return sliced trace given begin/end relative to starttime.
-
pymodule.seis.snr(tr, **kwargs)[source]¶ Return SNR defined as (peak of signal amplitude) / (RMS of trailing noise)
Parameters: - dsn – differential time between signal and noise
- nlen – length of noise window
- Tmax –
- [be]fact – [tau - bfact*Tmax, tau + efact*Tmax]
- fill – fill value if failing to measure SNR
-
pymodule.seis.transect(lon1, lat1, lon2, lat2, step=None, npts=None, **kwargs)[source]¶ Return coordinates along a great circle.
Parameters: - ends – If include initial and terminus points
- npts – Number of points in the transect.
- step – Transect interval in km.
-
pymodule.seis.x_cor(tr1, tr2, **kwargs)[source]¶ Do correlation/convolution between two
Traceobjects.ObsPy:
\[\int f(\tau) g(t+\tau) d\tau\]The definition in SAC is different:
\[\int f(t+\tau) g(\tau) d\tau\]Results agree except at ends (~100 s for one lag of ~1400 s). Not sure about the reason.
Parameters: - demean – demean data beforehand
- normalize – for correlation coefficient
- domain – “time” or “freq”
- Welch – apply Welch’s method for correlation
- subwin – length of subwindow [s]
- lap – lap fraction of subwindows
- op – correlation, convolution
signal¶
Signal processing.
-
pymodule.signal.conv_spc(in1, in2)[source]¶ Return spectra of convolution (spectral multiplication) of two 1-D signals.
https://github.com/scipy/scipy/blob/v1.6.0/scipy/signal/signaltools.py#L551-L663
-
pymodule.signal.corr2(a, b)[source]¶ 2-D correlation coefficient.
https://www.mathworks.com/help/images/ref/corr2.html#f1-227958
-
pymodule.signal.corr_coef(reference, current, shift=None, demean=True, abs_max=True, domain='freq')[source]¶ Return shift and value of maximum of cross-correlation.
-
pymodule.signal.gradient_2d(z, dx, dy, order=2)[source]¶ Not use Numpy because np.gradient dx or dy must be 1D.
https://github.com/numpy/numpy/issues/9401 https://github.com/Unidata/MetPy/issues/174
-
pymodule.signal.intersect2d(a, b, assume_unique=False, return_indices=False)[source]¶ Find the intersection of two 2-D arrays.
https://stackoverflow.com/a/8317403/8877268
Parameters: - assume_unique –
- return_indices –
-
pymodule.signal.normalized(a, norm=None)[source]¶ Normalize 1D array to its absolute maximum.
https://docs.obspy.org/_modules/obspy/core/trace.html#Trace.normalize
-
pymodule.signal.spectrum(a, delta=1, **kwargs)[source]¶ Return frequencies, amplitude and phase of FFT.
-
pymodule.signal.weighted_mean(x, w, axis=0)[source]¶ https://www.wikiwand.com/en/Weighted_arithmetic_mean#/Mathematical_definition
-
pymodule.signal.weighted_sd(x, w, axis=0)[source]¶ https://www.wikiwand.com/en/Weighted_arithmetic_mean#/Weighted_sample_variance
-
pymodule.signal.weighted_sem(x, w, axis=0)[source]¶ No n/(n-1) factor.
https://www.wikiwand.com/en/Weighted_arithmetic_mean#/Bootstrapping_validation
sys_tool¶
System related tools.
-
pymodule.sys_tool.log_cmd(cmd, logger)[source]¶ Pass stdout to logger. https://www.endpoint.com/blog/2015/01/28/getting-realtime-output-using-python
-
pymodule.sys_tool.mkdir(path)[source]¶ Meke intermediate directories and OK if exists. https://stackoverflow.com/a/14364249/8877268
-
pymodule.sys_tool.setup_logging(fpar='logging.yml', env_key='LOG_CFG', default_level=20)[source]¶ Setup logging configuration. https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
Parameters: - fpar –
- env_key – environment variable e.g. LOG_CFG=my_logging.yml python my_server.py
timing¶
Show time elapsed.