seismolib package
Submodules
seismolib.geo module
- seismolib.geo.deg2km(deg, R0=6371.0)
角距離(deg.)を距離(km)に変換する.オプションで地球サイズ`R0`も変更できる.
- Parameters:
deg (number) – 角距離
R0 (number, optional) – 地球半径(6371kmがデフォルト)
- seismolib.geo.epdist(event_lon, event_lat, station_lon, station_lat, is_elliptic=False)
2組の緯度経度から震央距離・Azimuth・Back Azimuthの計算を行う
定式化は地震の辞典第2版 p.52に基づく.方位角は北から時計回りに測る. 基本的には球面三角法だが,距離が近いときにベッセル楕円体の地心半径を 用いた高精度計算(is_elliptic = True ) も行える.
- Parameters:
event_lon (float) – 震源の緯度経度 (degrees)
event_lat (float) – 震源の緯度経度 (degrees)
station_lon (float) – 観測点緯度経度(degrees)
station_lat (float) – 観測点緯度経度(degrees)
- Returns:
(dist (km), azimuth (degree), back_azimuth (degree))
- Return type:
tuple
Examples
>>> epdist(135, 35, 136, 36) (143.38265213187395, 38.860270806043971, 219.4410056442396)
>>> epdist(135, 35, 136, 36, True) (143.30662405398323, 38.986394043530979, 219.5645515565227)
- seismolib.geo.km2deg(km, R0=6371.0)
距離(km)を角距離(deg.)に変換する.オプションで地球サイズ`R0`も変更できる.
- Parameters:
km (number) – 距離
R0 (number, optional) – 地球半径(6371kmがデフォルト)
- seismolib.geo.mercator_aspect(region, e=0.08181919104281579)
PyGMT形式で与えられた地図領域 [lon0, lon1, lat0, lat1] から, メルカトル投影された地図の縦横比Rを返す. ただし離心率 e のデフォルト値は地球のものが仮定されている. 他惑星で利用するときはこの値をオプション変数として変更すること.
- seismolib.geo.polygon(x, y, px, py)
Return if (x,y) is inside a polygon having vertices at (px(:), py(:))
- Parameters:
x (float) – Location to be investigated
y (float) – Location to be investigated
px (Array-like) – Polygon vertices
py (Array-like) – Polygon vertices
- Returns:
True if (x,y) is inside the polygon
- Return type:
bool
Examples
>>> polygon(0.5, 0.5, [0, 1, 1, 0], [0, 0, 1, 1]) True
>>> polygon(1.5, 1.5, [0, 1, 1, 0], [0, 0, 1, 1]) False
seismolib.gk module
Gauss-Krugeur projection based on GSI’s formula
http://goo.gl/qoYh8t, http://goo.gl/mSuDxm
- seismolib.gk.ll2xy(lon, lat, clon, clat)
Convert longitude & latitude (deg.) to x, y (km)
- Parameters:
lon (float) – longitude and latitude (degrees) to be converted to cartesian
lat (float) – longitude and latitude (degrees) to be converted to cartesian
clon (float) – longitude and latitude of reference point (deg.)
clat (float) – longitude and latitude of reference point (deg.)
- Returns:
x, y – Northing/Easting coordinate (km) measured from (clon, clat)
- Return type:
float
Example
>>> ll2xy(144, 43, 144.25, 44) (-111.061047360681, -20.38320805146281)
- seismolib.gk.xy2ll(x, y, clon, clat)
Convert x & y (km) to x, y (km). Inverse of ll2xy
- Parameters:
x (float) – Northing & easting coordinate location measured from reference (km)
y (float) – Northing & easting coordinate location measured from reference (km)
clon (float) – longitude and latitude of reference point (degrees)
clat (float) – longitude and latitude of reference point (degrees)
- Returns:
lon, lat – longitude and latitude (degrees)
- Return type:
float
Example
>>> sl.xy2ll(-111.061047360681, -20.38320805146281, 144.25, 44) (144.0, 43.0)
seismolib.signal module
- seismolib.signal.bp(dat, sfreq, fl, fh, nord, twopass)
band-pass filter
Apply band-pass filter of nord-th order, with the corner frequencies of (fl, fh). Essentially same with obspy.signal.filter.bandpass
- Parameters:
dat (numpy.ndarray) – Original data to be filtered
sfreq (float/int) – Sampling frequency of data (usually in Hz)
fl (float) – lower corner frequency of the band pass (the same unit w/sfreq)
fh (float) – lower corner frequency of the band pass (the same unit w/sfreq)
nord (int) – filter order
twopass (bool) – apply the same filter from positive and netgative directions to realize zero-phase filter. In this case, filter order will be doubled.
- Returns:
Filtered data
- Return type:
numpy.ndarray
- seismolib.signal.envelope_hilbert(d)
ヒルベルト変換による時系列dのエンベロープ dの解析信号の絶対値として定義される.
- Parameters:
d (array-like) – input data
- Returns:
envelope of input data
- Return type:
array-like
- seismolib.signal.envelope_rms(d, hw)
半値幅 hw のRMS平均による時系列 d のエンベロープ
- Parameters:
d (array-like) – input data
hw (half-window length)
- Returns:
envelope of input data
- Return type:
array-like
- seismolib.signal.freq2time(c, dt, nfft=None, sign='negative')
Inverse of time2freq
計算の定義は
- $$
u(t) = sum_{i=0}^{N-1} u(f_i) exp[-j 2 pi f_i t] dt
$$
- Parameters:
c (array-like, complex) – fourier spectrum of u
dt (float) – sampling interval (usualy in seconds)
nfft (integer (optional)) – size of fft. Power of 2 is highly recommended for efficient computation default: (len(u)-1)*2
sign (str) – ‘positive’ or ‘negative
- Returns:
u (array-like, real) – time series
t (array-like, real) – time, starting from zero
- seismolib.signal.hp(dat, sfreq, fl, nord, twopass)
high-pass filter
Apply low-pass filter of nord-th order, with the corner frequencies of fh. Essentially same with obspy.signal.filter.bandpass
- Parameters:
dat (numpy.ndarray)) – Original data to be filtered
sfreq (float/int) – Sampling frequency of data (usually in Hz)
fl (float) – corner frequency of the high-pass filter (the same unit w/sfreq)
nord (int) – filter order
twopass (bool) – apply the same filter from positive and netgative directions to realize zero-phase filter. In this case, filter order will be doubled.
- Returns:
Filtered data
- Return type:
numpy.ndarray
- seismolib.signal.lp(dat, sfreq, fh, nord, twopass)
low-pass filter
Apply low-pass filter of nord-th order, with the corner frequencies of fh. Essentially same with obspy.signal.filter.bandpass
- Parameters:
dat (numpy.ndarray)) – Original data to be filtered
sfreq (float/int) – Sampling frequency of data (usually in Hz)
fh (float) – Corner frequency of the low-pass filter (the same unit w/sfreq)
nord (int) – filter order
twopass (bool) – apply the same filter from positive and netgative directions to realize zero-phase filter. In this case, filter order will be doubled.
- Returns:
Filtered data
- Return type:
numpy.ndarray
- seismolib.signal.psdf_fft(u, dt, nfft=None, taper=None, alpha=0.2)
Power spectral density function by means of FFT
- Parameters:
u (array-like) – time-series data of which PSDF is estimated.
dt (float) – sampling interval (usually in sec.)
nfft (int, optional) – number of samples to perform FFT. Power of 2 is highly recommended.
taper (str, optional) – type of tapering window. ‘Hanning’/’Hamming’/’Cosine’ if taper is not None, Hamming is used as default taper window.
alpha (float, optional) – Taper shape parameter for the ‘Cosine’ type taper. See taper_cosine for detail.
- seismolib.signal.rmean(u)
remove mean from array u
- Parameters:
u (array-like) – input data
- Returns:
data with mean subtracted
- Return type:
array-like
- seismolib.signal.rot_hcmp(data_x, data_y, cmpaz_x, cmpaz_y, rot_angle)
水平動2成分データを rot_angle 方向に回転する.
角度はすべて北を0として時計回りに測る.入力地震動の成分は - x: 北から cmpaz_x 方向 - y: 北から cmpaz_y 方向 の成分を仮定する.わざわざ角度表現で2成分を独立にあらわしているのは, 地震計の設置方位が南北東西から回転していることがあること,さらに cmpaz_y = cmpaz + 90 であるとは限らないためである.たとえば東西成分の+-を逆につないだらcmpaz=-90である. NE→RT変換には rot_angle を back_azimuth - 180° とする
- Parameters:
data_x (array-like) – 入力2成分データ. 標準的には南北と東西だがその方向はcmpaz_x, cmpaz_yで定義
data_y (array-like) – 入力2成分データ. 標準的には南北と東西だがその方向はcmpaz_x, cmpaz_yで定義
cmpaz_x (float or int) – 入力データの角度.北から時計回り. 南北動なら0,東西動なら90が入る.
cmpaz_y (float or int) – 入力データの角度.北から時計回り. 南北動なら0,東西動なら90が入る.
rot_angle (float or int) – data_x, data_y をそれぞれ この角度だけ時計周りに回転する.
- Returns:
data_v, data_w – それぞれdata_x, data_yを回転したもの
- Return type:
array-like
- seismolib.signal.rtrend(u)
remove linear trend from array u This function is equivalent to scipy.signal.detrend
- Parameters:
u (array-like) – input data
- Returns:
detrended data
- Return type:
array-like
- seismolib.signal.rtrend2(y)
Remove linear trend from array y The trend is estimated by least square method.
- Parameters:
y (array-like) – input data
- Returns:
detrended data
- Return type:
array-like
- seismolib.signal.seismometer_decon(dat, dt, f0=1.0, h0=0.7, f1=0.008333333333333333, h1=0.7071067811865475)
Inverse filterにより地震計特性の逆畳み込みと,広帯域特性の畳み込みを同時に行う.
- Parameters:
dat (array-like) – 地震波形データ
dt (float) – サンプリング間隔
f0 (floats) – 入力記録の地震計の自然周波数とダンピング係数.デフォルトはHi-netの値
h0 (floats) – 入力記録の地震計の自然周波数とダンピング係数.デフォルトはHi-netの値
f1 (floats) – 出力記録の地震計の自然周波数とダンピング係数.デフォルトは120s, critical damping
h1 (floats) – 出力記録の地震計の自然周波数とダンピング係数.デフォルトは120s, critical damping
- Returns:
dat – 畳み込み後のデータ.元データと同じ長さ.
- Return type:
array-like
Notes
Maeda, T., Obara, K., Furumura, T., & Saito, T. (2011). Interference of long-period seismic wavefield observed by dense Hi-net array in Japan, Journal of Geophysical Research: Solid Earth, 116, B10303, doi:10.1029/2011JB008464. http://doi.org/10.1029/2011JB008464
- seismolib.signal.smooth(x, hw)
リスト x の半値幅 hw の移動平均を計算する.
- Parameters:
x (array-like) – input data
hw (integer) – half-window
- Returns:
y – smoothed array of x
- Return type:
array
- seismolib.signal.taper_cosine(d, r=5, nh=None)
Apply cosine (Tukey) taper to data d
- Parameters:
d (array-like) – input data
r (float, optional (0-100)) – Fraction of the window inside the cosine taperd region in % 0 is box-car window 100 returns Hann window
nh (integer) – instead of r, users may specify the length of taper region by specifing number of samples in half-window nh
- Returns:
dt (array-like) – data with taper applied
ta (array-like) – taper window array (dt = d * ta)
- seismolib.signal.taper_hamming(d)
Apply Hamming taper to data d
- Parameters:
d (array-like) – input data
- Returns:
dt (array-like) – data with taper applied
ta (array-like) – taper window array (dt = d * ta)
- seismolib.signal.taper_hanning(d)
Apply Hanning (Han) taper to data d
- Parameters:
d (array-like) – input data
- Returns:
dt (array-like) – data with taper applied
ta (array-like) – taper window array (dt = d * ta)
- seismolib.signal.time2freq(u, dt, nfft=None, sign='positive')
Fourier transform of time series (real-valued) u(t) with sampling interval dt
計算の定義は $$
u(f) = sum_{i=0}^{N-1} u(t_i) exp[j 2 pi f t_i] dt
$$ ただし,オプション変数 sign=’negative’ のときには指数部の符号がマイナスになる.
- Parameters:
u (array-like) – time series data (real)
dt (float) – sampling interval (usualy in seconds)
nfft (integer (optional)) – size of fft. Power of 2 is highly recommended for efficient computation default: len(u)
sign (str) – ‘positive’ or ‘negative
- Returns:
c (array-like (Complex)) – Fourier transform of u
f (array-like (size: nfft/2+1)) – Frequency (1/(unit of dt))
seismolib.times module
- seismolib.times.date(year, month, day)
日付のみの情報からdatetime.dateオブジェクトを返す.
- Parameters:
year (int or str)
month (int or str)
day (int or str)
- Returns:
result
- Return type:
datetime.date object
- seismolib.times.date2jul(date)
Returns julian day (day of the year).
- Parameters:
date (datetime.date or datetime.datetime) – A datetime object of which the julian day is calculated
- Returns:
julday – Julian day of the year
- Return type:
integer
Examples
>>> date2jul(datetime.date(2015, 12, 31)) 365
- seismolib.times.date_time(year, month, day, hour, minute, second)
日時情報からdatetime.datetimeオブジェクトを返す.secondが実数でもOK
- Parameters:
year (int or str)
month (int or str)
day (int or str)
hour (int or str)
minute (int or str)
second (int or float or str) – 秒数は実数でも可.整数部とマイクロ秒部に分割してdatetimeに入力する.
- Returns:
result
- Return type:
datetime.datetime object
Examples
>>> date_time(2021, 10, 1, 0, 0, 0.5) datetime.datetime(2021, 10, 1, 0, 0, 0, 500000)
- seismolib.times.gmtime(t)
Inverse of timegm
- Parameters:
t (float or int) – seconds from 1970-01-01 00:00:00 (UTC)
- Returns:
date
- Return type:
datetime.datetime
- seismolib.times.is_leapyear(yr)
True if the input yr is a leap year
- Parameters:
yr (int)
- Return type:
bool
- seismolib.times.jul2date(year, julday)
Calculate datetime from year and julian day
- Parameters:
year (integer)
juday (integer)
- Return type:
datetime.datetime
Examples
>>> jul2date(2000, 366) datetime.datetime(2000, 12, 31, 0, 0, 0)
- seismolib.times.time_range(start, stop, step=datetime.timedelta(days=1))
datetime.date オブジェクトの start, stop の間を step 間隔で返すジェネレータ yieldされるのは常にdatetime
- Parameters:
start (datetime.date or datetime.datetime) – start day
stop (datetime.date or datetime.datetime) – end day
step (datetime.timdedelta) – step between start and stop
- Yields:
datetime.datetime
Examples
>>> for tim in time_range(datetime.date(2020, 10, 5), datetime.date(2020, 10, 7)): ... print(tim) 2020-10-05 00:00:00 2020-10-06 00:00:00 2020-10-07 00:00:00
File
seismolabpy/times.py
- seismolib.times.timegm(tim)
Returns seconds from 1970-01-01 00:00:00 (UTC)
- Parameters:
tim (float) – time to be converted
Returns
tim – time in seconds
- seismolib.times.to_datetime(datetime64)
convert numpy.datetime64 to datetime.datetime
- Parameters:
datetime64 (numpy.datetime64)
- Return type:
datetime.datetime
seismolib.utils module
- seismolib.utils.chk_value(var, err)
伝統的なエラー判定「未定義の場合に -12345.0 を取る」のような条件を判断する.
未定義定数 err に値が十分近い場合には Noneを,そうでない場合には varを返す. 整数・実数・複素数・文字列に対応.
- Parameters:
var (int or float or complex or str) – 検査値
err (int or float or complex or str) – エラー判定定数
- Returns:
result – var or None
- Return type:
same type with var
Examples
>>> chk_value(3.0, 3.0)
>>> chk_value(3.1, 3.0) 3.1
>>> chk_value('3.1', 'abc') '3.1'
- seismolib.utils.deg2dms(deg)
10進法のdegree を60進法の degree(d):minute(m):second に変換する
Paremters
- degnumber
degree in decimal
- returns:
(d, m, s) – where d, m, s means degree, minute, and second d and m should be integer, while s is float.
- rtype:
tuple of numbers
- seismolib.utils.dms2deg(d, m, s)
60進法の degree(d):minute(m):second を 10進法のdegreeに変換する
- Parameters:
d (number) – degree. can be either positive or negative
m (number) – minutes. usually positive
s (number) – seconds. usually positive
- Returns:
deg – degrees in decimal
- Return type:
float
- seismolib.utils.i2s(i, w=-1)
integer to string
整数値 i を桁数 w の文字列にする.桁数がwに満たない場合は左にゼロを埋める. 桁数が指定されていない場合は必要な最小限の長さの文字列になる. 桁数が指定され,かつ足りない場合はAssertionErrorになる.
- Parameters:
i (int) – integer to be converted
w (int) – column width
- Returns:
result – string representing integer i
- Return type:
str
Examples
>>> i2s(3, 5) '00003'
>>> i2s(-1, 3) '-01'
>>> i2s(-32351) '-32351
- seismolib.utils.split_list(l, n)
split list into lists whose length of n
Examples
>>> for li in split_list(glob.glob(*),10): >>> for f in li: >>> print(f)
seismolib.vmodels module
- seismolib.vmodels.brocher_density(vp)
Brocher (2005)’s empirical relationship between vp and density
- Parameters:
vp (float) – P-wave velocity in km/s
- Returns:
rho – density in g/cm^3
- Return type:
float
- seismolib.vmodels.vmodel_ak135(z)
AK135 velocity model
- Parameters:
z (float) – depth in km
- Returns:
vp, vs (floats) – wavespeeds of P and S waves in km/s
rho (float) – density in g/cm^3
qp, qs (float) – Quality factors of P and S waves
- seismolib.vmodels.vmodel_hinet(z)
Hi-net速度構造
- Parameters:
z (float) – depth in km
- Returns:
vp, vs – wavespeeds of P and S waves
- Return type:
floats
- seismolib.vmodels.vmodel_iasp91(z)
iasp91 velcity model
- Parameters:
z (float) – depth in km
- Returns:
vp, vs – wavespeeds in km/s
- Return type:
floats
Notes
Kennet and Engdahl (1991) GJI 105, 429-465, https://doi.org/10.1111/j.1365-246X.1991.tb06724.x
- seismolib.vmodels.vmodel_jma(z, model='2001')
JMA2001 velocity model
- Parameters:
z (float) – depth in km
model (str) – velocity model version (‘2001’, ‘2020a’, ‘2020b’, ‘2020c’)
- Returns:
vp, vs – wavespeeds of P and S waves in km/s
- Return type:
floats
- seismolib.vmodels.vmodel_prem(z)
Return the modified PREM 1D velocity structure
Compared to the original model of the Diewonski and Anderson (1981), the seawater layer is substituted to a crustal structure if type=’modified’ is given:
rho=2.6 g/cm^3, vp=5.8 km/s, vs=3.2 km/s qmu=600, qkappa = 57823
Or, ‘
This routine returns Q_P and Q_S rather than Q_kappa and Q_mu, by converting using a formula of (9.59) & (9.60) of Dahlen and Tromp (1998)
- Parameters:
z (float) – depth in km
- Returns:
vp, vs (floats) – wavespeeds of P and S waves
rho (float) – density in g/cm^3
qp, qs (float) – Quality factor of P and S waves
- seismolib.vmodels.vmodel_tohoku(z)
東北大ルーチン速度構造
- Parameters:
z (float) – depth in km
- Returns:
vp, vs – wavespeeds of P and S waves
- Return type:
floats
seismolib.traveltime module
- seismolib.traveltime.traveltime_jma(delta, depth)
JMA2001構造による走時計算
- Parameters:
delta (Float) – 震央距離 (km)
depth (Float) – 震源深さ (km)
- Returns:
tp (Float) – P波到達時間 (s)
ts (Float) – S波到達時間 (s)
theta (Float) – 震源射出角 (deg)
seismolib.plot module
- seismolib.plots.eqplot(df, region=None, dep=None, xsize=12, zsize=5, magsize=<function _magnitude_size>, cmap='roma', zdiv=5)
地震活動の断面図プロットを作成する. magsize には マグニチュードからサイズ(cm)への変換を行う関数を与える.
- Parameters:
df (pandas.DataFrame) – 地震カタログデータフレーム.longitude, latitude, depth, magnitude の列を持つ必要がある.
region (array-like) – [lon0, lon1, lat0, lat1] の順で与える.デフォルトはデータフレームの範囲.
dep (array-like) – [z0, z1] の順で与える.デフォルトはデータフレームの範囲.
xsize (float) – 横幅(cm)
zsize (float) – 高さ(cm)
magsize (function) – マグニチュードからサイズ(cm)への変換関数
cmap (str) – カラーマップ名
zdiv (int) – カラーマップの深さ方向の分割数
- seismolib.plots.get_color(col, transp=None)
PyGMTのフォーマットで色を返す
- Parameters:
col (str or list or tuple or int or float) – 色を表す文字列,もしくはRGBのリスト,もしくは整数(色番号)
transp (int or float) – 透明度(0-100)
- Returns:
PyGMTの色表現
- Return type:
str
- seismolib.plots.get_font(fontsize, font, col='Black', transp=None)
Return font specification in PyGMT format
- Parameters:
fontsize (int or str) – Font size
font (str) – Font
col (str or list or tuple or int or float) – Font color
transp (int or float)
- seismolib.plots.get_pen(width, col, transp=None, dash=None)
Return pen type in PyGMT format
- Parameters:
width (float or str) – Pen width
col (str or list or tuple or int or float) – Pen color
transp (int or float) – Transparency (0-100; Default: None)
dash (str) – Dash style (Default: None)
- seismolib.plots.hsv2rgb(h, s=1, v=1)
HSV to RGB conversion
- Parameters:
h (float) – Hue (0-360)
s (float) – Saturation (0-1)
v (float) – Value (0-1)
- Returns:
RGB color in PyGMT format
- Return type:
str
- seismolib.plots.plot(x, y, size=(12, 12), region=None, labels=None, symbol='-', axis=('lin', 'lin'), title=None, show_script=False)
Easy plot by using pyGMT
- Parameters:
x (array-like) – 独立変数
y (array-like (or tuple of array-like)) – 従属変数. 同じ独立変数に対する複数の従属変数を (y1, y2) のようにタプルで与えられる.
region (array or tuple) – (xmin, xmax, ymin, ymax) .デフォルトでは自動設定.
labels (list) – [x軸ラベル, y軸ラベル]
title (str) – プロットタイトル(上部に表示)
symbol (str) – デフォルト(’-’)で線,それ以外で◯.他のシンボルは未対応
axis (array (or tuple) of str) – x軸とy軸それぞれ ‘lin’ or ‘log’ で軸の線形か対数かを指定.デフォルトは線形.
show_script (bool) – 自動生成したスクリプトを表示する.デフォルトは False
- seismolib.plots.plot_mech(strike, dip, rake, azimuth=None, takeoff=None, polarization=None, compressionfill='250/50/150@50', polarizationfill='red')
Plot focal mechanism with azimuth, takeoff and polarization
- Parameters:
strike (floats) – Strike, dip and rake angles of the focal mechanism
dip (floats) – Strike, dip and rake angles of the focal mechanism
rake (floats) – Strike, dip and rake angles of the focal mechanism
azimuth (list of floats (optional)) – Azimuth, takeoff and polarization angles of the radiation pattern if these lists are not provided, only the focal mechanism is plotted.
takeoff (list of floats (optional)) – Azimuth, takeoff and polarization angles of the radiation pattern if these lists are not provided, only the focal mechanism is plotted.
polarization (list of floats (optional)) – Azimuth, takeoff and polarization angles of the radiation pattern if these lists are not provided, only the focal mechanism is plotted.
compressionfill (str) – Fill color for the compression quadrants
polarizationfill (str) – Fill color for the observation points with compressional polarity
- seismolib.plots.pygmt_config(out=False)
標準的なGMT設定.
- Parameters:
out (bool) – Trueの場合は,設定文字列を返す.デフォルトは False
Example
- with pygmt_config():
fig.XXX()
のように with 句と使う.
- seismolib.plots.pygmt_config_S()
標準的なGMT設定.(Small igure version)
- Parameters:
out (bool) – Trueの場合は,設定文字列を返す.デフォルトは False
Example
- with pygmt_config():
fig.XXX()
のように with 句と使う.
- seismolib.plots.record_section(stream, dist=None, tim=None, size=(20, 12), decimation=1, transparency=0, orientation='horizontal', otim=None, filt='raw', fc=None, nord=2, twopass=True, scale='auto', mag=1.0, color=('134/49/74', '85/80/39', '63/70/138', '111/47/127', '44/86/105'), plot_stcode=False, reduce=None, azimuth=[0, 360])
Plot record section of the seismogram: PyGMT version
簡易プロットで良いなら,obspy.Stream.plot(type=’section’) のほうが高速に動作する.
- Parameters:
stream (obspy.Stream) – 地震波形データ. その中のTraceにstats.distance (m) もしくは stats.sac.dist (km) が入っていることが前提
dist (array-like (optional)) – プロットする距離範囲 (km) の下限と上限を list か tuple で与える. デフォルトはstreamに含まれる距離の最小値から最大値まで
tim (array-like (optional)) – プロットする時間範囲 (s) の下限と上限を list か tuple で与える. デフォルトはstreamに含まれる時間の最小値から最大値まで
size (array-like (optional)) – (width, height) を cm 単位で与える.デフォルトは (20, 12)
decimation (int (optional)) – プロットを高速化するために,波形をdecimationごとに間引いてプロットする. たとえばdecimation=10なら波形の 0, 10, 20 … サンプルが飛び飛びにプロットされる. デフォルトは1(間引きなし). 1つの地震波形のサンプル数が数千程度以下におさまる程度にするのがよい.サンプル数が多くなると極端に遅くなる.
transparency (int (optional)) – 波形の透明度.0-100の数値で与える.デフォルトは0(不透明)
orientation ('horizontal' or 'vertical') – horizontal は 横軸に距離,縦軸に時間(デフォルト:ObsPyと同じ),vertical はその逆
otim (datetime.datetime (optional)) – 時刻 0 の時間(地震発生時刻)を強制的に otim にずらす デフォルトでは trace.stats.starttime を 時間 t = trace.stats.sac.b のであるとして,t=0 に相当する時刻がotimに相当する.これは,eventdataの仕様に合わせてある.
filt ('raw', 'bp' ,'lp' , 'hp' (optional)) – フィルタの種類.デフォルトは ‘raw’ (生波形=なにもしない). bp の場合には fc = (fl, fh) で低周波と高周波の下限上限を Hz で, lp と hp の場合には fc に上限もしくは下限の周波数を Hz で,それぞれ与える.
fc (フィルタの周波数パラメタ.(optional)) – filt パラメタの説明参照.
nord (int (optional)) – フィルタの次数.デフォルトは 2
twopass (Bool (optional)) – 前後からのゼロ位相フィルタを適用するかどうか.デフォルトはTrue Trueの場合,フィルタが2回適用されるため,フィルタ次数は nord * 2 になる.
scale ('auto' or flort (optional)) – ‘auto’ の場合,波形ごとの最大値で規格化される. 数値で与えられた場合,波形の単位におけるその数値が基準振幅となる.デフォルトは’auto’
mag (float (optional)) – scaleで指定された倍率を全体に mag 倍する.主に’auto’のときに全体の倍率を調整する用途. デフォルトは 1
color (array-like of str or str(optional)) – 波形の色.単一の文字列で与えられたとき(例:’black’)はすべてその色になる. list/tupleで与えられたとき([‘black’, ‘blue’, ‘red’, ‘orange’])波形の色はリスト内の 色を周期的に用いる. デフォルトは (“134/49/74”, “85/80/39”, “63/70/138”, “111/47/127”, “44/86/105”)
plot_stcode (Bool (optional)) – 観測点名をプロットする場合 True にする.デフォルトはFalse
reduce (float (optional)) – 数値が与えられたとき,それを km/s 単位のレデュース速度とみなして波形をレデュースする. デフォルトは None (レデュースしない)
azimuth (array-like) – (az1, az2) という長さ2のlist/tupleが与えられたとき,震源から見た観測点の方位角(Azimuth)が az1 <= azimuth < az2 の観測点だけプロットする.
- seismolib.plots.spectrogram(trace, nwin=512, wshift=100, nfft=None, frange=None, trange=None, prange=None, flog=True, plog=True, cmap='abyss', cmap_cont=True, return_data=False)
Plot spectrogram of a given trace.
- Parameters:
trace (Obspy trace (or stream)) – if this is stream, use trace[0] data. trace must contain trace.stats.delta and trace.stats.npts headers.
nwin (int) – length of time window to estimate spectrum, in number of samples.
wshift (int) – length of time shift to calculate spectorgram, in number of samples.
nfft (int) – length of time window length to perform FFT, in number of samples . nfft must be equall or larger than nwin. It is most computationally efficient if nfft is power of 2 (like 256, 512, 1024 … )
frange (list of two float numbers) – frequency range to be plotted. Given in (f_minimum, f_maximum) if it is None (default), frequency range is automatically detemined by using nfft and sampling interval of trace.
trange (list of two float numbers) – temporal range to be plotted. if it is None (default), temporal range is automatically detemined by using length of the given trace.
prange (list of two float numbers) – minimum and maximum of the colar pallete.
flog (Bool) – Plot frequency axis in logarithmic scale. True for default.
plog (Bool) – Plot power spectral density function (color) in logarithmic scale. True for default.
cmap (str) – Specify color map. Default is ‘abyss’
cmap_cont (Bool) – Use continuous color palette. Default is True.
return_data (Bool) – if this value is set to True, this funciton returns (fig, time, frequency, PSDF)
- Returns:
fig (PyGMT.Figure) – PyGMT figure object.
time (array) – time axis of the spectrogram
frequency (array) – frequency axis of the spectrogram
PSDF (array)
- seismolib.plots.surface(x, y, z, region=None, dx=None, dy=None, tension=0.0)
Convert xyz data to grd data by usin PyGMT.surface module
- Parameters:
x (array-like) – independent variable arrays x[nx], y[ny]
y (array-like) – independent variable arrays x[nx], y[ny]
z (array-like) – two-dimensional array z[nx,ny]
region (array-like or str) – GMT’s region setting (automatically detemined by default)
dx (float) – grid spacing. default is x[1]-x[0] and y[1]-y[0]
dy (float) – grid spacing. default is x[1]-x[0] and y[1]-y[0]
tension (float) – tension parameter of PyGMT.surface
- Return type:
pygmt.grddata
- seismolib.plots.wiggleplot(stream, timrange, xlabel='time [s]', ylabel='traces')
Wiggle plot of the seismogram.
Note
the detailed documentation will be available later.
- seismolib.plots.xyz2grd(x, y, z, region=None, dx=None, dy=None)
Convert xyz data to grd data by usin PyGMT.xyz2grd module
- Parameters:
x (array-like) – independent variable arrays x[nx], y[ny]
y (array-like) – independent variable arrays x[nx], y[ny]
z (array-like) – two-dimensional array z[nx,ny]
region (array-like or str) – GMT’s region setting (automatically detemined by default)
- Return type:
pygmt.grddata
seismolib.movie module
- seismolib.movie.gif_movie(figs, dpi=720, crop='0.5c')
PyGMTのFigureオブジェクトのリストからGifアニメーションを作成する.Jupyter Notebook上で表示されるオブジェクトを返す.
- Parameters:
figs (list of Figure) – PyGMTのFigureオブジェクトのリスト
dpi (int, optional) – 解像度 (default: 720)
crop (str, optional) – 余白のトリミング量 (default: ‘0.5c’)
- Returns:
HTML – Gifアニメーション
- Return type:
IPython.display.HTML
Module contents
- seismolib.bp(dat, sfreq, fl, fh, nord, twopass)
band-pass filter
Apply band-pass filter of nord-th order, with the corner frequencies of (fl, fh). Essentially same with obspy.signal.filter.bandpass
- Parameters:
dat (numpy.ndarray) – Original data to be filtered
sfreq (float/int) – Sampling frequency of data (usually in Hz)
fl (float) – lower corner frequency of the band pass (the same unit w/sfreq)
fh (float) – lower corner frequency of the band pass (the same unit w/sfreq)
nord (int) – filter order
twopass (bool) – apply the same filter from positive and netgative directions to realize zero-phase filter. In this case, filter order will be doubled.
- Returns:
Filtered data
- Return type:
numpy.ndarray
- seismolib.brocher_density(vp)
Brocher (2005)’s empirical relationship between vp and density
- Parameters:
vp (float) – P-wave velocity in km/s
- Returns:
rho – density in g/cm^3
- Return type:
float
- seismolib.chk_value(var, err)
伝統的なエラー判定「未定義の場合に -12345.0 を取る」のような条件を判断する.
未定義定数 err に値が十分近い場合には Noneを,そうでない場合には varを返す. 整数・実数・複素数・文字列に対応.
- Parameters:
var (int or float or complex or str) – 検査値
err (int or float or complex or str) – エラー判定定数
- Returns:
result – var or None
- Return type:
same type with var
Examples
>>> chk_value(3.0, 3.0)
>>> chk_value(3.1, 3.0) 3.1
>>> chk_value('3.1', 'abc') '3.1'
- seismolib.date(year, month, day)
日付のみの情報からdatetime.dateオブジェクトを返す.
- Parameters:
year (int or str)
month (int or str)
day (int or str)
- Returns:
result
- Return type:
datetime.date object
- seismolib.date2jul(date)
Returns julian day (day of the year).
- Parameters:
date (datetime.date or datetime.datetime) – A datetime object of which the julian day is calculated
- Returns:
julday – Julian day of the year
- Return type:
integer
Examples
>>> date2jul(datetime.date(2015, 12, 31)) 365
- seismolib.date_time(year, month, day, hour, minute, second)
日時情報からdatetime.datetimeオブジェクトを返す.secondが実数でもOK
- Parameters:
year (int or str)
month (int or str)
day (int or str)
hour (int or str)
minute (int or str)
second (int or float or str) – 秒数は実数でも可.整数部とマイクロ秒部に分割してdatetimeに入力する.
- Returns:
result
- Return type:
datetime.datetime object
Examples
>>> date_time(2021, 10, 1, 0, 0, 0.5) datetime.datetime(2021, 10, 1, 0, 0, 0, 500000)
- seismolib.deg2dms(deg)
10進法のdegree を60進法の degree(d):minute(m):second に変換する
Paremters
- degnumber
degree in decimal
- returns:
(d, m, s) – where d, m, s means degree, minute, and second d and m should be integer, while s is float.
- rtype:
tuple of numbers
- seismolib.deg2km(deg, R0=6371.0)
角距離(deg.)を距離(km)に変換する.オプションで地球サイズ`R0`も変更できる.
- Parameters:
deg (number) – 角距離
R0 (number, optional) – 地球半径(6371kmがデフォルト)
- seismolib.dms2deg(d, m, s)
60進法の degree(d):minute(m):second を 10進法のdegreeに変換する
- Parameters:
d (number) – degree. can be either positive or negative
m (number) – minutes. usually positive
s (number) – seconds. usually positive
- Returns:
deg – degrees in decimal
- Return type:
float
- seismolib.envelope_hilbert(d)
ヒルベルト変換による時系列dのエンベロープ dの解析信号の絶対値として定義される.
- Parameters:
d (array-like) – input data
- Returns:
envelope of input data
- Return type:
array-like
- seismolib.envelope_rms(d, hw)
半値幅 hw のRMS平均による時系列 d のエンベロープ
- Parameters:
d (array-like) – input data
hw (half-window length)
- Returns:
envelope of input data
- Return type:
array-like
- seismolib.epdist(event_lon, event_lat, station_lon, station_lat, is_elliptic=False)
2組の緯度経度から震央距離・Azimuth・Back Azimuthの計算を行う
定式化は地震の辞典第2版 p.52に基づく.方位角は北から時計回りに測る. 基本的には球面三角法だが,距離が近いときにベッセル楕円体の地心半径を 用いた高精度計算(is_elliptic = True ) も行える.
- Parameters:
event_lon (float) – 震源の緯度経度 (degrees)
event_lat (float) – 震源の緯度経度 (degrees)
station_lon (float) – 観測点緯度経度(degrees)
station_lat (float) – 観測点緯度経度(degrees)
- Returns:
(dist (km), azimuth (degree), back_azimuth (degree))
- Return type:
tuple
Examples
>>> epdist(135, 35, 136, 36) (143.38265213187395, 38.860270806043971, 219.4410056442396)
>>> epdist(135, 35, 136, 36, True) (143.30662405398323, 38.986394043530979, 219.5645515565227)
- seismolib.eqplot(df, region=None, dep=None, xsize=12, zsize=5, magsize=<function _magnitude_size>, cmap='roma', zdiv=5)
地震活動の断面図プロットを作成する. magsize には マグニチュードからサイズ(cm)への変換を行う関数を与える.
- Parameters:
df (pandas.DataFrame) – 地震カタログデータフレーム.longitude, latitude, depth, magnitude の列を持つ必要がある.
region (array-like) – [lon0, lon1, lat0, lat1] の順で与える.デフォルトはデータフレームの範囲.
dep (array-like) – [z0, z1] の順で与える.デフォルトはデータフレームの範囲.
xsize (float) – 横幅(cm)
zsize (float) – 高さ(cm)
magsize (function) – マグニチュードからサイズ(cm)への変換関数
cmap (str) – カラーマップ名
zdiv (int) – カラーマップの深さ方向の分割数
- seismolib.freq2time(c, dt, nfft=None, sign='negative')
Inverse of time2freq
計算の定義は
- $$
u(t) = sum_{i=0}^{N-1} u(f_i) exp[-j 2 pi f_i t] dt
$$
- Parameters:
c (array-like, complex) – fourier spectrum of u
dt (float) – sampling interval (usualy in seconds)
nfft (integer (optional)) – size of fft. Power of 2 is highly recommended for efficient computation default: (len(u)-1)*2
sign (str) – ‘positive’ or ‘negative
- Returns:
u (array-like, real) – time series
t (array-like, real) – time, starting from zero
- seismolib.get_color(col, transp=None)
PyGMTのフォーマットで色を返す
- Parameters:
col (str or list or tuple or int or float) – 色を表す文字列,もしくはRGBのリスト,もしくは整数(色番号)
transp (int or float) – 透明度(0-100)
- Returns:
PyGMTの色表現
- Return type:
str
- seismolib.get_font(fontsize, font, col='Black', transp=None)
Return font specification in PyGMT format
- Parameters:
fontsize (int or str) – Font size
font (str) – Font
col (str or list or tuple or int or float) – Font color
transp (int or float)
- seismolib.get_pen(width, col, transp=None, dash=None)
Return pen type in PyGMT format
- Parameters:
width (float or str) – Pen width
col (str or list or tuple or int or float) – Pen color
transp (int or float) – Transparency (0-100; Default: None)
dash (str) – Dash style (Default: None)
- seismolib.gif_movie(figs, dpi=720, crop='0.5c')
PyGMTのFigureオブジェクトのリストからGifアニメーションを作成する.Jupyter Notebook上で表示されるオブジェクトを返す.
- Parameters:
figs (list of Figure) – PyGMTのFigureオブジェクトのリスト
dpi (int, optional) – 解像度 (default: 720)
crop (str, optional) – 余白のトリミング量 (default: ‘0.5c’)
- Returns:
HTML – Gifアニメーション
- Return type:
IPython.display.HTML
- seismolib.gmtime(t)
Inverse of timegm
- Parameters:
t (float or int) – seconds from 1970-01-01 00:00:00 (UTC)
- Returns:
date
- Return type:
datetime.datetime
- seismolib.hp(dat, sfreq, fl, nord, twopass)
high-pass filter
Apply low-pass filter of nord-th order, with the corner frequencies of fh. Essentially same with obspy.signal.filter.bandpass
- Parameters:
dat (numpy.ndarray)) – Original data to be filtered
sfreq (float/int) – Sampling frequency of data (usually in Hz)
fl (float) – corner frequency of the high-pass filter (the same unit w/sfreq)
nord (int) – filter order
twopass (bool) – apply the same filter from positive and netgative directions to realize zero-phase filter. In this case, filter order will be doubled.
- Returns:
Filtered data
- Return type:
numpy.ndarray
- seismolib.hsv2rgb(h, s=1, v=1)
HSV to RGB conversion
- Parameters:
h (float) – Hue (0-360)
s (float) – Saturation (0-1)
v (float) – Value (0-1)
- Returns:
RGB color in PyGMT format
- Return type:
str
- seismolib.i2s(i, w=-1)
integer to string
整数値 i を桁数 w の文字列にする.桁数がwに満たない場合は左にゼロを埋める. 桁数が指定されていない場合は必要な最小限の長さの文字列になる. 桁数が指定され,かつ足りない場合はAssertionErrorになる.
- Parameters:
i (int) – integer to be converted
w (int) – column width
- Returns:
result – string representing integer i
- Return type:
str
Examples
>>> i2s(3, 5) '00003'
>>> i2s(-1, 3) '-01'
>>> i2s(-32351) '-32351
- seismolib.is_leapyear(yr)
True if the input yr is a leap year
- Parameters:
yr (int)
- Return type:
bool
- seismolib.jul2date(year, julday)
Calculate datetime from year and julian day
- Parameters:
year (integer)
juday (integer)
- Return type:
datetime.datetime
Examples
>>> jul2date(2000, 366) datetime.datetime(2000, 12, 31, 0, 0, 0)
- seismolib.km2deg(km, R0=6371.0)
距離(km)を角距離(deg.)に変換する.オプションで地球サイズ`R0`も変更できる.
- Parameters:
km (number) – 距離
R0 (number, optional) – 地球半径(6371kmがデフォルト)
- seismolib.ll2xy(lon, lat, clon, clat)
Convert longitude & latitude (deg.) to x, y (km)
- Parameters:
lon (float) – longitude and latitude (degrees) to be converted to cartesian
lat (float) – longitude and latitude (degrees) to be converted to cartesian
clon (float) – longitude and latitude of reference point (deg.)
clat (float) – longitude and latitude of reference point (deg.)
- Returns:
x, y – Northing/Easting coordinate (km) measured from (clon, clat)
- Return type:
float
Example
>>> ll2xy(144, 43, 144.25, 44) (-111.061047360681, -20.38320805146281)
- seismolib.lp(dat, sfreq, fh, nord, twopass)
low-pass filter
Apply low-pass filter of nord-th order, with the corner frequencies of fh. Essentially same with obspy.signal.filter.bandpass
- Parameters:
dat (numpy.ndarray)) – Original data to be filtered
sfreq (float/int) – Sampling frequency of data (usually in Hz)
fh (float) – Corner frequency of the low-pass filter (the same unit w/sfreq)
nord (int) – filter order
twopass (bool) – apply the same filter from positive and netgative directions to realize zero-phase filter. In this case, filter order will be doubled.
- Returns:
Filtered data
- Return type:
numpy.ndarray
- seismolib.mercator_aspect(region, e=0.08181919104281579)
PyGMT形式で与えられた地図領域 [lon0, lon1, lat0, lat1] から, メルカトル投影された地図の縦横比Rを返す. ただし離心率 e のデフォルト値は地球のものが仮定されている. 他惑星で利用するときはこの値をオプション変数として変更すること.
- seismolib.plot(x, y, size=(12, 12), region=None, labels=None, symbol='-', axis=('lin', 'lin'), title=None, show_script=False)
Easy plot by using pyGMT
- Parameters:
x (array-like) – 独立変数
y (array-like (or tuple of array-like)) – 従属変数. 同じ独立変数に対する複数の従属変数を (y1, y2) のようにタプルで与えられる.
region (array or tuple) – (xmin, xmax, ymin, ymax) .デフォルトでは自動設定.
labels (list) – [x軸ラベル, y軸ラベル]
title (str) – プロットタイトル(上部に表示)
symbol (str) – デフォルト(’-’)で線,それ以外で◯.他のシンボルは未対応
axis (array (or tuple) of str) – x軸とy軸それぞれ ‘lin’ or ‘log’ で軸の線形か対数かを指定.デフォルトは線形.
show_script (bool) – 自動生成したスクリプトを表示する.デフォルトは False
- seismolib.plot_mech(strike, dip, rake, azimuth=None, takeoff=None, polarization=None, compressionfill='250/50/150@50', polarizationfill='red')
Plot focal mechanism with azimuth, takeoff and polarization
- Parameters:
strike (floats) – Strike, dip and rake angles of the focal mechanism
dip (floats) – Strike, dip and rake angles of the focal mechanism
rake (floats) – Strike, dip and rake angles of the focal mechanism
azimuth (list of floats (optional)) – Azimuth, takeoff and polarization angles of the radiation pattern if these lists are not provided, only the focal mechanism is plotted.
takeoff (list of floats (optional)) – Azimuth, takeoff and polarization angles of the radiation pattern if these lists are not provided, only the focal mechanism is plotted.
polarization (list of floats (optional)) – Azimuth, takeoff and polarization angles of the radiation pattern if these lists are not provided, only the focal mechanism is plotted.
compressionfill (str) – Fill color for the compression quadrants
polarizationfill (str) – Fill color for the observation points with compressional polarity
- seismolib.polygon(x, y, px, py)
Return if (x,y) is inside a polygon having vertices at (px(:), py(:))
- Parameters:
x (float) – Location to be investigated
y (float) – Location to be investigated
px (Array-like) – Polygon vertices
py (Array-like) – Polygon vertices
- Returns:
True if (x,y) is inside the polygon
- Return type:
bool
Examples
>>> polygon(0.5, 0.5, [0, 1, 1, 0], [0, 0, 1, 1]) True
>>> polygon(1.5, 1.5, [0, 1, 1, 0], [0, 0, 1, 1]) False
- seismolib.psdf_fft(u, dt, nfft=None, taper=None, alpha=0.2)
Power spectral density function by means of FFT
- Parameters:
u (array-like) – time-series data of which PSDF is estimated.
dt (float) – sampling interval (usually in sec.)
nfft (int, optional) – number of samples to perform FFT. Power of 2 is highly recommended.
taper (str, optional) – type of tapering window. ‘Hanning’/’Hamming’/’Cosine’ if taper is not None, Hamming is used as default taper window.
alpha (float, optional) – Taper shape parameter for the ‘Cosine’ type taper. See taper_cosine for detail.
- seismolib.pygmt_config(out=False)
標準的なGMT設定.
- Parameters:
out (bool) – Trueの場合は,設定文字列を返す.デフォルトは False
Example
- with pygmt_config():
fig.XXX()
のように with 句と使う.
- seismolib.pygmt_config_S()
標準的なGMT設定.(Small igure version)
- Parameters:
out (bool) – Trueの場合は,設定文字列を返す.デフォルトは False
Example
- with pygmt_config():
fig.XXX()
のように with 句と使う.
- seismolib.record_section(stream, dist=None, tim=None, size=(20, 12), decimation=1, transparency=0, orientation='horizontal', otim=None, filt='raw', fc=None, nord=2, twopass=True, scale='auto', mag=1.0, color=('134/49/74', '85/80/39', '63/70/138', '111/47/127', '44/86/105'), plot_stcode=False, reduce=None, azimuth=[0, 360])
Plot record section of the seismogram: PyGMT version
簡易プロットで良いなら,obspy.Stream.plot(type=’section’) のほうが高速に動作する.
- Parameters:
stream (obspy.Stream) – 地震波形データ. その中のTraceにstats.distance (m) もしくは stats.sac.dist (km) が入っていることが前提
dist (array-like (optional)) – プロットする距離範囲 (km) の下限と上限を list か tuple で与える. デフォルトはstreamに含まれる距離の最小値から最大値まで
tim (array-like (optional)) – プロットする時間範囲 (s) の下限と上限を list か tuple で与える. デフォルトはstreamに含まれる時間の最小値から最大値まで
size (array-like (optional)) – (width, height) を cm 単位で与える.デフォルトは (20, 12)
decimation (int (optional)) – プロットを高速化するために,波形をdecimationごとに間引いてプロットする. たとえばdecimation=10なら波形の 0, 10, 20 … サンプルが飛び飛びにプロットされる. デフォルトは1(間引きなし). 1つの地震波形のサンプル数が数千程度以下におさまる程度にするのがよい.サンプル数が多くなると極端に遅くなる.
transparency (int (optional)) – 波形の透明度.0-100の数値で与える.デフォルトは0(不透明)
orientation ('horizontal' or 'vertical') – horizontal は 横軸に距離,縦軸に時間(デフォルト:ObsPyと同じ),vertical はその逆
otim (datetime.datetime (optional)) – 時刻 0 の時間(地震発生時刻)を強制的に otim にずらす デフォルトでは trace.stats.starttime を 時間 t = trace.stats.sac.b のであるとして,t=0 に相当する時刻がotimに相当する.これは,eventdataの仕様に合わせてある.
filt ('raw', 'bp' ,'lp' , 'hp' (optional)) – フィルタの種類.デフォルトは ‘raw’ (生波形=なにもしない). bp の場合には fc = (fl, fh) で低周波と高周波の下限上限を Hz で, lp と hp の場合には fc に上限もしくは下限の周波数を Hz で,それぞれ与える.
fc (フィルタの周波数パラメタ.(optional)) – filt パラメタの説明参照.
nord (int (optional)) – フィルタの次数.デフォルトは 2
twopass (Bool (optional)) – 前後からのゼロ位相フィルタを適用するかどうか.デフォルトはTrue Trueの場合,フィルタが2回適用されるため,フィルタ次数は nord * 2 になる.
scale ('auto' or flort (optional)) – ‘auto’ の場合,波形ごとの最大値で規格化される. 数値で与えられた場合,波形の単位におけるその数値が基準振幅となる.デフォルトは’auto’
mag (float (optional)) – scaleで指定された倍率を全体に mag 倍する.主に’auto’のときに全体の倍率を調整する用途. デフォルトは 1
color (array-like of str or str(optional)) – 波形の色.単一の文字列で与えられたとき(例:’black’)はすべてその色になる. list/tupleで与えられたとき([‘black’, ‘blue’, ‘red’, ‘orange’])波形の色はリスト内の 色を周期的に用いる. デフォルトは (“134/49/74”, “85/80/39”, “63/70/138”, “111/47/127”, “44/86/105”)
plot_stcode (Bool (optional)) – 観測点名をプロットする場合 True にする.デフォルトはFalse
reduce (float (optional)) – 数値が与えられたとき,それを km/s 単位のレデュース速度とみなして波形をレデュースする. デフォルトは None (レデュースしない)
azimuth (array-like) – (az1, az2) という長さ2のlist/tupleが与えられたとき,震源から見た観測点の方位角(Azimuth)が az1 <= azimuth < az2 の観測点だけプロットする.
- seismolib.rmean(u)
remove mean from array u
- Parameters:
u (array-like) – input data
- Returns:
data with mean subtracted
- Return type:
array-like
- seismolib.rot_hcmp(data_x, data_y, cmpaz_x, cmpaz_y, rot_angle)
水平動2成分データを rot_angle 方向に回転する.
角度はすべて北を0として時計回りに測る.入力地震動の成分は - x: 北から cmpaz_x 方向 - y: 北から cmpaz_y 方向 の成分を仮定する.わざわざ角度表現で2成分を独立にあらわしているのは, 地震計の設置方位が南北東西から回転していることがあること,さらに cmpaz_y = cmpaz + 90 であるとは限らないためである.たとえば東西成分の+-を逆につないだらcmpaz=-90である. NE→RT変換には rot_angle を back_azimuth - 180° とする
- Parameters:
data_x (array-like) – 入力2成分データ. 標準的には南北と東西だがその方向はcmpaz_x, cmpaz_yで定義
data_y (array-like) – 入力2成分データ. 標準的には南北と東西だがその方向はcmpaz_x, cmpaz_yで定義
cmpaz_x (float or int) – 入力データの角度.北から時計回り. 南北動なら0,東西動なら90が入る.
cmpaz_y (float or int) – 入力データの角度.北から時計回り. 南北動なら0,東西動なら90が入る.
rot_angle (float or int) – data_x, data_y をそれぞれ この角度だけ時計周りに回転する.
- Returns:
data_v, data_w – それぞれdata_x, data_yを回転したもの
- Return type:
array-like
- seismolib.rtrend(u)
remove linear trend from array u This function is equivalent to scipy.signal.detrend
- Parameters:
u (array-like) – input data
- Returns:
detrended data
- Return type:
array-like
- seismolib.rtrend2(y)
Remove linear trend from array y The trend is estimated by least square method.
- Parameters:
y (array-like) – input data
- Returns:
detrended data
- Return type:
array-like
- seismolib.seismometer_decon(dat, dt, f0=1.0, h0=0.7, f1=0.008333333333333333, h1=0.7071067811865475)
Inverse filterにより地震計特性の逆畳み込みと,広帯域特性の畳み込みを同時に行う.
- Parameters:
dat (array-like) – 地震波形データ
dt (float) – サンプリング間隔
f0 (floats) – 入力記録の地震計の自然周波数とダンピング係数.デフォルトはHi-netの値
h0 (floats) – 入力記録の地震計の自然周波数とダンピング係数.デフォルトはHi-netの値
f1 (floats) – 出力記録の地震計の自然周波数とダンピング係数.デフォルトは120s, critical damping
h1 (floats) – 出力記録の地震計の自然周波数とダンピング係数.デフォルトは120s, critical damping
- Returns:
dat – 畳み込み後のデータ.元データと同じ長さ.
- Return type:
array-like
Notes
Maeda, T., Obara, K., Furumura, T., & Saito, T. (2011). Interference of long-period seismic wavefield observed by dense Hi-net array in Japan, Journal of Geophysical Research: Solid Earth, 116, B10303, doi:10.1029/2011JB008464. http://doi.org/10.1029/2011JB008464
- seismolib.smooth(x, hw)
リスト x の半値幅 hw の移動平均を計算する.
- Parameters:
x (array-like) – input data
hw (integer) – half-window
- Returns:
y – smoothed array of x
- Return type:
array
- seismolib.spectrogram(trace, nwin=512, wshift=100, nfft=None, frange=None, trange=None, prange=None, flog=True, plog=True, cmap='abyss', cmap_cont=True, return_data=False)
Plot spectrogram of a given trace.
- Parameters:
trace (Obspy trace (or stream)) – if this is stream, use trace[0] data. trace must contain trace.stats.delta and trace.stats.npts headers.
nwin (int) – length of time window to estimate spectrum, in number of samples.
wshift (int) – length of time shift to calculate spectorgram, in number of samples.
nfft (int) – length of time window length to perform FFT, in number of samples . nfft must be equall or larger than nwin. It is most computationally efficient if nfft is power of 2 (like 256, 512, 1024 … )
frange (list of two float numbers) – frequency range to be plotted. Given in (f_minimum, f_maximum) if it is None (default), frequency range is automatically detemined by using nfft and sampling interval of trace.
trange (list of two float numbers) – temporal range to be plotted. if it is None (default), temporal range is automatically detemined by using length of the given trace.
prange (list of two float numbers) – minimum and maximum of the colar pallete.
flog (Bool) – Plot frequency axis in logarithmic scale. True for default.
plog (Bool) – Plot power spectral density function (color) in logarithmic scale. True for default.
cmap (str) – Specify color map. Default is ‘abyss’
cmap_cont (Bool) – Use continuous color palette. Default is True.
return_data (Bool) – if this value is set to True, this funciton returns (fig, time, frequency, PSDF)
- Returns:
fig (PyGMT.Figure) – PyGMT figure object.
time (array) – time axis of the spectrogram
frequency (array) – frequency axis of the spectrogram
PSDF (array)
- seismolib.split_list(l, n)
split list into lists whose length of n
Examples
>>> for li in split_list(glob.glob(*),10): >>> for f in li: >>> print(f)
- seismolib.surface(x, y, z, region=None, dx=None, dy=None, tension=0.0)
Convert xyz data to grd data by usin PyGMT.surface module
- Parameters:
x (array-like) – independent variable arrays x[nx], y[ny]
y (array-like) – independent variable arrays x[nx], y[ny]
z (array-like) – two-dimensional array z[nx,ny]
region (array-like or str) – GMT’s region setting (automatically detemined by default)
dx (float) – grid spacing. default is x[1]-x[0] and y[1]-y[0]
dy (float) – grid spacing. default is x[1]-x[0] and y[1]-y[0]
tension (float) – tension parameter of PyGMT.surface
- Return type:
pygmt.grddata
- seismolib.taper_cosine(d, r=5, nh=None)
Apply cosine (Tukey) taper to data d
- Parameters:
d (array-like) – input data
r (float, optional (0-100)) – Fraction of the window inside the cosine taperd region in % 0 is box-car window 100 returns Hann window
nh (integer) – instead of r, users may specify the length of taper region by specifing number of samples in half-window nh
- Returns:
dt (array-like) – data with taper applied
ta (array-like) – taper window array (dt = d * ta)
- seismolib.taper_hamming(d)
Apply Hamming taper to data d
- Parameters:
d (array-like) – input data
- Returns:
dt (array-like) – data with taper applied
ta (array-like) – taper window array (dt = d * ta)
- seismolib.taper_hanning(d)
Apply Hanning (Han) taper to data d
- Parameters:
d (array-like) – input data
- Returns:
dt (array-like) – data with taper applied
ta (array-like) – taper window array (dt = d * ta)
- seismolib.time2freq(u, dt, nfft=None, sign='positive')
Fourier transform of time series (real-valued) u(t) with sampling interval dt
計算の定義は $$
u(f) = sum_{i=0}^{N-1} u(t_i) exp[j 2 pi f t_i] dt
$$ ただし,オプション変数 sign=’negative’ のときには指数部の符号がマイナスになる.
- Parameters:
u (array-like) – time series data (real)
dt (float) – sampling interval (usualy in seconds)
nfft (integer (optional)) – size of fft. Power of 2 is highly recommended for efficient computation default: len(u)
sign (str) – ‘positive’ or ‘negative
- Returns:
c (array-like (Complex)) – Fourier transform of u
f (array-like (size: nfft/2+1)) – Frequency (1/(unit of dt))
- seismolib.time_range(start, stop, step=datetime.timedelta(days=1))
datetime.date オブジェクトの start, stop の間を step 間隔で返すジェネレータ yieldされるのは常にdatetime
- Parameters:
start (datetime.date or datetime.datetime) – start day
stop (datetime.date or datetime.datetime) – end day
step (datetime.timdedelta) – step between start and stop
- Yields:
datetime.datetime
Examples
>>> for tim in time_range(datetime.date(2020, 10, 5), datetime.date(2020, 10, 7)): ... print(tim) 2020-10-05 00:00:00 2020-10-06 00:00:00 2020-10-07 00:00:00
File
seismolabpy/times.py
- seismolib.timegm(tim)
Returns seconds from 1970-01-01 00:00:00 (UTC)
- Parameters:
tim (float) – time to be converted
Returns
tim – time in seconds
- seismolib.to_datetime(datetime64)
convert numpy.datetime64 to datetime.datetime
- Parameters:
datetime64 (numpy.datetime64)
- Return type:
datetime.datetime
- seismolib.traveltime_jma(delta, depth)
JMA2001構造による走時計算
- Parameters:
delta (Float) – 震央距離 (km)
depth (Float) – 震源深さ (km)
- Returns:
tp (Float) – P波到達時間 (s)
ts (Float) – S波到達時間 (s)
theta (Float) – 震源射出角 (deg)
- seismolib.vmodel_ak135(z)
AK135 velocity model
- Parameters:
z (float) – depth in km
- Returns:
vp, vs (floats) – wavespeeds of P and S waves in km/s
rho (float) – density in g/cm^3
qp, qs (float) – Quality factors of P and S waves
- seismolib.vmodel_hinet(z)
Hi-net速度構造
- Parameters:
z (float) – depth in km
- Returns:
vp, vs – wavespeeds of P and S waves
- Return type:
floats
- seismolib.vmodel_iasp91(z)
iasp91 velcity model
- Parameters:
z (float) – depth in km
- Returns:
vp, vs – wavespeeds in km/s
- Return type:
floats
Notes
Kennet and Engdahl (1991) GJI 105, 429-465, https://doi.org/10.1111/j.1365-246X.1991.tb06724.x
- seismolib.vmodel_jma(z, model='2001')
JMA2001 velocity model
- Parameters:
z (float) – depth in km
model (str) – velocity model version (‘2001’, ‘2020a’, ‘2020b’, ‘2020c’)
- Returns:
vp, vs – wavespeeds of P and S waves in km/s
- Return type:
floats
- seismolib.vmodel_prem(z)
Return the modified PREM 1D velocity structure
Compared to the original model of the Diewonski and Anderson (1981), the seawater layer is substituted to a crustal structure if type=’modified’ is given:
rho=2.6 g/cm^3, vp=5.8 km/s, vs=3.2 km/s qmu=600, qkappa = 57823
Or, ‘
This routine returns Q_P and Q_S rather than Q_kappa and Q_mu, by converting using a formula of (9.59) & (9.60) of Dahlen and Tromp (1998)
- Parameters:
z (float) – depth in km
- Returns:
vp, vs (floats) – wavespeeds of P and S waves
rho (float) – density in g/cm^3
qp, qs (float) – Quality factor of P and S waves
- seismolib.vmodel_tohoku(z)
東北大ルーチン速度構造
- Parameters:
z (float) – depth in km
- Returns:
vp, vs – wavespeeds of P and S waves
- Return type:
floats
- seismolib.wiggleplot(stream, timrange, xlabel='time [s]', ylabel='traces')
Wiggle plot of the seismogram.
Note
the detailed documentation will be available later.
- seismolib.xy2ll(x, y, clon, clat)
Convert x & y (km) to x, y (km). Inverse of ll2xy
- Parameters:
x (float) – Northing & easting coordinate location measured from reference (km)
y (float) – Northing & easting coordinate location measured from reference (km)
clon (float) – longitude and latitude of reference point (degrees)
clat (float) – longitude and latitude of reference point (degrees)
- Returns:
lon, lat – longitude and latitude (degrees)
- Return type:
float
Example
>>> sl.xy2ll(-111.061047360681, -20.38320805146281, 144.25, 44) (144.0, 43.0)
- seismolib.xyz2grd(x, y, z, region=None, dx=None, dy=None)
Convert xyz data to grd data by usin PyGMT.xyz2grd module
- Parameters:
x (array-like) – independent variable arrays x[nx], y[ny]
y (array-like) – independent variable arrays x[nx], y[ny]
z (array-like) – two-dimensional array z[nx,ny]
region (array-like or str) – GMT’s region setting (automatically detemined by default)
- Return type:
pygmt.grddata