first semi-working plot of all traces
This commit is contained in:
parent
be8035e118
commit
a07162d668
38
QtPyLoT.py
38
QtPyLoT.py
@ -42,6 +42,11 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from obspy import UTCDateTime
|
from obspy import UTCDateTime
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pyqtgraph as pg
|
||||||
|
except:
|
||||||
|
pg = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from matplotlib.backends.backend_qt4agg import FigureCanvas
|
from matplotlib.backends.backend_qt4agg import FigureCanvas
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -66,7 +71,7 @@ from pylot.core.util.utils import fnConstructor, getLogin, \
|
|||||||
full_range
|
full_range
|
||||||
from pylot.core.io.location import create_creation_info, create_event
|
from pylot.core.io.location import create_creation_info, create_event
|
||||||
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
||||||
WaveformWidget, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
||||||
getDataType, ComparisonDialog, TuneAutopicker, AutoPickParaBox
|
getDataType, ComparisonDialog, TuneAutopicker, AutoPickParaBox
|
||||||
from pylot.core.util.map_projection import map_projection
|
from pylot.core.util.map_projection import map_projection
|
||||||
from pylot.core.util.structure import DATASTRUCTURE
|
from pylot.core.util.structure import DATASTRUCTURE
|
||||||
@ -210,8 +215,14 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# create central matplotlib figure canvas widget
|
# create central matplotlib figure canvas widget
|
||||||
plottitle = "Overview: {0} components ".format(self.getComponent())
|
plottitle = "Overview: {0} components ".format(self.getComponent())
|
||||||
self.dataPlot = WaveformWidget(parent=self, xlabel=xlab, ylabel=None,
|
if pg:
|
||||||
title=plottitle)
|
self.pg = True
|
||||||
|
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
|
||||||
|
title=plottitle)
|
||||||
|
else:
|
||||||
|
self.pg = False
|
||||||
|
self.dataPlot = WaveformWidget(parent=self, xlabel=xlab, ylabel=None,
|
||||||
|
title=plottitle)
|
||||||
self.dataPlot.setCursor(Qt.CrossCursor)
|
self.dataPlot.setCursor(Qt.CrossCursor)
|
||||||
|
|
||||||
# add scroll area used in case number of traces gets too high
|
# add scroll area used in case number of traces gets too high
|
||||||
@ -1187,6 +1198,12 @@ 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:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.connect_mpl()
|
||||||
|
|
||||||
|
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',
|
||||||
self.pickOnStation)
|
self.pickOnStation)
|
||||||
@ -1198,11 +1215,16 @@ class MainWindow(QMainWindow):
|
|||||||
self.scroll_id = self.dataPlot.mpl_connect('scroll_event',
|
self.scroll_id = self.dataPlot.mpl_connect('scroll_event',
|
||||||
self.scrollPlot)
|
self.scrollPlot)
|
||||||
|
|
||||||
|
|
||||||
def disconnectWFplotEvents(self):
|
def disconnectWFplotEvents(self):
|
||||||
'''
|
'''
|
||||||
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:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.disconnect_mpl()
|
||||||
|
|
||||||
|
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)
|
||||||
if self.ae_id:
|
if self.ae_id:
|
||||||
@ -1237,7 +1259,10 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def clearWaveformDataPlot(self):
|
def clearWaveformDataPlot(self):
|
||||||
self.disconnectWFplotEvents()
|
self.disconnectWFplotEvents()
|
||||||
self.dataPlot.getAxes().cla()
|
if self.pg:
|
||||||
|
self.dataPlot.plotitem.clear()
|
||||||
|
else:
|
||||||
|
self.dataPlot.getAxes().cla()
|
||||||
self.loadlocationaction.setEnabled(False)
|
self.loadlocationaction.setEnabled(False)
|
||||||
self.auto_tune.setEnabled(False)
|
self.auto_tune.setEnabled(False)
|
||||||
self.auto_pick.setEnabled(False)
|
self.auto_pick.setEnabled(False)
|
||||||
@ -1254,6 +1279,7 @@ class MainWindow(QMainWindow):
|
|||||||
'''
|
'''
|
||||||
Open a modal thread to plot current waveform data.
|
Open a modal thread to plot current waveform data.
|
||||||
'''
|
'''
|
||||||
|
#self.plotWaveformData()
|
||||||
wfp_thread = Thread(self, self.plotWaveformData,
|
wfp_thread = Thread(self, self.plotWaveformData,
|
||||||
progressText='Plotting waveform data...')
|
progressText='Plotting waveform data...')
|
||||||
wfp_thread.finished.connect(self.finishWaveformDataPlot)
|
wfp_thread.finished.connect(self.finishWaveformDataPlot)
|
||||||
@ -1284,7 +1310,7 @@ class MainWindow(QMainWindow):
|
|||||||
plotWidget.figure.tight_layout()
|
plotWidget.figure.tight_layout()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self._max_xlims = self.dataPlot.getXLims()
|
#self._max_xlims = self.dataPlot.getXLims()
|
||||||
|
|
||||||
def adjustPlotHeight(self):
|
def adjustPlotHeight(self):
|
||||||
height_need = len(self.data.getWFData())*self.height_factor
|
height_need = len(self.data.getWFData())*self.height_factor
|
||||||
|
@ -1 +1 @@
|
|||||||
0af79-dirty
|
be8035-dirty
|
||||||
|
@ -12,6 +12,11 @@ import copy
|
|||||||
import datetime
|
import datetime
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pyqtgraph as pg
|
||||||
|
except:
|
||||||
|
pg = None
|
||||||
|
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
from pylot.core.util.utils import find_horizontals
|
from pylot.core.util.utils import find_horizontals
|
||||||
|
|
||||||
@ -42,6 +47,12 @@ from autoPyLoT import autoPyLoT
|
|||||||
from pylot.core.util.thread import Thread
|
from pylot.core.util.thread import Thread
|
||||||
import icons_rc
|
import icons_rc
|
||||||
|
|
||||||
|
if pg:
|
||||||
|
pg.setConfigOption('background', 'w')
|
||||||
|
pg.setConfigOption('foreground', 'k')
|
||||||
|
pg.setConfigOptions(antialias=True)
|
||||||
|
#pg.setConfigOption('leftButtonPan', False)
|
||||||
|
|
||||||
def getDataType(parent):
|
def getDataType(parent):
|
||||||
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
||||||
["manual", "automatic"])
|
["manual", "automatic"])
|
||||||
@ -393,6 +404,173 @@ class PlotWidget(FigureCanvas):
|
|||||||
return self._parent
|
return self._parent
|
||||||
|
|
||||||
|
|
||||||
|
class WaveformWidgetPG(QtGui.QWidget):
|
||||||
|
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
||||||
|
QtGui.QWidget.__init__(self, parent)#, 1)
|
||||||
|
self.setParent(parent)
|
||||||
|
self._parent = parent
|
||||||
|
# attribute plotdict is a dictionary connecting position and a name
|
||||||
|
self.plotdict = dict()
|
||||||
|
# create plot
|
||||||
|
self.main_layout = QtGui.QVBoxLayout()
|
||||||
|
self.setLayout(self.main_layout)
|
||||||
|
#self.win = pg.GraphicsWindow(title="Window")
|
||||||
|
self.plot = pg.PlotWidget(title=title)
|
||||||
|
self.main_layout.addWidget(self.plot)
|
||||||
|
#self.plot = self.win.addPlot(title=title)
|
||||||
|
self.plot.setMouseEnabled(False, False)
|
||||||
|
self.plot.showGrid(x=False, y=True, alpha=0.2)
|
||||||
|
# update labels of the entire widget
|
||||||
|
#self.updateWidget(xlabel, ylabel, title)
|
||||||
|
|
||||||
|
self.vLine = pg.InfiniteLine(angle=90, movable=False)
|
||||||
|
self.hLine = pg.InfiniteLine(angle=0, movable=False)
|
||||||
|
self.plot.addItem(self.vLine, ignoreBounds=True)
|
||||||
|
self.plot.addItem(self.hLine, ignoreBounds=True)
|
||||||
|
self._proxy = pg.SignalProxy(self.plot.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
|
||||||
|
|
||||||
|
def mouseMoved(self, evt):
|
||||||
|
pos = evt[0] ## using signal proxy turns original arguments into a tuple
|
||||||
|
if self.plot.sceneBoundingRect().contains(pos):
|
||||||
|
mousePoint = self.plot.getPlotItem().vb.mapSceneToView(pos)
|
||||||
|
index = int(mousePoint.x())
|
||||||
|
# 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]))
|
||||||
|
self.vLine.setPos(mousePoint.x())
|
||||||
|
self.hLine.setPos(mousePoint.y())
|
||||||
|
|
||||||
|
def getPlotDict(self):
|
||||||
|
return self.plotdict
|
||||||
|
|
||||||
|
def setPlotDict(self, key, value):
|
||||||
|
self.plotdict[key] = value
|
||||||
|
|
||||||
|
def clearPlotDict(self):
|
||||||
|
self.plotdict = dict()
|
||||||
|
|
||||||
|
def getParent(self):
|
||||||
|
return self._parent
|
||||||
|
|
||||||
|
def setParent(self, parent):
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
|
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
||||||
|
noiselevel=None, scaleddata=False, mapping=True,
|
||||||
|
component='*', nth_sample=1, iniPick=None):
|
||||||
|
#self.getAxes().cla()
|
||||||
|
self.clearPlotDict()
|
||||||
|
wfstart, wfend = full_range(wfdata)
|
||||||
|
nmax = 0
|
||||||
|
|
||||||
|
settings = QSettings()
|
||||||
|
compclass = settings.value('compclass')
|
||||||
|
if not compclass:
|
||||||
|
print('Warning: No settings for channel components found. Using default')
|
||||||
|
compclass = SetChannelComponents()
|
||||||
|
|
||||||
|
if not component == '*':
|
||||||
|
alter_comp = compclass.getCompPosition(component)
|
||||||
|
#alter_comp = str(alter_comp[0])
|
||||||
|
|
||||||
|
wfdata = wfdata.select(component=component)
|
||||||
|
wfdata += wfdata.select(component=alter_comp)
|
||||||
|
|
||||||
|
# list containing tuples of network, station, channel (for sorting)
|
||||||
|
nsc = []
|
||||||
|
for trace in wfdata:
|
||||||
|
nsc.append((trace.stats.network, trace.stats.station, trace.stats.channel))
|
||||||
|
nsc.sort()
|
||||||
|
nsc.reverse()
|
||||||
|
|
||||||
|
for n, (network, station, channel) in enumerate(nsc):
|
||||||
|
st = wfdata.select(network=network, station=station, channel=channel)
|
||||||
|
trace = st[0]
|
||||||
|
if mapping:
|
||||||
|
comp = channel[-1]
|
||||||
|
n = compclass.getPlotPosition(str(comp))
|
||||||
|
#n = n[0]
|
||||||
|
if n > nmax:
|
||||||
|
nmax = n
|
||||||
|
msg = 'plotting %s channel of station %s' % (channel, station)
|
||||||
|
print(msg)
|
||||||
|
stime = trace.stats.starttime - wfstart
|
||||||
|
time_ax = prepTimeAxis(stime, trace)
|
||||||
|
if time_ax is not None:
|
||||||
|
if not scaleddata:
|
||||||
|
trace.detrend('constant')
|
||||||
|
trace.normalize(np.max(np.abs(trace.data)) * 2)
|
||||||
|
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]
|
||||||
|
self.plot.plot(times, data, pen=(0, 0, 0))
|
||||||
|
if noiselevel is not None:
|
||||||
|
for level in noiselevel:
|
||||||
|
self.plot.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))
|
||||||
|
xlabel = 'seconds since {0}'.format(wfstart)
|
||||||
|
ylabel = ''
|
||||||
|
#self.updateWidget(xlabel, ylabel, title)
|
||||||
|
# self.setXLims([0, wfend - wfstart])
|
||||||
|
# self.setYLims([-0.5, nmax + 0.5])
|
||||||
|
# if zoomx is not None:
|
||||||
|
# self.setXLims(zoomx)
|
||||||
|
# if zoomy is not None:
|
||||||
|
# self.setYLims(zoomy)
|
||||||
|
# self.draw()
|
||||||
|
|
||||||
|
# def getAxes(self):
|
||||||
|
# return self.axes
|
||||||
|
|
||||||
|
# def getXLims(self):
|
||||||
|
# return self.getAxes().get_xlim()
|
||||||
|
|
||||||
|
# def getYLims(self):
|
||||||
|
# return self.getAxes().get_ylim()
|
||||||
|
|
||||||
|
# def setXLims(self, lims):
|
||||||
|
# self.getAxes().set_xlim(lims)
|
||||||
|
|
||||||
|
# def setYLims(self, lims):
|
||||||
|
# self.getAxes().set_ylim(lims)
|
||||||
|
|
||||||
|
def setYTickLabels(self, pos, labels):
|
||||||
|
ticks = zip(pos, labels)
|
||||||
|
leftAx = self.plot.getPlotItem().axes['left']['item']
|
||||||
|
# leftAx.tickLength = 5
|
||||||
|
# leftAx.orientation = 'right'
|
||||||
|
leftAx.setTicks([ticks, []])
|
||||||
|
|
||||||
|
# def updateXLabel(self, text):
|
||||||
|
# self.getAxes().set_xlabel(text)
|
||||||
|
# self.draw()
|
||||||
|
|
||||||
|
# def updateYLabel(self, text):
|
||||||
|
# self.getAxes().set_ylabel(text)
|
||||||
|
# self.draw()
|
||||||
|
|
||||||
|
# def updateTitle(self, text):
|
||||||
|
# self.getAxes().set_title(text)
|
||||||
|
# self.draw()
|
||||||
|
|
||||||
|
# def updateWidget(self, xlabel, ylabel, title):
|
||||||
|
# self.updateXLabel(xlabel)
|
||||||
|
# self.updateYLabel(ylabel)
|
||||||
|
# self.updateTitle(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):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WaveformWidget(FigureCanvas):
|
class WaveformWidget(FigureCanvas):
|
||||||
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user