[change] several updates updates to filterOptions, FILTERDEFAULTS now loaded from pylot.in, filterOptions should be 'shared' between filterOptionsDialog and pylotParameter

This commit is contained in:
Marcel Paffrath 2017-07-11 16:03:24 +02:00
parent 0e566f9748
commit 1d9e52f577
5 changed files with 70 additions and 53 deletions

View File

@ -65,7 +65,8 @@ from pylot.core.pick.compare import Comparison
from pylot.core.pick.utils import symmetrize_error from pylot.core.pick.utils import symmetrize_error
from pylot.core.io.phases import picksdict_from_picks from pylot.core.io.phases import picksdict_from_picks
import pylot.core.loc.nll as nll import pylot.core.loc.nll as nll
from pylot.core.util.defaults import FILTERDEFAULTS, OUTPUTFORMATS, SetChannelComponents from pylot.core.util.defaults import FILTERDEFAULTS, OUTPUTFORMATS, SetChannelComponents, \
readFilterInformation
from pylot.core.util.errors import FormatError, DatastructureError, \ from pylot.core.util.errors import FormatError, DatastructureError, \
OverwriteError, ProcessingError OverwriteError, ProcessingError
from pylot.core.util.connection import checkurl from pylot.core.util.connection import checkurl
@ -180,8 +181,15 @@ class MainWindow(QMainWindow):
# setup UI # setup UI
self.setupUi() self.setupUi()
self.filteroptions = {'P': FilterOptions(), filter_info = readFilterInformation(self._inputs)
'S': FilterOptions()} p_filter = filter_info['P']
s_filter = filter_info['S']
self.filteroptions = {'P': FilterOptions(p_filter['filtertype'],
p_filter['freq'],
p_filter['order']),
'S': FilterOptions(s_filter['filtertype'],
s_filter['freq'],
s_filter['order'])}
self.pylot_picks = {} self.pylot_picks = {}
self.pylot_autopicks = {} self.pylot_autopicks = {}
self.loc = False self.loc = False
@ -1543,16 +1551,23 @@ class MainWindow(QMainWindow):
def adjustFilterOptions(self): def adjustFilterOptions(self):
fstring = "Filter Options" fstring = "Filter Options"
filterDlg = FilterOptionsDialog(titleString=fstring, self.filterDlg = FilterOptionsDialog(titleString=fstring,
parent=self) parent=self)
if filterDlg.exec_(): if self.filterDlg.exec_():
filteroptions = filterDlg.getFilterOptions() filteroptions = self.filterDlg.getFilterOptions()
self.setFilterOptions(filteroptions) self.setFilterOptions(filteroptions)
if self.filterAction.isChecked(): if self.filterAction.isChecked():
kwargs = self.getFilterOptions().parseFilterOptions() kwargs = self.getFilterOptions().parseFilterOptions()
self.pushFilterWF(kwargs) self.pushFilterWF(kwargs)
self.plotWaveformDataThread() self.plotWaveformDataThread()
def checkFilterOptions(self):
fstring = "Filter Options"
self.filterDlg = FilterOptionsDialog(titleString=fstring,
parent=self)
filteroptions = self.filterDlg.getFilterOptions()
self.setFilterOptions(filteroptions)
def getFilterOptions(self): def getFilterOptions(self):
return self.filteroptions return self.filteroptions
# try: # try:
@ -1584,7 +1599,7 @@ class MainWindow(QMainWindow):
maxP, maxS = self._inputs['maxfreq'] maxP, maxS = self._inputs['maxfreq']
orderP, orderS = self._inputs['filter_order'] orderP, orderS = self._inputs['filter_order']
typeP, typeS = self._inputs['filter_type'] typeP, typeS = self._inputs['filter_type']
filterP = self.getFilterOptions()['P'] filterP = self.getFilterOptions()['P']
filterP.setFreq([minP, maxP]) filterP.setFreq([minP, maxP])
filterP.setOrder(orderP) filterP.setOrder(orderP)
@ -1595,6 +1610,8 @@ class MainWindow(QMainWindow):
filterS.setOrder(orderS) filterS.setOrder(orderS)
filterS.setFilterType(typeS) filterS.setFilterType(typeS)
self.checkFilterOptions()
def updateFilterOptions(self): def updateFilterOptions(self):
try: try:
settings = QSettings() settings = QSettings()
@ -2496,10 +2513,8 @@ class MainWindow(QMainWindow):
def setParameter(self, show=True): def setParameter(self, show=True):
if not self.paraBox: if not self.paraBox:
self.paraBox = PylotParaBox(self._inputs) self.paraBox = PylotParaBox(self._inputs)
self.paraBox._apply.clicked.connect(self._setDirty) self.paraBox.accepted.connect(self._setDirty)
self.paraBox._okay.clicked.connect(self._setDirty) self.paraBox.accepted.connect(self.filterOptionsFromParameter)
self.paraBox._apply.clicked.connect(self.filterOptionsFromParameter)
self.paraBox._okay.clicked.connect(self.filterOptionsFromParameter)
if show: if show:
self.paraBox.params_to_gui() self.paraBox.params_to_gui()
self.paraBox.show() self.paraBox.show()

