[bugfix] several bugfixes mostly refering to plotting from plotWaveformDataThread, now only plot data are generated from within thread

This commit is contained in:
Marcel Paffrath 2017-06-08 16:14:37 +02:00
parent 909e2241a7
commit d6dd8bfaa8
3 changed files with 38 additions and 40 deletions

View File

@ -1226,7 +1226,7 @@ class MainWindow(QMainWindow):
def disconnect_pg(self): def disconnect_pg(self):
if self.poS_id: if self.poS_id:
self.dataPlot.plotWidget.scene().sigMouseClicked.disconnect(self.poS_id) self.dataPlot.plotWidget.scene().sigMouseClicked.disconnect()
def disconnect_mpl(self): def disconnect_mpl(self):
if self.poS_id: if self.poS_id:
@ -1240,8 +1240,22 @@ class MainWindow(QMainWindow):
self.scroll_id = None self.scroll_id = None
def finishWaveformDataPlot(self): def finishWaveformDataPlot(self):
if pg: if self.pg:
self.getPlotWidget().updateWidget() self.getPlotWidget().updateWidget()
plots = self.wfp_thread.data
for times, data in plots:
self.dataPlot.plotWidget.getPlotItem().plot(times, data, pen='k')
self.dataPlot.reinitMoveProxy()
plotWidget = self.getPlotWidget()
plotDict = plotWidget.getPlotDict()
pos = plotDict.keys()
labels = [plotDict[n][2]+'.'+plotDict[n][0] for n in pos]
plotWidget.setYTickLabels(pos, labels)
try:
plotWidget.figure.tight_layout()
except:
pass
#self._max_xlims = self.dataPlot.getXLims()
self.connectWFplotEvents() self.connectWFplotEvents()
self.loadlocationaction.setEnabled(True) self.loadlocationaction.setEnabled(True)
self.auto_tune.setEnabled(True) self.auto_tune.setEnabled(True)
@ -1266,7 +1280,7 @@ class MainWindow(QMainWindow):
def clearWaveformDataPlot(self): def clearWaveformDataPlot(self):
self.disconnectWFplotEvents() self.disconnectWFplotEvents()
if self.pg: if self.pg:
self.dataPlot.plotWidgetitem.clear() self.dataPlot.plotWidget.getPlotItem().clear()
else: else:
self.dataPlot.getAxes().cla() self.dataPlot.getAxes().cla()
self.loadlocationaction.setEnabled(False) self.loadlocationaction.setEnabled(False)
@ -1285,11 +1299,11 @@ class MainWindow(QMainWindow):
''' '''
Open a modal thread to plot current waveform data. Open a modal thread to plot current waveform data.
''' '''
#self.plotWaveformData() self.clearWaveformDataPlot()
wfp_thread = Thread(self, self.plotWaveformData, self.wfp_thread = Thread(self, self.plotWaveformData,
progressText='Plotting waveform data...') progressText='Plotting waveform data...')
wfp_thread.finished.connect(self.finishWaveformDataPlot) self.wfp_thread.finished.connect(self.finishWaveformDataPlot)
wfp_thread.start() self.wfp_thread.start()
def plotWaveformData(self): def plotWaveformData(self):
''' '''
@ -1307,16 +1321,8 @@ class MainWindow(QMainWindow):
# wfst += self.get_data().getWFData().select(component=alter_comp) # wfst += self.get_data().getWFData().select(component=alter_comp)
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
self.adjustPlotHeight() self.adjustPlotHeight()
plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp, nth_sample=int(nth_sample)) plots = plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp, nth_sample=int(nth_sample))
plotDict = plotWidget.getPlotDict() return plots
pos = plotDict.keys()
labels = [plotDict[n][2]+'.'+plotDict[n][0] for n in pos]
plotWidget.setYTickLabels(pos, labels)
try:
plotWidget.figure.tight_layout()
except:
pass
#self._max_xlims = self.dataPlot.getXLims()
def adjustPlotHeight(self): def adjustPlotHeight(self):
if self.pg: if self.pg:
@ -1331,20 +1337,20 @@ class MainWindow(QMainWindow):
def plotZ(self): def plotZ(self):
self.setComponent('Z') self.setComponent('Z')
self.plotWaveformDataThread() self.plotWaveformDataThread()
self.drawPicks() # self.drawPicks()
self.draw() # self.draw()
def plotN(self): def plotN(self):
self.setComponent('N') self.setComponent('N')
self.plotWaveformDataThread() self.plotWaveformDataThread()
self.drawPicks() # self.drawPicks()
self.draw() # self.draw()
def plotE(self): def plotE(self):
self.setComponent('E') self.setComponent('E')
self.plotWaveformDataThread() self.plotWaveformDataThread()
self.drawPicks() # self.drawPicks()
self.draw() # self.draw()
def pushFilterWF(self, param_args): def pushFilterWF(self, param_args):
self.get_data().filterWFData(param_args) self.get_data().filterWFData(param_args)

