[new] set cuttimes for waveforms in properties tab to speedup reading and visualization

[improvements] only re-read/re-plot if needed after changing properties
This commit is contained in:
Marcel Paffrath 2019-12-17 16:24:32 +01:00
parent aa38e2b851
commit 29440deb6f
3 changed files with 98 additions and 19 deletions

View File

@ -77,7 +77,7 @@ from pylot.core.util.utils import fnConstructor, getLogin, \
full_range, readFilterInformation, make_pen, pick_color_plt, \ full_range, readFilterInformation, make_pen, pick_color_plt, \
pick_linestyle_plt, identifyPhaseID, excludeQualityClasses, \ pick_linestyle_plt, identifyPhaseID, excludeQualityClasses, \
transform_colors_mpl, transform_colors_mpl_str, getAutoFilteroptions, check_all_obspy, \ transform_colors_mpl, transform_colors_mpl_str, getAutoFilteroptions, check_all_obspy, \
check_all_pylot, get_Bool, SetChannelComponents check_all_pylot, get_Bool, get_None, SetChannelComponents
from pylot.core.util.event import Event from pylot.core.util.event import Event
from pylot.core.io.location import create_creation_info, create_event from pylot.core.io.location import create_creation_info, create_event
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \ from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
@ -1849,10 +1849,24 @@ class MainWindow(QMainWindow):
# else: # else:
# ans = False # ans = False
settings = QSettings()
curr_event = self.get_current_event()
if len(curr_event.origins) > 0:
origin_time = curr_event.origins[0].time
tstart = settings.value('tstart') if get_None(settings.value('tstart')) else 0
tstop = settings.value('tstop') if get_None(settings.value('tstop')) else 0
tstart = origin_time + tstart
tstop = origin_time + tstop
else:
tstart = None
tstop = None
self.data.setWFData(self.fnames, self.data.setWFData(self.fnames,
self.fnames_syn, self.fnames_syn,
checkRotated=True, checkRotated=True,
metadata=self.metadata) metadata=self.metadata,
tstart=tstart,
tstop=tstop,)
def prepareObspyDMT_data(self, eventpath): def prepareObspyDMT_data(self, eventpath):
qcbox_processed = self.dataPlot.qcombo_processed qcbox_processed = self.dataPlot.qcombo_processed
@ -3655,9 +3669,15 @@ class MainWindow(QMainWindow):
if not self._props: if not self._props:
self._props = PropertiesDlg(self, infile=self.infile, self._props = PropertiesDlg(self, infile=self.infile,
inputs=self._inputs) inputs=self._inputs)
else:
self._props.setDirty(False)
if self._props.exec_(): if self._props.exec_():
self.init_wfWidget() if self._props.dirty == 1:
if self.get_current_event():
self.plotWaveformDataThread()
elif self._props.dirty == 2:
self.refreshEvents()
return return
def helpHelp(self): def helpHelp(self):

View File

@ -386,7 +386,7 @@ class Data(object):
data.filter(**kwargs) data.filter(**kwargs)
self.dirty = True self.dirty = True
def setWFData(self, fnames, fnames_syn=None, checkRotated=False, metadata=None): def setWFData(self, fnames, fnames_syn=None, checkRotated=False, metadata=None, tstart=0, tstop=0):
""" """
Clear current waveform data and set given waveform data Clear current waveform data and set given waveform data
:param fnames: waveform data names to append :param fnames: waveform data names to append
@ -395,6 +395,11 @@ class Data(object):
self.wfdata = Stream() self.wfdata = Stream()
self.wforiginal = None self.wforiginal = None
self.wfsyn = Stream() self.wfsyn = Stream()
if tstart == tstop:
tstart = tstop = None
self.tstart = tstart
self.tstop = tstop
# if obspy_dmt: # if obspy_dmt:
# wfdir = 'raw' # wfdir = 'raw'
# self.processed = False # self.processed = False
@ -452,13 +457,13 @@ class Data(object):
warnmsg = '' warnmsg = ''
for fname in set(fnames): for fname in set(fnames):
try: try:
real_or_syn_data[synthetic] += read(fname) real_or_syn_data[synthetic] += read(fname, starttime=self.tstart, endtime=self.tstop)
except TypeError: except TypeError:
try: try:
real_or_syn_data[synthetic] += read(fname, format='GSE2') real_or_syn_data[synthetic] += read(fname, format='GSE2', starttime=self.tstart, endtime=self.tstop)
except Exception as e: except Exception as e:
try: try:
real_or_syn_data[synthetic] += read(fname, format='SEGY') real_or_syn_data[synthetic] += read(fname, format='SEGY', starttime=self.tstart, endtime=self.tstop)
except Exception as e: except Exception as e:
warnmsg += '{0}\n{1}\n'.format(fname, e) warnmsg += '{0}\n{1}\n'.format(fname, e)
except SacIOError as se: except SacIOError as se:

