Skip to content

Commit

Permalink
add seisview to prf
Browse files Browse the repository at this point in the history
  • Loading branch information
xumi1993 committed Nov 24, 2023
1 parent de2f9de commit 3d3bb6a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
22 changes: 13 additions & 9 deletions seispy/eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,24 @@ def _get_time(self, time_before, time_after):
t2 = self.st[2].stats.starttime + (arr + self.trigger_shift + time_after)
return t1, t2

def phase_trigger(self, time_before, time_after, stl=5, ltl=10):
def phase_trigger(self, time_before, time_after, prepick=True, stl=5, ltl=10):
t1, t2 = self._get_time(time_before, time_after)
self.st_pick = self.st.copy().trim(t1, t2)
if len(self.st_pick) == 0:
return
if self.phase[-1] == 'P':
tr = self.st_pick.select(channel='*Z')[0]
if prepick:
if self.phase[-1] == 'P':
tr = self.st_pick.select(channel='*Z')[0]
else:
tr = self.st_pick.select(channel='*T')[0]
df = tr.stats.sampling_rate
cft = recursive_sta_lta(tr.data, int(stl*df), int(ltl*df))
n_trigger = np.argmax(np.diff(cft)[int(ltl*df):])+int(ltl*df)
self.t_trigger = t1 + n_trigger/df
self.trigger_shift = n_trigger/df - time_before
else:
tr = self.st_pick.select(channel='*T')[0]
df = tr.stats.sampling_rate
cft = recursive_sta_lta(tr.data, int(stl*df), int(ltl*df))
n_trigger = np.argmax(np.diff(cft)[int(ltl*df):])+int(ltl*df)
self.t_trigger = t1 + n_trigger/df
self.trigger_shift = n_trigger/df - time_before
self.t_trigger = t1
self.trigger_shift = 0.0

def trim(self, time_before, time_after, isreturn=False):
"""
Expand Down
19 changes: 18 additions & 1 deletion seispy/para.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def __init__(self):
self.stel = 0.
self.channel = '*'
self.location = '*'

def __repr__(self) -> str:
# print the station name, channel, location
return '{0}.{1}.{2}:{}'.format(self.network, self.station, self.channel, self.location)

def link_server(self, server, user=None, password=None):
"""_summary_
Expand Down Expand Up @@ -238,7 +242,20 @@ def read_para(cls, cfg_file):
sections.remove('path')
if 'fetch' in sections:
for key, value in cf.items('fetch'):
pa.stainfo.__dict__[key] = value
if key == 'use_remote_data':
pa.__dict__[key] = cf.getboolean('fetch', 'use_remote_data')
elif key == 'data_server_user':
if value == '':
continue
else:
pa.__dict__[key] = value
elif key == 'data_server_password':
if value == '':
continue
else:
pa.__dict__[key] = value
else:
pa.stainfo.__dict__[key] = value
sections.remove('fetch')
for sec in sections:
for key, value in cf.items(sec):
Expand Down
3 changes: 1 addition & 2 deletions seispy/pickseis/sviewerui.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def set_properties(self):
self.axs[2].set_xlabel('Time (s)')
self.axs[0].legend(loc=2)


def clear(self):
for ax in self.axs:
ax.cla()
Expand Down Expand Up @@ -184,7 +183,7 @@ def initUi(self, eqs, para, logger):

self._set_geom_center()
self._define_global_shortcuts()
self.setWindowTitle('Pick S Phase')
self.setWindowTitle('Pick Phase')
self.setWindowIcon(QIcon(join(dirname(__file__), 'data', 'seispy.png')))

