[add] synthetic data plot (not yet flexible)

This commit is contained in:
Marcel Paffrath 2018-04-05 15:33:40 +02:00
parent bd086e6cd4
commit 4cf785a135
5 changed files with 58 additions and 21 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.pyc
*~
*~
pylot/RELEASE-VERSION

View File

@ -994,14 +994,10 @@ class MainWindow(QMainWindow):
# TODO: add dataStructure class for obspyDMT here, this is just a workaround!
eventpath = self.get_current_event_path(eventbox)
basepath = eventpath.split(os.path.basename(eventpath))[0]
if check_obspydmt_structure(basepath):
directory = os.path.join(eventpath, 'raw')
else:
directory = eventpath
if self.dataStructure:
if not directory:
if not eventpath:
return
fnames = [os.path.join(directory, f) for f in os.listdir(directory)]
fnames = [os.path.join(eventpath, f) for f in os.listdir(eventpath)]
else:
raise DatastructureError('not specified')
return fnames
@ -1661,9 +1657,13 @@ class MainWindow(QMainWindow):
# else:
# ans = False
self.fnames = self.getWFFnames_from_eventbox()
eventpath = self.get_current_event_path()
basepath = eventpath.split(os.path.basename(eventpath))[0]
obspy_dmt = check_obspydmt_structure(basepath)
self.data.setWFData(self.fnames,
checkRotated=True,
metadata=self.metadata)
metadata=self.metadata,
obspy_dmt=obspy_dmt)
def connectWFplotEvents(self):
'''
@ -1719,9 +1719,12 @@ class MainWindow(QMainWindow):
def finish_pg_plot(self):
self.getPlotWidget().updateWidget()
plots = self.wfp_thread.data
for times, data in plots:
for times, data, times_syn, data_syn in plots:
self.dataPlot.plotWidget.getPlotItem().plot(times, data,
pen=self.dataPlot.pen_linecolor)
if data_syn:
self.dataPlot.plotWidget.getPlotItem().plot(times_syn, data_syn,
pen=self.dataPlot.pen_linecolor_syn)
self.dataPlot.reinitMoveProxy()
self.dataPlot.plotWidget.showAxis('left')
self.dataPlot.plotWidget.showAxis('bottom')
@ -1848,6 +1851,7 @@ class MainWindow(QMainWindow):
comp = self.getComponent()
title = 'section: {0} components'.format(zne_text[comp])
wfst = self.get_data().getWFData()
wfsyn = self.get_data().getSynWFData()
if self.filterActionP.isChecked() and filter:
self.filterWaveformData(plot=False, phase='P')
elif self.filterActionS.isChecked() and filter:
@ -1856,7 +1860,7 @@ class MainWindow(QMainWindow):
# wfst += self.get_data().getWFData().select(component=alter_comp)
plotWidget = self.getPlotWidget()
self.adjustPlotHeight()
plots = plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp,
plots = plotWidget.plotWFData(wfdata=wfst, wfsyn=wfsyn, title=title, mapping=False, component=comp,
nth_sample=int(nth_sample))
return plots

View File

@ -368,7 +368,7 @@ class Data(object):
data.filter(**kwargs)
self.dirty = True
def setWFData(self, fnames, checkRotated=False, metadata=None):
def setWFData(self, fnames, checkRotated=False, metadata=None, obspy_dmt=False):
"""
Clear current waveform data and set given waveform data
:param fnames: waveform data names to append
@ -376,8 +376,21 @@ class Data(object):
"""
self.wfdata = Stream()
self.wforiginal = None
if fnames is not None:
self.appendWFData(fnames)
self.wfsyn = Stream()
wffnames = None
wffnames_syn = None
if obspy_dmt:
for fpath in fnames:
if fpath.endswith('raw'):
wffnames = [os.path.join(fpath, fname) for fname in os.listdir(fpath)]
if 'syngine' in fpath.split('/')[-1]:
wffnames_syn = [os.path.join(fpath, fname) for fname in os.listdir(fpath)]
else:
wffnames = fnames
if wffnames is not None:
self.appendWFData(wffnames)
if wffnames_syn is not None:
self.appendWFData(wffnames_syn, synthetic=True)
else:
return False
@ -399,8 +412,7 @@ class Data(object):
return True
def appendWFData(self, fnames):
def appendWFData(self, fnames, synthetic=False):
"""
Read waveform data from fnames and append it to current wf data
:param fnames: waveform data to append
@ -413,13 +425,16 @@ class Data(object):
if self.dirty:
self.resetWFData()
real_or_syn_data = {True: self.wfsyn,
False: self.wfdata}
warnmsg = ''
for fname in fnames:
try:
self.wfdata += read(fname)
real_or_syn_data[synthetic] += read(fname)
except TypeError:
try:
self.wfdata += read(fname, format='GSE2')
real_or_syn_data[synthetic] += read(fname, format='GSE2')
except Exception as e:
warnmsg += '{0}\n{1}\n'.format(fname, e)
except SacIOError as se:
@ -434,6 +449,9 @@ class Data(object):
def getOriginalWFData(self):
return self.wforiginal
def getSynWFData(self):
return self.wfsyn
def resetWFData(self):
"""
Set waveform data to original waveform data

View File

@ -192,7 +192,7 @@ def read_metadata(path_to_inventory):
robj = inv[invtype]
else:
print("Reading metadata information from inventory-xml file ...")
robj = inv[invtype]
robj = read_inventory(inv[invtype])
return invtype, robj

View File

@ -450,7 +450,7 @@ class WaveformWidgetPG(QtGui.QWidget):
self.main_layout = QtGui.QVBoxLayout()
self.label = QtGui.QLabel()
self.setLayout(self.main_layout)
self.plotWidget = self.pg.PlotWidget(self.parent(), title=title, autoDownsample=True)
self.plotWidget = self.pg.PlotWidget(self.parent(), title=title)
self.main_layout.addWidget(self.plotWidget)
self.main_layout.addWidget(self.label)
self.plotWidget.showGrid(x=False, y=True, alpha=0.3)
@ -459,8 +459,10 @@ class WaveformWidgetPG(QtGui.QWidget):
self.wfstart, self.wfend = 0, 0
self.pen_multicursor = self.pg.mkPen(self.parent()._style['multicursor']['rgba'])
self.pen_linecolor = self.pg.mkPen(self.parent()._style['linecolor']['rgba'])
self.pen_linecolor_syn = self.pg.mkPen((100, 0, 255, 255))
self.reinitMoveProxy()
self._proxy = self.pg.SignalProxy(self.plotWidget.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
self.plotWidget.getPlotItem().setDownsampling(auto=True)
def reinitMoveProxy(self):
self.vLine = self.pg.InfiniteLine(angle=90, movable=False, pen=self.pen_multicursor)
@ -491,7 +493,7 @@ class WaveformWidgetPG(QtGui.QWidget):
def clearPlotDict(self):
self.plotdict = dict()
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
def plotWFData(self, wfdata, wfsyn=None, title=None, zoomx=None, zoomy=None,
noiselevel=None, scaleddata=False, mapping=True,
component='*', nth_sample=1, iniPick=None, verbosity=0):
if not wfdata:
@ -536,7 +538,10 @@ class WaveformWidgetPG(QtGui.QWidget):
for n, (network, station, channel) in enumerate(nsc):
n+=1
st = st_select.select(network=network, station=station, channel=channel)
st_syn = wfsyn.select(network=network, station=station, channel=channel)
trace = st[0]
if st_syn:
trace_syn = st_syn[0]
if mapping:
comp = channel[-1]
n = compclass.getPlotPosition(str(comp))
@ -548,13 +553,22 @@ class WaveformWidgetPG(QtGui.QWidget):
print(msg)
stime = trace.stats.starttime - self.wfstart
time_ax = prepTimeAxis(stime, trace)
if st_syn:
stime_syn = trace_syn.stats.starttime - self.wfstart
time_ax_syn = prepTimeAxis(stime_syn, trace_syn)
if time_ax is not None:
if not scaleddata:
trace.detrend('constant')
trace.normalize(np.max(np.abs(trace.data)) * 2)
if st_syn:
trace_syn.detrend('constant')
trace_syn.normalize(np.max(np.abs(trace_syn.data)) * 2)
times = [time for index, time in enumerate(time_ax) if not index % nth_sample]
times_syn = [time for index, time in enumerate(time_ax_syn) if not index % nth_sample] if st_syn else []
data = [datum + n for index, datum in enumerate(trace.data) if not index % nth_sample]
plots.append((times, data))
data_syn = [datum + n for index, datum in enumerate(trace_syn.data)
if not index % nth_sample] if st_syn else []
plots.append((times, data, times_syn, data_syn))
self.setPlotDict(n, (station, channel, network))
self.xlabel = 'seconds since {0}'.format(self.wfstart)
self.ylabel = ''