Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xumi1993 committed Feb 29, 2024
1 parent 436b16f commit 2dc205e
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 75 deletions.
23 changes: 16 additions & 7 deletions seispy/ccpprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def _prof_range(lat, lon):

def create_center_bin_profile(stations, val=5, method='linear'):
"""Create bins along a profile with given stations
:param stations: Stations along a profile
:type stations: :class:`seispy.rf2depth_makedata.Station`
:param val: The interval between two points in km
Expand Down Expand Up @@ -109,6 +110,7 @@ def init_profile(lat1, lon1, lat2, lon2, val):
class CCPProfile():
def __init__(self, cfg_file=None, log:SetupLog=SetupLog()):
"""CCPProfile class for CCP stacking along a profile
:param cfg_file: Configure file for CCP stacking
:type cfg_file: str
:param log: Log class for logging
Expand All @@ -118,12 +120,12 @@ def __init__(self, cfg_file=None, log:SetupLog=SetupLog()):
if cfg_file is None:
self.cpara = CCPPara()
elif isinstance(cfg_file, str):
self.load_para(cfg_file)
self._load_para(cfg_file)
else:
raise ValueError('cfg_file must be str format.')
self.stack_data = []

def load_para(self, cfg_file):
def _load_para(self, cfg_file):
try:
self.cpara = ccppara(cfg_file)
except Exception as e:
Expand Down Expand Up @@ -277,12 +279,19 @@ def stack(self):
self.stack_data.append(boot_stack)

def save_stack_data(self, format='npz'):
"""If format is \'npz\', saving stacked data and parameters to local as a npz file. To load the file, please use data = np.load(fname, allow_pickle=True).
data['cpara'] is the parameters when CCP stacking.
data['stack_data'] is the result of stacked data.
"""If format is ``npz``, saving stacked data and parameters to local as a npz file. To load the file, please use data = np.load(fname, allow_pickle=True).
``data['cpara']`` is the parameters when CCP stacking.
``data['stack_data']`` is the result of stacked data.
If format is \'dat\' the stacked data will be save into a txt file with 8 columns, including bin_lat, bin_lon, profile_dis, depth, amp, ci_low, ci_high and count.
where bin_lat and bin_lon represent the position of each bin; profile_dis represents the distance in km between each bin and the start point of the profile; depth represents depth of each bin; amp means the stacked amplitude; ci_low and ci_high mean confidence interval with bootstrap method; count represents stacking number of each bin.
If format is ``dat`` the stacked data will be save into a txt file with 8 columns,
including ``bin_lat``, ``bin_lon``, ``profile_dis``, ``depth``, ``amp``, ``ci_low``, ``ci_high`` and ``count``.
- ``bin_lat`` and ``bin_lon`` represent the position of each bin;
- ``profile_dis`` represents the distance in km between each bin and the start point of the profile;
- ``depth`` represents depth of each bin;
- ``amp`` means the stacked amplitude;
- ``ci_low`` and ``ci_high`` mean confidence interval with bootstrap method;
- ``count`` represents stacking number of each bin.
:param format: Format for stacked data
:type format: str
Expand Down
58 changes: 7 additions & 51 deletions seispy/distaz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,15 @@
import numpy as np


def sind(deg):
rad = math.radians(deg)
return math.sin(rad)


def cosd(deg):
rad = math.radians(deg)
return math.cos(rad)


def tand(deg):
rad = math.radians(deg)
return math.tan(rad)


def cotd(deg):
rad = math.radians(deg)
return math.cos(rad) / math.sin(rad)


def asind(x):
rad = math.asin(x)
return math.degrees(rad)


def acosd(x):
rad = math.acos(x)
return math.degrees(rad)


def atand(x):
rad = math.atan(x)
return math.degrees(rad)


def km2deg(kilometers):
return kilometers / 111.19


def deg2km(degree):
return degree * 111.19


class distaz:
"""
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
Subroutine to calculate the Great Circle Arc distance
between two sets of geographic coordinates
Equations take from Bullen, pages 154, 155
T. Owens, September 19, 1991
Sept. 25 -- fixed az and baz calculations
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.
Expand Down
22 changes: 22 additions & 0 deletions seispy/eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __str__(self):
return '{}'.format(self.matchkey)

def rotateZNE(st):
"""Rotate Z, N, E components to Z, N, E components
"""
try:
zne = rotate2zne(
st[0], st[0].stats.sac.cmpaz, st[0].stats.sac.cmpinc,
Expand Down Expand Up @@ -92,6 +94,7 @@ def _cleanstream(self):
@classmethod
def from_stream(cls, stream):
"""Create EQ object from obspy stream
:param stream: obspy stream
:type stream: obspy.Stream
:return: EQ object
Expand Down Expand Up @@ -138,6 +141,13 @@ def channel_correct(self, switchEN=False, reverseE=False, reverseN=False):
self.st.select(channel='*[N1]')[0].stats.channel = chE