View File

@ -32,7 +32,7 @@ from obspy import read
from PySide import QtCore, QtGui from PySide import QtCore, QtGui
from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \ from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \
QDateTimeEdit, QDialog, QDialogButtonBox, QDoubleSpinBox, QGroupBox, \ QDateTimeEdit, QDialog, QDialogButtonBox, QDoubleSpinBox, QGroupBox, \
QGridLayout, QIcon, QLabel, QLineEdit, QMessageBox, \ QGridLayout, QFormLayout, QIcon, QLabel, QLineEdit, QMessageBox, \
QPixmap, QSpinBox, QTabWidget, QToolBar, QVBoxLayout, QHBoxLayout, QWidget, \ QPixmap, QSpinBox, QTabWidget, QToolBar, QVBoxLayout, QHBoxLayout, QWidget, \
QPushButton, QFileDialog, QInputDialog, QKeySequence QPushButton, QFileDialog, QInputDialog, QKeySequence
from PySide.QtCore import QSettings, Qt, QUrl, Signal from PySide.QtCore import QSettings, Qt, QUrl, Signal
@ -51,7 +51,8 @@ from pylot.core.util.utils import prepTimeAxis, full_range, demeanTrace, isSorte
pick_linestyle_plt, pick_color_plt, \ pick_linestyle_plt, pick_color_plt, \
check4rotated, check4doubled, merge_stream, identifyPhase, \ check4rotated, check4doubled, merge_stream, identifyPhase, \
loopIdentifyPhase, trim_station_components, transformFilteroptions2String, \ loopIdentifyPhase, trim_station_components, transformFilteroptions2String, \
identifyPhaseID, get_Bool, pick_color, getAutoFilteroptions, SetChannelComponents, station_id_remove_channel identifyPhaseID, get_Bool, get_None, pick_color, getAutoFilteroptions, SetChannelComponents,\
station_id_remove_channel
from autoPyLoT import autoPyLoT from autoPyLoT import autoPyLoT
from pylot.core.util.thread import Thread from pylot.core.util.thread import Thread
from pylot.core.util.dataprocessing import Metadata from pylot.core.util.dataprocessing import Metadata
@ -4464,6 +4465,7 @@ class PropertiesDlg(QDialog):
self.infile = infile self.infile = infile
self.inputs = inputs self.inputs = inputs
self.dirty = False
self.setWindowTitle("PyLoT Properties") self.setWindowTitle("PyLoT Properties")
self.tabWidget = QTabWidget() self.tabWidget = QTabWidget()
@ -4490,6 +4492,12 @@ class PropertiesDlg(QDialog):
self.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.apply) self.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.apply)
self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.restore) self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.restore)
def setDirty(self, level=1):
if type(self.dirty) == int:
if level < self.dirty:
return
self.dirty = level
def getinfile(self): def getinfile(self):
return self.infile return self.infile
@ -4500,6 +4508,8 @@ class PropertiesDlg(QDialog):
def apply(self): def apply(self):
for widint in range(self.tabWidget.count()): for widint in range(self.tabWidget.count()):
curwid = self.tabWidget.widget(widint) curwid = self.tabWidget.widget(widint)
if curwid.dirty:
self.setDirty(curwid.dirty)
values = curwid.getValues() values = curwid.getValues()
if values is not None: if values is not None:
self.setValues(values) self.setValues(values)
@ -4570,6 +4580,7 @@ class InputsTab(PropTab):
def __init__(self, parent, infile=None): def __init__(self, parent, infile=None):
super(InputsTab, self).__init__(parent) super(InputsTab, self).__init__(parent)
self.dirty = False
settings = QSettings() settings = QSettings()
pylot_user = getpass.getuser() pylot_user = getpass.getuser()
fulluser = settings.value("user/FullName") fulluser = settings.value("user/FullName")
@ -4587,12 +4598,22 @@ class InputsTab(PropTab):
# information about data structure # information about data structure
dataroot = settings.value("data/dataRoot") dataroot = settings.value("data/dataRoot")
curstructure = settings.value("data/Structure") curstructure = settings.value("data/Structure")
dataDirLabel = QLabel("data root directory: ")
self.dataDirEdit = QLineEdit() self.dataDirEdit = QLineEdit()
self.dataDirEdit.setText(dataroot) self.dataDirEdit.setText(dataroot)
self.dataDirEdit.selectAll() self.dataDirEdit.selectAll()
structureLabel = QLabel("data structure: ")
self.structureSelect = QComboBox() self.structureSelect = QComboBox()
self.cutLabel = QLabel
self.cuttimesLayout = QHBoxLayout()
self.tstartBox = QSpinBox()
self.tstopBox = QSpinBox()
for spinbox in [self.tstartBox, self.tstopBox]:
spinbox.setRange(-99999, 99999)
self.tstartBox.setValue(settings.value('tstart') if get_None(settings.value('tstart')) else 0)
self.tstopBox.setValue(settings.value('tstop') if get_None(settings.value('tstop')) else 0)
self.cuttimesLayout.addWidget(self.tstartBox, 10)
self.cuttimesLayout.addWidget(QLabel('[s] and'), 0)
self.cuttimesLayout.addWidget(self.tstopBox, 10)
self.cuttimesLayout.addWidget(QLabel('[s]'), 0)
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
@ -4602,20 +4623,38 @@ class InputsTab(PropTab):
self.structureSelect.setCurrentIndex(dsind) self.structureSelect.setCurrentIndex(dsind)
layout = QGridLayout() layout = QFormLayout()
layout.addWidget(dataDirLabel, 0, 0) layout.addRow("Data root directory: ", self.dataDirEdit)
layout.addWidget(self.dataDirEdit, 0, 1) layout.addRow("Full name for user '{0}': ".format(pylot_user), self.fullNameEdit)
layout.addWidget(fullNameLabel, 1, 0) layout.addRow("Data structure: ", self.structureSelect)
layout.addWidget(self.fullNameEdit, 1, 1) layout.addRow('Cut waveforms between (relative to source origin time if given): ', self.cuttimesLayout)
layout.addWidget(structureLabel, 2, 0)
layout.addWidget(self.structureSelect, 2, 1)
self.setLayout(layout) self.setLayout(layout)
self.connectSignals()
def connectSignals(self):
self.tstartBox.valueChanged.connect(self.checkSpinboxStop)
self.tstopBox.valueChanged.connect(self.checkSpinboxStart)
self.tstartBox.valueChanged.connect(self.setDirty)
self.tstopBox.valueChanged.connect(self.setDirty)
def setDirty(self):
self.dirty = 2
def checkSpinboxStop(self):
if self.tstopBox.value() < self.tstartBox.value():
self.tstopBox.setValue(self.tstartBox.value())
def checkSpinboxStart(self):
if self.tstopBox.value() < self.tstartBox.value():
self.tstartBox.setValue(self.tstopBox.value())
def getValues(self): def getValues(self):
values = {"data/dataRoot": self.dataDirEdit.text(), values = {"data/dataRoot": self.dataDirEdit.text(),
"user/FullName": self.fullNameEdit.text(), "user/FullName": self.fullNameEdit.text(),
"data/Structure": self.structureSelect.currentText()} "data/Structure": self.structureSelect.currentText(),
"tstart": self.tstartBox.value(),
"tstop": self.tstopBox.value()}
return values return values
def resetValues(self, infile): def resetValues(self, infile):
@ -4641,6 +4680,7 @@ class OutputsTab(PropTab):
def __init__(self, parent=None, infile=None): def __init__(self, parent=None, infile=None):
super(OutputsTab, self).__init__(parent) super(OutputsTab, self).__init__(parent)
self.dirty = False
settings = QSettings() settings = QSettings()
curval = settings.value("output/Format", None) curval = settings.value("output/Format", None)
@ -4671,6 +4711,7 @@ class PhasesTab(PropTab):
def __init__(self, parent=None, inputs=None): def __init__(self, parent=None, inputs=None):
super(PhasesTab, self).__init__(parent) super(PhasesTab, self).__init__(parent)
self.inputs = inputs self.inputs = inputs
self.dirty = False
self.Pphases = 'P, Pg, Pn, PmP, P1, P2, P3' self.Pphases = 'P, Pg, Pn, PmP, P1, P2, P3'
self.Sphases = 'S, Sg, Sn, SmS, S1, S2, S3' self.Sphases = 'S, Sg, Sn, SmS, S1, S2, S3'
@ -4765,6 +4806,7 @@ class PhasesTab(PropTab):
class GraphicsTab(PropTab): class GraphicsTab(PropTab):
def __init__(self, parent=None): def __init__(self, parent=None):
super(GraphicsTab, self).__init__(parent) super(GraphicsTab, self).__init__(parent)
self.dirty = False
self.pylot_mainwindow = parent._pylot_mainwindow self.pylot_mainwindow = parent._pylot_mainwindow
self.init_layout() self.init_layout()
# self.add_pg_cb() # self.add_pg_cb()
@ -4802,6 +4844,10 @@ class GraphicsTab(PropTab):
self.spinbox_nth_sample.setValue(int(nth_sample)) self.spinbox_nth_sample.setValue(int(nth_sample))
self.main_layout.addWidget(label, 1, 0) self.main_layout.addWidget(label, 1, 0)
self.main_layout.addWidget(self.spinbox_nth_sample, 1, 1) self.main_layout.addWidget(self.spinbox_nth_sample, 1, 1)
self.spinbox_nth_sample.valueChanged.connect(self.setDirty)
def setDirty(self):
self.dirty = 1
def set_current_style(self): def set_current_style(self):
selected_style = self.style_cb.currentText() selected_style = self.style_cb.currentText()
@ -4820,6 +4866,7 @@ class ChannelOrderTab(PropTab):
def __init__(self, parent=None, infile=None): def __init__(self, parent=None, infile=None):
super(ChannelOrderTab, self).__init__(parent) super(ChannelOrderTab, self).__init__(parent)
self.dirty = False
settings = QSettings() settings = QSettings()
compclass = settings.value('compclass') compclass = settings.value('compclass')
if not compclass: if not compclass:
@ -4861,6 +4908,12 @@ class ChannelOrderTab(PropTab):
self.ChannelOrderZEdit.textEdited.connect(self.checkDoubleZ) self.ChannelOrderZEdit.textEdited.connect(self.checkDoubleZ)
self.ChannelOrderNEdit.textEdited.connect(self.checkDoubleN) self.ChannelOrderNEdit.textEdited.connect(self.checkDoubleN)
self.ChannelOrderEEdit.textEdited.connect(self.checkDoubleE) self.ChannelOrderEEdit.textEdited.connect(self.checkDoubleE)
self.ChannelOrderZEdit.textEdited.connect(self.setDirty)
self.ChannelOrderNEdit.textEdited.connect(self.setDirty)
self.ChannelOrderEEdit.textEdited.connect(self.setDirty)
def setDirty(self):
self.dirty = 1
def checkDoubleZ(self, text): def checkDoubleZ(self, text):
self.checkDouble(text, 'Z') self.checkDouble(text, 'Z')
@ -4907,6 +4960,7 @@ class LocalisationTab(PropTab):
def __init__(self, parent=None, infile=None): def __init__(self, parent=None, infile=None):
super(LocalisationTab, self).__init__(parent) super(LocalisationTab, self).__init__(parent)
self.dirty = False
settings = QSettings() settings = QSettings()
curtool = settings.value("loc/tool", None) curtool = settings.value("loc/tool", None)