WIP: figure generating in threads partly working

This commit is contained in:
Marcel Paffrath 2017-05-12 11:03:41 +02:00
parent f58d17be14
commit 184983bc87
7 changed files with 84 additions and 49 deletions

View File

@ -1150,24 +1150,35 @@ class MainWindow(QMainWindow):
self.listWidget.scrollToBottom() self.listWidget.scrollToBottom()
def tune_autopicker(self): def tune_autopicker(self):
self.fig_dict = { self.fig_dict = {}
'mainFig':, self.canvas_dict = {}
'aicFig':, self.fig_keys = [
'slength':, 'mainFig',
'checkZ4s':, 'aicFig',
'refPpick':, 'slength',
'el_Ppick':, 'checkZ4s',
'fm_picker':, 'refPpick',
'el_S1pick':, 'el_Ppick',
'el_S2pick':, 'fm_picker',
'refSpick':, 'el_S1pick',
'el_S2pick',
'refSpick',
'aicARHfig', 'aicARHfig',
} ]
for key in self.fig_keys:
fig = Figure()
self.fig_dict[key] = fig
ap = self._inputs ap = self._inputs
if not self.tap: if not self.tap:
self.tap = TuneAutopicker(ap, self.fig_dict, self) self.tap = TuneAutopicker(ap, self.fig_dict, self)
self.tap.show() self.tap.update.connect(self.update_autopicker)
self.tap.show()
def update_autopicker(self):
for key in self.fig_dict.keys():
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
self.tap.fill_tabs(self.canvas_dict)
def autoPick(self): def autoPick(self):
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output') self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')

View File

@ -29,7 +29,7 @@ from pylot.core.util.version import get_git_version as _getVersionString
__version__ = _getVersionString() __version__ = _getVersionString()
def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=0, fig_dict=None): def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, savepath=None, iplot=0):
""" """
Determine phase onsets automatically utilizing the automatic picking Determine phase onsets automatically utilizing the automatic picking
algorithms by Kueperkoch et al. 2010/2012. algorithms by Kueperkoch et al. 2010/2012.
@ -55,6 +55,16 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
***********************************'''.format(version=_getVersionString()) ***********************************'''.format(version=_getVersionString())
print(splash) print(splash)
if input_dict:
if input_dict.has_key('parameter'):
parameter = input_dict['parameter']
if input_dict.has_key('fig_dict'):
fig_dict = input_dict['fig_dict']
if input_dict.has_key('fnames'):
fnames = input_dict['fnames']
if input_dict.has_key('iplot'):
iplot = input_dict['iplot']
if not parameter: if not parameter:
if inputfile: if inputfile:
parameter = AutoPickParameter(inputfile) parameter = AutoPickParameter(inputfile)
@ -166,7 +176,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
print(data) print(data)
########################################################## ##########################################################
# !automated picking starts here! # !automated picking starts here!
picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict) picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
########################################################## ##########################################################
# locating # locating
if locflag == 1: if locflag == 1:
@ -317,7 +327,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
The Python picking and Location Tool\n The Python picking and Location Tool\n
************************************'''.format(version=_getVersionString()) ************************************'''.format(version=_getVersionString())
print(endsp) print(endsp)
return picks, mainFig return picks
if __name__ == "__main__": if __name__ == "__main__":
@ -344,4 +354,5 @@ if __name__ == "__main__":
cla = parser.parse_args() cla = parser.parse_args()
picks, mainFig = autoPyLoT(str(cla.inputfile), str(cla.fnames), str(cla.spath)) picks, mainFig = autoPyLoT(inputfile=str(cla.inputfile),
fnames=str(cla.fnames), savepath=str(cla.spath))

View File

@ -1 +1 @@
d135-dirty f58d1-dirty

View File