View File

@ -1 +1 @@
a071-dirty 909e-dirty

View File

@ -418,6 +418,7 @@ class WaveformWidgetPG(QtGui.QWidget):
self.main_layout.addWidget(self.plotWidget) self.main_layout.addWidget(self.plotWidget)
#self.plotWidget.setMouseEnabled(False, False) #self.plotWidget.setMouseEnabled(False, False)
self.plotWidget.showGrid(x=False, y=True, alpha=0.2) self.plotWidget.showGrid(x=False, y=True, alpha=0.2)
self.reinitMoveProxy()
self._proxy = pg.SignalProxy(self.plotWidget.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved) self._proxy = pg.SignalProxy(self.plotWidget.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
def reinitMoveProxy(self): def reinitMoveProxy(self):
@ -455,7 +456,7 @@ class WaveformWidgetPG(QtGui.QWidget):
noiselevel=None, scaleddata=False, mapping=True, noiselevel=None, scaleddata=False, mapping=True,
component='*', nth_sample=1, iniPick=None): component='*', nth_sample=1, iniPick=None):
self.title = title self.title = title
self.plotWidget.getPlotItem().clear() #self.plotWidget.clear()
self.clearPlotDict() self.clearPlotDict()
wfstart, wfend = full_range(wfdata) wfstart, wfend = full_range(wfdata)
nmax = 0 nmax = 0
@ -479,6 +480,7 @@ class WaveformWidgetPG(QtGui.QWidget):
nsc.append((trace.stats.network, trace.stats.station, trace.stats.channel)) nsc.append((trace.stats.network, trace.stats.station, trace.stats.channel))
nsc.sort() nsc.sort()
nsc.reverse() nsc.reverse()
plots = []
for n, (network, station, channel) in enumerate(nsc): for n, (network, station, channel) in enumerate(nsc):
st = wfdata.select(network=network, station=station, channel=channel) st = wfdata.select(network=network, station=station, channel=channel)
@ -499,23 +501,13 @@ class WaveformWidgetPG(QtGui.QWidget):
trace.normalize(np.max(np.abs(trace.data)) * 2) trace.normalize(np.max(np.abs(trace.data)) * 2)
times = [time for index, time in enumerate(time_ax) if not index%nth_sample] times = [time for index, time in enumerate(time_ax) if not index%nth_sample]
data = [datum + n for index, datum in enumerate(trace.data) if not index%nth_sample] data = [datum + n for index, datum in enumerate(trace.data) if not index%nth_sample]
self.plotWidget.plot(times, data, pen=(0, 0, 0)) plots.append((times, data))
if noiselevel is not None:
for level in noiselevel:
self.plotWidget.plot([time_ax[0], time_ax[-1]],
[level, level], pen=(0, 0, 0))
# if iniPick:
# ax = self.getAxes()
# ax.vlines(iniPick, ax.get_ylim()[0], ax.get_ylim()[1],
# colors='m', linestyles='dashed',
# linewidth=2)
self.setPlotDict(n, (station, channel, network)) self.setPlotDict(n, (station, channel, network))
self.reinitMoveProxy()
self.xlabel = 'seconds since {0}'.format(wfstart) self.xlabel = 'seconds since {0}'.format(wfstart)
self.ylabel = '' self.ylabel = ''
self.setXLims([0, wfend - wfstart]) self.setXLims([0, wfend - wfstart])
self.setYLims([-0.5, nmax + 0.5]) self.setYLims([-0.5, nmax + 0.5])
self.draw() return plots
# def getAxes(self): # def getAxes(self):
# return self.axes # return self.axes