implementation of reading and plotting seismograms (work in progress)
This commit is contained in:
parent
7092f6e8b5
commit
d3199a5798
16
QtPyLoT.py
16
QtPyLoT.py
@ -83,7 +83,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.filterOptionsS = FilterOptions(**filterOptionsS)
|
self.filterOptionsS = FilterOptions(**filterOptionsS)
|
||||||
|
|
||||||
# initialize data
|
# initialize data
|
||||||
self.data = None
|
self.data = Data()
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
self.loadData()
|
self.loadData()
|
||||||
self.updateFilterOptions()
|
self.updateFilterOptions()
|
||||||
@ -248,11 +248,14 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def loadData(self, fname=None):
|
def loadData(self, fname=None):
|
||||||
if fname is None:
|
if fname is None:
|
||||||
|
try:
|
||||||
|
self.data = Data(evtdata=self.fname)
|
||||||
|
except AttributeError:
|
||||||
action = self.sender()
|
action = self.sender()
|
||||||
if isinstance(action, QAction):
|
if isinstance(action, QAction):
|
||||||
if action.data() is None:
|
if action.data() is None:
|
||||||
filt = """Supported event formats (*.mat *.qml *.xml *.kor
|
filt = """Supported event formats (*.mat *.qml *.xml
|
||||||
*.evt)"""
|
*.kor *.evt)"""
|
||||||
caption = 'Select event to open'
|
caption = 'Select event to open'
|
||||||
self.fname = QFileDialog().getOpenFileName(self,
|
self.fname = QFileDialog().getOpenFileName(self,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
@ -262,8 +265,6 @@ class MainWindow(QMainWindow):
|
|||||||
if not self.okToContinue():
|
if not self.okToContinue():
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
return
|
|
||||||
if fname:
|
|
||||||
self.fname = fname
|
self.fname = fname
|
||||||
self.data = Data(evtdata=self.fname)
|
self.data = Data(evtdata=self.fname)
|
||||||
|
|
||||||
@ -326,11 +327,16 @@ class MainWindow(QMainWindow):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def openWaveformData(self):
|
def openWaveformData(self):
|
||||||
|
try:
|
||||||
if self.fnames and self.okToContinue():
|
if self.fnames and self.okToContinue():
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
self.data.wfdata = self.data.setWFData(self.fnames)
|
self.data.wfdata = 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())
|
||||||
|
except AttributeError, e:
|
||||||
|
print (e)
|
||||||
|
self.getWFFnames()
|
||||||
|
self.openWaveformData()
|
||||||
|
|
||||||
def plotData(self):
|
def plotData(self):
|
||||||
self.getData().plotData(self.getDataWidget())
|
self.getData().plotData(self.getDataWidget())
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PySide.QtGui import QMessageBox
|
from PySide.QtGui import QMessageBox
|
||||||
from obspy.core import (read, Stream)
|
from obspy.core import (read, Stream, UTCDateTime)
|
||||||
from obspy import readEvents
|
from obspy import readEvents
|
||||||
from obspy.core.event import (Event, Catalog)
|
from obspy.core.event import (Event, Catalog)
|
||||||
from pylot.core.util import fnConstructor
|
from pylot.core.util import fnConstructor
|
||||||
@ -30,7 +30,10 @@ class Data(object):
|
|||||||
def __init__(self, parent=None, evtdata=None):
|
def __init__(self, parent=None, evtdata=None):
|
||||||
try:
|
try:
|
||||||
if parent:
|
if parent:
|
||||||
self.wfdata = read(parent.getWFFnames())
|
self.setWFData(parent.getWFFnames())
|
||||||
|
self.comp = parent.getComponent()
|
||||||
|
else:
|
||||||
|
self.comp = 'Z'
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
msg = 'An I/O error occured while loading data!'
|
msg = 'An I/O error occured while loading data!'
|
||||||
inform = 'Variable wfdata will be empty.'
|
inform = 'Variable wfdata will be empty.'
|
||||||
@ -50,15 +53,23 @@ class Data(object):
|
|||||||
self.newevent = False
|
self.newevent = False
|
||||||
if evtdata is not None and isinstance(evtdata, Event):
|
if evtdata is not None and isinstance(evtdata, Event):
|
||||||
self.evtdata = evtdata
|
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)
|
cat = readEvents(evtdata)
|
||||||
self.evtdata = cat[0]
|
self.evtdata = cat[0]
|
||||||
elif evtdata is not None:
|
elif evtdata is not None:
|
||||||
cat = self.readMatPhases(evtdata)
|
cat = self.readPILOTEvent(**evtdata)
|
||||||
else: # create an empty Event object
|
else: # create an empty Event object
|
||||||
self.newevent = True
|
self.newevent = True
|
||||||
self.evtdata = Event()
|
self.evtdata = Event()
|
||||||
self.orig = self.wfdata.copy()
|
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):
|
def isNew(self):
|
||||||
return self.newevent
|
return self.newevent
|
||||||
@ -94,10 +105,25 @@ class Data(object):
|
|||||||
not implemented: {1}'''.format(evtformat, e))
|
not implemented: {1}'''.format(evtformat, e))
|
||||||
|
|
||||||
def plotData(self, widget):
|
def plotData(self, widget):
|
||||||
wfst = self.getWFData()
|
wfst = self.getWFData().select(component = self.getComp())
|
||||||
time_ax = np.arange(0, len(wfst[0].data) / wfst[0].stats.sampling_rate,
|
for n, trace in enumerate(wfst):
|
||||||
wfst[0].stats.delta)
|
stime = trace.stats.starttime - self.cuttimes[0]
|
||||||
widget.axes.plot(time_ax, wfst[0].data)
|
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):
|
def getID(self):
|
||||||
try:
|
try:
|
||||||
@ -112,6 +138,10 @@ class Data(object):
|
|||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
self.wfdata += read(fname)
|
self.wfdata += read(fname)
|
||||||
|
|
||||||
|
def appenWFData(self, fnames):
|
||||||
|
for fname in fnames:
|
||||||
|
self.wfdata += read(fname)
|
||||||
|
|
||||||
def getWFData(self):
|
def getWFData(self):
|
||||||
return self.wfdata
|
return self.wfdata
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user