@ -74,7 +74,7 @@ def call_autopickstation(input_tuple):
return autopickstation(wfstream, pickparam, verbose, iplot=0) 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 :param wfstream: `~obspy.core.stream.Stream` containing waveform
:type wfstream: obspy.core.stream.Stream :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 # get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
# of class AutoPicking # of class AutoPicking
key = 'aicFig' 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: if aicpick.getpick() is not None:
# check signal length to detect spuriously picked noise peaks # 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') trH2_filt.taper(max_percentage=0.05, type='hann')
zne += trH1_filt zne += trH1_filt
zne += trH2_filt zne += trH2_filt
key = 'slenght' key = 'slength'
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz, Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength, minsiglength,
nfacsl, minpercent, iplot, nfacsl, minpercent, iplot,
@ -281,7 +281,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
if verbose: print(msg) if verbose: print(msg)
else: else:
if iplot>1: if iplot>1:
key = 'checkZ4S' key = 'checkZ4s'
Pflag = checkZ4S(zne, aicpick.getpick(), zfac, Pflag = checkZ4S(zne, aicpick.getpick(), zfac,
tsnrz[3], iplot, fig_dict[key]) tsnrz[3], iplot, fig_dict[key])
if Pflag == 0: if Pflag == 0:

View File

@ -73,6 +73,7 @@ class AutoPicker(object):
self.setTsmooth(Tsmooth) self.setTsmooth(Tsmooth)
self.setpick1(Pick1) self.setpick1(Pick1)
self.fig = fig self.fig = fig
self.calcPick()
def __str__(self): def __str__(self):
return '''\n\t{name} object:\n return '''\n\t{name} object:\n

View File

