RF package

seispy.eq module

class seispy.eq.EQ(pathname, datestr, suffix='SAC')[source]

Bases: object

Methods

arr_correct([write_to_sac])

offset = sac.b - real o

channel_correct([switchEN, reverseE, reverseN])

Correct channel name for R, E, N components

decon_p(tshift[, tcomp])

Deconvolution for P wave

decon_s(tshift, **kwargs)

Deconvolution for S wave

deconvolute(shift, time_after[, f0, method, ...])

Deconvolution

detrend()

Detrend and demean

filter([freqmin, freqmax, order])

Bandpass filter

fix_channel_name()

Fix channel name for R, E, N components

from_stream(stream)

Create EQ object from obspy stream

get_arrival(model, evdp, dis[, phase])

Get arrival time, ray parameter and incident angle from TauP model

get_time_offset([event_time])

Get time offset from SAC header

judge_rf(gauss, shift, npts[, criterion, ...])

Judge whether receiver function is valid

phase_trigger(time_before, time_after[, ...])

Trigger P or S phase

readstream()

Read SAC files to stream

rotate(baz[, inc, method, search_inc, baz_shift])

Rotate to radial and transverse components

saverf(path[, evtstr, shift, evla, evlo, ...])

Save receiver function to SAC file

search_baz(bazi[, time_b, time_e, offset])

Search back azimuth for P wave

search_inc(bazi)

Search incident angle for S wave

set_comp()

Set component name

snr([length])

Calculate SNR

trim(time_before, time_after[, isreturn])

offset = sac.b - real o

write(path, evt_datetime)

Write raw stream to SAC files

arr_correct(write_to_sac=True)[source]

offset = sac.b - real o

channel_correct(switchEN=False, reverseE=False, reverseN=False)[source]

Correct channel name for R, E, N components

Parameters:
  • switchEN (bool, optional) – _description_, defaults to False

  • reverseE (bool, optional) – _description_, defaults to False

  • reverseN (bool, optional) – _description_, defaults to False

decon_p(tshift, tcomp=False, **kwargs)[source]

Deconvolution for P wave

Parameters:
  • tshift (float) – Time shift before P arrival

  • tcomp (bool, optional) – Whether calculate transverse component, defaults to False

decon_s(tshift, **kwargs)[source]

Deconvolution for S wave

Parameters:

tshift (float) – Time shift before P arrival

deconvolute(shift, time_after, f0=2.0, method='iter', only_r=False, itmax=400, minderr=0.001, wlevel=0.05, target_dt=None)[source]

Deconvolution

Parameters:
shiftfloat

Time shift before P arrival

time_afterfloat

Time length after P arrival

f0float or list, optional

Gaussian factors, by default 2.0

methodstr, optional

method for deconvolution in iter or water, by default iter

only_rbool, optional

Whether only calculate RF in prime component, by default False

itmaxint, optional

Maximum iterative number, valid for method of iter, by default 400

minderrfloat, optional

Minium residual error, valid for method of iter, by default 0.001

wlevelfloat, optional

Water level, valid for method of water, by default 0.05

target_dtNone or float, optional

Time delta for resampling, by default None

detrend()[source]

Detrend and demean

filter(freqmin=0.05, freqmax=1, order=4)[source]

Bandpass filter

Parameters:
  • freqmin (float, optional) – minimum frequency, defaults to 0.05

  • freqmax (float, optional) – maximum frequency, defaults to 1

  • order (int, optional) – filter order, defaults to 4

fix_channel_name()[source]

Fix channel name for R, E, N components

classmethod from_stream(stream)[source]

Create EQ object from obspy stream

Parameters:

stream (obspy.Stream) – obspy stream

Returns:

EQ object

Return type:

EQ

get_arrival(model, evdp, dis, phase='P')[source]

Get arrival time, ray parameter and incident angle from TauP model

