WIP on autopick settings widget

This commit is contained in:
Marcel Paffrath 2017-05-10 11:06:55 +02:00
parent 29915f3669
commit aeaa13e277
3 changed files with 184 additions and 2 deletions

View File

@ -1 +1 @@
3090-dirty 2991-dirty

View File

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from pylot.core.util.errors import ParameterError from pylot.core.util.errors import ParameterError
import default_parameters
class AutoPickParameter(object): class AutoPickParameter(object):
''' '''
@ -44,6 +44,8 @@ class AutoPickParameter(object):
contain all parameters. contain all parameters.
''' '''
self.__init_default_paras()
self.__init_subsettings()
self.__filename = fnin self.__filename = fnin
parFileCont = {} parFileCont = {}
# io from parsed arguments alternatively # io from parsed arguments alternatively
@ -100,6 +102,19 @@ class AutoPickParameter(object):
string += 'Empty parameter dictionary.' string += 'Empty parameter dictionary.'
return string return string
# Set default values of parameter names
def __init_default_paras(self):
parameters=default_parameters.defaults
self.__defaults = parameters
def __init_subsettings(self):
self._settings_main=default_parameters.settings_main
self._settings_nlloc=default_parameters.settings_nlloc
self._settings_smoment=default_parameters.settings_smoment
self._settings_focmec=default_parameters.settings_focmec
self._settings_common_pick=default_parameters.settings_common_pick
self._settings_special_pick=default_parameters.settings_special_pick
# String representation of the object # String representation of the object
def __repr__(self): def __repr__(self):
return "AutoPickParameter('%s')" % self.__filename return "AutoPickParameter('%s')" % self.__filename
@ -147,6 +162,47 @@ class AutoPickParameter(object):
self._printParameterError(e) self._printParameterError(e)
raise ParameterError(e) raise ParameterError(e)
def get_defaults(self):
return self.__defaults
def get_main_para_names(self):
return self._settings_main
def get_nlloc_para_names(self):
return self._settings_nlloc
def get_seis_moment_para_names(self):
return self._settings_smoment
def get_focmec_para_names(self):
return self._settings_focmec
def get_common_pick_names(self):
return self._settings_common_pick
def get_special_pick_names(self):
return self._settings_special_pick
# main_settings = parameter[:8]
# main_settings
# paramter[8]
# parameter[8]
# parameter[8:14]
# nlloc_settings = parameter[8:14]
# len(nlloc_settings)
# sm_settings = parameter[14:17]
# sm_settings
# fmec_settings = parmeter[17]
# fmec_settings = parameter[17]
# fmec_settings
# common_picker_settings = parameter[18:26]
# common_picker_settings
# special_picker_settings = parameter[18:]
def setParam(self, **kwargs): def setParam(self, **kwargs):
for param, value in kwargs.items(): for param, value in kwargs.items():
self.__setitem__(param, value) self.__setitem__(param, value)

View File

@ -1574,6 +1574,132 @@ class LocalisationTab(PropTab):
values = {"nll/rootPath": self.rootedit.setText("%s" % nllocroot), values = {"nll/rootPath": self.rootedit.setText("%s" % nllocroot),
"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.QHBoxLayout()
self.layout.addWidget(self.tabs)
self.setLayout(self.layout)
self.add_main_parameters_tab()
self.add_special_pick_parameters_tab()
def init_boxes(self, parameter_names, defaults=True):
self.boxes = {}
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 type(default_item['type']) == str:
if defaults:
value = default_item['value']
typ = default_item['type']
box = self.create_box(value, typ, tooltip)
self.boxes[name] = box
elif type(default_item['type']) == tuple:
boxes = []
if defaults:
values = default_item['value']
for index2, val in enumerate(values):
typ = default_item['type'][index2]
boxes.append(self.create_box(val, 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, value, typ, tooltip):
if typ == 'str':
box = QtGui.QLineEdit()
box.setText(value)
elif typ == 'float':
box = QtGui.QSpinBox()
box.setMaximum(100*value)
box.setValue(value)
elif typ == 'int':
box = QtGui.QSpinBox()
box.setMaximum(100*value)
box.setValue(value)
elif typ == 'bool':
box = QtGui.QCheckBox()
box.setChecked(value)
#box.setToolTip(tooltip)
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):
vb_layout = QtGui.QVBoxLayout()
vb_layout.addWidget(self.gen_headline('Directories'))
vb_layout.addLayout(self.init_boxes(self.ap.get_main_para_names()))
vb_layout.addWidget(self.gen_h_seperator())
vb_layout.addWidget(self.gen_headline('NLLoc'))
vb_layout.addLayout(self.init_boxes(self.ap.get_nlloc_para_names()))
vb_layout.addWidget(self.gen_h_seperator())
vb_layout.addWidget(self.gen_headline('Seismic Moment'))
vb_layout.addLayout(self.init_boxes(self.ap.get_seis_moment_para_names()))
vb_layout.addWidget(self.gen_h_seperator())
vb_layout.addWidget(self.gen_headline('Focal Mechanism'))
vb_layout.addLayout(self.init_boxes(self.ap.get_focmec_para_names()))
vb_layout.addWidget(self.gen_h_seperator())
vb_layout.addWidget(self.gen_headline('Pick Settings'))
vb_layout.addLayout(self.init_boxes(self.ap.get_common_pick_names()))
self.add_tab(vb_layout, 'Main 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_special_pick_parameters_tab(self):
grid = self.init_boxes(self.ap.get_special_pick_names())
self.add_tab(grid, 'Advanced Settings')
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)