@ -129,12 +129,12 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False, fig=Non
ax.legend() ax.legend()
if iplot: if iplot:
return EPick, LPick, PickError, fig return EPick, LPick, PickError
else: else:
return EPick, LPick, PickError 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. Function to derive first motion (polarity) of given phase onset Pick.
Calculation is based on zero crossings determined within time window pickwin 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) print ("fmpicker: Found polarity %s" % FM)
if iplot > 1: if iplot > 1:
fig = plt.figure()#iplot) if not fig:
fig = plt.figure()#iplot)
ax1 = fig.add_subplot(211) ax1 = fig.add_subplot(211)
ax1.plot(t, xraw, 'k') ax1.plot(t, xraw, 'k')
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick') 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([]) ax2.set_yticks([])
if iplot: if iplot:
return FM, fig return FM
else: else:
return FM return FM
@ -621,7 +622,7 @@ def wadaticheck(pickdic, dttolerance, iplot):
return checkedonsets 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. Function to detect spuriously picked noise peaks.
Uses RMS trace of all 3 components (if available) to determine, 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 returnflag = 0
if iplot == 2: if iplot == 2:
fig = plt.figure()#iplot) if not fig:
fig = plt.figure()#iplot)
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(t, rms, 'k', label='RMS Data') ax.plot(t, rms, 'k', label='RMS Data')
ax.plot(t[inoise], rms[inoise], 'c', label='RMS Noise Window') 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_title('Check for Signal Length, Station %s' % X[0].stats.station)
ax.set_yticks([]) ax.set_yticks([])
return returnflag, fig return returnflag
def checkPonsets(pickdic, dttolerance, iplot): def checkPonsets(pickdic, dttolerance, iplot):
@ -869,7 +871,7 @@ def jackknife(X, phi, h):
return PHI_jack, PHI_pseudo, PHI_sub 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 Function to compare energy content of vertical trace with
energy content of horizontal traces to detect spuriously energy content of horizontal traces to detect spuriously
@ -963,7 +965,8 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
edat[0].stats.delta) edat[0].stats.delta)
tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate, tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate,
ndat[0].stats.delta) ndat[0].stats.delta)
fig = plt.figure() if not fig:
fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(tz, z / max(z), 'k') ax.plot(tz, z / max(z), 'k')
ax.plot(tz[isignal], z[isignal] / max(z), 'r') 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.set_title('CheckZ4S, Station %s' % zdat[0].stats.station)
ax.legend() ax.legend()
return returnflag, fig return returnflag
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1271,11 +1271,13 @@ class PickDlg(QDialog):
class TuneAutopicker(QWidget): class TuneAutopicker(QWidget):
update = QtCore.Signal(str)
def __init__(self, ap, fig_dict, parent=None): def __init__(self, ap, fig_dict, parent=None):
QtGui.QWidget.__init__(self, parent, 1) QtGui.QWidget.__init__(self, parent, 1)
self.ap = ap self.ap = ap
self.parent = parent self.parent = parent
self.station = 'AH11' ############# justs for testing self.station = 'TMO53' ############# justs for testing
self.fig_dict = fig_dict self.fig_dict = fig_dict
self.layout = QtGui.QHBoxLayout() self.layout = QtGui.QHBoxLayout()
self.parameter_layout = QtGui.QVBoxLayout() self.parameter_layout = QtGui.QVBoxLayout()
@ -1293,8 +1295,8 @@ class TuneAutopicker(QWidget):
self.p_tabs = QtGui.QTabWidget() self.p_tabs = QtGui.QTabWidget()
self.s_tabs = QtGui.QTabWidget() self.s_tabs = QtGui.QTabWidget()
self.layout.insertWidget(0, self.main_tabs) self.layout.insertWidget(0, self.main_tabs)
self.init_tab_names() #self.init_tab_names()
self.fill_tabs() #self.fill_tabs(None)
def add_parameter(self): def add_parameter(self):
self.parameters = AutoPickParaBox(self.ap) self.parameters = AutoPickParaBox(self.ap)
@ -1307,13 +1309,22 @@ class TuneAutopicker(QWidget):
self.parameter_layout.addWidget(self.pick_button) self.parameter_layout.addWidget(self.pick_button)
def call_picker(self): 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() 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.main_tabs.setParent(None)
self.init_figure_tabs() self.init_figure_tabs()
self.set_stretch() self.set_stretch()
self.update.emit('Update')
def update_params(self): def update_params(self):
ap = self.parameters.update_params() ap = self.parameters.update_params()
@ -1329,37 +1340,35 @@ class TuneAutopicker(QWidget):
self.ptb_names = ['aicFig', 'slenght', 'checkZ4S', 'refPpick', 'el_Ppick', 'fm_picker'] self.ptb_names = ['aicFig', 'slenght', 'checkZ4S', 'refPpick', 'el_Ppick', 'fm_picker']
self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick'] self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick']
def fill_tabs(self): def fill_tabs(self, canvas_dict):
try: try:
main_fig = self.fd['mainFig'] self.main_tabs.addTab(canvas_dict['mainFig'], 'Overview')
self.main_tabs.addTab(main_fig.canvas, 'Overview')
except Exception as e: except Exception as e:
self.main_tabs.addTab(QtGui.QWidget(), 'Overview') self.main_tabs.addTab(QtGui.QWidget(), 'Overview')
self.main_tabs.addTab(self.p_tabs, 'P') self.main_tabs.addTab(self.p_tabs, 'P')
self.main_tabs.addTab(self.s_tabs, 'S') self.main_tabs.addTab(self.s_tabs, 'S')
self.fill_p_tabs() self.fill_p_tabs(canvas_dict)
self.fill_s_tabs() self.fill_s_tabs(canvas_dict)
try: try:
main_fig.tight_layout() main_fig.tight_layout()
except: except:
pass pass
def fill_p_tabs(self): def fill_p_tabs(self, canvas_dict):
for name in self.ptb_names: for name in self.ptb_names:
try: try:
figure = self.fd[name] id = self.p_tabs.addTab(canvas_dict[name], name)
id = self.p_tabs.addTab(figure.canvas, name)
self.p_tabs.setTabEnabled(id, True) self.p_tabs.setTabEnabled(id, True)
figure.tight_layout() figure.tight_layout()
except Exception as e: except Exception as e:
id = self.p_tabs.addTab(QtGui.QWidget(), name) id = self.p_tabs.addTab(QtGui.QWidget(), name)
self.p_tabs.setTabEnabled(id, False) self.p_tabs.setTabEnabled(id, False)
def fill_s_tabs(self): def fill_s_tabs(self, canvas_dict):
for name in self.stb_names: for name in self.stb_names:
try: try:
figure = self.fd[name] figure = self.fig_dict[name]
id = self.s_tabs.addTab(figure.canvas, name) id = self.s_tabs.addTab(canvas_dict[name], name)
self.s_tabs.setTabEnabled(id, True) self.s_tabs.setTabEnabled(id, True)
figure.tight_layout() figure.tight_layout()
except Exception as e: except Exception as e: