From ba37d587a631e0e454d34692d996cee0484dc1b7 Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 13 Apr 2018 10:56:52 +0200 Subject: [PATCH] [update] testing min/max plot (WIP) --- PyLoT.py | 7 ++++--- pylot/core/io/data.py | 3 ++- pylot/core/util/widgets.py | 42 ++++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/PyLoT.py b/PyLoT.py index 86375c78..4e2ddd41 100755 --- a/PyLoT.py +++ b/PyLoT.py @@ -1667,8 +1667,8 @@ class MainWindow(QMainWindow): def check_plot_quantity(self): settings = QSettings() - nth_sample = settings.value("nth_sample") if settings.value("nth_sample") else 1 - npts_max = 1e6 + nth_sample = int(settings.value("nth_sample")) if settings.value("nth_sample") else 1 + npts_max = 1e7 npts = self.get_npts_to_plot() npts2plot = npts/nth_sample if npts2plot < npts_max: @@ -1677,7 +1677,8 @@ class MainWindow(QMainWindow): message = "You are about to plot a huge dataset with {npts} datapoints. With a current setting of " \ "nth_sample = {nth_sample} a total of {npts2plot} points will be plotted which is more " \ "than the maximum setting of {npts_max}. " \ - "PyLoT recommends to raise nth_sample from {nth_sample} to {nth_sample_new}. Continue?" + "PyLoT recommends to raise nth_sample from {nth_sample} to {nth_sample_new}. Do you want "\ + "to change nth_sample to {nth_sample_new} now?" ans = QMessageBox.question(self, self.tr("Optimize plot performance..."), self.tr(message.format(npts=npts, diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 24626fe5..a7cb85d5 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -379,9 +379,10 @@ class Data(object): self.wfsyn = Stream() wffnames = None wffnames_syn = None + wfdir = 'processed' if 'processed' in [fname.split('/')[-1] for fname in fnames] else 'raw' if obspy_dmt: for fpath in fnames: - if fpath.endswith('raw'): + if fpath.endswith(wfdir): 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)] diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 98b50fb1..637f178c 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -25,6 +25,7 @@ except ImportError: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT from matplotlib.widgets import MultiCursor from matplotlib.tight_layout import get_renderer, get_subplotspec_list, get_tight_layout_figure +from scipy.signal import argrelmin, argrelmax from PySide import QtCore, QtGui from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \ @@ -539,9 +540,9 @@ class WaveformWidgetPG(QtGui.QWidget): 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] + trace = st[0].copy() if st_syn: - trace_syn = st_syn[0] + trace_syn = st_syn[0].copy() if mapping: comp = channel[-1] n = compclass.getPlotPosition(str(comp)) @@ -552,23 +553,46 @@ class WaveformWidgetPG(QtGui.QWidget): msg = 'plotting %s channel of station %s' % (channel, station) 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: + + # TEST TEST max/min plot + minsamples = argrelmin(trace.data) + maxsamples = argrelmax(trace.data) + plot_samples = np.sort(np.append(minsamples, maxsamples)) + trace.data = trace.data[plot_samples] + time_ax = time_ax[plot_samples] + if st_syn: + minsamples_syn = argrelmin(trace_syn.data) + maxsamples_syn = argrelmax(trace_syn.data) + plot_samples_syn = np.sort(np.append(minsamples_syn, maxsamples_syn)) + trace_syn.data = trace_syn.data[plot_samples_syn] + time_ax_syn = time_ax_syn[plot_samples_syn] + + # TEST TEST Remove middle of seismograms for overview plot + # trace.data = trace.data[abs(trace.data) > 0.1 * max(abs(trace.data))] + # if st_syn: + # trace.data_syn = trace.data_syn[abs(trace.data_syn) > 0.1 * max(abs(trace.data))] + # TEST TEST ------ + + if time_ax not in [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] - 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)) + # TODO: change this to numpy operations instead of lists? + times = np.array([time for index, time in enumerate(time_ax) if not index % nth_sample]) + times_syn = np.array([time for index, time in enumerate(time_ax_syn) if not index % nth_sample] if st_syn else []) + trace.data = np.array([datum + n for index, datum in enumerate(trace.data) if not index % nth_sample]) + trace.data_syn = np.array([datum + n for index, datum in enumerate(trace.data_syn) + if not index % nth_sample] if st_syn else []) + plots.append((times, trace.data, + times_syn, trace.data_syn)) self.setPlotDict(n, (station, channel, network)) self.xlabel = 'seconds since {0}'.format(self.wfstart) self.ylabel = ''