export and save picks implemented successfully
This commit is contained in:
parent
fc86179c39
commit
f4f744e22c
35
QtPyLoT.py
35
QtPyLoT.py
@ -23,7 +23,7 @@ https://www.iconfinder.com/iconsets/flavour
|
|||||||
(http://www.gnu.org/copyleft/lesser.html)
|
(http://www.gnu.org/copyleft/lesser.html)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import os, sys
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
|
||||||
matplotlib.use('Qt4Agg')
|
matplotlib.use('Qt4Agg')
|
||||||
@ -64,7 +64,6 @@ class MainWindow(QMainWindow):
|
|||||||
super(MainWindow, self).__init__(parent)
|
super(MainWindow, self).__init__(parent)
|
||||||
|
|
||||||
self.createAction = createAction
|
self.createAction = createAction
|
||||||
self.dirty = False
|
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
if settings.value("user/FullName", None) is None:
|
if settings.value("user/FullName", None) is None:
|
||||||
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
||||||
@ -102,8 +101,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.data = Data(self)
|
self.data = Data(self)
|
||||||
|
|
||||||
# load and display waveform data
|
# load and display waveform data
|
||||||
self.loadWaveformData()
|
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
|
self.loadWaveformData()
|
||||||
self.loadData()
|
self.loadData()
|
||||||
self.updateFilterOptions()
|
self.updateFilterOptions()
|
||||||
|
|
||||||
@ -333,6 +332,10 @@ class MainWindow(QMainWindow):
|
|||||||
self.fileMenu.addSeparator()
|
self.fileMenu.addSeparator()
|
||||||
self.fileMenu.addAction(self.fileMenuActions[-1])
|
self.fileMenu.addAction(self.fileMenuActions[-1])
|
||||||
|
|
||||||
|
def getRoot(self):
|
||||||
|
settings = QSettings()
|
||||||
|
return settings.value("data/dataRoot")
|
||||||
|
|
||||||
def loadData(self, fname=None):
|
def loadData(self, fname=None):
|
||||||
if fname is None:
|
if fname is None:
|
||||||
try:
|
try:
|
||||||
@ -390,18 +393,27 @@ class MainWindow(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def getEventFileName(self):
|
||||||
|
return self.getData().getEventFileName()
|
||||||
|
|
||||||
def saveData(self):
|
def saveData(self):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
exform = settings.value('data/exportFormat', 'QUAKEML')
|
exform = settings.value('data/exportFormat', 'QUAKEML')
|
||||||
|
self.getData().applyEVTData(self.getPicks())
|
||||||
try:
|
try:
|
||||||
self.data.exportEvent(self.fname, exform)
|
self.getData().exportEvent(self.fname, exform)
|
||||||
except FormatError:
|
except FormatError:
|
||||||
return False
|
return False
|
||||||
except AttributeError, e:
|
except AttributeError, e:
|
||||||
print 'warning: {0}'.format(e)
|
print 'warning: {0}'.format(e)
|
||||||
fname = QFileDialog.getSaveFileName(self, 'Save event')
|
directory = os.path.join(self.getRoot(), self.getEventFileName())
|
||||||
fname = fname[0]
|
file_filter = "Seismic observation files (*.cnv *.obs *.xml)"
|
||||||
self.getData().exportEvent(fname, exform)
|
fname = QFileDialog.getSaveFileName(self, 'Save event data ...',
|
||||||
|
directory, file_filter)
|
||||||
|
fbasename, exform = os.path.splitext(fname[0])
|
||||||
|
if not fbasename:
|
||||||
|
return False
|
||||||
|
self.getData().exportEvent(fbasename, exform)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getComponent(self):
|
def getComponent(self):
|
||||||
@ -455,7 +467,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def loadWaveformData(self):
|
def loadWaveformData(self):
|
||||||
if self.fnames and self.okToContinue():
|
if self.fnames and self.okToContinue():
|
||||||
self.dirty = True
|
self.setDirty(True)
|
||||||
self.data.setWFData(self.fnames)
|
self.data.setWFData(self.fnames)
|
||||||
elif self.fnames is None and self.okToContinue():
|
elif self.fnames is None and self.okToContinue():
|
||||||
self.data.setWFData(self.getWFFnames())
|
self.data.setWFData(self.getWFFnames())
|
||||||
@ -585,6 +597,7 @@ class MainWindow(QMainWindow):
|
|||||||
station=station,
|
station=station,
|
||||||
picks=self.getPicksOnStation(station))
|
picks=self.getPicksOnStation(station))
|
||||||
if pickDlg.exec_():
|
if pickDlg.exec_():
|
||||||
|
self.setDirty(True)
|
||||||
self.updateStatus('picks accepted ({0})'.format(station))
|
self.updateStatus('picks accepted ({0})'.format(station))
|
||||||
self.addPicks(station, pickDlg.getPicks())
|
self.addPicks(station, pickDlg.getPicks())
|
||||||
self.drawPicks(station)
|
self.drawPicks(station)
|
||||||
@ -593,6 +606,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def autoPick(self):
|
def autoPick(self):
|
||||||
list = QListWidget()
|
list = QListWidget()
|
||||||
|
self.setDirty(True)
|
||||||
logDockWidget = QDockWidget("AutoPickLog", self)
|
logDockWidget = QDockWidget("AutoPickLog", self)
|
||||||
logDockWidget.setObjectName("LogDockWidget")
|
logDockWidget.setObjectName("LogDockWidget")
|
||||||
logDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)
|
logDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)
|
||||||
@ -700,11 +714,14 @@ class MainWindow(QMainWindow):
|
|||||||
cinfo = createCreationInfo(agency_id=self.agency)
|
cinfo = createCreationInfo(agency_id=self.agency)
|
||||||
event = createEvent(evtpar['origintime'], cinfo)
|
event = createEvent(evtpar['origintime'], cinfo)
|
||||||
self.data = Data(self, evtdata=event)
|
self.data = Data(self, evtdata=event)
|
||||||
self.dirty = True
|
self.setDirty(True)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.getPlotWidget().draw()
|
self.getPlotWidget().draw()
|
||||||
|
|
||||||
|
def setDirty(self, value):
|
||||||
|
self.dirty = value
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
if self.okToContinue():
|
if self.okToContinue():
|
||||||
self.closing.emit()
|
self.closing.emit()
|
||||||
|
@ -68,29 +68,25 @@ class Data(object):
|
|||||||
def updateCutTimes(self):
|
def updateCutTimes(self):
|
||||||
self.cuttimes = getGlobalTimes(self.getWFData())
|
self.cuttimes = getGlobalTimes(self.getWFData())
|
||||||
|
|
||||||
def exportEvent(self, fnout=None, evtformat='QUAKEML'):
|
def getEventFileName(self):
|
||||||
|
ID = self.getID()
|
||||||
|
# handle forbidden filenames especially on windows systems
|
||||||
|
return fnConstructor(str(ID))
|
||||||
|
|
||||||
|
def exportEvent(self, fnout, fnext='.xml'):
|
||||||
|
|
||||||
from pylot.core.util.defaults import OUTPUTFORMATS
|
from pylot.core.util.defaults import OUTPUTFORMATS
|
||||||
|
|
||||||
if evtformat.strip() not in OUTPUTFORMATS.values():
|
try:
|
||||||
errmsg = 'selected format {0} not available'.format(evtformat)
|
evtformat = OUTPUTFORMATS[fnext]
|
||||||
|
except KeyError, e:
|
||||||
|
errmsg = '{0}; selected file extension {1} not ' \
|
||||||
|
'supported'.format(e, fnext)
|
||||||
raise FormatError(errmsg)
|
raise FormatError(errmsg)
|
||||||
|
|
||||||
if fnout is None:
|
|
||||||
ID = self.getID()
|
|
||||||
# handle forbidden filenames especially on windows systems
|
|
||||||
fnout = fnConstructor(str(ID))
|
|
||||||
else:
|
|
||||||
fnout = fnConstructor(str(fnout))
|
|
||||||
|
|
||||||
evtformat = evtformat.upper().strip()
|
|
||||||
|
|
||||||
# establish catalog object (event object has no write method)
|
|
||||||
cat = Catalog()
|
|
||||||
cat.append(self.getEvtData())
|
|
||||||
# try exporting event via ObsPy
|
# try exporting event via ObsPy
|
||||||
try:
|
try:
|
||||||
cat.write(fnout + evtformat.lower(), format=evtformat)
|
self.getEvtData().write(fnout + fnext, format=evtformat)
|
||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
raise KeyError('''{0} export format
|
raise KeyError('''{0} export format
|
||||||
not implemented: {1}'''.format(evtformat, e))
|
not implemented: {1}'''.format(evtformat, e))
|
||||||
|
Loading…
Reference in New Issue
Block a user