def write(self, path, evt_datetime):
"""Write raw stream to SAC files
:param path: path to save SAC files
:type path: str
:param evt_datetime: event datetime
:type evt_datetime: obspy.core.utcdatetime.UTCDateTime
"""
for tr in self.st:
sac = SACTrace.from_obspy_trace(tr)
sac.b = 0
Expand All @@ -158,6 +168,7 @@ def detrend(self):

def filter(self, freqmin=0.05, freqmax=1, order=4):
"""Bandpass filter
:param freqmin: minimum frequency, defaults to 0.05
:type freqmin: float, optional
:param freqmax: maximum frequency, defaults to 1
Expand All @@ -169,6 +180,7 @@ def filter(self, freqmin=0.05, freqmax=1, order=4):

def get_arrival(self, model, evdp, dis, phase='P'):
"""Get arrival time, ray parameter and incident angle from TauP model
:param model: TauP model
:type model: TauPyModel
:param evdp: focal depth
Expand All @@ -192,6 +204,7 @@ def get_arrival(self, model, evdp, dis, phase='P'):

def search_inc(self, bazi):
"""Search incident angle for S wave
:param bazi: back azimuth
:type bazi: float
:return: incident angle
Expand All @@ -211,6 +224,7 @@ def search_inc(self, bazi):

def search_baz(self, bazi, time_b=10, time_e=20, offset=90):
"""Search back azimuth for P wave
:param bazi: back azimuth
:type bazi: float
:param time_b: time before P arrival, defaults to 10
Expand Down Expand Up @@ -261,6 +275,7 @@ def fix_channel_name(self):

def rotate(self, baz, inc=None, method='NE->RT', search_inc=False, baz_shift=0):
"""Rotate to radial and transverse components
:param baz: back azimuth
:type baz: float
:param inc: incident angle, defaults to None
Expand Down Expand Up @@ -294,6 +309,7 @@ def rotate(self, baz, inc=None, method='NE->RT', search_inc=False, baz_shift=0):

def snr(self, length=50):
"""Calculate SNR
:param length: length for noise, defaults to 50
:type length: int, optional
:return: SNR of E, N, Z components
Expand All @@ -317,6 +333,7 @@ def snr(self, length=50):

def get_time_offset(self, event_time=None):
"""Get time offset from SAC header
:param event_time: event time, defaults to None
:type event_time: obspy.core.utcdatetime.UTCDateTime, optional
"""
Expand Down Expand Up @@ -347,6 +364,7 @@ def _get_time(self, time_before, time_after):

def phase_trigger(self, time_before, time_after, prepick=True, stl=5, ltl=10):
""" Trigger P or S phase
:param time_before: time before P or S arrival
:type time_before: float
:param time_after: time after P or S arrival
Expand Down Expand Up @@ -445,6 +463,7 @@ def deconvolute(self, shift, time_after, f0=2.0, method='iter', only_r=False,

def decon_p(self, tshift, tcomp=False, **kwargs):
"""Deconvolution for P wave
:param tshift: Time shift before P arrival
:type tshift: float
:param tcomp: Whether calculate transverse component, defaults to False
Expand All @@ -468,6 +487,7 @@ def decon_p(self, tshift, tcomp=False, **kwargs):

def decon_s(self, tshift, **kwargs):
"""Deconvolution for S wave
:param tshift: Time shift before P arrival
:type tshift: float
"""
Expand All @@ -487,6 +507,7 @@ def saverf(self, path, evtstr=None, shift=0, evla=-12345.,
evlo=-12345., evdp=-12345., mag=-12345.,
gauss=0, baz=-12345., gcarc=-12345., only_r=False, **kwargs):
"""Save receiver function to SAC file
:param path: path to save SAC file
:type path: str
:param evtstr: event string, defaults to None
Expand Down Expand Up @@ -560,6 +581,7 @@ def _s_condition(self, trrf, shift):

def judge_rf(self, gauss, shift, npts, criterion='crust', rmsgate=None):
"""Judge whether receiver function is valid
:param gauss: Gaussian factor
:type gauss: float
:param shift: time shift before P arrival
Expand Down
1 change: 1 addition & 0 deletions seispy/hk.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def ci(allstack, h, kappa, ev_num):
"""
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
Expand Down
2 changes: 2 additions & 0 deletions seispy/rf2depth_makedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class RFDepth():
def __init__(self, cpara:CCPPara, log:Logger=SetupLog().RF2depthlog,
raytracing3d=False, velmod3d=None, modfolder1d=None) -> None:
"""
Convert receiver function to depth axis
:param cpara: CCPPara object
:type cpara: CCPPara
:param log: Log object
Expand Down
Loading

0 comments on commit 2dc205e

Please sign in to comment.