diff --git a/QtPyLoT.py b/QtPyLoT.py index c1d4dddd..582f41e1 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1669,10 +1669,22 @@ class MainWindow(QMainWindow): if event.pylot_picks and event.pylot_autopicks: for station in event.pylot_picks: if station in event.pylot_autopicks: - autopick_p = event.pylot_autopicks[station]['P']['spe'] - manupick_p = event.pylot_picks[station]['P']['spe'] - autopick_s = event.pylot_autopicks[station]['S']['spe'] - manupick_s = event.pylot_picks[station]['S']['spe'] + try: + autopick_p = event.pylot_autopicks[station]['P']['spe'] + except KeyError: + autopick_p = None + try: + manupick_p = event.pylot_picks[station]['P']['spe'] + except KeyError: + manupick_p = None + try: + autopick_s = event.pylot_autopicks[station]['S']['spe'] + except KeyError: + autopick_s = None + try: + manupick_s = event.pylot_picks[station]['S']['spe'] + except KeyError: + manupick_s = None if autopick_p and manupick_p: return True elif autopick_s and manupick_s: diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 30d93ba4..e558b124 100644 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -228,8 +228,10 @@ def autopickstation(wfstream, pickparam, verbose=False, data=str(zdat)) if verbose: print(msg) z_copy = zdat.copy() - # filter and taper data tr_filt = zdat[0].copy() + #remove constant offset from data to avoid unwanted filter response + tr_filt.detrend(type='demean') + # filter and taper data tr_filt.filter('bandpass', freqmin=bpz1[0], freqmax=bpz1[1], zerophase=False) tr_filt.taper(max_percentage=0.05, type='hann') @@ -364,6 +366,9 @@ def autopickstation(wfstream, pickparam, verbose=False, # filter and taper horizontal traces trH1_filt = edat.copy() trH2_filt = ndat.copy() + # remove constant offset from data to avoid unwanted filter response + trH1_filt.detrend(type='demean') + trH2_filt.detrend(type='demean') trH1_filt.filter('bandpass', freqmin=bph1[0], freqmax=bph1[1], zerophase=False) @@ -424,6 +429,7 @@ def autopickstation(wfstream, pickparam, verbose=False, # re-filter waveform with larger bandpass z_copy = zdat.copy() tr_filt = zdat[0].copy() + tr_filt.detrend(type='demean') tr_filt.filter('bandpass', freqmin=bpz2[0], freqmax=bpz2[1], zerophase=False) tr_filt.taper(max_percentage=0.05, type='hann') @@ -471,6 +477,7 @@ def autopickstation(wfstream, pickparam, verbose=False, else: fig = None linecolor = 'k' + fig._tight = True epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz, mpickP, iplot, fig=fig, linecolor=linecolor) @@ -506,6 +513,7 @@ def autopickstation(wfstream, pickparam, verbose=False, linecolor = fig_dict['plot_style']['linecolor']['rgba_mpl'] else: fig = None + fig._tight = True FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot, fig, linecolor) else: FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot) @@ -586,6 +594,8 @@ def autopickstation(wfstream, pickparam, verbose=False, # filter and taper data trH1_filt = hdat[0].copy() trH2_filt = hdat[1].copy() + trH1_filt.detrend(type='demean') + trH2_filt.detrend(type='demean') trH1_filt.filter('bandpass', freqmin=bph1[0], freqmax=bph1[1], zerophase=False) trH2_filt.filter('bandpass', freqmin=bph1[0], freqmax=bph1[1], @@ -604,6 +614,9 @@ def autopickstation(wfstream, pickparam, verbose=False, trH1_filt = hdat[0].copy() trH2_filt = hdat[1].copy() trH3_filt = hdat[2].copy() + trH1_filt.detrend(type='demean') + trH2_filt.detrend(type='demean') + trH3_filt.detrend(type='demean') trH1_filt.filter('bandpass', freqmin=bph1[0], freqmax=bph1[1], zerophase=False) trH2_filt.filter('bandpass', freqmin=bph1[0], freqmax=bph1[1], @@ -671,6 +684,8 @@ def autopickstation(wfstream, pickparam, verbose=False, if algoS == 'ARH': trH1_filt = hdat[0].copy() trH2_filt = hdat[1].copy() + trH1_filt.detrend(type='demean') + trH2_filt.detrend(type='demean') trH1_filt.filter('bandpass', freqmin=bph2[0], freqmax=bph2[1], zerophase=False) trH2_filt.filter('bandpass', freqmin=bph2[0], freqmax=bph2[1], @@ -686,6 +701,9 @@ def autopickstation(wfstream, pickparam, verbose=False, trH1_filt = hdat[0].copy() trH2_filt = hdat[1].copy() trH3_filt = hdat[2].copy() + trH1_filt.detrend(type='demean') + trH2_filt.detrend(type='demean') + trH3_filt.detrend(type='demean') trH1_filt.filter('bandpass', freqmin=bph2[0], freqmax=bph2[1], zerophase=False) trH2_filt.filter('bandpass', freqmin=bph2[0], freqmax=bph2[1], @@ -709,6 +727,7 @@ def autopickstation(wfstream, pickparam, verbose=False, else: fig = None linecolor = 'k' + fig._tight = True refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS, tsmoothS, aicarhpick.getpick(), fig, linecolor) mpickS = refSpick.getpick() @@ -724,6 +743,7 @@ def autopickstation(wfstream, pickparam, verbose=False, else: fig = None linecolor = 'k' + fig._tight = True epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS, tsnrh, mpickS, iplot, @@ -742,6 +762,7 @@ def autopickstation(wfstream, pickparam, verbose=False, else: fig = None linecolor = '' + fig._tight = True epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS, tsnrh, mpickS, iplot, @@ -859,6 +880,7 @@ def autopickstation(wfstream, pickparam, verbose=False, else: fig = fig_dict['mainFig'] linecolor = fig_dict['plot_style']['linecolor']['rgba_mpl'] + fig._tight = True ax1 = fig.add_subplot(311) tdata = np.arange(0, zdat[0].stats.npts / tr_filt.stats.sampling_rate, tr_filt.stats.delta) diff --git a/pylot/core/pick/picker.py b/pylot/core/pick/picker.py index 5d44d9f0..87000468 100644 --- a/pylot/core/pick/picker.py +++ b/pylot/core/pick/picker.py @@ -23,6 +23,7 @@ import warnings import matplotlib.pyplot as plt import numpy as np +from scipy.signal import argrelmax from pylot.core.pick.charfuns import CharacteristicFunction from pylot.core.pick.utils import getnoisewin, getsignalwin @@ -253,8 +254,12 @@ class AICPicker(AutoPicker): if len(dataslope) < 1: print('No data in slope window found!') return - imax = np.argmax(dataslope) - iislope = islope[0][0:imax+1] + imaxs, = argrelmax(dataslope) + if imaxs.size: + imax = imaxs[0] + else: + imax = np.argmax(dataslope) + iislope = islope[0][0:imax + 1] if len(iislope) < 2: # calculate slope from initial onset to maximum of AIC function print("AICPicker: Not enough data samples left for slope calculation!") @@ -304,6 +309,7 @@ class AICPicker(AutoPicker): plt_flag = 1 else: fig = self.fig + fig._tight = True ax1 = fig.add_subplot(211) x = self.Data[0].data if len(self.Tcf) > len(self.Data[0].data): # why? LK @@ -473,6 +479,7 @@ class PragPicker(AutoPicker): plt_flag = 1 else: fig = self.fig + fig._tight = True ax = fig.add_subplot(111) ax.plot(Tcfpick, cfipick, color=self._linecolor, linewidth=0.7, label='CF') ax.plot(Tcfpick, cfsmoothipick, 'r', label='Smoothed CF') diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 92b4f23f..3cafc490 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -616,6 +616,7 @@ def wadaticheck(pickdic, dttolerance, iplot=0, fig_dict=None): checkedPpicks = [] checkedSpicks = [] checkedSPtimes = [] + badstations = [] # calculate deviations from Wadati regression ii = 0 ibad = 0 @@ -631,6 +632,7 @@ def wadaticheck(pickdic, dttolerance, iplot=0, fig_dict=None): # # (not used anymore) # marker = 'badWadatiCheck' # pickdic[key]['S']['weight'] = 9 + badstations.append(key) ibad += 1 else: marker = 'goodWadatiCheck' @@ -643,6 +645,8 @@ def wadaticheck(pickdic, dttolerance, iplot=0, fig_dict=None): pickdic[key]['S']['marked'] = marker #pickdic[key]['S']['marked'] = marker + print("wadaticheck: the following stations failed the check:") + print(badstations) if len(checkedPpicks) >= 3: # calculate new slope @@ -791,6 +795,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi fig = plt.figure() # iplot) plt_flag = 1 ax = fig.add_subplot(111) + fig._tight = True ax.plot(t, rms, color=linecolor, linewidth=0.7, label='RMS Data') ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window') ax.axvspan(t[isignal[0]], t[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window') @@ -868,6 +873,7 @@ def checkPonsets(pickdic, dttolerance, jackfactor=5, iplot=0, fig_dict=None): print("checkPonsets: %d pick(s) deviate too much from median!" % len(ibad)) print("checkPonsets: Skipped %d P pick(s) out of %d" % (len(badstations) \ + len(badjkstations), len(stations))) + print(badstations) goodmarker = 'goodPonsetcheck' badmarker = 'badPonsetcheck' @@ -1114,6 +1120,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None, linecolor='k'): fig = plt.figure() # self.iplot) ### WHY? MP MP plt_flag = 1 ax = fig.add_subplot(3, 1, i + 1, sharex=ax1) + fig._tight = True ax.plot(t, abs(trace.data), color='b', label='abs') ax.plot(t, trace.data, color=linecolor, linewidth=0.7) name = str(trace.stats.channel) + ': {}'.format(rms) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index cb304947..e12d6680 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -2469,6 +2469,12 @@ class TuneAutopicker(QWidget): # self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) # self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) + def set_fig_dict(self, fig_dict): + for key, value in fig_dict.items(): + if key is not 'mainFig': + value._tight = True + self.fig_dict = fig_dict + def init_main_layouts(self): self.main_layout = QtGui.QVBoxLayout() self.tune_layout = QtGui.QHBoxLayout()