View File

@ -50,9 +50,9 @@ for regional distance seismicity
cp path-to-pylot/inputs/autoPyLoT_regional.in ~/.pylot/autoPyLoT.in cp path-to-pylot/inputs/autoPyLoT_regional.in ~/.pylot/autoPyLoT.in
and some extra information on filtering, error estimates (just needed for reading old PILOT data) and the Richter magnitude scaling relation and some extra information on error estimates (just needed for reading old PILOT data) and the Richter magnitude scaling relation
cp path-to-pylot/inputs/filter.in path-to-pylot/inputs/PILOT_TimeErrors.in path-to-pylot/inputs/richter_scaling.data ~/.pylot/ cp path-to-pylot/inputs/PILOT_TimeErrors.in path-to-pylot/inputs/richter_scaling.data ~/.pylot/
You may need to do some modifications to these files. Especially folder names should be reviewed. You may need to do some modifications to these files. Especially folder names should be reviewed.

View File

@ -159,8 +159,7 @@ def buildPyLoT(verbosity=None):
def installPyLoT(verbosity=None): def installPyLoT(verbosity=None):
files_to_copy = {'autoPyLoT_local.in':['~', '.pylot'], files_to_copy = {'autoPyLoT_local.in':['~', '.pylot'],
'autoPyLoT_regional.in':['~', '.pylot'], 'autoPyLoT_regional.in':['~', '.pylot']}
'filter.in':['~', '.pylot']}
if verbosity > 0: if verbosity > 0:
print ('starting installation of PyLoT ...') print ('starting installation of PyLoT ...')
if verbosity > 1: if verbosity > 1:

View File

