[update] working on filter bugs WIP

This commit is contained in:
Marcel Paffrath 2017-12-21 13:13:44 +01:00
parent 1296e914c3
commit 8c9fded873
5 changed files with 57 additions and 14 deletions

View File

@ -270,8 +270,8 @@ class MainWindow(QMainWindow):
s_icon.addPixmap(QPixmap(':/icons/key_S.png'))
print_icon = QIcon()
print_icon.addPixmap(QPixmap(':/icons/printer.png'))
filter_icon = QIcon()
filter_icon.addPixmap(QPixmap(':/icons/filter.png'))
self.filter_icon = QIcon()
self.filter_icon.addPixmap(QPixmap(':/icons/filter.png'))
z_icon = QIcon()
z_icon.addPixmap(QPixmap(':/icons/key_Z.png'))
n_icon = QIcon()
@ -367,14 +367,14 @@ class MainWindow(QMainWindow):
None, paraIcon,
"Modify Parameter")
self.filterAction = self.createAction(self, "&Filter ...",
self.filterWaveformData,
"Ctrl+F", filter_icon,
self.plotWaveformDataThread,
"Ctrl+F", self.filter_icon,
"""Toggle un-/filtered waveforms
to be displayed, according to the
desired seismic phase.""", True)
filterEditAction = self.createAction(self, "&Filter parameter ...",
self.adjustFilterOptions,
"Alt+F", filter_icon,
"Alt+F", self.filter_icon,
"""Adjust filter parameters.""")
self.inventoryAction = self.createAction(self, "Select &Inventory ...",
self.get_new_metadata,
@ -1631,6 +1631,7 @@ class MainWindow(QMainWindow):
def finishWaveformDataPlot(self):
self.comparable = self.checkEvents4comparison()
self.filterWaveformData()
if self.pg:
self.finish_pg_plot()
else:
@ -1796,7 +1797,6 @@ class MainWindow(QMainWindow):
self.adjustFilterOptions()
else:
self.get_data().resetWFData()
self.plotWaveformDataThread()
self.drawPicks()
self.draw()

View File

@ -361,7 +361,10 @@ class Data(object):
Filter waveform data
:param kwargs: arguments to pass through to filter function
"""
self.getWFData().filter(**kwargs)
data = self.getWFData()
data.detrend('linear')
data.taper(0.02, type='cosine')
data.filter(**kwargs)
self.dirty = True
def setWFData(self, fnames):
@ -418,7 +421,10 @@ class Data(object):
"""
Set waveform data to original waveform data
"""
self.wfdata = self.getOriginalWFData().copy()
if self.getOriginalWFData():
self.wfdata = self.getOriginalWFData().copy()
else:
self.wfdata = Stream()
self.dirty = False
def resetPicks(self):

View File

@ -439,7 +439,9 @@ class FilterOptions(object):
def parseFilterOptions(self):
if self:
robject = {'type': self.getFilterType(), 'corners': self.getOrder()}
robject = {'type': self.getFilterType(),
'corners': self.getOrder(),
'zerophase': True}
if not self.getFilterType() in ['highpass', 'lowpass']:
robject['freqmin'] = self.getFreq()[0]
robject['freqmax'] = self.getFreq()[1]

View File

@ -1135,7 +1135,7 @@ def identifyPhase(phase):
:rtype: str or bool
"""
# common phase suffix for P and S
common_P = ['P', 'p']
common_P = ['P', 'p', 'R']
common_S = ['S', 's']
if phase[-1] in common_P:
return 'P'

View File

@ -494,6 +494,9 @@ class WaveformWidgetPG(QtGui.QWidget):
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
noiselevel=None, scaleddata=False, mapping=True,
component='*', nth_sample=1, iniPick=None, verbosity=0):
if not wfdata:
print('Nothing to plot.')
return
self.title = title
self.clearPlotDict()
self.wfstart, self.wfend = full_range(wfdata)
@ -924,6 +927,9 @@ class PylotCanvas(FigureCanvas):
# list containing tuples of network, station, channel (for sorting)
nsc = []
for trace in st_select:
if not trace.stats.channel[-1] in ['Z', 'N', 'E', '1', '2', '3']:
print('Warning: Unrecognized channel {}'.format(trace.stats.channel))
continue
nsc.append((trace.stats.network, trace.stats.station, trace.stats.channel))
nsc.sort()
nsc.reverse()
@ -1479,6 +1485,7 @@ class PickDlg(QDialog):
nHotkey = 4 # max hotkeys per phase
hotkey = 1 # start hotkey
# loop over P and S (use explicit list instead of iter over dict.keys to keep order)
for phaseIndex, phaseID in enumerate(['P', 'S']):
# loop through phases in list
@ -1502,6 +1509,16 @@ class PickDlg(QDialog):
if phaseIndex == 0:
picksMenu.addSeparator()
filterAction = createAction(parent=self, text="&Filter parameter ...",
slot=self.filterOptions,
shortcut='Alt+F',
icon=self.orig_parent.filter_icon)
filterMenu = menuBar.addMenu('Filter')
filterMenu.addAction(filterAction)
def filterOptions(self):
self.orig_parent.adjustFilterOptions()
def disable_ar_buttons(self):
self.enable_ar_buttons(False)
@ -4159,9 +4176,25 @@ class FilterOptionsDialog(QDialog):
self.buttonBox.rejected.connect(self.reject)
def accept(self):
if not self.checkMinMax():
QMessageBox.warning(self, "Value error",
"Maximum frequency must be at least the "
"same value as minimum frequency (notch)! "
"Adjusted maximum frequency automatically!")
return
self.updateUi()
QDialog.accept(self)
def checkMinMax(self):
returnvals = []
for foWidget in self.filterOptionWidgets.values():
returnvals.append(foWidget.checkMin())
returnvals.append(foWidget.checkMax())
if all(returnvals):
return True
else:
return False
def updateUi(self):
returnvals = []
for foWidget in self.filterOptionWidgets.values():
@ -4186,7 +4219,7 @@ class FilterOptionsWidget(QWidget):
self.freqminLabel.setText("minimum:")
self.freqminSpinBox = QDoubleSpinBox()
self.freqminSpinBox.setRange(5e-7, 1e6)
self.freqminSpinBox.setDecimals(2)
self.freqminSpinBox.setDecimals(5)
self.freqminSpinBox.setSingleStep(0.01)
self.freqminSpinBox.setSuffix(' Hz')
self.freqminSpinBox.setEnabled(_enable)
@ -4195,7 +4228,7 @@ class FilterOptionsWidget(QWidget):
self.freqmaxLabel.setText("maximum:")
self.freqmaxSpinBox = QDoubleSpinBox()
self.freqmaxSpinBox.setRange(5e-7, 1e6)
self.freqmaxSpinBox.setDecimals(2)
self.freqmaxSpinBox.setDecimals(5)
self.freqmaxSpinBox.setSingleStep(0.01)
self.freqmaxSpinBox.setSuffix(' Hz')
@ -4253,18 +4286,20 @@ class FilterOptionsWidget(QWidget):
self.setLayout(grid)
self.freqminSpinBox.valueChanged.connect(self.checkMin)
self.freqmaxSpinBox.valueChanged.connect(self.checkMax)
self.orderSpinBox.valueChanged.connect(self.updateUi)
self.selectTypeCombo.currentIndexChanged.connect(self.updateUi)
def checkMin(self):
if not self.freqminSpinBox.value() <= self.freqmaxSpinBox.value():
self.freqmaxSpinBox.setValue(self.freqminSpinBox.value())
return False
return True
def checkMax(self):
if not self.freqminSpinBox.value() <= self.freqmaxSpinBox.value():
self.freqminSpinBox.setValue(self.freqmaxSpinBox.value())
return False
return True
def updateUi(self):
type = self.selectTypeCombo.currentText()