Parameters:
  • model (TauPyModel) – TauP model

  • evdp (float) – focal depth

  • dis (float) – epicentral distance

  • phase (str, optional) – phase name, defaults to ‘P’

get_time_offset(event_time=None)[source]

Get time offset from SAC header

Parameters:

event_time (obspy.core.utcdatetime.UTCDateTime, optional) – event time, defaults to None

judge_rf(gauss, shift, npts, criterion='crust', rmsgate=None)[source]

Judge whether receiver function is valid

Parameters:
  • gauss (float) – Gaussian factor

  • shift (float) – time shift before P arrival

  • npts (int) – number of points for RF

  • criterion (str, optional) – criterion for judging, defaults to ‘crust’

  • rmsgate (float, optional) – RMS gate, defaults to None

Returns:

whether RF is valid

Return type:

bool

phase_trigger(time_before, time_after, prepick=True, stl=5, ltl=10)[source]

Trigger P or S phase

Parameters:
  • time_before (float) – time before P or S arrival

  • time_after (float) – time after P or S arrival

  • prepick (bool, optional) – whether use prepick, defaults to True

  • stl (int, optional) – short time length for STA/LTA, defaults to 5

  • ltl (int, optional) – long time length for STA/LTA, defaults to 10

readstream()[source]

Read SAC files to stream

rotate(baz, inc=None, method='NE->RT', search_inc=False, baz_shift=0)[source]

Rotate to radial and transverse components

Parameters:
  • baz (float) – back azimuth

  • inc (float, optional) – incident angle, defaults to None

  • method (str, optional) – method for rotation, defaults to ‘NE->RT’

  • search_inc (bool, optional) – whether search incident angle, defaults to False

  • baz_shift (int, optional) – shift back azimuth, defaults to 0

saverf(path, evtstr=None, shift=0, evla=-12345.0, evlo=-12345.0, evdp=-12345.0, mag=-12345.0, gauss=0, baz=-12345.0, gcarc=-12345.0, only_r=False, **kwargs)[source]

Save receiver function to SAC file

Parameters:
  • path (str) – path to save SAC file

  • evtstr (str, optional) – event string, defaults to None

  • shift (int, optional) – time shift before P arrival, defaults to 0

  • evla (float, optional) – event latitude, defaults to -12345.

  • evlo (float, optional) – event longitude, defaults to -12345.

  • evdp (float, optional) – event depth, defaults to -12345.

  • mag (float, optional) – event magnitude, defaults to -12345.

  • gauss (float, optional) – Gaussian factor, defaults to 0

  • baz (float, optional) – back azimuth, defaults to -12345.

  • gcarc (float, optional) – epicentral distance, defaults to -12345.

  • only_r (bool, optional) – whether only save R component, defaults to False

search_baz(bazi, time_b=10, time_e=20, offset=90)[source]

Search back azimuth for P wave

Parameters:
  • bazi (float) – back azimuth

  • time_b (int, optional) – time before P arrival, defaults to 10

  • time_e (int, optional) – time after P arrival, defaults to 20

  • offset (int, optional) – offset for searching, defaults to 90

Returns:

back azimuth and amplitude

Return type:

(float, np.ndarray)

search_inc(bazi)[source]

Search incident angle for S wave

Parameters:

bazi (float) – back azimuth

Returns:

incident angle

Return type:

float

set_comp()[source]

Set component name

snr(length=50)[source]

Calculate SNR

Parameters:

length (int, optional) – length for noise, defaults to 50

Returns:

SNR of E, N, Z components

Return type:

(float, float, float)

trim(time_before, time_after, isreturn=False)[source]

offset = sac.b - real o

write(path, evt_datetime)[source]

Write raw stream to SAC files

Parameters:
  • path (str) – path to save SAC files

  • evt_datetime (obspy.core.utcdatetime.UTCDateTime) – event datetime

exception seispy.eq.NotEnoughComponent(matchkey)[source]

Bases: Exception

