pylot/QtPyLoT.py

313 lines
11 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2014-03-31 12:57:08 +02:00
# -*- coding: utf-8 -*-
"""
PyLoT: Main program
===================
PyLoT is a seismic data processing software capable of picking seismic
phases (symmetric and asymmetric error assignment), exporting these to
several common phase data formats and post process the data, e.g. locating
events, via external localization software.
Additionally PyLoT is meant as an interface to autoPyLoT which can
automatically pick seismic phases, if the parameters have properly been
chosen for the particular data set.
2014-11-28 09:19:16 +01:00
Some icons are out of a free of charge icon set, which can be found here:
https://www.iconfinder.com/iconsets/flavour
2014-03-31 12:57:08 +02:00
:author:
Sebastian Wehling-Benatelli
:copyright:
The PyLoT Development Team (https://ariadne.geophysik.rub.de/trac/PyLoT)
:license:
GNU Lesser General Public License, Version 3
(http://www.gnu.org/copyleft/lesser.html)
"""
import os
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from obspy.core import (read, UTCDateTime)
from pylot import *
from pylot.core.util import _getVersionString
from pylot.core.read import (Data,
FilterOptions)
from pylot.core.util import FILTERDEFAULTS
from pylot.core.util import fnConstructor
2014-03-31 12:57:08 +02:00
from pylot.core.util import checkurl
2014-06-10 16:37:07 +02:00
from pylot.core.util import (PickDlg,
FilterOptionsDialog,
2014-06-10 16:37:07 +02:00
PropertiesDlg,
MPLWidget,
HelpForm)
from pylot.core.util import layoutStationButtons
import qrc_resources
# Version information
__version__ = _getVersionString()
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
2014-11-28 11:15:49 +01:00
settings = QSettings()
2014-12-01 12:36:23 +01:00
self.recentEvents = settings.value("recentEvents", [])
2014-11-28 11:15:49 +01:00
self.setWindowTitle("PyLoT - do seismic processing the pythonic way")
self.setWindowIcon(QIcon(":/icon.ico"))
self.seismicPhase = str(settings.value("phase", "P"))
2014-12-01 12:36:23 +01:00
if settings.value("dataRoot", None) is None:
dirname = QFileDialog().getExistingDirectory()
settings.setValue("dataRoot", dirname)
settings.sync()
2014-11-28 11:15:49 +01:00
# initialize filter parameter
filterOptionsP = FILTERDEFAULTS['P']
filterOptionsS = FILTERDEFAULTS['S']
2014-11-28 11:15:49 +01:00
print filterOptionsP, "\n", filterOptionsS
self.filterOptionsP = FilterOptions(**filterOptionsP)
self.filterOptionsS = FilterOptions(**filterOptionsS)
# initialize data
self.data = None
self.loadData()
self.updateFilterOptions()
2014-11-28 11:15:49 +01:00
print self.filteroptions
try:
self.startTime = min([tr.stats.starttime for tr in self.data.wfdata])
except:
self.startTime = UTCDateTime()
self.setupUi()
def _getCurrentPlotType(self):
return 'TestType'
def createAction(self, text, slot=None, shortcut=None, icon=None,
tip=None, checkable=False):
action = QAction(text, self)
if icon is not None:
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
if slot is not None:
action.triggered.connect(slot)
if checkable:
action.setCheckable(True)
return action
def updateFileMenu(self):
self.fileMenu.clear()
self.addActions(self.fileMenu, self.fileMenuActions[:-1])
current = self.data.evtdata.getEventID()
recentEvents = []
for eventID in self.recentEvents:
fname = fnConstructor(eventID)
if eventID != current and QFile.exists(fname):
recentEvents.append(eventID)
if recentEvents:
self.fileMenu.addSeparator()
for i, eventID in enumerate(recentEvents):
fname = fnConstructor(eventID)
action = QAction(QIcon(":/icon.png"),
"&{0} {1}".format(i + 1,
QFileInfo(fname).fileName()),
self)
action.setData(fname)
self.connect(action, SIGNAL("triggered()"),
self.loadData)
self.fileMenu.addAction(action)
self.fileMenu.addSeparator()
self.fileMenu.addAction(self.fileMenuActions[-1])
2014-11-28 11:15:49 +01:00
def loadData(self, fname=None):
if fname is None:
action = self.sender()
if isinstance(action, QAction):
if action.data() is None:
fname = QFileDialog()
else:
fname = unicode(action.data().toString())
if not self.okToContinue():
return
else:
return
if fname:
self.data = Data(evtdata=fname)
2014-11-28 11:15:49 +01:00
def saveData(self):
pass
def getComponent(self):
return self
def getData(self):
return self.data
def getDataWidget(self):
return self.DataPlot
def setupUi(self):
2014-11-28 09:19:16 +01:00
self.setWindowIcon(QIcon(":/icon.ico"))
xlab = self.startTime.strftime('seconds since %d %b %Y %H:%M:%S (%Z)')
2014-10-27 11:55:06 +01:00
plottitle = self._getCurrentPlotType()
# create central matplotlib figure widget
self.DataPlot = MPLWidget(parent=self,
xlabel=xlab,
2014-10-27 11:55:06 +01:00
ylabel=None,
title=plottitle)
self.setCentralWidget(self.getDataWidget())
2014-11-28 09:19:16 +01:00
openIcon = self.style().standardIcon(QStyle.SP_DirOpenIcon)
quitIcon = self.style().standardIcon(QStyle.SP_MediaStop)
2014-11-28 11:15:49 +01:00
saveIcon = self.style().standardIcon(QStyle.SP_DriveHDIcon)
openEventAction = self.createAction("&Open event ...", self.loadData,
QKeySequence.Open, openIcon,
"Open an event.")
openEventAction.setData(None)
saveEventAction = self.createAction("&Save event ...", self.saveData,
QKeySequence.Save, saveIcon,
"Save actual event data.")
quitAction = self.createAction("&Quit",
QCoreApplication.instance().quit,
QKeySequence.Close, quitIcon,
"Close event and quit PyLoT")
filterAction = self.createAction("&Filter ...", self.filterData,
"Ctrl+F", QIcon(":/filter.png"),
"""Toggle un-/filtered waveforms
to be displayed, according to the
desired seismic phase.""", True)
filterEditAction = self.createAction("&Filter parameter ...",
self.adjustFilterOptions,
"Alt+F", QIcon(None),
"""Adjust filter parameters.""")
selectPAction = self.createAction("&P", self.alterPhase, "Alt+P",
QIcon(":/picon.png"),
"Toggle P phase.", True)
selectSAction = self.createAction("&S", self.alterPhase, "Alt+S",
QIcon(":/sicon.png"),
"Toggle S phase", True)
printAction = self.createAction("&Print event ...",
self.printEvent, QKeySequence.Print,
QIcon(":/printer.png"),
"Print waveform overview.")
self.fileMenu = self.menuBar().addMenu('&File')
self.fileMenuActions = (openEventAction, saveEventAction, None,
quitAction)
self.fileMenu.aboutToShow.connect(self.updateFileMenu)
self.createMenu('&Edit', (filterAction, filterEditAction, None,
selectPAction, selectSAction, None,
printAction))
self.eventLabel = QLabel()
self.eventLabel.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)
status = self.statusBar()
status.setSizeGripEnabled(False)
status.addPermanentWidget(self.eventLabel)
2014-12-01 08:40:35 +01:00
status.showMessage("Ready", 500)
# statLayout = layoutStationButtons(self.getData(), self.getComponent())
# dataLayout = self.getDataWidget()
# maingrid = QGridLayout()
# maingrid.setSpacing(10)
# maingrid.addLayout(statLayout, 0, 0)
# maingrid.addWidget(self.getDataWidget(), 0, 1)
# self.setLayout(maingrid)
def okToContinue(self):
if self.dirty:
return self.saveData()
return True
def plotData(self):
pass #self.data.plotData(self.DataPlot)
2014-03-19 12:24:41 +01:00
2014-11-28 11:15:49 +01:00
def filterData(self):
pass
def adjustFilterOptions(self):
fstring = "Filter Options ({0})".format(self.getSeismicPhase())
filterDlg = FilterOptionsDialog(titleString=fstring,
parent=self,
filterOptions=self.getFilterOptions())
if filterDlg.exec_():
filterOptions = filterDlg.getFilterOptions()
self.setFilterOptions(filterOptions)
def getFilterOptions(self):
return self.filteroptions
def setFilterOptions(self, filterOptions):
cases = {'P':self.filterOptionsP,
'S':self.filterOptionsS}
cases[self.getSeismicPhase()] = filterOptions
self.updateFilterOptions()
def updateFilterOptions(self):
try:
self.filteroptions = [self.filterOptionsP
if not self.seismicPhase == 'S'
2014-11-28 11:15:49 +01:00
else self.filterOptionsS][0]
except Exception, e:
2014-11-28 09:19:16 +01:00
self.updateStatus('Error ...')
2014-11-28 11:15:49 +01:00
emsg = QErrorMessage(self)
emsg.showMessage('Error: {0}'.format(e))
else:
2014-11-28 09:19:16 +01:00
self.updateStatus('Filter loaded ...')
def getSeismicPhase(self):
return self.seismicPhase
2014-11-28 11:15:49 +01:00
def alterPhase(self):
pass
def setSeismicPhase(self, phase):
2014-11-28 09:19:16 +01:00
self.seismicPhase = self.seismicPhaseButtonGroup.getValue()
def updateStatus(self, message):
self.statusBar().showMessage(message, 5000)
2014-11-28 11:15:49 +01:00
def printEvent(self):
pass
def closeEvent(self):
return self.saveData()
2014-11-28 11:15:49 +01:00
def helpHelp(self):
if checkurl():
form = HelpForm('https://ariadne.geophysik.ruhr-uni-bochum.de/trac/PyLoT/wiki')
else:
form = HelpForm(':/help.html')
form.show()
def main():
# create the Qt application
2014-12-01 08:40:35 +01:00
pylot_app = QApplication(sys.argv[0])
# set Application Information
pylot_app.setOrganizationName("Ruhr-University Bochum / MAGS2")
pylot_app.setOrganizationDomain("rub.de")
pylot_app.setApplicationName("PyLoT")
2014-11-28 09:19:16 +01:00
pylot_app.setWindowIcon(QIcon(":/icon.ico"))
# create the main window
pylot_form = MainWindow()
# Show main window and run the app
pylot_form.show()
2014-12-01 08:40:35 +01:00
sys.exit(pylot_app.exec_())
if __name__ == "__main__":
main()