def add_btn(self):
Expand Down
12 changes: 6 additions & 6 deletions seispy/rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def fetch_waveform(eq_lst, para, model, logger):
except:
logger.RFlog.error('Please load station information and search earthquake before fetch waveform')
new_col = ['dis', 'bazi', 'data', 'datestr']
eq_match = pd.DataFrame(columns=new_col)
eqall = []
for i, row in eq_lst.iterrows():
datestr = row['date'].strftime('%Y.%j.%H.%M.%S')
daz = distaz(para.stainfo.stla, para.stainfo.stlo, row['evla'], row['evlo'])
Expand Down Expand Up @@ -149,7 +149,8 @@ def fetch_waveform(eq_lst, para, model, logger):
continue
this_eq.get_time_offset(row['date'])
this_df = pd.DataFrame([[daz.delta, daz.baz, this_eq, datestr]], columns=new_col, index=[i])
eq_match = pd.concat([eq_match, this_df])
eqall.append(this_df)
eq_match = pd.concat(eqall)
ind = eq_match.index.drop_duplicates(keep=False)
eq_match = eq_match.loc[ind]
return pd.concat([eq_lst, eq_match], axis=1, join='inner')
Expand Down Expand Up @@ -494,13 +495,12 @@ def trim(self):
def pick(self, prepick=True, stl=5, ltl=10):
if prepick:
self.logger.RFlog.info('Pre-pick {} arrival using STA/LTA method'.format(self.para.phase))
for _, row in self.eqs.iterrows():
row['data'].phase_trigger(self.para.time_before, self.para.time_after,
stl=stl, ltl=ltl)
for _, row in self.eqs.iterrows():
row['data'].phase_trigger(self.para.time_before, self.para.time_after,
prepick=prepick, stl=stl, ltl=ltl)
pickphase(self.eqs, self.para, self.logger)
self.logger.RFlog.info('{0} events left after visual checking'.format(self.eqs.shape[0]))


def deconv(self):
shift = self.para.time_before
time_after = self.para.time_after
Expand Down
15 changes: 9 additions & 6 deletions seispy/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ def get_pierce_points():
def common_parser():
parser = argparse.ArgumentParser(description="Calculating RFs for single station")
parser.add_argument('cfg_file', type=str, help='Path to RF configure file')
parser.add_argument('-l', help="use local catalog, defaults to false", dest='islocal', action='store_true')
parser.add_argument('-r', help='Reverse components: N, E or NE', dest='comp',
metavar='N|E|NE', default=None, type=str)
parser.add_argument('-s', help='Switch the East and North components', dest='isswitch', action='store_true')
parser.add_argument('-b', help='Correct back-azimuth. \nIf "baz" is specified, the corr_baz = raw_baz + baz. \n'
'If there is no argument, the back-azimuth will be corrected with minimal '
'energy of T component. The searching range is raw_baz +/- 90',
dest='baz', nargs='?', const=0, type=float)
parser.add_argument('-l', help="use local catalog, defaults to false", dest='islocal', action='store_true')
parser.add_argument('-p', help='Wether or not manually pick arrival time and waveforms arround P/S phase with a GUI.',
action='store_true', default=False)
parser.add_argument('-r', help='Reverse components: N, E or NE', dest='comp',
metavar='N|E|NE', default=None, type=str)
parser.add_argument('-s', help='Switch the East and North components', dest='isswitch', action='store_true')
parser.add_argument('-w', help='Write project to localfile', action='store_true')

return parser


Expand Down Expand Up @@ -179,6 +182,8 @@ def prf():
if arg.w:
pjt.savepjt()
pjt.rotate()
if arg.p:
pjt.pick(prepick=False)
pjt.trim()
pjt.deconv()
pjt.saverf()
Expand All @@ -188,8 +193,6 @@ def prf():

def srf():
parser = common_parser()
parser.add_argument('-p', help='Wether or not manually pick arrival time and waveforms arround S phase with a GUI.',
action='store_true')
parser.add_argument('-i', help='Wether grid search incidence angle',
action='store_true')
arg = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion seispy/setuplog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, filename=join(expanduser('~'), '.RF.log')):
"""
self.filename = filename
fh = logging.FileHandler(filename)
fh = logging.FileHandler(filename, mode='w')
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s [%(name)s] %(levelname)s: %(message)s')
fh.setFormatter(formatter)
Expand Down

0 comments on commit 3d3bb6a

Please sign in to comment.