implement picking window and station selection (tests pending due to not working station selection so far)

This commit is contained in:
Sebastian Wehling-Benatelli 2015-03-09 11:21:33 +01:00
parent 54916fa421
commit c7aeb1959b
2 changed files with 99 additions and 29 deletions

View File

@ -35,7 +35,7 @@ from pylot.core.read import Data, FilterOptions
from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \ from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \
checkurl, FormatError, FilterOptionsDialog, \ checkurl, FormatError, FilterOptionsDialog, \
NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \ NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \
DatastructureError, createAction, getLogin, createCreationInfo DatastructureError, createAction, getLogin, createCreationInfo, PickDlg
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
@ -73,6 +73,7 @@ class MainWindow(QMainWindow):
settings.sync() settings.sync()
self.filteroptions = {} self.filteroptions = {}
self.pickDlgs = {}
# UI has to be set up before(!) children widgets are about to show up # UI has to be set up before(!) children widgets are about to show up
self.setupUi() self.setupUi()
@ -322,6 +323,9 @@ class MainWindow(QMainWindow):
def getPlotWidget(self): def getPlotWidget(self):
return self.DataPlot return self.DataPlot
def getWFID(self):
return self.getPlotWidget().getStatID()
def addActions(self, target, actions): def addActions(self, target, actions):
for action in actions: for action in actions:
if action is None: if action is None:
@ -417,6 +421,10 @@ class MainWindow(QMainWindow):
def getSeismicPhase(self): def getSeismicPhase(self):
return self.seismicPhase return self.seismicPhase
def getStationName(self, wfID):
data = self.getData().copy().select(component=self.getComponent())
return data[wfID].stats.station
def alterPhase(self): def alterPhase(self):
pass pass
@ -425,6 +433,15 @@ class MainWindow(QMainWindow):
self.updateStatus('Seismic phase changed to ' self.updateStatus('Seismic phase changed to '
'{0}'.format(self.getSeismicPhase())) '{0}'.format(self.getSeismicPhase()))
def pickOnStation(self):
wfID = self.getWFID()
station = self.getStationName(wfID)
self.pickDlgs[wfID] = PickDlg(self,
self.getData().select(station=station),
station)
def updateStatus(self, message): def updateStatus(self, message):
self.statusBar().showMessage(message, 5000) self.statusBar().showMessage(message, 5000)
if self.getData() is not None: if self.getData() is not None:

View File