exception seispy.eq.TooMoreComponents(matchkey)[source]

Bases: Exception

seispy.eq.rotateZNE(st)[source]

Rotate Z, N, E components to Z, N, E components

seispy.rf module

seispy.rf.CfgModify(cfg_file, session, key, value)[source]
class seispy.rf.RF(cfg_file=None, log=None)[source]

Bases: object

Attributes:
date_begin
date_end

Methods

baz_correct([time_b, time_e, offset, ...])

Correct back-azimuth for all data

cal_phase()

Calculate arrivals and ray parameters for all data

channel_correct()

Correct channel components

deconv()

Deconvolution for all data

detrend()

Detrend all data

drop_eq_snr([length, z_only])

Drop earthquakes with low SNR

filter([freqmin, freqmax, order])

Filter all data

load_stainfo([use_date_range])

Load station information from local file or remote web-service

loadpjt(path)

Load project from local disk

match_eq()

Assosiate earthquakes with local data file or online data.

pick([prepick, stl, ltl])

Pick phase arrival

rotate([search_inc])

Rotate all data to ZNE or RTZ

save_raw_data()

Save raw data to local disk

savepjt()

Save project to local disk

saverf([gauss])

Save receiver functions to local disk

search_eq([local, catalog])

Search earthquakes from local or online data server

trim()

Trim waveforms from start to end

baz_correct(time_b=10, time_e=20, offset=90, correct_angle=None)[source]

Correct back-azimuth for all data

Parameters:
  • time_b (int, optional) – Begin time of searching, defaults to 10

  • time_e (int, optional) – End time of searching, defaults to 20

  • offset (int, optional) – Offset of searching, defaults to 90

  • correct_angle (float, optional) – Correct angle, defaults to None

cal_phase()[source]

Calculate arrivals and ray parameters for all data

channel_correct()[source]

Correct channel components

property date_begin
property date_end
deconv()[source]

Deconvolution for all data

detrend()[source]

Detrend all data

drop_eq_snr(length=None, z_only=False)[source]

Drop earthquakes with low SNR

Parameters:
  • length (int, optional) – Length of data, defaults to None

  • z_only (bool, optional) – Use Z component only, defaults to False

filter(freqmin=None, freqmax=None, order=4)[source]

Filter all data

Parameters:
  • freqmin (float, optional) – Minimum frequency, defaults to self.para.freqmin

  • freqmax (float, optional) – Maximum frequency, defaults to self.para.freqmax

  • order (int, optional) – Order of filter, defaults to 4

load_stainfo(use_date_range=True)[source]

Load station information from local file or remote web-service

Parameters:

use_date_range (bool, optional) – Use date range to search station information, defaults to True

classmethod loadpjt(path)[source]

Load project from local disk

Parameters:

path (str) – Path to project file

Returns:

Project object

Return type:

seispy.rf.RF

match_eq()[source]

Assosiate earthquakes with local data file or online data.

pick(prepick=True, stl=5, ltl=10)[source]

Pick phase arrival

Parameters:
  • prepick (bool, optional) – Use STA/LTA method, defaults to True

  • stl (int, optional) – Short time length, defaults to 5

  • ltl (int, optional) – Long time length, defaults to 10

rotate(search_inc=False)[source]

Rotate all data to ZNE or RTZ

Parameters:

search_inc (bool, optional) – Search incidence angle, defaults to False

save_raw_data()[source]

Save raw data to local disk

savepjt()[source]

Save project to local disk

saverf(gauss=None)[source]

Save receiver functions to local disk

Parameters:

gauss (float, optional) – Gaussian width, defaults to self.para.gauss

search_eq(local=False, catalog=None)[source]

Search earthquakes from local or online data server

Parameters:
  • local (bool, optional) – Search from local data, defaults to False

  • catalog (str, optional) – Catalog type, defaults to None

trim()[source]

Trim waveforms from start to end

