[change] Extract function that calculates cuttimes

This commit is contained in:
Darius Arnold 2018-07-30 12:42:41 +02:00
parent da2b1ed133
commit c89e47ac43

View File

@ -863,7 +863,7 @@ class AutopickStation(object):
print(ae) print(ae)
except MissingTraceException as mte: except MissingTraceException as mte:
print(mte) print(mte)
cuttimes = [self.p_params.pstart, self.p_params.pstop] cuttimes = self._calculate_cuttimes('P', 1)
# calculate first CF # calculate first CF
if self.p_params.algoP == 'HOS': if self.p_params.algoP == 'HOS':
@ -917,9 +917,7 @@ class AutopickStation(object):
# save filtered trace in instance for later plotting # save filtered trace in instance for later plotting
self.tr_filt_z_bpz2 = tr_filt self.tr_filt_z_bpz2 = tr_filt
# determine new times around initial onset # determine new times around initial onset
starttime2 = round(max(aicpick.getpick() - self.p_params.Precalcwin, 0)) cuttimes2 = self._calculate_cuttimes('P', 2)
endtime2 = round(min(len(self.ztrace.data) * self.ztrace.stats.delta, aicpick.getpick() + self.p_params.Precalcwin))
cuttimes2 = [starttime2, endtime2]
if self.p_params.algoP == 'HOS': if self.p_params.algoP == 'HOS':
cf2 = HOScf(z_copy, cuttimes2, self.p_params.tlta, self.p_params.hosorder) cf2 = HOScf(z_copy, cuttimes2, self.p_params.tlta, self.p_params.hosorder)
elif self.p_params.algoP == 'ARZ': elif self.p_params.algoP == 'ARZ':
@ -966,20 +964,45 @@ class AutopickStation(object):
print(msg) print(msg)
self.s_results.Sflag = 1 self.s_results.Sflag = 1
def pick_s_phase(self): def _calculate_cuttimes(self, type, iteration):
"""
# determine time window for calculating CF after P onset Calculate cuttimes for a trace
start = round(max(self.p_results.mpickP + self.s_params.sstart, 0)) :param type: 'P' or 'S', denoting the pick for which cuttime should be calculated
stop = round(min([ :type type: str
self.p_results.mpickP + self.s_params.sstop, :param iteration: Calculate cut times for initial pick or for the smaller window of the precise pick around
self.etrace.stats.endtime - self.etrace.stats.starttime, the initial pick
self.ntrace.stats.endtime - self.ntrace.stats.starttime :type iteration: int
])) :return: tuple of (starttime, endtime) in seconds
cuttimesh = (start, stop) :rtype: (int, int)
"""
if cuttimesh[1] <= cuttimesh[0]: if type.upper() == 'P':
pickSonset = False if iteration == 1:
raise PickingFailedException('Cut window for horizontal phases too small! Will not pick S onsets.') return [self.p_params.pstart, self.p_params.pstop]
if iteration == 2:
starttime2 = round(max(self.p_results.aicpick.getpick() - self.p_params.Precalcwin, 0))
endtime2 = round(
min(len(self.ztrace.data) * self.ztrace.stats.delta, self.p_results.aicpick.getpick() + self.p_params.Precalcwin))
return [starttime2, endtime2]
elif type.upper() == 'S':
if iteration == 1:
# Calculate start times for preliminary S onset
start = round(max(self.p_results.mpickP + self.s_params.sstart, 0)) # limit start time to >0 seconds
stop = round(min([
self.p_results.mpickP + self.s_params.sstop,
self.etrace.stats.endtime - self.etrace.stats.starttime,
self.ntrace.stats.endtime - self.ntrace.stats.starttime
]))
cuttimesh = (start, stop)
if cuttimesh[1] <= cuttimesh[0]:
raise PickingFailedException('Cut window for horizontal phases too small! Will not pick S onsets.')
return cuttimesh
if iteration == 2:
# recalculate cf from refiltered trace in vicinity of initial onset
start = round(self.aicarhpick.getpick() - self.s_params.Srecalcwin)
stop = round(self.aicarhpick.getpick() + self.s_params.Srecalcwin)
return (start, stop)
else:
raise ValueError('Wrong type given, can only be P or S')
# prepare traces for picking by filtering, taper # prepare traces for picking by filtering, taper
if self.s_params.algoS == 'ARH': if self.s_params.algoS == 'ARH':
@ -1006,10 +1029,13 @@ class AutopickStation(object):
arhcf1 = AR3Ccf(h_copy, cuttimesh, self.s_params.tpred1h, self.s_params.Sarorder, self.s_params.tdet1h, self.p_params.addnoise) arhcf1 = AR3Ccf(h_copy, cuttimesh, self.s_params.tpred1h, self.s_params.Sarorder, self.s_params.tdet1h, self.p_params.addnoise)
# save cf for later plotting # save cf for later plotting
self.arhcf1 = arhcf1 self.arhcf1 = arhcf1
def pick_s_phase(self):
tr_arhaic = trH1_filt.copy() tr_arhaic = trH1_filt.copy()
tr_arhaic.data = arhcf1.getCF() tr_arhaic.data = arhcf1.getCF()
h_copy[0].data = tr_arhaic.data h_copy[0].data = tr_arhaic.data
# determine time window for calculating CF after P onset
cuttimesh = self._calculate_cuttimes(type='S', iteration=1)
# calculate AIC cf # calculate AIC cf
haiccf = AICcf(h_copy, cuttimesh) haiccf = AICcf(h_copy, cuttimesh)
@ -1042,10 +1068,7 @@ class AutopickStation(object):
'...'.format(aicarhpick.getSlope(), aicarhpick.getSNR()) '...'.format(aicarhpick.getSlope(), aicarhpick.getSNR())
self.vprint(msg) self.vprint(msg)
# recalculate cf from refiltered trace in vicinity of initial onset cuttimesh2 = self._calculate_cuttimes('S', 2)
start = round(aicarhpick.getpick() - self.s_params.Srecalcwin)
stop = round(aicarhpick.getpick() + self.s_params.Srecalcwin)
cuttimesh2 = (start, stop)
# refilter waveform with larger bandpass # refilter waveform with larger bandpass
if self.s_params.algoS == 'ARH': if self.s_params.algoS == 'ARH':