[change] working version of pyqtgraph for dataPlot, WIP: fill not working on versions lower 0.9.9

This commit is contained in:
Marcel Paffrath 2017-06-08 14:09:01 +02:00
parent a07162d668
commit 909e2241a7
3 changed files with 135 additions and 84 deletions

View File

@ -1009,10 +1009,7 @@ class MainWindow(QMainWindow):
return self.dataPlot return self.dataPlot
@staticmethod @staticmethod
def getWFID(gui_event): def getWFID(ycoord):
ycoord = gui_event.ydata
try: try:
statID = int(round(ycoord)) statID = int(round(ycoord))
except TypeError as e: except TypeError as e:
@ -1199,10 +1196,13 @@ class MainWindow(QMainWindow):
Connect signals refering to WF-Dataplot (select station, tutor_user, scrolling) Connect signals refering to WF-Dataplot (select station, tutor_user, scrolling)
''' '''
if self.pg: if self.pg:
pass self.connect_pg()
else: else:
self.connect_mpl() self.connect_mpl()
def connect_pg(self):
self.poS_id = self.dataPlot.plotWidget.scene().sigMouseClicked.connect(self.pickOnStation)
def connect_mpl(self): def connect_mpl(self):
if not self.poS_id: if not self.poS_id:
self.poS_id = self.dataPlot.mpl_connect('button_press_event', self.poS_id = self.dataPlot.mpl_connect('button_press_event',
@ -1220,10 +1220,14 @@ class MainWindow(QMainWindow):
Disconnect all signals refering to WF-Dataplot (select station, tutor_user, scrolling) Disconnect all signals refering to WF-Dataplot (select station, tutor_user, scrolling)
''' '''
if self.pg: if self.pg:
pass self.disconnect_pg()
else: else:
self.disconnect_mpl() self.disconnect_mpl()
def disconnect_pg(self):
if self.poS_id:
self.dataPlot.plotWidget.scene().sigMouseClicked.disconnect(self.poS_id)
def disconnect_mpl(self): def disconnect_mpl(self):
if self.poS_id: if self.poS_id:
self.dataPlot.mpl_disconnect(self.poS_id) self.dataPlot.mpl_disconnect(self.poS_id)
@ -1236,6 +1240,8 @@ class MainWindow(QMainWindow):
self.scroll_id = None self.scroll_id = None
def finishWaveformDataPlot(self): def finishWaveformDataPlot(self):
if pg:
self.getPlotWidget().updateWidget()
self.connectWFplotEvents() self.connectWFplotEvents()
self.loadlocationaction.setEnabled(True) self.loadlocationaction.setEnabled(True)
self.auto_tune.setEnabled(True) self.auto_tune.setEnabled(True)
@ -1260,7 +1266,7 @@ class MainWindow(QMainWindow):
def clearWaveformDataPlot(self): def clearWaveformDataPlot(self):
self.disconnectWFplotEvents() self.disconnectWFplotEvents()
if self.pg: if self.pg:
self.dataPlot.plotitem.clear() self.dataPlot.plotWidgetitem.clear()
else: else:
self.dataPlot.getAxes().cla() self.dataPlot.getAxes().cla()
self.loadlocationaction.setEnabled(False) self.loadlocationaction.setEnabled(False)
@ -1313,6 +1319,8 @@ class MainWindow(QMainWindow):
#self._max_xlims = self.dataPlot.getXLims() #self._max_xlims = self.dataPlot.getXLims()
def adjustPlotHeight(self): def adjustPlotHeight(self):
if self.pg:
return
height_need = len(self.data.getWFData())*self.height_factor height_need = len(self.data.getWFData())*self.height_factor
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
if self.tabs.widget(0).frameSize().height() < height_need: if self.tabs.widget(0).frameSize().height() < height_need:
@ -1408,7 +1416,9 @@ class MainWindow(QMainWindow):
return self.seismicPhase return self.seismicPhase
def getStationName(self, wfID): def getStationName(self, wfID):
return self.getPlotWidget().getPlotDict()[wfID][0] plot_dict = self.getPlotWidget().getPlotDict()
if wfID in plot_dict.keys():
return plot_dict[wfID][0]
def alterPhase(self): def alterPhase(self):
pass pass
@ -1455,14 +1465,25 @@ class MainWindow(QMainWindow):
self.dataPlot.draw() self.dataPlot.draw()
def pickOnStation(self, gui_event): def pickOnStation(self, gui_event):
if self.pg:
if not gui_event.button() == 1:
return
else:
if not gui_event.button == 1: if not gui_event.button == 1:
return return
wfID = self.getWFID(gui_event) if self.pg:
ycoord = self.dataPlot.plotWidget.getPlotItem().vb.mapSceneToView(gui_event.scenePos()).y()
else:
ycoord = gui_event.ydata
wfID = self.getWFID(ycoord)
if wfID is None: return if wfID is None: return
station = self.getStationName(wfID) station = self.getStationName(wfID)
if not station:
return
self.update_status('picking on station {0}'.format(station)) self.update_status('picking on station {0}'.format(station))
data = self.get_data().getWFData() data = self.get_data().getWFData()
pickDlg = PickDlg(self, parameter=self._inputs, pickDlg = PickDlg(self, parameter=self._inputs,
@ -1629,8 +1650,19 @@ class MainWindow(QMainWindow):
plotID = self.getStationID(station) plotID = self.getStationID(station)
if plotID is None: if plotID is None:
return return
if pg:
pw = self.getPlotWidget().plotWidget
else:
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
ylims = np.array([-.5, +.5]) + plotID ylims = np.array([-.5, +.5]) + plotID
if pg:
dashed = QtCore.Qt.DashLine
dotted = QtCore.Qt.DotLine
phase_col = {
'P': (pg.mkPen('c'), pg.mkPen((0, 255, 255, 100), style=dashed), pg.mkPen('b', style=dashed), pg.mkPen('b', style=dotted)),
'S': (pg.mkPen('m'), pg.mkPen((255, 0, 255, 100), style=dashed), pg.mkPen('r', style=dashed), pg.mkPen('r', style=dotted))
}
else:
phase_col = { phase_col = {
'P': ('c', 'c--', 'b-', 'bv', 'b^', 'b'), 'P': ('c', 'c--', 'b-', 'bv', 'b^', 'b'),
'S': ('m', 'm--', 'r-', 'rv', 'r^', 'r') 'S': ('m', 'm--', 'r-', 'rv', 'r^', 'r')
@ -1655,6 +1687,31 @@ class MainWindow(QMainWindow):
if not spe and epp and lpp: if not spe and epp and lpp:
spe = symmetrize_error(mpp - epp, lpp - mpp) spe = symmetrize_error(mpp - epp, lpp - mpp)
if pg:
if picktype == 'manual':
if picks['epp'] and picks['lpp']:
pw.plot([epp, epp], ylims,
alpha=.25, pen=colors[0], name='EPP')
pw.plot([lpp, lpp], ylims,
alpha=.25, pen=colors[0], name='LPP')
if spe:
spe_l = pg.PlotDataItem([mpp - spe, mpp - spe], ylims, pen=colors[1], name='{}-SPE'.format(phase))
spe_r = pg.PlotDataItem([mpp + spe, mpp + spe], ylims, pen=colors[1])
pw.addItem(spe_l)
pw.addItem(spe_r)
try:
fill = pg.FillBetweenItem(spe_l, spe_r, brush=colors[1].brush())
fb = pw.addItem(fill)
except:
print('Could not create fill for SPE.')
pw.plot([mpp, mpp], ylims, pen=colors[2], name='{}-Pick'.format(phase))
else:
pw.plot([mpp, mpp], ylims, pen=colors[0], name='{}-Pick (NO PICKERROR)'.format(phase))
elif picktype == 'auto':
pw.plot([mpp, mpp], ylims, pen=colors[3])
else:
raise TypeError('Unknown picktype {0}'.format(picktype))
else:
if picktype == 'manual': if picktype == 'manual':
if picks['epp'] and picks['lpp']: if picks['epp'] and picks['lpp']:
ax.fill_between([epp, lpp], ylims[0], ylims[1], ax.fill_between([epp, lpp], ylims[0], ylims[1],

View File

@ -1 +1 @@
be8035-dirty a071-dirty

View File

@ -414,26 +414,23 @@ class WaveformWidgetPG(QtGui.QWidget):
# create plot # create plot
self.main_layout = QtGui.QVBoxLayout() self.main_layout = QtGui.QVBoxLayout()
self.setLayout(self.main_layout) self.setLayout(self.main_layout)
#self.win = pg.GraphicsWindow(title="Window") self.plotWidget = pg.PlotWidget(title=title, autoDownsample=True)
self.plot = pg.PlotWidget(title=title) self.main_layout.addWidget(self.plotWidget)
self.main_layout.addWidget(self.plot) #self.plotWidget.setMouseEnabled(False, False)
#self.plot = self.win.addPlot(title=title) self.plotWidget.showGrid(x=False, y=True, alpha=0.2)
self.plot.setMouseEnabled(False, False) self._proxy = pg.SignalProxy(self.plotWidget.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
self.plot.showGrid(x=False, y=True, alpha=0.2)
# update labels of the entire widget
#self.updateWidget(xlabel, ylabel, title)
def reinitMoveProxy(self):
self.vLine = pg.InfiniteLine(angle=90, movable=False) self.vLine = pg.InfiniteLine(angle=90, movable=False)
self.hLine = pg.InfiniteLine(angle=0, movable=False) self.hLine = pg.InfiniteLine(angle=0, movable=False)
self.plot.addItem(self.vLine, ignoreBounds=True) self.plotWidget.addItem(self.vLine, ignoreBounds=True)
self.plot.addItem(self.hLine, ignoreBounds=True) self.plotWidget.addItem(self.hLine, ignoreBounds=True)
self._proxy = pg.SignalProxy(self.plot.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
def mouseMoved(self, evt): def mouseMoved(self, evt):
pos = evt[0] ## using signal proxy turns original arguments into a tuple pos = evt[0] ## using signal proxy turns original arguments into a tuple
if self.plot.sceneBoundingRect().contains(pos): if self.plotWidget.sceneBoundingRect().contains(pos):
mousePoint = self.plot.getPlotItem().vb.mapSceneToView(pos) mousePoint = self.plotWidget.getPlotItem().vb.mapSceneToView(pos)
index = int(mousePoint.x()) # index = int(mousePoint.x())
# if index > 0 and index < len(data1): # if index > 0 and index < len(data1):
# label.setText("<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>y1=%0.1f</span>, <span style='color: green'>y2=%0.1f</span>" % (mousePoint.x(), data1[index], data2[index])) # label.setText("<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>y1=%0.1f</span>, <span style='color: green'>y2=%0.1f</span>" % (mousePoint.x(), data1[index], data2[index]))
self.vLine.setPos(mousePoint.x()) self.vLine.setPos(mousePoint.x())
@ -457,7 +454,8 @@ class WaveformWidgetPG(QtGui.QWidget):
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None, def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
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.getAxes().cla() self.title = title
self.plotWidget.getPlotItem().clear()
self.clearPlotDict() self.clearPlotDict()
wfstart, wfend = full_range(wfdata) wfstart, wfend = full_range(wfdata)
nmax = 0 nmax = 0
@ -501,10 +499,10 @@ 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.plot.plot(times, data, pen=(0, 0, 0)) self.plotWidget.plot(times, data, pen=(0, 0, 0))
if noiselevel is not None: if noiselevel is not None:
for level in noiselevel: for level in noiselevel:
self.plot.plot([time_ax[0], time_ax[-1]], self.plotWidget.plot([time_ax[0], time_ax[-1]],
[level, level], pen=(0, 0, 0)) [level, level], pen=(0, 0, 0))
# if iniPick: # if iniPick:
# ax = self.getAxes() # ax = self.getAxes()
@ -512,16 +510,12 @@ class WaveformWidgetPG(QtGui.QWidget):
# colors='m', linestyles='dashed', # colors='m', linestyles='dashed',
# linewidth=2) # linewidth=2)
self.setPlotDict(n, (station, channel, network)) self.setPlotDict(n, (station, channel, network))
xlabel = 'seconds since {0}'.format(wfstart) self.reinitMoveProxy()
ylabel = '' self.xlabel = 'seconds since {0}'.format(wfstart)
#self.updateWidget(xlabel, ylabel, title) 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])
# if zoomx is not None: self.draw()
# self.setXLims(zoomx)
# if zoomy is not None:
# self.setYLims(zoomy)
# self.draw()
# def getAxes(self): # def getAxes(self):
# return self.axes # return self.axes
@ -532,41 +526,41 @@ class WaveformWidgetPG(QtGui.QWidget):
# def getYLims(self): # def getYLims(self):
# return self.getAxes().get_ylim() # return self.getAxes().get_ylim()
# def setXLims(self, lims): def setXLims(self, lims):
# self.getAxes().set_xlim(lims) vb = self.plotWidget.getPlotItem().getViewBox()
vb.setXRange(lims[0], lims[1], padding=0)
# def setYLims(self, lims): def setYLims(self, lims):
# self.getAxes().set_ylim(lims) vb = self.plotWidget.getPlotItem().getViewBox()
vb.setYRange(lims[0], lims[1], padding=0)
def setYTickLabels(self, pos, labels): def setYTickLabels(self, pos, labels):
ticks = zip(pos, labels) ticks = zip(pos, labels)
leftAx = self.plot.getPlotItem().axes['left']['item'] minorTicks = [(0, 0) for item in labels]
# leftAx.tickLength = 5 # leftAx.tickLength = 5
# leftAx.orientation = 'right' # leftAx.orientation = 'right'
leftAx.setTicks([ticks, []]) self.getAxItem('left').setTicks([ticks, minorTicks])
# def updateXLabel(self, text): def updateXLabel(self, text):
# self.getAxes().set_xlabel(text) self.getAxItem('bottom').setLabel(text)
# self.draw() self.draw()
# def updateYLabel(self, text): def updateYLabel(self, text):
# self.getAxes().set_ylabel(text) self.getAxItem('left').setLabel(text)
# self.draw() self.draw()
# def updateTitle(self, text): def getAxItem(self, position):
# self.getAxes().set_title(text) return self.plotWidget.getPlotItem().axes[position]['item']
# self.draw()
# def updateWidget(self, xlabel, ylabel, title): def updateTitle(self, text):
# self.updateXLabel(xlabel) self.plotWidget.getPlotItem().setTitle(text)
# self.updateYLabel(ylabel) self.draw()
# self.updateTitle(title)
def updateWidget(self):#, xlabel, ylabel, title):
self.updateXLabel(self.xlabel)
self.updateYLabel(self.ylabel)
self.updateTitle(self.title)
# def insertLabel(self, pos, text):
# pos = pos / max(self.getAxes().ylim)
# axann = self.getAxes().annotate(text, xy=(.03, pos),
# xycoords='axes fraction')
# axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
def draw(self): def draw(self):
pass pass