now the station selection works fine and a picking window is opened when the waveform has been clicked
This commit is contained in:
parent
a0bbe8ca04
commit
474622027e
15
QtPyLoT.py
15
QtPyLoT.py
@ -115,7 +115,7 @@ class MainWindow(QMainWindow):
|
|||||||
# create central matplotlib figure canvas widget
|
# create central matplotlib figure canvas widget
|
||||||
self.DataPlot = MPLWidget(parent=self, xlabel=xlab, ylabel=None,
|
self.DataPlot = MPLWidget(parent=self, xlabel=xlab, ylabel=None,
|
||||||
title=plottitle)
|
title=plottitle)
|
||||||
|
self.DataPlot.mpl_connect('button_press_event', self.pickOnStation)
|
||||||
_layout.addWidget(self.DataPlot)
|
_layout.addWidget(self.DataPlot)
|
||||||
|
|
||||||
openIcon = self.style().standardIcon(QStyle.SP_DirOpenIcon)
|
openIcon = self.style().standardIcon(QStyle.SP_DirOpenIcon)
|
||||||
@ -340,7 +340,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
ycoord = event.ydata
|
ycoord = event.ydata
|
||||||
|
|
||||||
statID = round(ycoord)
|
statID = int(round(ycoord))
|
||||||
|
|
||||||
return statID
|
return statID
|
||||||
|
|
||||||
@ -440,8 +440,7 @@ class MainWindow(QMainWindow):
|
|||||||
return self.seismicPhase
|
return self.seismicPhase
|
||||||
|
|
||||||
def getStationName(self, wfID):
|
def getStationName(self, wfID):
|
||||||
data = self.getData().copy().select(component=self.getComponent())
|
return self.getPlotWidget().getPlotDict()[wfID]
|
||||||
return data[wfID].stats.station
|
|
||||||
|
|
||||||
def alterPhase(self):
|
def alterPhase(self):
|
||||||
pass
|
pass
|
||||||
@ -456,9 +455,11 @@ class MainWindow(QMainWindow):
|
|||||||
wfID = self.getWFID(event)
|
wfID = self.getWFID(event)
|
||||||
|
|
||||||
station = self.getStationName(wfID)
|
station = self.getStationName(wfID)
|
||||||
self.pickDlgs[wfID] = PickDlg(self,
|
data = self.getData().getWFData()
|
||||||
self.getData().select(station=station),
|
pickDlg = PickDlg(self, data.select(station=station), station)
|
||||||
station)
|
print 'picking on station {0}'.format(station)
|
||||||
|
pickDlg.exec_()
|
||||||
|
|
||||||
|
|
||||||
def updateStatus(self, message):
|
def updateStatus(self, message):
|
||||||
self.statusBar().showMessage(message, 5000)
|
self.statusBar().showMessage(message, 5000)
|
||||||
|
@ -30,7 +30,8 @@ class Data(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, parent=None, evtdata=None):
|
def __init__(self, parent=None, evtdata=None):
|
||||||
if parent:
|
self._parent = parent
|
||||||
|
if self.getParent():
|
||||||
self.comp = parent.getComponent()
|
self.comp = parent.getComponent()
|
||||||
else:
|
else:
|
||||||
self.comp = 'Z'
|
self.comp = 'Z'
|
||||||
@ -50,6 +51,9 @@ class Data(object):
|
|||||||
self.cuttimes = None
|
self.cuttimes = None
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
|
|
||||||
|
def getParent(self):
|
||||||
|
return self._parent
|
||||||
|
|
||||||
def isNew(self):
|
def isNew(self):
|
||||||
return self.newevent
|
return self.newevent
|
||||||
|
|
||||||
@ -104,6 +108,7 @@ class Data(object):
|
|||||||
srate = trace.stats.sampling_rate
|
srate = trace.stats.sampling_rate
|
||||||
nsamp = len(trace.data)
|
nsamp = len(trace.data)
|
||||||
tincr = trace.stats.delta
|
tincr = trace.stats.delta
|
||||||
|
station = trace.stats.station
|
||||||
time_ax = np.arange(stime, nsamp / srate, tincr)
|
time_ax = np.arange(stime, nsamp / srate, tincr)
|
||||||
trace.normalize(trace.data.max() * 2)
|
trace.normalize(trace.data.max() * 2)
|
||||||
widget.axes.plot(time_ax, trace.data + n, 'k')
|
widget.axes.plot(time_ax, trace.data + n, 'k')
|
||||||
@ -112,6 +117,10 @@ class Data(object):
|
|||||||
zne_text = {'Z': 'vertical', 'N': 'north-south', 'E': 'east-west'}
|
zne_text = {'Z': 'vertical', 'N': 'north-south', 'E': 'east-west'}
|
||||||
title = 'overview: {0} components'.format(zne_text[self.getComp()])
|
title = 'overview: {0} components'.format(zne_text[self.getComp()])
|
||||||
widget.updateWidget(xlabel, ylabel, title)
|
widget.updateWidget(xlabel, ylabel, title)
|
||||||
|
widget.setPlotDict(n, station)
|
||||||
|
|
||||||
|
widget.axes.autoscale(tight=True)
|
||||||
|
|
||||||
|
|
||||||
def getComp(self):
|
def getComp(self):
|
||||||
return self.comp
|
return self.comp
|
||||||
|
@ -6,13 +6,14 @@ Created on Wed Mar 19 11:27:35 2014
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import numpy as np
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
|
||||||
matplotlib.use('Qt4Agg')
|
matplotlib.use('Qt4Agg')
|
||||||
matplotlib.rcParams['backend.qt4'] = 'PySide'
|
matplotlib.rcParams['backend.qt4'] = 'PySide'
|
||||||
|
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
|
from matplotlib.backends.backend_qt4agg import FigureCanvas
|
||||||
from matplotlib.widgets import MultiCursor
|
from matplotlib.widgets import MultiCursor
|
||||||
from PySide.QtGui import (QAction,
|
from PySide.QtGui import (QAction,
|
||||||
QApplication,
|
QApplication,
|
||||||
@ -65,19 +66,25 @@ def createAction(parent, text, slot=None, shortcut=None, icon=None,
|
|||||||
class MPLWidget(FigureCanvas):
|
class MPLWidget(FigureCanvas):
|
||||||
|
|
||||||
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
||||||
super(MPLWidget, self).__init__(Figure())
|
|
||||||
|
|
||||||
self._parent = None
|
self._parent = None
|
||||||
self.setParent(parent)
|
self.setParent(parent)
|
||||||
self.figure = Figure()
|
self.figure = Figure()
|
||||||
self.canvas = FigureCanvas(self.figure)
|
self.plotdict = dict()
|
||||||
|
|
||||||
self.axes = self.figure.add_subplot(111)
|
self.axes = self.figure.add_subplot(111)
|
||||||
self.axes.autoscale(tight=True)
|
|
||||||
self._statID = None
|
self._statID = None
|
||||||
self.multiCursor = MultiCursor(self.canvas, (self.axes,), horizOn=True,
|
FigureCanvas.__init__(self, self.figure)
|
||||||
|
self.multiCursor = MultiCursor(self.figure.canvas, (self.axes,), horizOn=True,
|
||||||
color='m', lw=1)
|
color='m', lw=1)
|
||||||
self.updateWidget(xlabel, ylabel, title)
|
self.updateWidget(xlabel, ylabel, title)
|
||||||
|
|
||||||
|
def getPlotDict(self):
|
||||||
|
return self.plotdict
|
||||||
|
|
||||||
|
def setPlotDict(self, key, value):
|
||||||
|
self.plotdict[key] = value
|
||||||
|
|
||||||
def getParent(self):
|
def getParent(self):
|
||||||
return self._parent
|
return self._parent
|
||||||
|
|
||||||
@ -101,51 +108,100 @@ class MPLWidget(FigureCanvas):
|
|||||||
|
|
||||||
class multiComponentPlot(FigureCanvas):
|
class multiComponentPlot(FigureCanvas):
|
||||||
|
|
||||||
def __init__(self, parent=None, components='ZNE'):
|
def __init__(self, data, parent=None, components='ZNE'):
|
||||||
super(multiComponentPlot, self).__init__(Figure())
|
|
||||||
|
self.data = data
|
||||||
|
self._parent = parent
|
||||||
|
self.components = components
|
||||||
|
|
||||||
self.setParent(parent)
|
|
||||||
self.figure = Figure()
|
self.figure = Figure()
|
||||||
self.canvas = FigureCanvas(self.figure)
|
|
||||||
self.noc = len(components)
|
|
||||||
self.axeslist = []
|
|
||||||
|
|
||||||
def plotData(self, components, data):
|
self.noc = len(components)
|
||||||
if self.axeslist:
|
FigureCanvas.__init__(self, self.figure)
|
||||||
self.axeslist = []
|
self.multiCursor = None
|
||||||
|
self.resetPlot(components, data)
|
||||||
|
|
||||||
|
def getData(self):
|
||||||
|
return self.data
|
||||||
|
|
||||||
|
def setData(self, data):
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
def getParent(self):
|
||||||
|
return self._parent
|
||||||
|
|
||||||
|
def setParent(self, parent):
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
|
def getComponents(self):
|
||||||
|
return self.components
|
||||||
|
|
||||||
|
def setComponents(self, components):
|
||||||
|
self.components = components
|
||||||
|
|
||||||
|
def getNoC(self):
|
||||||
|
return self.noc
|
||||||
|
|
||||||
|
def setNoC(self, noc):
|
||||||
|
self.noc = noc
|
||||||
|
|
||||||
|
def resetPlot(self, components=None, data=None):
|
||||||
|
|
||||||
|
# clear figure
|
||||||
self.figure.clf()
|
self.figure.clf()
|
||||||
xlabel = 'time since {0} [s]'.format(data[0].stats.starttime)
|
|
||||||
|
# delete multiCursor if existing
|
||||||
|
if self.multiCursor is not None:
|
||||||
|
self.multiCursor = None
|
||||||
|
|
||||||
|
# set new attribute values
|
||||||
|
if data is not None:
|
||||||
|
self.setData(data)
|
||||||
|
if components is not None:
|
||||||
|
self.setComponents(components)
|
||||||
|
noc = len(self.getComponents())
|
||||||
|
if self.getNoC() != noc:
|
||||||
|
self.setNoC(noc)
|
||||||
|
self.axesdict = dict()
|
||||||
|
|
||||||
|
# prepare variables for plotting
|
||||||
|
trace = data[0]
|
||||||
|
stime = trace.stats.starttime
|
||||||
|
srate = trace.stats.sampling_rate
|
||||||
|
npts = trace.stats.npts
|
||||||
|
tincr = trace.stats.delta
|
||||||
|
time_ax = np.arange(0, npts / srate, tincr)
|
||||||
|
xlabel = 'time since {0} [s]'.format(stime)
|
||||||
|
|
||||||
|
# plot individual component traces in separate subplots
|
||||||
for n, comp in enumerate(components):
|
for n, comp in enumerate(components):
|
||||||
nsub = '{0}1{1}'.format(self.noc, n)
|
nsub = '{0}1{1}'.format(self.noc, n+1)
|
||||||
if n >= 1:
|
if n >= 1:
|
||||||
self.axeslist.insert(
|
subax = self.figure.add_subplot(nsub, sharex=self.axesdict[0])
|
||||||
n,
|
|
||||||
self.figure.add_subplot(nsub,
|
|
||||||
sharex=self.axeslist[0],
|
|
||||||
sharey=self.axeslist[0])
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
subax = self.figure.add_subplot(nsub)
|
subax = self.figure.add_subplot(nsub)
|
||||||
subax.autoscale(tight=True)
|
subax.autoscale(tight=True)
|
||||||
self.axeslist.insert(n, subax)
|
subset = data.copy().select(component=comp)[0].data
|
||||||
|
subax.plot(time_ax, subset)
|
||||||
|
self.axesdict[n] = subax
|
||||||
self.updateYLabel(n, comp)
|
self.updateYLabel(n, comp)
|
||||||
if n == self.noc:
|
if n == self.noc:
|
||||||
self.updateXLabel(self.noc, xlabel)
|
self.updateXLabel(self.noc, xlabel)
|
||||||
else:
|
else:
|
||||||
self.updateXLabel(n, '')
|
self.updateXLabel(n, '')
|
||||||
self.multiCursor = MultiCursor(self.canvas, tuple(self.axeslist))
|
|
||||||
|
self.multiCursor = MultiCursor(self.figure.canvas, tuple(self.axesdict.values()), color='r', lw=1)
|
||||||
|
|
||||||
def insertLabel(self, pos, text):
|
def insertLabel(self, pos, text):
|
||||||
subax = self.axeslist[pos]
|
subax = self.axesdict[pos]
|
||||||
axann = subax.annotate(text, xy=(.03, .97), xycoords='axes fraction')
|
axann = subax.annotate(text, xy=(.03, .97), xycoords='axes fraction')
|
||||||
axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
|
axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
|
||||||
|
|
||||||
def updateXLabel(self, pos, text):
|
def updateXLabel(self, pos, text):
|
||||||
self.axeslist[pos].set_xlabel(text)
|
self.axesdict[pos].set_xlabel(text)
|
||||||
|
|
||||||
def updateYLabel(self, pos, text):
|
def updateYLabel(self, pos, text):
|
||||||
self.axeslist[pos].set_ylabel(text)
|
self.axesdict[pos].set_ylabel(text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PickDlg(QDialog):
|
class PickDlg(QDialog):
|
||||||
@ -153,9 +209,11 @@ class PickDlg(QDialog):
|
|||||||
def __init__(self, parent=None, data=None, station=None, rotate=False):
|
def __init__(self, parent=None, data=None, station=None, rotate=False):
|
||||||
super(PickDlg, self).__init__(parent)
|
super(PickDlg, self).__init__(parent)
|
||||||
|
|
||||||
|
# initialize attributes
|
||||||
self.station = station
|
self.station = station
|
||||||
self.rotate = rotate
|
self.rotate = rotate
|
||||||
self.components = 'ZNE'
|
self.components = 'ZNE'
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
try:
|
try:
|
||||||
data = parent.getData().getWFData().copy()
|
data = parent.getData().getWFData().copy()
|
||||||
@ -163,13 +221,13 @@ class PickDlg(QDialog):
|
|||||||
except AttributeError, e:
|
except AttributeError, e:
|
||||||
errmsg = 'You either have to put in a data or an appropriate ' \
|
errmsg = 'You either have to put in a data or an appropriate ' \
|
||||||
'parent (PyLoT MainWindow) object: {0}'.format(e)
|
'parent (PyLoT MainWindow) object: {0}'.format(e)
|
||||||
raise Exception()
|
raise Exception(errmsg)
|
||||||
else:
|
else:
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
self.setupUi()
|
self.multicompfig = multiComponentPlot(data=data, parent=self,
|
||||||
self.multicompfig = multiComponentPlot(parent=self,
|
|
||||||
components=self.getComponents())
|
components=self.getComponents())
|
||||||
|
self.setupUi()
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
|
|
||||||
@ -202,6 +260,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
_outerlayout.addWidget(_dialtoolbar)
|
_outerlayout.addWidget(_dialtoolbar)
|
||||||
_outerlayout.addLayout(_innerlayout)
|
_outerlayout.addLayout(_innerlayout)
|
||||||
|
self.setLayout(_outerlayout)
|
||||||
|
|
||||||
|
|
||||||
def getComponents(self):
|
def getComponents(self):
|
||||||
@ -214,11 +273,9 @@ class PickDlg(QDialog):
|
|||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def filterWFData(self):
|
def filterWFData(self):
|
||||||
self.data.filterWFData()
|
self.data.filter(type='bandpass', freqmin=.5, freqmax=15.)
|
||||||
self.plotData()
|
self.getPlotWidget().resetPlot(self.getComponents(), self.getWFData())
|
||||||
|
|
||||||
def plotData(self):
|
|
||||||
self.getPlotWidget().plotData(self.getComponents(), self.getWFData())
|
|
||||||
|
|
||||||
class PropertiesDlg(QDialog):
|
class PropertiesDlg(QDialog):
|
||||||
|
|
||||||
|
13
testPickDlg.py
Normal file
13
testPickDlg.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PySide.QtGui import QApplication
|
||||||
|
from obspy.core import read
|
||||||
|
from pylot.core.util.widgets import PickDlg
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
data = read()
|
||||||
|
win = PickDlg(data=data)
|
||||||
|
win.show()
|
||||||
|
app.exec_()
|
Loading…
Reference in New Issue
Block a user