@ -36,8 +36,8 @@ from PySide.QtGui import (QAction,
from PySide.QtCore import (QSettings, from PySide.QtCore import (QSettings,
Qt, Qt,
QUrl, QUrl,
SIGNAL, Signal,
SLOT) Slot)
from PySide.QtWebKit import QWebView from PySide.QtWebKit import QWebView
from pylot.core.read import FilterOptions from pylot.core.read import FilterOptions
from pylot.core.util.defaults import OUTPUTFORMATS from pylot.core.util.defaults import OUTPUTFORMATS
@ -66,14 +66,35 @@ 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()) super(MPLWidget, self).__init__(Figure())
self._parent = None
self.setParent(parent) self.setParent(parent)
self.figure = Figure() self.figure = Figure()
self.canvas = FigureCanvas(self.figure) self.canvas = FigureCanvas(self.figure)
self.canvas.mpl_connect('button_press_event', self.emitSelection)
self.axes = self.figure.add_subplot(111) self.axes = self.figure.add_subplot(111)
self.axes.autoscale(tight=True) self.axes.autoscale(tight=True)
self._statID = None
self.updateWidget(xlabel, ylabel, title) self.updateWidget(xlabel, ylabel, title)
def emitSelection(self, event):
self._statID = round(event.ydata)
if self.getParent():
self.getParent().pickOnStation()
def getStatID(self):
if self._statID is None:
return
else:
return self._statID
def getParent(self):
return self._parent
def setParent(self, parent):
self._parent = parent
def updateXLabel(self, text): def updateXLabel(self, text):
self.axes.set_xlabel(text) self.axes.set_xlabel(text)
@ -91,7 +112,7 @@ class MPLWidget(FigureCanvas):
class multiComponentPlot(FigureCanvas): class multiComponentPlot(FigureCanvas):
def __init__(self, parent=None, components='ZNE', xlabel='x', ylabel='y', title='Title'): def __init__(self, parent=None, components='ZNE'):
super(multiComponentPlot, self).__init__(Figure()) super(multiComponentPlot, self).__init__(Figure())
self.setParent(parent) self.setParent(parent)
@ -101,20 +122,27 @@ class multiComponentPlot(FigureCanvas):
self.axeslist = [] self.axeslist = []
def plotData(self, components, data):
if self.axeslist:
self.axeslist = []
self.figure.clf()
xlabel = 'time since {0} [s]'.format(data[0].stats.starttime)
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)
if n >= 1: if n >= 1:
self.axeslist.insert(n, self.axeslist.insert(
self.figure.add_subplot(nsub, n,
sharex=self.axeslist[0], self.figure.add_subplot(nsub,
sharey=self.axeslist[0])) 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) self.axeslist.insert(n, subax)
self.updateYLabel(n, ylabel[n]) self.updateYLabel(n, comp)
if n == noc: if n == self.noc:
self.updateXLabel(noc, xlabel) self.updateXLabel(self.noc, xlabel)
else: else:
self.updateXLabel(n, '') self.updateXLabel(n, '')
@ -133,19 +161,26 @@ class multiComponentPlot(FigureCanvas):
class PickDlg(QDialog): class PickDlg(QDialog):
def __init__(self, parent=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)
self.station = station self.station = station
self.rotate = rotate self.rotate = rotate
self.components = 'ZNE' self.components = 'ZNE'
self.data = parent.getData().getWFData().copy() if data is None:
try:
multicompfig = multiComponentPlot() data = parent.getData().getWFData().copy()
_layout.addWidget() self.data = data.select(station=station)
def plotData(self, data): except AttributeError, e:
errmsg = 'You either have to put in a data or an appropriate ' \
'parent (PyLoT MainWindow) object: {0}'.format(e)
raise Exception()
else:
self.data = data
self.setupUi() self.setupUi()
self.multicompfig = multiComponentPlot(parent=self,
components=self.getComponents())
def setupUi(self): def setupUi(self):
@ -168,15 +203,33 @@ class PickDlg(QDialog):
_dialtoolbar.addWidget(self.selectPhase) _dialtoolbar.addWidget(self.selectPhase)
_innerlayout = QHBoxLayout() _innerlayout = QHBoxLayout()
_toolslayout = QVBoxLayout() _toolslayout = QVBoxLayout()
_toolslabel = QLabel('Place for Tools')
_toolslayout.addWidget(_toolslabel)
_innerlayout.addLayout(_toolslayout)
_innerlayout.addWidget(self.multicompfig)
_outerlayout.addWidget(_dialtoolbar)
_outerlayout.addLayout(_innerlayout)
def getComponents(self):
return self.components
def getPlotWidget(self):
return self.multicompfig
def getWFData(self):
return self.data
def filterWFData(self): def filterWFData(self):
self.data.filterWFData() self.data.filterWFData()
self.plotData() self.plotData()
def plotData(self): def plotData(self):
for comp in self.components: self.getPlotWidget().plotData(self.getComponents(), self.getWFData())
self.getPlotWidget()
class PropertiesDlg(QDialog): class PropertiesDlg(QDialog):
@ -201,12 +254,12 @@ class PropertiesDlg(QDialog):
layout.addWidget(self.buttonBox) layout.addWidget(self.buttonBox)
self.setLayout(layout) self.setLayout(layout)
self.connect(self.buttonBox, SIGNAL("accepted()"), self, self.connect(self.buttonBox, Signal("accepted()"), self,
SLOT("accept()")) Slot("accept()"))
self.connect(self.buttonBox.button(QDialogButtonBox.Apply), self.connect(self.buttonBox.button(QDialogButtonBox.Apply),
SIGNAL("clicked()"), self.apply) Signal("clicked()"), self.apply)
self.connect(self.buttonBox, SIGNAL("rejected()"), self.connect(self.buttonBox, Signal("rejected()"),
self, SLOT("reject()")) self, Slot("reject()"))
def accept(self, *args, **kwargs): def accept(self, *args, **kwargs):
self.apply() self.apply()
@ -549,11 +602,11 @@ class HelpForm(QDialog):
layout.addWidget(self.webBrowser, 1) layout.addWidget(self.webBrowser, 1)
self.setLayout(layout) self.setLayout(layout)
self.connect(backAction, SIGNAL("triggered()"), self.connect(backAction, Signal("triggered()"),
self.webBrowser, SLOT("backward()")) self.webBrowser, Slot("backward()"))
self.connect(homeAction, SIGNAL("triggered()"), self.connect(homeAction, Signal("triggered()"),
self.webBrowser, SLOT("home()")) self.webBrowser, Slot("home()"))
self.connect(self.webBrowser, SIGNAL("sourceChanged(QUrl)"), self.connect(self.webBrowser, Signal("sourceChanged(QUrl)"),
self.updatePageTitle) self.updatePageTitle)
self.resize(400, 600) self.resize(400, 600)