implementation of reading and plotting seismograms (work in progress)

This commit is contained in:
Sebastian Wehling-Benatelli 2015-02-07 09:05:08 +01:00
parent 7092f6e8b5
commit d3199a5798
2 changed files with 64 additions and 28 deletions

View File

@ -83,7 +83,7 @@ class MainWindow(QMainWindow):
self.filterOptionsS = FilterOptions(**filterOptionsS)
# initialize data
self.data = None
self.data = Data()
self.dirty = False
self.loadData()
self.updateFilterOptions()
@ -248,22 +248,23 @@ class MainWindow(QMainWindow):
def loadData(self, fname=None):
if fname is None:
action = self.sender()
if isinstance(action, QAction):
if action.data() is None:
filt = """Supported event formats (*.mat *.qml *.xml *.kor
*.evt)"""
caption = 'Select event to open'
self.fname = QFileDialog().getOpenFileName(self,
caption=caption,
filter=filt)
else:
self.fname = unicode(action.data().toString())
try:
self.data = Data(evtdata=self.fname)
except AttributeError:
action = self.sender()
if isinstance(action, QAction):
if action.data() is None:
filt = """Supported event formats (*.mat *.qml *.xml
*.kor *.evt)"""
caption = 'Select event to open'
self.fname = QFileDialog().getOpenFileName(self,
caption=caption,
filter=filt)
else:
self.fname = unicode(action.data().toString())
if not self.okToContinue():
return
else:
return
if fname:
else:
self.fname = fname
self.data = Data(evtdata=self.fname)
@ -326,11 +327,16 @@ class MainWindow(QMainWindow):
return True
def openWaveformData(self):
if self.fnames and self.okToContinue():
self.dirty = True
self.data.wfdata = self.data.setWFData(self.fnames)
elif self.fnames is None and self.okToContinue():
self.data.setWFData(self.getWFFnames())
try:
if self.fnames and self.okToContinue():
self.dirty = True
self.data.wfdata = self.data.setWFData(self.fnames)
elif self.fnames is None and self.okToContinue():
self.data.setWFData(self.getWFFnames())
except AttributeError, e:
print (e)
self.getWFFnames()
self.openWaveformData()
def plotData(self):
self.getData().plotData(self.getDataWidget())

View File

@ -4,7 +4,7 @@
import os
import numpy as np
from PySide.QtGui import QMessageBox
from obspy.core import (read, Stream)
from obspy.core import (read, Stream, UTCDateTime)
from obspy import readEvents
from obspy.core.event import (Event, Catalog)
from pylot.core.util import fnConstructor
@ -30,7 +30,10 @@ class Data(object):
def __init__(self, parent=None, evtdata=None):
try:
if parent:
self.wfdata = read(parent.getWFFnames())
self.setWFData(parent.getWFFnames())
self.comp = parent.getComponent()
else:
self.comp = 'Z'
except IOError, e:
msg = 'An I/O error occured while loading data!'
inform = 'Variable wfdata will be empty.'
@ -50,15 +53,23 @@ class Data(object):
self.newevent = False
if evtdata is not None and isinstance(evtdata, Event):
self.evtdata = evtdata
elif evtdata is not None and not evtdata.endswith('.mat'):
elif evtdata is not None and not isinstance(evtdata, dict):
cat = readEvents(evtdata)
self.evtdata = cat[0]
elif evtdata is not None:
cat = self.readMatPhases(evtdata)
cat = self.readPILOTEvent(**evtdata)
else: # create an empty Event object
self.newevent = True
self.evtdata = Event()
self.orig = self.wfdata.copy()
min_start = UTCDateTime()
max_end = None
for trace in self.getWFData().select(component = self.getComp()):
if trace.stats.starttime < min_start:
min_start = trace.stats.starttime
if max_end is None or trace.stats.endtime > max_end:
max_end = trace.stats.endtime
self.cuttimes = [min_start, max_end]
def isNew(self):
return self.newevent
@ -94,10 +105,25 @@ class Data(object):
not implemented: {1}'''.format(evtformat, e))
def plotData(self, widget):
wfst = self.getWFData()
time_ax = np.arange(0, len(wfst[0].data) / wfst[0].stats.sampling_rate,
wfst[0].stats.delta)
widget.axes.plot(time_ax, wfst[0].data)
wfst = self.getWFData().select(component = self.getComp())
for n, trace in enumerate(wfst):
stime = trace.stats.starttime - self.cuttimes[0]
etime = trace.stats.endtime - self.cuttimes[1]
srate = trace.stats.sampling_rate
nsamp = len(trace.data)
tincr = trace.stats.delta
time_ax = np.arange(stime, nsamp / srate, tincr)
trace.normalize()
widget.axes.plot(time_ax, trace.data + n, 'k')
xlabel = 'seconds since {0}'.format(self.cuttimes[0])
ylabel = ''
zne_text = {'Z':'vertical', 'N':'north-south', 'E':'east-west'}
title = 'overview: {0} components'.format(zne_text[self.getComp()])
widget.updateWidget(xlabel, ylabel, title)
def getComp(self):
return self.comp
def getID(self):
try:
@ -112,6 +138,10 @@ class Data(object):
for fname in fnames:
self.wfdata += read(fname)
def appenWFData(self, fnames):
for fname in fnames:
self.wfdata += read(fname)
def getWFData(self):
return self.wfdata