exception seispy.rf.SACFileNotFoundError(matchkey)[source]

Bases: Exception

seispy.rf.datestr2regex(datestr)[source]
seispy.rf.fetch_waveform(eq_lst, para, model, logger)[source]

Fetch waveforms from remote data server

Parameters:
Returns:

Earthquake list with fetched waveforms

Return type:

pandas.DataFrame

seispy.rf.match_eq(eq_lst, pathname, stla, stlo, logger, ref_comp='Z', suffix='SAC', offset=None, tolerance=210, dateformat='%Y.%j.%H.%M.%S')[source]

Match earthquakes with local SAC files

Parameters:
  • eq_lst (pandas.DataFrame) – Earthquake list

  • pathname (str) – Path to SAC files

  • stla (float) – Station latitude

  • stlo (float) – Station longitude

  • logger (seispy.setuplog.SetupLog) – Logger

  • ref_comp (str, optional) – Reference component, defaults to ‘Z’

  • suffix (str, optional) – Suffix of SAC files, defaults to ‘SAC’

  • offset (float, optional) – Time offset between SAC files and earthquakes, defaults to None

  • tolerance (int, optional) – Tolerance of time offset, defaults to 210

  • dateformat (str, optional) – Date format of SAC files, defaults to ‘%Y.%j.%H.%M.%S’

Returns:

Earthquake list with matched SAC files

Return type:

pandas.DataFrame

seispy.rf.pickphase(eqs, para, logger)[source]
seispy.rf.process_row(i, size, row, para, model, query, tb, te, logger)[source]
seispy.rf.read_catalog(logpath: str, b_time, e_time, stla: float, stlo: float, magmin=5.5, magmax=10.0, dismin=30.0, dismax=90.0, depthmin=0, depthmax=800)[source]

Read local catalog with seispy or QUAKEML format

Parameters:
  • logpath (str) – Path to catalogs

  • b_time (obspy.UTCDateTime) – Start time

  • e_time (obspy.UTCDateTime) – End time

  • stla (float) – Station latitude

  • stlo (float) – Station longitude

  • magmin (float, optional) – Minimum magnitude, defaults to 5.5

  • magmax (float, optional) – Maximum magnitude, defaults to 10

  • dismin (float, optional) – Minimum distance, defaults to 30

  • dismax (float, optional) – Maximum distance, defaults to 90

Returns:

list of earthquakes

Return type:

pandas.DataFrame

seispy.rf.setpar()[source]

Set parameters to configure file

seispy.para module

class seispy.para.RFPara[source]

Bases: object

Attributes:
catalogpath
criterion
datapath
decon_method
rfpath
server

Methods

read_para(cfg_file)

Read parameters from configure file :param cfg_file: Path to configure file :type cfg_file: str

get_para

property catalogpath
property criterion
property datapath
property decon_method
get_para()[source]
classmethod read_para(cfg_file)[source]

Read parameters from configure file :param cfg_file: Path to configure file :type cfg_file: str

property rfpath
property server
class seispy.para.StaInfo[source]

Bases: object

Methods

get_stainfo()

Get station information

get_station_from_ws(**kwargs)

Get station information from web-service with given network and station or other optional condition.

link_server(server[, user, password])

_summary_

load_stainfo(pathname, ref_comp, suffix)

Load station information from SAC file

get_stainfo()[source]

Get station information

Returns:

Station information

Return type:

dict

get_station_from_ws(**kwargs)[source]

Get station information from web-service with given network and station or other optional condition.

_summary_

Parameters:
  • server (str) – Sever name of FDSN web-service, by default ‘IRIS’

  • user (str, optional) – username, defaults to None

  • password (str, optional) – password, defaults to None

load_stainfo(pathname, ref_comp, suffix)[source]

Load station information from SAC file

Parameters:
  • pathname (str) – Path to SAC file

  • ref_comp (str) – Reference component

  • suffix (str) – Suffix of SAC file