WIP: figure generating in threads partly working
This commit is contained in:
@@ -1 +1 @@
|
||||
d135-dirty
|
||||
f58d1-dirty
|
||||
|
||||
@@ -74,7 +74,7 @@ def call_autopickstation(input_tuple):
|
||||
return autopickstation(wfstream, pickparam, verbose, iplot=0)
|
||||
|
||||
|
||||
def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
|
||||
"""
|
||||
:param wfstream: `~obspy.core.stream.Stream` containing waveform
|
||||
:type wfstream: obspy.core.stream.Stream
|
||||
@@ -233,7 +233,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
|
||||
# of class AutoPicking
|
||||
key = 'aicFig'
|
||||
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig_dict[key])
|
||||
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig=fig_dict[key])
|
||||
##############################################################
|
||||
if aicpick.getpick() is not None:
|
||||
# check signal length to detect spuriously picked noise peaks
|
||||
@@ -266,7 +266,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
trH2_filt.taper(max_percentage=0.05, type='hann')
|
||||
zne += trH1_filt
|
||||
zne += trH2_filt
|
||||
key = 'slenght'
|
||||
key = 'slength'
|
||||
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
|
||||
minsiglength,
|
||||
nfacsl, minpercent, iplot,
|
||||
@@ -281,7 +281,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
if verbose: print(msg)
|
||||
else:
|
||||
if iplot>1:
|
||||
key = 'checkZ4S'
|
||||
key = 'checkZ4s'
|
||||
Pflag = checkZ4S(zne, aicpick.getpick(), zfac,
|
||||
tsnrz[3], iplot, fig_dict[key])
|
||||
if Pflag == 0:
|
||||
|
||||
@@ -73,6 +73,7 @@ class AutoPicker(object):
|
||||
self.setTsmooth(Tsmooth)
|
||||
self.setpick1(Pick1)
|
||||
self.fig = fig
|
||||
self.calcPick()
|
||||
|
||||
def __str__(self):
|
||||
return '''\n\t{name} object:\n
|
||||
|
||||
@@ -129,12 +129,12 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False, fig=Non
|
||||
ax.legend()
|
||||
|
||||
if iplot:
|
||||
return EPick, LPick, PickError, fig
|
||||
return EPick, LPick, PickError
|
||||
else:
|
||||
return EPick, LPick, PickError
|
||||
|
||||
|
||||
def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None, fig_dict):
|
||||
def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None, fig=None):
|
||||
'''
|
||||
Function to derive first motion (polarity) of given phase onset Pick.
|
||||
Calculation is based on zero crossings determined within time window pickwin
|
||||
@@ -279,7 +279,8 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None, fig_dict):
|
||||
print ("fmpicker: Found polarity %s" % FM)
|
||||
|
||||
if iplot > 1:
|
||||
fig = plt.figure()#iplot)
|
||||
if not fig:
|
||||
fig = plt.figure()#iplot)
|
||||
ax1 = fig.add_subplot(211)
|
||||
ax1.plot(t, xraw, 'k')
|
||||
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick')
|
||||
@@ -307,7 +308,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None, fig_dict):
|
||||
ax2.set_yticks([])
|
||||
|
||||
if iplot:
|
||||
return FM, fig
|
||||
return FM
|
||||
else:
|
||||
return FM
|
||||
|
||||
@@ -621,7 +622,7 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
return checkedonsets
|
||||
|
||||
|
||||
def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fig_dict=None):
|
||||
def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fig=None):
|
||||
'''
|
||||
Function to detect spuriously picked noise peaks.
|
||||
Uses RMS trace of all 3 components (if available) to determine,
|
||||
@@ -693,7 +694,8 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
returnflag = 0
|
||||
|
||||
if iplot == 2:
|
||||
fig = plt.figure()#iplot)
|
||||
if not fig:
|
||||
fig = plt.figure()#iplot)
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(t, rms, 'k', label='RMS Data')
|
||||
ax.plot(t[inoise], rms[inoise], 'c', label='RMS Noise Window')
|
||||
@@ -707,7 +709,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
||||
ax.set_title('Check for Signal Length, Station %s' % X[0].stats.station)
|
||||
ax.set_yticks([])
|
||||
|
||||
return returnflag, fig
|
||||
return returnflag
|
||||
|
||||
|
||||
def checkPonsets(pickdic, dttolerance, iplot):
|
||||
@@ -869,7 +871,7 @@ def jackknife(X, phi, h):
|
||||
return PHI_jack, PHI_pseudo, PHI_sub
|
||||
|
||||
|
||||
def checkZ4S(X, pick, zfac, checkwin, iplot):
|
||||
def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
|
||||
'''
|
||||
Function to compare energy content of vertical trace with
|
||||
energy content of horizontal traces to detect spuriously
|
||||
@@ -963,7 +965,8 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
|
||||
edat[0].stats.delta)
|
||||
tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate,
|
||||
ndat[0].stats.delta)
|
||||
fig = plt.figure()
|
||||
if not fig:
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(tz, z / max(z), 'k')
|
||||
ax.plot(tz[isignal], z[isignal] / max(z), 'r')
|
||||
@@ -981,7 +984,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
|
||||
ax.set_title('CheckZ4S, Station %s' % zdat[0].stats.station)
|
||||
ax.legend()
|
||||
|
||||
return returnflag, fig
|
||||
return returnflag
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1271,11 +1271,13 @@ class PickDlg(QDialog):
|
||||
|
||||
|
||||
class TuneAutopicker(QWidget):
|
||||
update = QtCore.Signal(str)
|
||||
|
||||
def __init__(self, ap, fig_dict, parent=None):
|
||||
QtGui.QWidget.__init__(self, parent, 1)
|
||||
self.ap = ap
|
||||
self.parent = parent
|
||||
self.station = 'AH11' ############# justs for testing
|
||||
self.station = 'TMO53' ############# justs for testing
|
||||
self.fig_dict = fig_dict
|
||||
self.layout = QtGui.QHBoxLayout()
|
||||
self.parameter_layout = QtGui.QVBoxLayout()
|
||||
@@ -1293,8 +1295,8 @@ class TuneAutopicker(QWidget):
|
||||
self.p_tabs = QtGui.QTabWidget()
|
||||
self.s_tabs = QtGui.QTabWidget()
|
||||
self.layout.insertWidget(0, self.main_tabs)
|
||||
self.init_tab_names()
|
||||
self.fill_tabs()
|
||||
#self.init_tab_names()
|
||||
#self.fill_tabs(None)
|
||||
|
||||
def add_parameter(self):
|
||||
self.parameters = AutoPickParaBox(self.ap)
|
||||
@@ -1307,13 +1309,22 @@ class TuneAutopicker(QWidget):
|
||||
self.parameter_layout.addWidget(self.pick_button)
|
||||
|
||||
def call_picker(self):
|
||||
self.pb_thread = Thread(self, self._hover, arg=None, progressText='Picking trace...')
|
||||
self.pb_thread.start()
|
||||
self.ap = self.update_params()
|
||||
picks = autoPyLoT(self.ap, fnames='None', iplot=2, self.fig_dict)
|
||||
args = {'parameter': self.ap,
|
||||
'fnames': 'None',
|
||||
'iplot': 2,
|
||||
'fig_dict': self.fig_dict}
|
||||
self.ap_thread = Thread(self, autoPyLoT, arg=args, progressText='Picking trace...')
|
||||
self.ap_thread.finished.connect(self.finish_picker)
|
||||
self.ap_thread.start()
|
||||
#picks = autoPyLoT(self.ap, fnames='None', iplot=2, fig_dict=self.fig_dict)
|
||||
|
||||
def finish_picker(self):
|
||||
self.picks = self.ap_thread.data
|
||||
self.main_tabs.setParent(None)
|
||||
self.init_figure_tabs()
|
||||
self.set_stretch()
|
||||
self.update.emit('Update')
|
||||
|
||||
def update_params(self):
|
||||
ap = self.parameters.update_params()
|
||||
@@ -1329,37 +1340,35 @@ class TuneAutopicker(QWidget):
|
||||
self.ptb_names = ['aicFig', 'slenght', 'checkZ4S', 'refPpick', 'el_Ppick', 'fm_picker']
|
||||
self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick']
|
||||
|
||||
def fill_tabs(self):
|
||||
def fill_tabs(self, canvas_dict):
|
||||
try:
|
||||
main_fig = self.fd['mainFig']
|
||||
self.main_tabs.addTab(main_fig.canvas, 'Overview')
|
||||
self.main_tabs.addTab(canvas_dict['mainFig'], 'Overview')
|
||||
except Exception as e:
|
||||
self.main_tabs.addTab(QtGui.QWidget(), 'Overview')
|
||||
self.main_tabs.addTab(self.p_tabs, 'P')
|
||||
self.main_tabs.addTab(self.s_tabs, 'S')
|
||||
self.fill_p_tabs()
|
||||
self.fill_s_tabs()
|
||||
self.fill_p_tabs(canvas_dict)
|
||||
self.fill_s_tabs(canvas_dict)
|
||||
try:
|
||||
main_fig.tight_layout()
|
||||
except:
|
||||
pass
|
||||
|
||||
def fill_p_tabs(self):
|
||||
def fill_p_tabs(self, canvas_dict):
|
||||
for name in self.ptb_names:
|
||||
try:
|
||||
figure = self.fd[name]
|
||||
id = self.p_tabs.addTab(figure.canvas, name)
|
||||
id = self.p_tabs.addTab(canvas_dict[name], name)
|
||||
self.p_tabs.setTabEnabled(id, True)
|
||||
figure.tight_layout()
|
||||
except Exception as e:
|
||||
id = self.p_tabs.addTab(QtGui.QWidget(), name)
|
||||
self.p_tabs.setTabEnabled(id, False)
|
||||
|
||||
def fill_s_tabs(self):
|
||||
def fill_s_tabs(self, canvas_dict):
|
||||
for name in self.stb_names:
|
||||
try:
|
||||
figure = self.fd[name]
|
||||
id = self.s_tabs.addTab(figure.canvas, name)
|
||||
figure = self.fig_dict[name]
|
||||
id = self.s_tabs.addTab(canvas_dict[name], name)
|
||||
self.s_tabs.setTabEnabled(id, True)
|
||||
figure.tight_layout()
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user