@ -12,38 +12,27 @@ from pylot.core.loc import hyposat
from pylot.core.loc import hypo71 from pylot.core.loc import hypo71
from pylot.core.loc import hypodd from pylot.core.loc import hypodd
from pylot.core.loc import velest from pylot.core.loc import velest
from pylot.core.io.inputs import PylotParameter
def readDefaultFilterInformation(fname):
def readFilterInformation(fname): pparam = PylotParameter(fname)
def convert2FreqRange(*args): return readFilterInformation(pparam)
if len(args) > 1:
return [float(arg) for arg in args] def readFilterInformation(pylot_parameter):
elif len(args) == 1: p_filter = {'filtertype': pylot_parameter['filter_type'][0],
return float(args[0]) 'freq': [pylot_parameter['minfreq'][0], pylot_parameter['maxfreq'][0]],
return None 'order': int(pylot_parameter['filter_order'][0])}
s_filter = {'filtertype': pylot_parameter['filter_type'][1],
filter_file = open(fname, 'r') 'freq': [pylot_parameter['minfreq'][1], pylot_parameter['maxfreq'][1]],
filter_information = dict() 'order': int(pylot_parameter['filter_order'][1])}
for filter_line in filter_file.readlines(): filter_information = {'P': p_filter,
filter_line = filter_line.split(' ') 'S': s_filter}
for n, pos in enumerate(filter_line):
if pos == '\n':
filter_line[n] = ''
filter_information[filter_line[0]] = {'filtertype': filter_line[1]
if filter_line[1]
else None,
'order': int(filter_line[2])
if filter_line[1]
else None,
'freq': convert2FreqRange(*filter_line[3:])
if filter_line[1]
else None}
return filter_information return filter_information
FILTERDEFAULTS = readFilterInformation(os.path.join(os.path.expanduser('~'), FILTERDEFAULTS = readDefaultFilterInformation(os.path.join(os.path.expanduser('~'),
'.pylot', '.pylot',
'filter.in')) 'pylot.in'))
TIMEERROR_DEFAULTS = os.path.join(os.path.expanduser('~'), TIMEERROR_DEFAULTS = os.path.join(os.path.expanduser('~'),
'.pylot', '.pylot',

View File

@ -2048,7 +2048,7 @@ class TuneAutopicker(QWidget):
return parameters return parameters
def set_stretch(self): def set_stretch(self):
self.tune_layout.setStretch(0, 3) self.tune_layout.setStretch(0, 2)
self.tune_layout.setStretch(1, 1) self.tune_layout.setStretch(1, 1)
def clear_all(self): def clear_all(self):
@ -2079,7 +2079,9 @@ class TuneAutopicker(QWidget):
self.qmb.show() self.qmb.show()
class PylotParaBox(QtGui.QWidget): class PylotParaBox(QtGui.QWidget):
accepted = QtCore.Signal(str)
rejected = QtCore.Signal(str)
def __init__(self, parameter, parent=None): def __init__(self, parameter, parent=None):
''' '''
Generate Widget containing parameters for PyLoT. Generate Widget containing parameters for PyLoT.
@ -2106,7 +2108,9 @@ class PylotParaBox(QtGui.QWidget):
self.params_to_gui() self.params_to_gui()
self._toggle_advanced_settings() self._toggle_advanced_settings()
self.resize(720, 1280) self.resize(720, 1280)
self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
self.accepted.connect(self.params_from_gui)
self.rejected.connect(self.params_to_gui)
def _init_sublayouts(self): def _init_sublayouts(self):
self._main_layout = QtGui.QVBoxLayout() self._main_layout = QtGui.QVBoxLayout()
@ -2137,10 +2141,9 @@ class PylotParaBox(QtGui.QWidget):
self._dialog_buttons.addWidget(self._okay) self._dialog_buttons.addWidget(self._okay)
self._dialog_buttons.addWidget(self._close) self._dialog_buttons.addWidget(self._close)
self._dialog_buttons.addWidget(self._apply) self._dialog_buttons.addWidget(self._apply)
self._okay.clicked.connect(self.params_from_gui) self._okay.clicked.connect(self.accept)
self._okay.clicked.connect(self.close) self._okay.clicked.connect(self.close)
self._apply.clicked.connect(self.params_from_gui) self._apply.clicked.connect(self.accept)
self._close.clicked.connect(self.params_to_gui)
self._close.clicked.connect(self.close) self._close.clicked.connect(self.close)
self.layout.addLayout(self._dialog_buttons) self.layout.addLayout(self._dialog_buttons)
@ -2478,6 +2481,13 @@ class PylotParaBox(QtGui.QWidget):
self._exclusive_widgets = [] self._exclusive_widgets = []
QtGui.QWidget.show(self) QtGui.QWidget.show(self)
def close(self):
self.rejected.emit('reject')
QtGui.QWidget.close(self)
def accept(self):
self.accepted.emit('accept')
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)
@ -3058,8 +3068,10 @@ class FilterOptionsDialog(QDialog):
QDialog.accept(self) QDialog.accept(self)
def updateUi(self): def updateUi(self):
returnvals = []
for foWidget in self.filterOptionWidgets.values(): for foWidget in self.filterOptionWidgets.values():
foWidget.updateUi() returnvals.append(foWidget.updateUi())
return returnvals
def getFilterOptions(self): def getFilterOptions(self):
filteroptions = {'P': self.filterOptionWidgets['P'].getFilterOptions(), filteroptions = {'P': self.filterOptionWidgets['P'].getFilterOptions(),
@ -3174,15 +3186,17 @@ class FilterOptionsWidget(QWidget):
if not isSorted(freq): if not isSorted(freq):
QMessageBox.warning(self, "Value error", QMessageBox.warning(self, "Value error",
"Maximum frequency must be at least the " "Maximum frequency must be at least the "
"same value as minimum frequency (notch)!") "same value as minimum frequency (notch)! "
"Adjusted maximum frequency automatically!")
self.freqmaxSpinBox.setValue(freq[0]) self.freqmaxSpinBox.setValue(freq[0])
self.freqmaxSpinBox.selectAll() self.freqmaxSpinBox.selectAll()
self.freqmaxSpinBox.setFocus() self.freqmaxSpinBox.setFocus()
return return False
self.getFilterOptions().setFilterType(type) self.getFilterOptions().setFilterType(type)
self.getFilterOptions().setFreq(freq) self.getFilterOptions().setFreq(freq)
self.getFilterOptions().setOrder(self.orderSpinBox.value()) self.getFilterOptions().setOrder(self.orderSpinBox.value())
return True
def getFilterOptions(self): def getFilterOptions(self):
return self.filterOptions return self.filterOptions