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,25 +1150,36 @@ class MainWindow(QMainWindow):
self.listWidget.scrollToBottom()
def tune_autopicker(self):
self.fig_dict = {
'mainFig':,
'aicFig':,
'slength':,
'checkZ4s':,
'refPpick':,
'el_Ppick':,
'fm_picker':,
'el_S1pick':,
'el_S2pick':,
'refSpick':,
self.fig_dict = {}
self.canvas_dict = {}
self.fig_keys = [
'mainFig',
'aicFig',
'slength',
'checkZ4s',
'refPpick',
'el_Ppick',
'fm_picker',
'el_S1pick',
'el_S2pick',
'refSpick',
'aicARHfig',
}
]
for key in self.fig_keys:
fig = Figure()
self.fig_dict[key] = fig
ap = self._inputs
if not self.tap:
self.tap = TuneAutopicker(ap, self.fig_dict, self)
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):
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
if not os.path.exists(self.autosave):

View File

@ -29,7 +29,7 @@ from pylot.core.util.version import get_git_version as _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
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())
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 inputfile:
parameter = AutoPickParameter(inputfile)
@ -166,7 +176,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
print(data)
##########################################################
# !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
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
************************************'''.format(version=_getVersionString())
print(endsp)
return picks, mainFig
return picks
if __name__ == "__main__":
@ -344,4 +354,5 @@ if __name__ == "__main__":
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)
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:

View File

@ -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

View File

@ -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,6 +279,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None, fig_dict):
print ("fmpicker: Found polarity %s" % FM)
if iplot > 1:
if not fig:
fig = plt.figure()#iplot)
ax1 = fig.add_subplot(211)
ax1.plot(t, xraw, 'k')
@ -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,6 +694,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
returnflag = 0
if iplot == 2:
if not fig:
fig = plt.figure()#iplot)
ax = fig.add_subplot(111)
ax.plot(t, rms, 'k', label='RMS Data')
@ -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,6 +965,7 @@ 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)
if not fig:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(tz, z / max(z), 'k')
@ -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__':

View File

@ -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: