added pickdlg to tune autopick, small fixes; to do: add manual picks
This commit is contained in:
parent
c9d872d52b
commit
f43611aeda
36
QtPyLoT.py
36
QtPyLoT.py
@ -604,9 +604,10 @@ class MainWindow(QMainWindow):
|
|||||||
def getCurrentEvent(self, eventlist=None, eventbox=None):
|
def getCurrentEvent(self, eventlist=None, eventbox=None):
|
||||||
if not eventlist:
|
if not eventlist:
|
||||||
eventlist = self.project.eventlist
|
eventlist = self.project.eventlist
|
||||||
for event in eventlist:
|
if not eventbox:
|
||||||
if event.path == self.getCurrentEventPath(eventbox):
|
eventbox = self.eventBox
|
||||||
return event
|
index = eventbox.currentIndex()
|
||||||
|
return eventbox.itemData(index)
|
||||||
|
|
||||||
def getCurrentEventPath(self, eventbox=None):
|
def getCurrentEventPath(self, eventbox=None):
|
||||||
if not eventbox:
|
if not eventbox:
|
||||||
@ -684,7 +685,7 @@ class MainWindow(QMainWindow):
|
|||||||
if pl > plmax:
|
if pl > plmax:
|
||||||
plmax=pl
|
plmax=pl
|
||||||
|
|
||||||
for event in self.project.eventlist:
|
for index, event in enumerate(self.project.eventlist):
|
||||||
event_path = event.path
|
event_path = event.path
|
||||||
event_npicks = 0
|
event_npicks = 0
|
||||||
event_nautopicks = 0
|
event_nautopicks = 0
|
||||||
@ -695,11 +696,11 @@ class MainWindow(QMainWindow):
|
|||||||
event_ref = event.isRefEvent()
|
event_ref = event.isRefEvent()
|
||||||
event_test = event.isTestEvent()
|
event_test = event.isTestEvent()
|
||||||
|
|
||||||
text = '{path:{plen}} | manual: [{p:3d}] | auto: [{a:3d}]'
|
# text = '{path:{plen}} | manual: [{p:3d}] | auto: [{a:3d}]'
|
||||||
text = text.format(path=event_path,
|
# text = text.format(path=event_path,
|
||||||
plen=plmax,
|
# plen=plmax,
|
||||||
p=event_npicks,
|
# p=event_npicks,
|
||||||
a=event_nautopicks)
|
# a=event_nautopicks)
|
||||||
|
|
||||||
item_path = QtGui.QStandardItem('{path:{plen}}'.format(path=event_path, plen=plmax))
|
item_path = QtGui.QStandardItem('{path:{plen}}'.format(path=event_path, plen=plmax))
|
||||||
item_nmp = QtGui.QStandardItem(str(event_npicks))
|
item_nmp = QtGui.QStandardItem(str(event_npicks))
|
||||||
@ -732,6 +733,12 @@ class MainWindow(QMainWindow):
|
|||||||
for item in itemlist:
|
for item in itemlist:
|
||||||
item.setEnabled(False)
|
item.setEnabled(False)
|
||||||
model.appendRow(itemlist)
|
model.appendRow(itemlist)
|
||||||
|
if not event.path == self.eventBox.itemText(index):
|
||||||
|
message = ('Path missmatch creating eventbox.\n'
|
||||||
|
'{} unequal {}.'
|
||||||
|
.format(event.path, self.eventBox.itemText(index)))
|
||||||
|
raise ValueError(message)
|
||||||
|
eventBox.setItemData(index, event)
|
||||||
eventBox.setCurrentIndex(index)
|
eventBox.setCurrentIndex(index)
|
||||||
|
|
||||||
def filename_from_action(self, action):
|
def filename_from_action(self, action):
|
||||||
@ -929,7 +936,8 @@ class MainWindow(QMainWindow):
|
|||||||
self._eventChanged[0] = False
|
self._eventChanged[0] = False
|
||||||
|
|
||||||
def loadWaveformDataThread(self):
|
def loadWaveformDataThread(self):
|
||||||
wfd_thread = Thread(self, self.loadWaveformData, progressText='Reading data input...')
|
wfd_thread = Thread(self, self.loadWaveformData,
|
||||||
|
progressText='Reading data input...')
|
||||||
wfd_thread.finished.connect(self.plotWaveformDataThread)
|
wfd_thread.finished.connect(self.plotWaveformDataThread)
|
||||||
wfd_thread.start()
|
wfd_thread.start()
|
||||||
|
|
||||||
@ -999,7 +1007,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def plotWaveformDataThread(self):
|
def plotWaveformDataThread(self):
|
||||||
wfp_thread = Thread(self, self.plotWaveformData, progressText='Plotting waveform data...')
|
wfp_thread = Thread(self, self.plotWaveformData,
|
||||||
|
progressText='Plotting waveform data...')
|
||||||
wfp_thread.finished.connect(self.finishWaveformDataPlot)
|
wfp_thread.finished.connect(self.finishWaveformDataPlot)
|
||||||
wfp_thread.start()
|
wfp_thread.start()
|
||||||
|
|
||||||
@ -1131,7 +1140,7 @@ class MainWindow(QMainWindow):
|
|||||||
station = self.getStationName(wfID)
|
station = self.getStationName(wfID)
|
||||||
self.update_status('picking on station {0}'.format(station))
|
self.update_status('picking on station {0}'.format(station))
|
||||||
data = self.get_data().getWFData()
|
data = self.get_data().getWFData()
|
||||||
pickDlg = PickDlg(self, infile=self.getinfile(),
|
pickDlg = PickDlg(self, parameter=self._inputs,
|
||||||
data=data.select(station=station),
|
data=data.select(station=station),
|
||||||
station=station,
|
station=station,
|
||||||
picks=self.getPicksOnStation(station, 'manual'),
|
picks=self.getPicksOnStation(station, 'manual'),
|
||||||
@ -1183,6 +1192,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.tap = TuneAutopicker(self)
|
self.tap = TuneAutopicker(self)
|
||||||
self.update_autopicker()
|
self.update_autopicker()
|
||||||
self.tap.update.connect(self.update_autopicker)
|
self.tap.update.connect(self.update_autopicker)
|
||||||
|
self.tap.figure_tabs.setCurrentIndex(0)
|
||||||
else:
|
else:
|
||||||
self.tap.fill_eventbox()
|
self.tap.fill_eventbox()
|
||||||
self.tap.show()
|
self.tap.show()
|
||||||
@ -1190,7 +1200,7 @@ class MainWindow(QMainWindow):
|
|||||||
def update_autopicker(self):
|
def update_autopicker(self):
|
||||||
for key in self.fig_dict.keys():
|
for key in self.fig_dict.keys():
|
||||||
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
||||||
self.tap.fill_tabs(self.canvas_dict)
|
self.tap.fill_tabs(picked=True)
|
||||||
|
|
||||||
def autoPick(self):
|
def autoPick(self):
|
||||||
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
|
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
|
||||||
|
@ -1 +1 @@
|
|||||||
cae5-dirty
|
c9d8-dirty
|
||||||
|
@ -38,13 +38,14 @@ class map_projection(QtGui.QWidget):
|
|||||||
|
|
||||||
def onpick(self, event):
|
def onpick(self, event):
|
||||||
ind = event.ind
|
ind = event.ind
|
||||||
if ind == []:
|
button = event.mouseevent.button
|
||||||
|
if ind == [] or not button == 1:
|
||||||
return
|
return
|
||||||
data = self._parent.get_data().getWFData()
|
data = self._parent.get_data().getWFData()
|
||||||
for index in ind:
|
for index in ind:
|
||||||
station=str(self.station_names[index])
|
station=str(self.station_names[index])
|
||||||
try:
|
try:
|
||||||
pickDlg = PickDlg(self, infile=self._parent.getinfile(),
|
pickDlg = PickDlg(self, parameter=self._parent._inputs,
|
||||||
data=data.select(station=station),
|
data=data.select(station=station),
|
||||||
station=station,
|
station=station,
|
||||||
picks=self._parent.getPicksOnStation(station, 'manual'),
|
picks=self._parent.getPicksOnStation(station, 'manual'),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
import sys
|
||||||
from PySide.QtCore import QThread, Signal, Qt
|
from PySide.QtCore import QThread, Signal, Qt
|
||||||
from PySide.QtGui import QDialog, QProgressBar, QLabel, QVBoxLayout
|
from PySide.QtGui import QDialog, QProgressBar, QLabel, QHBoxLayout
|
||||||
|
|
||||||
|
|
||||||
class AutoPickThread(QThread):
|
class AutoPickThread(QThread):
|
||||||
@ -75,12 +75,12 @@ class Thread(QThread):
|
|||||||
self.pb_widget = QDialog(self.parent())
|
self.pb_widget = QDialog(self.parent())
|
||||||
self.pb_widget.setWindowFlags(Qt.SplashScreen)
|
self.pb_widget.setWindowFlags(Qt.SplashScreen)
|
||||||
self.pb_widget.setModal(True)
|
self.pb_widget.setModal(True)
|
||||||
vl = QVBoxLayout()
|
hl = QHBoxLayout()
|
||||||
pb = QProgressBar()
|
pb = QProgressBar()
|
||||||
pb.setRange(0, 0)
|
pb.setRange(0, 0)
|
||||||
vl.addWidget(pb)
|
hl.addWidget(pb)
|
||||||
vl.addWidget(QLabel(self.progressText))
|
hl.addWidget(QLabel(self.progressText))
|
||||||
self.pb_widget.setLayout(vl)
|
self.pb_widget.setLayout(hl)
|
||||||
self.pb_widget.show()
|
self.pb_widget.show()
|
||||||
|
|
||||||
def hideProgressbar(self):
|
def hideProgressbar(self):
|
||||||
|
@ -516,11 +516,12 @@ class WaveformWidget(FigureCanvas):
|
|||||||
|
|
||||||
class PickDlg(QDialog):
|
class PickDlg(QDialog):
|
||||||
def __init__(self, parent=None, data=None, station=None, picks=None,
|
def __init__(self, parent=None, data=None, station=None, picks=None,
|
||||||
autopicks=None, rotate=False, infile=None):
|
autopicks=None, rotate=False, parameter=None, buttons=True):
|
||||||
super(PickDlg, self).__init__(parent)
|
super(PickDlg, self).__init__(parent)
|
||||||
|
|
||||||
# initialize attributes
|
# initialize attributes
|
||||||
self.infile = infile
|
self.parameter = parameter
|
||||||
|
self._buttons = buttons
|
||||||
self.station = station
|
self.station = station
|
||||||
self.rotate = rotate
|
self.rotate = rotate
|
||||||
self.components = 'ZNE'
|
self.components = 'ZNE'
|
||||||
@ -661,7 +662,8 @@ class PickDlg(QDialog):
|
|||||||
QDialogButtonBox.Cancel)
|
QDialogButtonBox.Cancel)
|
||||||
|
|
||||||
# merge widgets and layouts to establish the dialog
|
# merge widgets and layouts to establish the dialog
|
||||||
_innerlayout.addWidget(_buttonbox)
|
if self._buttons:
|
||||||
|
_innerlayout.addWidget(_buttonbox)
|
||||||
_outerlayout.addWidget(_dialtoolbar)
|
_outerlayout.addWidget(_dialtoolbar)
|
||||||
_outerlayout.addLayout(_innerlayout)
|
_outerlayout.addLayout(_innerlayout)
|
||||||
|
|
||||||
@ -773,8 +775,8 @@ class PickDlg(QDialog):
|
|||||||
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
||||||
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
||||||
|
|
||||||
def getinfile(self):
|
def getParameter(self):
|
||||||
return self.infile
|
return self.parameter
|
||||||
|
|
||||||
def getStartTime(self):
|
def getStartTime(self):
|
||||||
return self.stime
|
return self.stime
|
||||||
@ -899,7 +901,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def setIniPickP(self, gui_event, wfdata, trace_number):
|
def setIniPickP(self, gui_event, wfdata, trace_number):
|
||||||
|
|
||||||
parameter = AutoPickParameter(self.getinfile())
|
parameter = self.parameter
|
||||||
ini_pick = gui_event.xdata
|
ini_pick = gui_event.xdata
|
||||||
|
|
||||||
nfac = parameter.get('nfacP')
|
nfac = parameter.get('nfacP')
|
||||||
@ -948,7 +950,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def setIniPickS(self, gui_event, wfdata):
|
def setIniPickS(self, gui_event, wfdata):
|
||||||
|
|
||||||
parameter = AutoPickParameter(self.getinfile())
|
parameter = self.parameter
|
||||||
ini_pick = gui_event.xdata
|
ini_pick = gui_event.xdata
|
||||||
|
|
||||||
nfac = parameter.get('nfacS')
|
nfac = parameter.get('nfacS')
|
||||||
@ -1002,7 +1004,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def setPick(self, gui_event):
|
def setPick(self, gui_event):
|
||||||
|
|
||||||
parameter = AutoPickParameter(self.getinfile())
|
parameter = self.parameter
|
||||||
|
|
||||||
# get axes limits
|
# get axes limits
|
||||||
self.updateCurrentLimits()
|
self.updateCurrentLimits()
|
||||||
@ -1282,20 +1284,21 @@ class TuneAutopicker(QWidget):
|
|||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QtGui.QWidget.__init__(self, parent, 1)
|
QtGui.QWidget.__init__(self, parent, 1)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.ap = parent._inputs
|
self.setParent(parent)
|
||||||
|
self.parameter = parent._inputs
|
||||||
self.fig_dict = parent.fig_dict
|
self.fig_dict = parent.fig_dict
|
||||||
self.data = Data()
|
self.data = Data()
|
||||||
self.init_main_layouts()
|
self.init_main_layouts()
|
||||||
self.init_eventlist()
|
self.init_eventlist()
|
||||||
self.init_stationlist()
|
|
||||||
self.init_figure_tabs()
|
self.init_figure_tabs()
|
||||||
|
self.init_stationlist()
|
||||||
self.init_pbwidget()
|
self.init_pbwidget()
|
||||||
|
self.connect_signals()
|
||||||
self.add_parameters()
|
self.add_parameters()
|
||||||
self.add_buttons()
|
self.add_buttons()
|
||||||
self.add_log()
|
self.add_log()
|
||||||
self.set_stretch()
|
self.set_stretch()
|
||||||
self.resize(1280, 720)
|
self.resize(1280, 720)
|
||||||
self.figure_tabs.setCurrentIndex(0)
|
|
||||||
#self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
|
#self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
|
||||||
#self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
|
#self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
|
||||||
|
|
||||||
@ -1312,16 +1315,21 @@ class TuneAutopicker(QWidget):
|
|||||||
def init_eventlist(self):
|
def init_eventlist(self):
|
||||||
self.eventBox = self.parent.createEventBox()
|
self.eventBox = self.parent.createEventBox()
|
||||||
self.fill_eventbox()
|
self.fill_eventbox()
|
||||||
self.eventBox.setCurrentIndex(1)
|
self.eventBox.setCurrentIndex(0)
|
||||||
self.trace_layout.addWidget(self.eventBox)
|
self.trace_layout.addWidget(self.eventBox)
|
||||||
self.eventBox.activated.connect(self.fill_stationbox)
|
|
||||||
self.eventBox.activated.connect(self.update_eventID)
|
|
||||||
|
|
||||||
def init_stationlist(self):
|
def init_stationlist(self):
|
||||||
self.stationBox = QtGui.QComboBox()
|
self.stationBox = QtGui.QComboBox()
|
||||||
self.trace_layout.addWidget(self.stationBox)
|
self.trace_layout.addWidget(self.stationBox)
|
||||||
self.fill_stationbox()
|
self.fill_stationbox()
|
||||||
|
self.figure_tabs.setCurrentIndex(0)
|
||||||
|
|
||||||
|
def connect_signals(self):
|
||||||
|
self.eventBox.activated.connect(self.fill_stationbox)
|
||||||
|
self.eventBox.activated.connect(self.update_eventID)
|
||||||
|
self.eventBox.activated.connect(self.fill_tabs)
|
||||||
|
self.stationBox.activated.connect(self.fill_tabs)
|
||||||
|
|
||||||
def fill_stationbox(self):
|
def fill_stationbox(self):
|
||||||
fnames = self.parent.getWFFnames_from_eventbox(eventbox=self.eventBox)
|
fnames = self.parent.getWFFnames_from_eventbox(eventbox=self.eventBox)
|
||||||
self.data.setWFData(fnames)
|
self.data.setWFData(fnames)
|
||||||
@ -1342,8 +1350,12 @@ class TuneAutopicker(QWidget):
|
|||||||
def init_pbwidget(self):
|
def init_pbwidget(self):
|
||||||
self.pb_widget = QtGui.QWidget()
|
self.pb_widget = QtGui.QWidget()
|
||||||
|
|
||||||
|
def init_tab_names(self):
|
||||||
|
self.ptb_names = ['aicFig', 'slength', 'checkZ4s', 'refPpick', 'el_Ppick', 'fm_picker']
|
||||||
|
self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick']
|
||||||
|
|
||||||
def add_parameters(self):
|
def add_parameters(self):
|
||||||
self.parameters = AutoPickParaBox(self.ap)
|
self.parameters = AutoPickParaBox(self.parameter)
|
||||||
self.parameters.set_tune_mode(True)
|
self.parameters.set_tune_mode(True)
|
||||||
self.update_eventID()
|
self.update_eventID()
|
||||||
self.parameter_layout.addWidget(self.parameters)
|
self.parameter_layout.addWidget(self.parameters)
|
||||||
@ -1358,105 +1370,66 @@ class TuneAutopicker(QWidget):
|
|||||||
|
|
||||||
def add_log(self):
|
def add_log(self):
|
||||||
self.listWidget = QtGui.QListWidget()
|
self.listWidget = QtGui.QListWidget()
|
||||||
self.figure_tabs.insertTab(3, self.listWidget, 'log')
|
self.figure_tabs.insertTab(4, self.listWidget, 'log')
|
||||||
|
|
||||||
def fill_figure_tabs(self):
|
|
||||||
self.p_tabs = QtGui.QTabWidget()
|
|
||||||
self.s_tabs = QtGui.QTabWidget()
|
|
||||||
self.tune_layout.insertWidget(0, self.figure_tabs)
|
|
||||||
self.init_tab_names()
|
|
||||||
|
|
||||||
def fill_eventbox(self):
|
|
||||||
self.parent.fill_eventbox(self.eventBox, 'ref')
|
|
||||||
|
|
||||||
def get_current_event(self):
|
|
||||||
return self.eventBox.currentText().split('/')[-1]
|
|
||||||
|
|
||||||
def update_eventID(self):
|
|
||||||
self.parameters.boxes['eventID'].setText(self.get_current_event())
|
|
||||||
|
|
||||||
def add_log_item(self, text):
|
def add_log_item(self, text):
|
||||||
self.listWidget.addItem(text)
|
self.listWidget.addItem(text)
|
||||||
self.listWidget.scrollToBottom()
|
self.listWidget.scrollToBottom()
|
||||||
|
|
||||||
def call_picker(self):
|
def get_current_event(self):
|
||||||
self.ap = self.params_from_gui()
|
index = self.eventBox.currentIndex()
|
||||||
station = str(self.stationBox.currentText())
|
return self.eventBox.itemData(index)
|
||||||
if not station:
|
|
||||||
self._warn('No station selected')
|
|
||||||
return
|
|
||||||
args = {'parameter': self.ap,
|
|
||||||
'station': station,
|
|
||||||
'fnames': 'None',
|
|
||||||
'iplot': 2,
|
|
||||||
'fig_dict': self.fig_dict,
|
|
||||||
'locflag': 0}
|
|
||||||
for key in self.fig_dict.keys():
|
|
||||||
self.fig_dict[key].clear()
|
|
||||||
self.ap_thread = Thread(self, autoPyLoT, arg=args,
|
|
||||||
progressText='Picking trace...', pb_widget=self.pb_widget,
|
|
||||||
redirect_stdout=True)
|
|
||||||
self.enable(False)
|
|
||||||
self.ap_thread.message.connect(self.add_log_item)
|
|
||||||
self.ap_thread.finished.connect(self.finish_picker)
|
|
||||||
self.figure_tabs.setCurrentIndex(3)
|
|
||||||
self.ap_thread.start()
|
|
||||||
#picks = autoPyLoT(self.ap, fnames='None', iplot=2, fig_dict=self.fig_dict)
|
|
||||||
|
|
||||||
def finish_picker(self):
|
|
||||||
self.enable(True)
|
|
||||||
if not self.ap_thread._executed:
|
|
||||||
self._warn('Could not execute picker:\n{}'.format(
|
|
||||||
self.ap_thread._executedError))
|
|
||||||
return
|
|
||||||
self.picks = self.ap_thread.data
|
|
||||||
if not self.picks:
|
|
||||||
self._warn('No picks found. See terminal output.')
|
|
||||||
return
|
|
||||||
#renew tabs
|
|
||||||
self.overview.setParent(None)
|
|
||||||
self.p_tabs.setParent(None)
|
|
||||||
self.s_tabs.setParent(None)
|
|
||||||
self.fill_figure_tabs()
|
|
||||||
self.set_stretch()
|
|
||||||
self.update.emit('Update')
|
|
||||||
self.figure_tabs.setCurrentIndex(0)
|
|
||||||
|
|
||||||
def enable(self, bool):
|
|
||||||
self.pick_button.setEnabled(bool)
|
|
||||||
self.parameters.setEnabled(bool)
|
|
||||||
self.eventBox.setEnabled(bool)
|
|
||||||
self.stationBox.setEnabled(bool)
|
|
||||||
self.overview.setEnabled(bool)
|
|
||||||
self.p_tabs.setEnabled(bool)
|
|
||||||
self.s_tabs.setEnabled(bool)
|
|
||||||
|
|
||||||
def params_from_gui(self):
|
def get_current_event_name(self):
|
||||||
ap = self.parameters.params_from_gui()
|
return self.eventBox.currentText().split('/')[-1]
|
||||||
if self.parent:
|
|
||||||
self.parent._inputs = ap
|
|
||||||
return ap
|
|
||||||
|
|
||||||
def set_stretch(self):
|
def get_current_event_fp(self):
|
||||||
self.tune_layout.setStretch(0, 3)
|
return self.eventBox.currentText()
|
||||||
self.tune_layout.setStretch(1, 1)
|
|
||||||
|
|
||||||
def init_tab_names(self):
|
def get_current_station(self):
|
||||||
self.ptb_names = ['aicFig', 'slength', 'checkZ4s', 'refPpick', 'el_Ppick', 'fm_picker']
|
return str(self.stationBox.currentText())
|
||||||
self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick']
|
|
||||||
|
def gen_tab_widget(self, name, canvas):
|
||||||
|
widget = QtGui.QWidget()
|
||||||
|
v_layout = QtGui.QVBoxLayout()
|
||||||
|
v_layout.addWidget(canvas)
|
||||||
|
v_layout.addWidget(NavigationToolbar2QT(canvas, self))
|
||||||
|
widget.setLayout(v_layout)
|
||||||
|
return widget
|
||||||
|
|
||||||
def fill_tabs(self, canvas_dict):
|
def gen_pick_dlg(self):
|
||||||
|
station = self.get_current_station()
|
||||||
|
data = self.data.getWFData()
|
||||||
|
pickDlg = PickDlg(self, data=data.select(station=station),
|
||||||
|
station=station, parameter=self.parameter,
|
||||||
|
picks=self.get_current_event().picks,
|
||||||
|
autopicks=self.get_current_event().autopicks,
|
||||||
|
buttons=False)
|
||||||
|
self.pickDlg = QtGui.QWidget()
|
||||||
|
hl = QtGui.QHBoxLayout()
|
||||||
|
self.pickDlg.setLayout(hl)
|
||||||
|
hl.addWidget(pickDlg)
|
||||||
|
|
||||||
|
def fill_tabs(self, event=None, picked=False):
|
||||||
|
self.clear_all()
|
||||||
|
canvas_dict = self.parent.canvas_dict
|
||||||
|
self.gen_pick_dlg()
|
||||||
self.overview = self.gen_tab_widget('Overview', canvas_dict['mainFig'])
|
self.overview = self.gen_tab_widget('Overview', canvas_dict['mainFig'])
|
||||||
id = self.figure_tabs.insertTab(0, self.overview, 'Overview')
|
id0 = self.figure_tabs.insertTab(0, self.pickDlg, 'Traces Plot')
|
||||||
#self.figure_tabs.setTabEnabled(id, bool(self.fig_dict['mainFig'].axes))
|
id1 = self.figure_tabs.insertTab(1, self.overview, 'Overview')
|
||||||
self.figure_tabs.insertTab(1, self.p_tabs, 'P')
|
id2 = self.figure_tabs.insertTab(2, self.p_tabs, 'P')
|
||||||
self.figure_tabs.insertTab(2, self.s_tabs, 'S')
|
id3 = self.figure_tabs.insertTab(3, self.s_tabs, 'S')
|
||||||
self.fill_p_tabs(canvas_dict)
|
if picked:
|
||||||
self.fill_s_tabs(canvas_dict)
|
self.fill_p_tabs(canvas_dict)
|
||||||
|
self.fill_s_tabs(canvas_dict)
|
||||||
|
self.toggle_autopickTabs(bool(self.fig_dict['mainFig'].axes))
|
||||||
|
else:
|
||||||
|
self.disable_autopickTabs()
|
||||||
try:
|
try:
|
||||||
main_fig.tight_layout()
|
main_fig.tight_layout()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
self.figure_tabs.setCurrentIndex(0)
|
||||||
|
|
||||||
def fill_p_tabs(self, canvas_dict):
|
def fill_p_tabs(self, canvas_dict):
|
||||||
for name in self.ptb_names:
|
for name in self.ptb_names:
|
||||||
@ -1476,20 +1449,360 @@ class TuneAutopicker(QWidget):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def gen_tab_widget(self, name, canvas):
|
def fill_figure_tabs(self):
|
||||||
widget = QtGui.QWidget()
|
self.clear_all()
|
||||||
v_layout = QtGui.QVBoxLayout()
|
self.p_tabs = QtGui.QTabWidget()
|
||||||
v_layout.addWidget(canvas)
|
self.s_tabs = QtGui.QTabWidget()
|
||||||
v_layout.addWidget(NavigationToolbar2QT(canvas, self))
|
self.tune_layout.insertWidget(0, self.figure_tabs)
|
||||||
widget.setLayout(v_layout)
|
self.init_tab_names()
|
||||||
return widget
|
|
||||||
|
|
||||||
|
def fill_eventbox(self):
|
||||||
|
self.parent.fill_eventbox(self.eventBox, 'ref')
|
||||||
|
|
||||||
|
def update_eventID(self):
|
||||||
|
self.parameters.boxes['eventID'].setText(
|
||||||
|
self.get_current_event_name())
|
||||||
|
self.figure_tabs.setCurrentIndex(0)
|
||||||
|
|
||||||
|
def call_picker(self):
|
||||||
|
self.parameter = self.params_from_gui()
|
||||||
|
station = self.get_current_station()
|
||||||
|
if not station:
|
||||||
|
self._warn('No station selected')
|
||||||
|
return
|
||||||
|
args = {'parameter': self.parameter,
|
||||||
|
'station': station,
|
||||||
|
'fnames': 'None',
|
||||||
|
'iplot': 2,
|
||||||
|
'fig_dict': self.fig_dict,
|
||||||
|
'locflag': 0}
|
||||||
|
for key in self.fig_dict.keys():
|
||||||
|
self.fig_dict[key].clear()
|
||||||
|
self.ap_thread = Thread(self, autoPyLoT, arg=args,
|
||||||
|
progressText='Picking trace...',
|
||||||
|
pb_widget=self.pb_widget,
|
||||||
|
redirect_stdout=True)
|
||||||
|
self.enable(False)
|
||||||
|
self.ap_thread.message.connect(self.add_log_item)
|
||||||
|
self.ap_thread.finished.connect(self.finish_picker)
|
||||||
|
self.figure_tabs.setCurrentIndex(4)
|
||||||
|
self.ap_thread.start()
|
||||||
|
#picks = autoPyLoT(self.parameter, fnames='None', iplot=2, fig_dict=self.fig_dict)
|
||||||
|
|
||||||
|
def finish_picker(self):
|
||||||
|
self.enable(True)
|
||||||
|
if not self.ap_thread._executed:
|
||||||
|
self._warn('Could not execute picker:\n{}'.format(
|
||||||
|
self.ap_thread._executedError))
|
||||||
|
return
|
||||||
|
self.picks = self.ap_thread.data
|
||||||
|
if not self.picks:
|
||||||
|
self._warn('No picks found. See terminal output.')
|
||||||
|
return
|
||||||
|
#renew tabs
|
||||||
|
#self.fill_figure_tabs()
|
||||||
|
self.set_stretch()
|
||||||
|
self.update.emit('Update')
|
||||||
|
self.figure_tabs.setCurrentIndex(1)
|
||||||
|
|
||||||
|
def enable(self, bool):
|
||||||
|
self.pick_button.setEnabled(bool)
|
||||||
|
self.parameters.setEnabled(bool)
|
||||||
|
self.eventBox.setEnabled(bool)
|
||||||
|
self.stationBox.setEnabled(bool)
|
||||||
|
self.overview.setEnabled(bool)
|
||||||
|
self.p_tabs.setEnabled(bool)
|
||||||
|
self.s_tabs.setEnabled(bool)
|
||||||
|
|
||||||
|
def params_from_gui(self):
|
||||||
|
parameters = self.parameters.params_from_gui()
|
||||||
|
if self.parent:
|
||||||
|
self.parent._inputs = parameters
|
||||||
|
return parameters
|
||||||
|
|
||||||
|
def set_stretch(self):
|
||||||
|
self.tune_layout.setStretch(0, 3)
|
||||||
|
self.tune_layout.setStretch(1, 1)
|
||||||
|
|
||||||
|
def clear_all(self):
|
||||||
|
if hasattr(self, 'pickDlg'):
|
||||||
|
self.pickDlg.setParent(None)
|
||||||
|
del(self.pickDlg)
|
||||||
|
if hasattr(self, 'overview'):
|
||||||
|
self.overview.setParent(None)
|
||||||
|
if hasattr(self, 'p_tabs'):
|
||||||
|
self.p_tabs.clear()
|
||||||
|
self.p_tabs.setParent(None)
|
||||||
|
if hasattr(self, 's_tabs'):
|
||||||
|
self.s_tabs.clear()
|
||||||
|
self.s_tabs.setParent(None)
|
||||||
|
|
||||||
|
def disable_autopickTabs(self):
|
||||||
|
self.toggle_autopickTabs(False)
|
||||||
|
|
||||||
|
def toggle_autopickTabs(self, bool):
|
||||||
|
self.figure_tabs.setTabEnabled(1, bool)
|
||||||
|
self.figure_tabs.setTabEnabled(2, bool)
|
||||||
|
self.figure_tabs.setTabEnabled(3, bool)
|
||||||
|
|
||||||
def _warn(self, message):
|
def _warn(self, message):
|
||||||
self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning,
|
self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning,
|
||||||
'Warning', message)
|
'Warning', message)
|
||||||
self.qmb.show()
|
self.qmb.show()
|
||||||
|
|
||||||
|
|
||||||
|
class AutoPickParaBox(QtGui.QWidget):
|
||||||
|
def __init__(self, parameter, parent=None):
|
||||||
|
'''
|
||||||
|
Generate Widget containing parameters for automatic picking algorithm.
|
||||||
|
|
||||||
|
:param: parameter
|
||||||
|
:type: AutoPickParameter (object)
|
||||||
|
|
||||||
|
'''
|
||||||
|
QtGui.QWidget.__init__(self, parent)
|
||||||
|
self.parameter = parameter
|
||||||
|
self.tabs = QtGui.QTabWidget()
|
||||||
|
self.layout = QtGui.QVBoxLayout()
|
||||||
|
self._init_buttons()
|
||||||
|
self.layout.addWidget(self.tabs)
|
||||||
|
self.boxes = {}
|
||||||
|
self._init_sublayouts()
|
||||||
|
self.setLayout(self.layout)
|
||||||
|
self.add_main_parameters_tab()
|
||||||
|
self.add_special_pick_parameters_tab()
|
||||||
|
self.params_to_gui()
|
||||||
|
self._toggle_advanced_settings()
|
||||||
|
|
||||||
|
def _init_sublayouts(self):
|
||||||
|
self._main_layout = QtGui.QVBoxLayout()
|
||||||
|
self._advanced_layout = QtGui.QVBoxLayout()
|
||||||
|
self._create_advanced_cb()
|
||||||
|
|
||||||
|
def _init_buttons(self):
|
||||||
|
self._buttons_layout = QtGui.QHBoxLayout()
|
||||||
|
self.loadButton = QtGui.QPushButton('&Load settings')
|
||||||
|
self.saveButton = QtGui.QPushButton('&Save settings')
|
||||||
|
self.defaultsButton = QtGui.QPushButton('&Defaults')
|
||||||
|
self._buttons_layout.addWidget(self.loadButton)
|
||||||
|
self._buttons_layout.addWidget(self.saveButton)
|
||||||
|
self._buttons_layout.addWidget(self.defaultsButton)
|
||||||
|
self.layout.addLayout(self._buttons_layout)
|
||||||
|
self.loadButton.clicked.connect(self.openFile)
|
||||||
|
self.saveButton.clicked.connect(self.saveFile)
|
||||||
|
self.defaultsButton.clicked.connect(self.restoreDefaults)
|
||||||
|
|
||||||
|
def _create_advanced_cb(self):
|
||||||
|
self._advanced_cb = QtGui.QCheckBox('Enable Advanced Settings')
|
||||||
|
self._advanced_layout.addWidget(self._advanced_cb)
|
||||||
|
self._advanced_cb.toggled.connect(self._toggle_advanced_settings)
|
||||||
|
|
||||||
|
def _toggle_advanced_settings(self):
|
||||||
|
if self._advanced_cb.isChecked():
|
||||||
|
self._enable_advanced(True)
|
||||||
|
else:
|
||||||
|
self._enable_advanced(False)
|
||||||
|
|
||||||
|
def _enable_advanced(self, enable):
|
||||||
|
for lst in self.parameter.get_special_para_names().values():
|
||||||
|
for param in lst:
|
||||||
|
box = self.boxes[param]
|
||||||
|
if type(box) is not list:
|
||||||
|
box.setEnabled(enable)
|
||||||
|
else:
|
||||||
|
for b in box:
|
||||||
|
b.setEnabled(enable)
|
||||||
|
|
||||||
|
def set_tune_mode(self, bool):
|
||||||
|
keys = ['rootpath', 'datapath', 'database',
|
||||||
|
'eventID', 'invdir', 'nllocbin',
|
||||||
|
'nllocroot', 'phasefile',
|
||||||
|
'ctrfile', 'ttpatter', 'outpatter']
|
||||||
|
for key in keys:
|
||||||
|
self.boxes[key].setEnabled(not(bool))
|
||||||
|
|
||||||
|
def init_boxes(self, parameter_names):
|
||||||
|
grid = QtGui.QGridLayout()
|
||||||
|
|
||||||
|
for index1, name in enumerate(parameter_names):
|
||||||
|
text = name + ' [?]'
|
||||||
|
label = QtGui.QLabel(text)
|
||||||
|
default_item = self.parameter.get_defaults()[name]
|
||||||
|
tooltip = default_item['tooltip']
|
||||||
|
tooltip += ' | type: {}'.format(default_item['type'])
|
||||||
|
if not type(default_item['type']) == tuple:
|
||||||
|
typ = default_item['type']
|
||||||
|
box = self.create_box(typ, tooltip)
|
||||||
|
self.boxes[name] = box
|
||||||
|
elif type(default_item['type']) == tuple:
|
||||||
|
boxes = []
|
||||||
|
values = self.parameter[name]
|
||||||
|
for index2, val in enumerate(values):
|
||||||
|
typ = default_item['type'][index2]
|
||||||
|
boxes.append(self.create_box(typ, tooltip))
|
||||||
|
box = self.create_multi_box(boxes)
|
||||||
|
self.boxes[name] = boxes
|
||||||
|
label.setToolTip(tooltip)
|
||||||
|
grid.addWidget(label, index1, 1)
|
||||||
|
grid.addWidget(box, index1, 2)
|
||||||
|
return grid
|
||||||
|
|
||||||
|
def create_box(self, typ, tooltip):
|
||||||
|
if typ == str:
|
||||||
|
box = QtGui.QLineEdit()
|
||||||
|
elif typ == float:
|
||||||
|
box = QtGui.QDoubleSpinBox()
|
||||||
|
elif typ == int:
|
||||||
|
box = QtGui.QSpinBox()
|
||||||
|
elif typ == bool:
|
||||||
|
box = QtGui.QCheckBox()
|
||||||
|
else:
|
||||||
|
raise TypeError('Unrecognized type {}'.format(typ))
|
||||||
|
return box
|
||||||
|
|
||||||
|
def create_multi_box(self, boxes):
|
||||||
|
box = QtGui.QWidget()
|
||||||
|
hl = QtGui.QHBoxLayout()
|
||||||
|
for b in boxes:
|
||||||
|
hl.addWidget(b)
|
||||||
|
box.setLayout(hl)
|
||||||
|
return box
|
||||||
|
|
||||||
|
def add_tab(self, layout, name):
|
||||||
|
widget = QtGui.QWidget()
|
||||||
|
scrollA = QtGui.QScrollArea()
|
||||||
|
scrollA.setWidgetResizable(True)
|
||||||
|
scrollA.setWidget(widget)
|
||||||
|
|
||||||
|
widget.setLayout(layout)
|
||||||
|
|
||||||
|
self.tabs.addTab(scrollA, name)
|
||||||
|
|
||||||
|
def add_main_parameters_tab(self):
|
||||||
|
self.add_to_layout(self._main_layout, 'Directories',
|
||||||
|
self.parameter.get_main_para_names()['dirs'])
|
||||||
|
self.add_to_layout(self._main_layout, 'NLLoc',
|
||||||
|
self.parameter.get_main_para_names()['nlloc'])
|
||||||
|
self.add_to_layout(self._main_layout, 'Seismic Moment',
|
||||||
|
self.parameter.get_main_para_names()['smoment'])
|
||||||
|
self.add_to_layout(self._main_layout, 'Focal Mechanism',
|
||||||
|
self.parameter.get_main_para_names()['focmec'])
|
||||||
|
self.add_to_layout(self._main_layout, 'Pick Settings',
|
||||||
|
self.parameter.get_main_para_names()['pick'],
|
||||||
|
False)
|
||||||
|
self.add_tab(self._main_layout, 'Main Settings')
|
||||||
|
|
||||||
|
def add_special_pick_parameters_tab(self):
|
||||||
|
self.add_to_layout(self._advanced_layout, 'Z-component',
|
||||||
|
self.parameter.get_special_para_names()['z'])
|
||||||
|
self.add_to_layout(self._advanced_layout, 'H-components',
|
||||||
|
self.parameter.get_special_para_names()['h'])
|
||||||
|
self.add_to_layout(self._advanced_layout, 'First-motion picker',
|
||||||
|
self.parameter.get_special_para_names()['fm'])
|
||||||
|
self.add_to_layout(self._advanced_layout, 'Quality assessment',
|
||||||
|
self.parameter.get_special_para_names()['quality'],
|
||||||
|
False)
|
||||||
|
self.add_tab(self._advanced_layout, 'Advanced Settings')
|
||||||
|
|
||||||
|
def gen_h_seperator(self):
|
||||||
|
seperator = QtGui.QFrame()
|
||||||
|
seperator.setFrameShape(QtGui.QFrame.HLine)
|
||||||
|
return seperator
|
||||||
|
|
||||||
|
def gen_headline(self, text):
|
||||||
|
label=QtGui.QLabel(text)
|
||||||
|
font=QtGui.QFont()
|
||||||
|
font.setBold(True)
|
||||||
|
label.setFont(font)
|
||||||
|
return label
|
||||||
|
|
||||||
|
def add_to_layout(self, layout, name, items, seperator=True):
|
||||||
|
layout.addWidget(self.gen_headline(name))
|
||||||
|
layout.addLayout(self.init_boxes(items))
|
||||||
|
if seperator:
|
||||||
|
layout.addWidget(self.gen_h_seperator())
|
||||||
|
|
||||||
|
def params_from_gui(self):
|
||||||
|
for param in self.parameter.get_all_para_names():
|
||||||
|
box = self.boxes[param]
|
||||||
|
value = self.getValue(box)
|
||||||
|
self.parameter.checkValue(param, value)
|
||||||
|
self.parameter.setParamKV(param, value)
|
||||||
|
return self.parameter
|
||||||
|
|
||||||
|
def params_to_gui(self):
|
||||||
|
for param in self.parameter.get_all_para_names():
|
||||||
|
box = self.boxes[param]
|
||||||
|
value = self.parameter[param]
|
||||||
|
#self.parameter.checkValue(param, value)
|
||||||
|
self.setValue(box, value)
|
||||||
|
|
||||||
|
def setValue(self, box, value):
|
||||||
|
if type(box) == QtGui.QLineEdit:
|
||||||
|
box.setText(value)
|
||||||
|
elif type(box) == QtGui.QSpinBox or type(box) == QtGui.QDoubleSpinBox:
|
||||||
|
box.setMaximum(100*value)
|
||||||
|
box.setValue(value)
|
||||||
|
elif type(box) == QtGui.QCheckBox:
|
||||||
|
if value == 'True':
|
||||||
|
value = True
|
||||||
|
if value == 'False':
|
||||||
|
value = False
|
||||||
|
box.setChecked(value)
|
||||||
|
elif type(box) == list:
|
||||||
|
for index, b in enumerate(box):
|
||||||
|
self.setValue(b, value[index])
|
||||||
|
|
||||||
|
def getValue(self, box):
|
||||||
|
if type(box) == QtGui.QLineEdit:
|
||||||
|
value = str(box.text())
|
||||||
|
elif type(box) == QtGui.QSpinBox or type(box) == QtGui.QDoubleSpinBox:
|
||||||
|
value = box.value()
|
||||||
|
elif type(box) == QtGui.QCheckBox:
|
||||||
|
value = box.isChecked()
|
||||||
|
elif type(box) == list:
|
||||||
|
value = []
|
||||||
|
for b in box:
|
||||||
|
value.append(self.getValue(b))
|
||||||
|
value = tuple(value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
def openFile(self):
|
||||||
|
fd = QtGui.QFileDialog()
|
||||||
|
fname = fd.getOpenFileName(self, 'Browse for settings file.', '*.in')
|
||||||
|
if fname[0]:
|
||||||
|
try:
|
||||||
|
self.parameter.from_file(fname[0])
|
||||||
|
self.params_to_gui()
|
||||||
|
except Exception as e:
|
||||||
|
self._warn('Could not open file {}:\n{}'.format(fname[0], e))
|
||||||
|
return
|
||||||
|
|
||||||
|
def saveFile(self):
|
||||||
|
fd = QtGui.QFileDialog()
|
||||||
|
fname = fd.getSaveFileName(self, 'Browse for settings file.', '*.in')
|
||||||
|
if fname[0]:
|
||||||
|
try:
|
||||||
|
self.params_from_gui()
|
||||||
|
self.parameter.export2File(fname[0])
|
||||||
|
except Exception as e:
|
||||||
|
self._warn('Could not save file {}:\n{}'.format(fname[0], e))
|
||||||
|
return
|
||||||
|
|
||||||
|
def restoreDefaults(self):
|
||||||
|
try:
|
||||||
|
self.parameter.reset_defaults()
|
||||||
|
self.params_to_gui()
|
||||||
|
except Exception as e:
|
||||||
|
self._warn('Could not restore defaults:\n{}'.format(e))
|
||||||
|
return
|
||||||
|
|
||||||
|
def _warn(self, message):
|
||||||
|
self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning,
|
||||||
|
'Warning', message)
|
||||||
|
self.qmb.show()
|
||||||
|
|
||||||
|
|
||||||
class PropertiesDlg(QDialog):
|
class PropertiesDlg(QDialog):
|
||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None):
|
||||||
super(PropertiesDlg, self).__init__(parent)
|
super(PropertiesDlg, self).__init__(parent)
|
||||||
@ -1752,258 +2065,6 @@ class LocalisationTab(PropTab):
|
|||||||
"nll/binPath": self.binedit.setText("%s" % nllocbin)}
|
"nll/binPath": self.binedit.setText("%s" % nllocbin)}
|
||||||
|
|
||||||
|
|
||||||
class AutoPickParaBox(QtGui.QWidget):
|
|
||||||
def __init__(self, ap, parent=None):
|
|
||||||
'''
|
|
||||||
Generate Widget containing parameters for automatic picking algorithm.
|
|
||||||
|
|
||||||
:param: ap
|
|
||||||
:type: AutoPickParameter (object)
|
|
||||||
|
|
||||||
'''
|
|
||||||
QtGui.QWidget.__init__(self, parent)
|
|
||||||
self.ap = ap
|
|
||||||
self.tabs = QtGui.QTabWidget()
|
|
||||||
self.layout = QtGui.QVBoxLayout()
|
|
||||||
self._init_buttons()
|
|
||||||
self.layout.addWidget(self.tabs)
|
|
||||||
self.boxes = {}
|
|
||||||
self._init_sublayouts()
|
|
||||||
self.setLayout(self.layout)
|
|
||||||
self.add_main_parameters_tab()
|
|
||||||
self.add_special_pick_parameters_tab()
|
|
||||||
self.params_to_gui()
|
|
||||||
self._toggle_advanced_settings()
|
|
||||||
|
|
||||||
def _init_sublayouts(self):
|
|
||||||
self._main_layout = QtGui.QVBoxLayout()
|
|
||||||
self._advanced_layout = QtGui.QVBoxLayout()
|
|
||||||
self._create_advanced_cb()
|
|
||||||
|
|
||||||
def _init_buttons(self):
|
|
||||||
self._buttons_layout = QtGui.QHBoxLayout()
|
|
||||||
self.loadButton = QtGui.QPushButton('&Load settings')
|
|
||||||
self.saveButton = QtGui.QPushButton('&Save settings')
|
|
||||||
self.defaultsButton = QtGui.QPushButton('&Defaults')
|
|
||||||
self._buttons_layout.addWidget(self.loadButton)
|
|
||||||
self._buttons_layout.addWidget(self.saveButton)
|
|
||||||
self._buttons_layout.addWidget(self.defaultsButton)
|
|
||||||
self.layout.addLayout(self._buttons_layout)
|
|
||||||
self.loadButton.clicked.connect(self.openFile)
|
|
||||||
self.saveButton.clicked.connect(self.saveFile)
|
|
||||||
self.defaultsButton.clicked.connect(self.restoreDefaults)
|
|
||||||
|
|
||||||
def _create_advanced_cb(self):
|
|
||||||
self._advanced_cb = QtGui.QCheckBox('Enable Advanced Settings')
|
|
||||||
self._advanced_layout.addWidget(self._advanced_cb)
|
|
||||||
self._advanced_cb.toggled.connect(self._toggle_advanced_settings)
|
|
||||||
|
|
||||||
def _toggle_advanced_settings(self):
|
|
||||||
if self._advanced_cb.isChecked():
|
|
||||||
self._enable_advanced(True)
|
|
||||||
else:
|
|
||||||
self._enable_advanced(False)
|
|
||||||
|
|
||||||
def _enable_advanced(self, enable):
|
|
||||||
for lst in self.ap.get_special_para_names().values():
|
|
||||||
for param in lst:
|
|
||||||
box = self.boxes[param]
|
|
||||||
if type(box) is not list:
|
|
||||||
box.setEnabled(enable)
|
|
||||||
else:
|
|
||||||
for b in box:
|
|
||||||
b.setEnabled(enable)
|
|
||||||
|
|
||||||
def set_tune_mode(self, bool):
|
|
||||||
keys = ['rootpath', 'datapath', 'database',
|
|
||||||
'eventID', 'invdir', 'nllocbin',
|
|
||||||
'nllocroot', 'phasefile',
|
|
||||||
'ctrfile', 'ttpatter', 'outpatter']
|
|
||||||
for key in keys:
|
|
||||||
self.boxes[key].setEnabled(not(bool))
|
|
||||||
|
|
||||||
def init_boxes(self, parameter_names):
|
|
||||||
grid = QtGui.QGridLayout()
|
|
||||||
|
|
||||||
for index1, name in enumerate(parameter_names):
|
|
||||||
text = name + ' [?]'
|
|
||||||
label = QtGui.QLabel(text)
|
|
||||||
default_item = self.ap.get_defaults()[name]
|
|
||||||
tooltip = default_item['tooltip']
|
|
||||||
tooltip += ' | type: {}'.format(default_item['type'])
|
|
||||||
if not type(default_item['type']) == tuple:
|
|
||||||
typ = default_item['type']
|
|
||||||
box = self.create_box(typ, tooltip)
|
|
||||||
self.boxes[name] = box
|
|
||||||
elif type(default_item['type']) == tuple:
|
|
||||||
boxes = []
|
|
||||||
values = self.ap[name]
|
|
||||||
for index2, val in enumerate(values):
|
|
||||||
typ = default_item['type'][index2]
|
|
||||||
boxes.append(self.create_box(typ, tooltip))
|
|
||||||
box = self.create_multi_box(boxes)
|
|
||||||
self.boxes[name] = boxes
|
|
||||||
label.setToolTip(tooltip)
|
|
||||||
grid.addWidget(label, index1, 1)
|
|
||||||
grid.addWidget(box, index1, 2)
|
|
||||||
return grid
|
|
||||||
|
|
||||||
def create_box(self, typ, tooltip):
|
|
||||||
if typ == str:
|
|
||||||
box = QtGui.QLineEdit()
|
|
||||||
elif typ == float:
|
|
||||||
box = QtGui.QDoubleSpinBox()
|
|
||||||
elif typ == int:
|
|
||||||
box = QtGui.QSpinBox()
|
|
||||||
elif typ == bool:
|
|
||||||
box = QtGui.QCheckBox()
|
|
||||||
else:
|
|
||||||
raise TypeError('Unrecognized type {}'.format(typ))
|
|
||||||
return box
|
|
||||||
|
|
||||||
def create_multi_box(self, boxes):
|
|
||||||
box = QtGui.QWidget()
|
|
||||||
hl = QtGui.QHBoxLayout()
|
|
||||||
for b in boxes:
|
|
||||||
hl.addWidget(b)
|
|
||||||
box.setLayout(hl)
|
|
||||||
return box
|
|
||||||
|
|
||||||
def add_tab(self, layout, name):
|
|
||||||
widget = QtGui.QWidget()
|
|
||||||
scrollA = QtGui.QScrollArea()
|
|
||||||
scrollA.setWidgetResizable(True)
|
|
||||||
scrollA.setWidget(widget)
|
|
||||||
|
|
||||||
widget.setLayout(layout)
|
|
||||||
|
|
||||||
self.tabs.addTab(scrollA, name)
|
|
||||||
|
|
||||||
def add_main_parameters_tab(self):
|
|
||||||
self.add_to_layout(self._main_layout, 'Directories',
|
|
||||||
self.ap.get_main_para_names()['dirs'])
|
|
||||||
self.add_to_layout(self._main_layout, 'NLLoc',
|
|
||||||
self.ap.get_main_para_names()['nlloc'])
|
|
||||||
self.add_to_layout(self._main_layout, 'Seismic Moment',
|
|
||||||
self.ap.get_main_para_names()['smoment'])
|
|
||||||
self.add_to_layout(self._main_layout, 'Focal Mechanism',
|
|
||||||
self.ap.get_main_para_names()['focmec'])
|
|
||||||
self.add_to_layout(self._main_layout, 'Pick Settings',
|
|
||||||
self.ap.get_main_para_names()['pick'],
|
|
||||||
False)
|
|
||||||
self.add_tab(self._main_layout, 'Main Settings')
|
|
||||||
|
|
||||||
def add_special_pick_parameters_tab(self):
|
|
||||||
self.add_to_layout(self._advanced_layout, 'Z-component',
|
|
||||||
self.ap.get_special_para_names()['z'])
|
|
||||||
self.add_to_layout(self._advanced_layout, 'H-components',
|
|
||||||
self.ap.get_special_para_names()['h'])
|
|
||||||
self.add_to_layout(self._advanced_layout, 'First-motion picker',
|
|
||||||
self.ap.get_special_para_names()['fm'])
|
|
||||||
self.add_to_layout(self._advanced_layout, 'Quality assessment',
|
|
||||||
self.ap.get_special_para_names()['quality'],
|
|
||||||
False)
|
|
||||||
self.add_tab(self._advanced_layout, 'Advanced Settings')
|
|
||||||
|
|
||||||
def gen_h_seperator(self):
|
|
||||||
seperator = QtGui.QFrame()
|
|
||||||
seperator.setFrameShape(QtGui.QFrame.HLine)
|
|
||||||
return seperator
|
|
||||||
|
|
||||||
def gen_headline(self, text):
|
|
||||||
label=QtGui.QLabel(text)
|
|
||||||
font=QtGui.QFont()
|
|
||||||
font.setBold(True)
|
|
||||||
label.setFont(font)
|
|
||||||
return label
|
|
||||||
|
|
||||||
def add_to_layout(self, layout, name, items, seperator=True):
|
|
||||||
layout.addWidget(self.gen_headline(name))
|
|
||||||
layout.addLayout(self.init_boxes(items))
|
|
||||||
if seperator:
|
|
||||||
layout.addWidget(self.gen_h_seperator())
|
|
||||||
|
|
||||||
def params_from_gui(self):
|
|
||||||
for param in self.ap.get_all_para_names():
|
|
||||||
box = self.boxes[param]
|
|
||||||
value = self.getValue(box)
|
|
||||||
self.ap.checkValue(param, value)
|
|
||||||
self.ap.setParamKV(param, value)
|
|
||||||
return self.ap
|
|
||||||
|
|
||||||
def params_to_gui(self):
|
|
||||||
for param in self.ap.get_all_para_names():
|
|
||||||
box = self.boxes[param]
|
|
||||||
value = self.ap[param]
|
|
||||||
#self.ap.checkValue(param, value)
|
|
||||||
self.setValue(box, value)
|
|
||||||
|
|
||||||
def setValue(self, box, value):
|
|
||||||
if type(box) == QtGui.QLineEdit:
|
|
||||||
box.setText(value)
|
|
||||||
elif type(box) == QtGui.QSpinBox or type(box) == QtGui.QDoubleSpinBox:
|
|
||||||
box.setMaximum(100*value)
|
|
||||||
box.setValue(value)
|
|
||||||
elif type(box) == QtGui.QCheckBox:
|
|
||||||
if value == 'True':
|
|
||||||
value = True
|
|
||||||
if value == 'False':
|
|
||||||
value = False
|
|
||||||
box.setChecked(value)
|
|
||||||
elif type(box) == list:
|
|
||||||
for index, b in enumerate(box):
|
|
||||||
self.setValue(b, value[index])
|
|
||||||
|
|
||||||
def getValue(self, box):
|
|
||||||
if type(box) == QtGui.QLineEdit:
|
|
||||||
value = str(box.text())
|
|
||||||
elif type(box) == QtGui.QSpinBox or type(box) == QtGui.QDoubleSpinBox:
|
|
||||||
value = box.value()
|
|
||||||
elif type(box) == QtGui.QCheckBox:
|
|
||||||
value = box.isChecked()
|
|
||||||
elif type(box) == list:
|
|
||||||
value = []
|
|
||||||
for b in box:
|
|
||||||
value.append(self.getValue(b))
|
|
||||||
value = tuple(value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
def openFile(self):
|
|
||||||
fd = QtGui.QFileDialog()
|
|
||||||
fname = fd.getOpenFileName(self, 'Browse for settings file.', '*.in')
|
|
||||||
if fname[0]:
|
|
||||||
try:
|
|
||||||
self.ap.from_file(fname[0])
|
|
||||||
self.params_to_gui()
|
|
||||||
except Exception as e:
|
|
||||||
self._warn('Could not open file {}:\n{}'.format(fname[0], e))
|
|
||||||
return
|
|
||||||
|
|
||||||
def saveFile(self):
|
|
||||||
fd = QtGui.QFileDialog()
|
|
||||||
fname = fd.getSaveFileName(self, 'Browse for settings file.', '*.in')
|
|
||||||
if fname[0]:
|
|
||||||
try:
|
|
||||||
self.params_from_gui()
|
|
||||||
self.ap.export2File(fname[0])
|
|
||||||
except Exception as e:
|
|
||||||
self._warn('Could not save file {}:\n{}'.format(fname[0], e))
|
|
||||||
return
|
|
||||||
|
|
||||||
def restoreDefaults(self):
|
|
||||||
try:
|
|
||||||
self.ap.reset_defaults()
|
|
||||||
self.params_to_gui()
|
|
||||||
except Exception as e:
|
|
||||||
self._warn('Could not restore defaults:\n{}'.format(e))
|
|
||||||
return
|
|
||||||
|
|
||||||
def _warn(self, message):
|
|
||||||
self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning,
|
|
||||||
'Warning', message)
|
|
||||||
self.qmb.show()
|
|
||||||
|
|
||||||
|
|
||||||
class ParametersTab(PropTab):
|
class ParametersTab(PropTab):
|
||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None):
|
||||||
super(ParametersTab, self).__init__(parent)
|
super(ParametersTab, self).__init__(parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user