[new] only load relevant waveforms into TAP widget

This commit is contained in:
Marcel Paffrath 2018-06-20 13:49:27 +02:00
parent 08124174b1
commit 910ed66676
2 changed files with 73 additions and 37 deletions

View File

@ -2294,13 +2294,14 @@ class MainWindow(QMainWindow):
self.update_status('picking on station {0}'.format(station)) self.update_status('picking on station {0}'.format(station))
data = self.get_data().getOriginalWFData().copy() data = self.get_data().getOriginalWFData().copy()
event = self.get_current_event() event = self.get_current_event()
wftype = self.dataPlot.qcombo_processed.currentText() if self.obspy_dmt else None
pickDlg = PickDlg(self, parameter=self._inputs, pickDlg = PickDlg(self, parameter=self._inputs,
data=data.select(station=station), data=data.select(station=station),
station=station, network=network, station=station, network=network,
picks=self.getPicksOnStation(station, 'manual'), picks=self.getPicksOnStation(station, 'manual'),
autopicks=self.getPicksOnStation(station, 'auto'), autopicks=self.getPicksOnStation(station, 'auto'),
metadata=self.metadata, event=event, metadata=self.metadata, event=event,
filteroptions=self.filteroptions) filteroptions=self.filteroptions, wftype=wftype)
if self.filterActionP.isChecked() or self.filterActionS.isChecked(): if self.filterActionP.isChecked() or self.filterActionS.isChecked():
pickDlg.currentPhase = self.getSeismicPhase() pickDlg.currentPhase = self.getSeismicPhase()
pickDlg.filterWFData() pickDlg.filterWFData()
@ -2398,8 +2399,7 @@ class MainWindow(QMainWindow):
self.init_fig_dict() self.init_fig_dict()
#if not self.tap: #if not self.tap:
# init TuneAutopicker object # init TuneAutopicker object
wftype = self.dataPlot.qcombo_processed.currentText() if self.obspy_dmt else None self.tap = TuneAutopicker(self, self.obspy_dmt)
self.tap = TuneAutopicker(self, wftype)
# first call of update to init tabs with empty canvas # first call of update to init tabs with empty canvas
self.update_autopicker() self.update_autopicker()
# connect update signal of TuneAutopicker with update function # connect update signal of TuneAutopicker with update function

View File

@ -26,6 +26,7 @@ from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT
from matplotlib.widgets import MultiCursor from matplotlib.widgets import MultiCursor
from matplotlib.tight_layout import get_renderer, get_subplotspec_list, get_tight_layout_figure from matplotlib.tight_layout import get_renderer, get_subplotspec_list, get_tight_layout_figure
from scipy.signal import argrelmin, argrelmax from scipy.signal import argrelmin, argrelmax
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, \
@ -1314,7 +1315,7 @@ class PickDlg(QDialog):
def __init__(self, parent=None, data=None, station=None, network=None, picks=None, def __init__(self, parent=None, data=None, station=None, network=None, picks=None,
autopicks=None, rotate=False, parameter=None, embedded=False, metadata=None, autopicks=None, rotate=False, parameter=None, embedded=False, metadata=None,
event=None, filteroptions=None, model='iasp91'): event=None, filteroptions=None, model='iasp91', wftype=None):
super(PickDlg, self).__init__(parent, 1) super(PickDlg, self).__init__(parent, 1)
self.orig_parent = parent self.orig_parent = parent
self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_DeleteOnClose)
@ -1326,6 +1327,7 @@ class PickDlg(QDialog):
self.network = network self.network = network
self.rotate = rotate self.rotate = rotate
self.metadata = metadata self.metadata = metadata
self.wftype = wftype
self.pylot_event = event self.pylot_event = event
self.components = 'ZNE' self.components = 'ZNE'
self.currentPhase = None self.currentPhase = None
@ -1415,8 +1417,12 @@ class PickDlg(QDialog):
actionS.setChecked(self.getChannelSettingsS(channel)) actionS.setChecked(self.getChannelSettingsS(channel))
# plot data # plot data
title = self.getStation()
if self.wftype is not None:
title += ' | ({})'.format(self.wftype)
self.multicompfig.plotWFData(wfdata=self.getWFData(), self.multicompfig.plotWFData(wfdata=self.getWFData(),
title=self.getStation()) title=title)
self.multicompfig.setZoomBorders2content() self.multicompfig.setZoomBorders2content()
@ -2583,6 +2589,9 @@ class PickDlg(QDialog):
filtops_str = transformFilteroptions2String(filtoptions) filtops_str = transformFilteroptions2String(filtoptions)
title += ' | Filteroptions: {}'.format(filtops_str) title += ' | Filteroptions: {}'.format(filtops_str)
if self.wftype is not None:
title += ' | ({})'.format(self.wftype)
plot_additional = bool(self.compareChannel.currentText()) plot_additional = bool(self.compareChannel.currentText())
additional_channel = self.compareChannel.currentText() additional_channel = self.compareChannel.currentText()
scale_channel = self.scaleChannel.currentText() scale_channel = self.scaleChannel.currentText()
@ -3015,13 +3024,15 @@ class TuneAutopicker(QWidget):
:type: PyLoT Mainwindow :type: PyLoT Mainwindow
''' '''
def __init__(self, parent, wftype=None): def __init__(self, parent, obspy_dmt=False):
QtGui.QWidget.__init__(self, parent, 1) QtGui.QWidget.__init__(self, parent, 1)
self._style = parent._style self._style = parent._style
self.setWindowTitle('PyLoT - Tune Autopicker') self.setWindowTitle('PyLoT - Tune Autopicker')
self.parameter = self.parent()._inputs self.parameter = self.parent()._inputs
self.fig_dict = self.parent().fig_dict self.fig_dict = self.parent().fig_dict
self.wftype = wftype self.data = Data()
self.obspy_dmt = obspy_dmt
self.wftype = None
self.pdlg_widget = None self.pdlg_widget = None
self.pylot_picks = None self.pylot_picks = None
self.init_main_layouts() self.init_main_layouts()
@ -3078,36 +3089,57 @@ class TuneAutopicker(QWidget):
self.eventBox.activated.connect(self.fill_tabs) self.eventBox.activated.connect(self.fill_tabs)
self.stationBox.activated.connect(self.fill_tabs) self.stationBox.activated.connect(self.fill_tabs)
def fill_stationbox(self): def catch_station_ids(self):
#fnames = self.parent().fnames #getWFFnames_from_eventbox(eventbox=self.eventBox) self.station_ids = {}
#self.data.setWFData(fnames) eventpath = self.get_current_event_fp()
self.data = self.parent().data self.wftype = 'processed' if self.obspy_dmt else ''
wfdat = self.data.getWFData() # all available streams wf_path = os.path.join(eventpath, self.wftype)
# remove possible underscores in station names if not os.path.exists(wf_path) and self.obspy_dmt:
# wfdat = remove_underscores(wfdat) self.wftype = 'raw'
# # rotate misaligned stations to ZNE wf_path = os.path.join(eventpath, self.wftype)
# # check for gaps and doubled channels for filename in os.listdir(wf_path):
# check4gaps(wfdat) filename = os.path.join(eventpath, self.wftype, filename)
# check4doubled(wfdat) try:
# wfdat = check4rotated(wfdat, self.parent().metadata, verbosity=0) st = read(filename, headonly=True)
# # trim station components to same start value except Exception as e:
# trim_station_components(wfdat, trim_start=True, trim_end=False) print('Warning: Could not read file {} as a stream object: {}'.format(filename, e))
self.stationBox.clear() continue
stations = [] for trace in st:
for trace in self.data.getWFData():
station = trace.stats.station
network = trace.stats.network network = trace.stats.network
ns_tup = (str(network), str(station)) station = trace.stats.station
if not ns_tup in stations: location = trace.stats.location
stations.append(ns_tup) station_id = '{}.{}.{}'.format(network, station, location)
stations.sort() if not station_id in self.station_ids:
self.station_ids[station_id] = []
self.station_ids[station_id].append(filename)
def fill_stationbox(self):
self.stationBox.clear()
model = self.stationBox.model() model = self.stationBox.model()
for network, station in stations:
item = QtGui.QStandardItem(network + '.' + station) self.catch_station_ids()
if station in self.get_current_event().pylot_picks: st_ids_list = list(self.station_ids.keys())
st_ids_list.sort()
for station_id in st_ids_list:
item = QtGui.QStandardItem(station_id)
if station_id.split('.')[1] in self.get_current_event().pylot_picks:
item.setBackground(self.parent()._ref_test_colors['ref']) item.setBackground(self.parent()._ref_test_colors['ref'])
model.appendRow(item) model.appendRow(item)
def load_wf_data(self):
fnames = self.station_ids[self.get_current_station_id()]
self.data.setWFData(fnames)
wfdat = self.data.getWFData() # all available streams
# remove possible underscores in station names
wfdat = remove_underscores(wfdat)
# rotate misaligned stations to ZNE
# check for gaps and doubled channels
check4gaps(wfdat)
check4doubled(wfdat)
wfdat = check4rotated(wfdat, self.parent().metadata, verbosity=0)
# trim station components to same start value
trim_station_components(wfdat, trim_start=True, trim_end=False)
def init_figure_tabs(self): def init_figure_tabs(self):
self.figure_tabs = QtGui.QTabWidget() self.figure_tabs = QtGui.QTabWidget()
self.fill_figure_tabs() self.fill_figure_tabs()
@ -3153,9 +3185,7 @@ class TuneAutopicker(QWidget):
return self.eventBox.currentText().split('/')[-1] return self.eventBox.currentText().split('/')[-1]
def get_current_event_fp(self): def get_current_event_fp(self):
wfext = self.wftype if self.wftype else '' return self.eventBox.currentText()
fp = os.path.join(self.eventBox.currentText(), wfext)
return fp
def get_current_event_picks(self, station): def get_current_event_picks(self, station):
event = self.get_current_event() event = self.get_current_event()
@ -3169,7 +3199,10 @@ class TuneAutopicker(QWidget):
return event.pylot_autopicks[station] return event.pylot_autopicks[station]
def get_current_station(self): def get_current_station(self):
return str(self.stationBox.currentText()).split('.')[-1] return str(self.stationBox.currentText()).split('.')[1]
def get_current_station_id(self):
return str(self.stationBox.currentText())
def gen_tab_widget(self, name, canvas): def gen_tab_widget(self, name, canvas):
widget = QtGui.QWidget() widget = QtGui.QWidget()
@ -3184,17 +3217,19 @@ class TuneAutopicker(QWidget):
self.pdlg_widget.setParent(None) self.pdlg_widget.setParent(None)
self.pdlg_widget = None self.pdlg_widget = None
return return
self.load_wf_data()
station = self.get_current_station() station = self.get_current_station()
wfdata = self.data.getWFData() wfdata = self.data.getWFData()
metadata = self.parent().metadata metadata = self.parent().metadata
event = self.get_current_event() event = self.get_current_event()
filteroptions = self.parent().filteroptions filteroptions = self.parent().filteroptions
wftype = self.wftype if self.obspy_dmt else ''
self.pickDlg = PickDlg(self.parent(), data=wfdata.select(station=station).copy(), self.pickDlg = PickDlg(self.parent(), data=wfdata.select(station=station).copy(),
station=station, parameter=self.parameter, station=station, parameter=self.parameter,
picks=self.get_current_event_picks(station), picks=self.get_current_event_picks(station),
autopicks=self.get_current_event_autopicks(station), autopicks=self.get_current_event_autopicks(station),
metadata=metadata, event=event, filteroptions=filteroptions, metadata=metadata, event=event, filteroptions=filteroptions,
embedded=True) embedded=True, wftype=wftype)
self.pickDlg.update_picks.connect(self.picks_from_pickdlg) self.pickDlg.update_picks.connect(self.picks_from_pickdlg)
self.pickDlg.update_picks.connect(self.fill_eventbox) self.pickDlg.update_picks.connect(self.fill_eventbox)
self.pickDlg.update_picks.connect(self.fill_stationbox) self.pickDlg.update_picks.connect(self.fill_stationbox)
@ -3381,7 +3416,8 @@ class TuneAutopicker(QWidget):
'iplot': 2, 'iplot': 2,
'fig_dict': self.fig_dict, 'fig_dict': self.fig_dict,
'locflag': 0, 'locflag': 0,
'savexml': False} 'savexml': False,
'obspyDMT_wfpath': self.obspy_dmt}
for key in self.fig_dict.keys(): for key in self.fig_dict.keys():
if not key == 'plot_style': if not key == 'plot_style':
self.fig_dict[key].clear() self.fig_dict[key].clear()