try to make filtering work

This commit is contained in:
Sebastian Wehling-Benatelli 2015-03-01 10:31:49 +01:00
parent b953377c58
commit addb8ae815
3 changed files with 48 additions and 31 deletions

View File

@ -34,7 +34,7 @@ from obspy.core import UTCDateTime
from pylot.core.read import Data, FilterOptions
from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \
checkurl, FormatError, layoutStationButtons, FilterOptionsDialog, \
checkurl, FormatError, FilterOptionsDialog, \
NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \
DatastructureError
from pylot.core.util.structure import DATASTRUCTURE
@ -62,8 +62,6 @@ class MainWindow(QMainWindow):
self.fnames = None
self.dataStructure = DATASTRUCTURE[
settings.value("data/Structure", None)]()
self.setWindowTitle("PyLoT - do seismic processing the python way")
self.setWindowIcon(QIcon(":/icon.ico"))
self.seismicPhase = str(settings.value("phase", "P"))
self.dispComponent = str(settings.value("plotting/dispComponent", "Z"))
if settings.value("data/dataRoot", None) is None:
@ -72,14 +70,9 @@ class MainWindow(QMainWindow):
settings.setValue("data/dataRoot", dirname)
settings.sync()
# initialize filter parameter
filterOptionsP = FILTERDEFAULTS['P']
filterOptionsS = FILTERDEFAULTS['S']
self.filteroptions = {}
self.filterOptionsP = FilterOptions(**filterOptionsP)
self.filterOptionsS = FilterOptions(**filterOptionsS)
# UI has to be set up before(!) children widgets are
# UI has to be set up before(!) children widgets are about to show up
self.setupUi()
# initialize event data
@ -105,6 +98,7 @@ class MainWindow(QMainWindow):
except:
self.startTime = UTCDateTime()
self.setWindowTitle("PyLoT - do seismic processing the python way")
self.setWindowIcon(QIcon(":/icon.ico"))
xlab = self.startTime.strftime('seconds since %d %b %Y %H:%M:%S (%Z)')
@ -272,9 +266,8 @@ class MainWindow(QMainWindow):
action = self.sender()
if isinstance(action, QAction):
if action.data() is None:
filt = "Supported event formats (*.mat *.qml *.xml " \
"*.kor *.evt)"
caption = 'Select event to open'
filt = "Supported event formats (*.mat *.qml *.xml *.kor *.evt)"
caption = "Open an event file"
fname = QFileDialog().getOpenFileName(self,
caption=caption,
filter=filt)
@ -399,24 +392,35 @@ class MainWindow(QMainWindow):
filterOptions=self.getFilterOptions())
if filterDlg.exec_():
filteroptions = filterDlg.getFilterOptions()
assert isinstance(filteroptions, FilterOptions)
self.setFilterOptions(filteroptions)
def getFilterOptions(self):
try:
return self.filteroptions[self.getSeismicPhase()]
except AttributeError, e:
print e
return FilterOptions(None, None, None)
def getFilters(self):
return self.filteroptions
def setFilterOptions(self, filterOptions):
cases = {'P': self.filterOptionsP,
'S': self.filterOptionsS}
cases[self.getSeismicPhase()] = filterOptions
self.updateFilterOptions()
def setFilterOptions(self, filterOptions, seismicPhase=None):
if seismicPhase is None:
self.getFilters()[self.getSeismicPhase()] = filterOptions
else:
self.getFilters()[seismicPhase] = filterOptions
def updateFilterOptions(self):
try:
self.filteroptions = [self.filterOptionsP
if not self.seismicPhase == 'S'
else self.filterOptionsS][0]
settings = QSettings()
if settings.value("filterdefaults", None) is None and not self.getFilters():
for key, value in FILTERDEFAULTS.iteritems():
self.setFilterOptions(FilterOptions(**value), key)
elif settings.value("filterdefaults", None) is not None:
for key, value in settings.value("filterdefaults"):
self.setFilterOptions(FilterOptions(**value), key)
except Exception, e:
self.updateStatus('Error ...')
emsg = QErrorMessage(self)

View File

@ -174,9 +174,9 @@ class FilterOptions(object):
Type:\t\t{ftype}\n
Frequencies:\t{freq}\n
Order:\t\t{order}\n
'''.format(ftype=self.getFilterType,
freq=self.getFreq,
order=self.getOrder)
'''.format(ftype=self.getFilterType(),
freq=self.getFreq(),
order=self.getOrder())
return hrs
def getFreq(self):

View File

@ -296,33 +296,45 @@ class FilterOptionsDialog(QDialog):
"""
super(FilterOptionsDialog, self).__init__()
if filterOptions is not None and parent.getSeismicPhase() != "P":
self.filterOptions = filterOptions
if parent is not None:
self.filterOptions = parent.getFilterOptions()
else:
self.filterOptions = FilterOptions()
_enable = True
if self.getFilterOptions().getFilterType() is None:
_enable = False
self.freqminLabel = QLabel()
self.freqminLabel.setText("minimum:")
self.freqminSpinBox = QDoubleSpinBox()
self.freqminSpinBox.setRange(5e-7, 1e6)
self.freqminSpinBox.setDecimals(2)
self.freqminSpinBox.setSuffix(' Hz')
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
self.freqminSpinBox.setEnabled(_enable)
self.freqmaxLabel = QLabel()
self.freqmaxLabel.setText("maximum:")
self.freqmaxSpinBox = QDoubleSpinBox()
self.freqmaxSpinBox.setRange(5e-7, 1e6)
self.freqmaxSpinBox.setDecimals(2)
self.freqmaxSpinBox.setSuffix(' Hz')
if self.getFilterOptions().getFilterType() in ['bandpass', 'bandstop']:
self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq()[1])
self.freqmaxSpinBox.setEnabled(_enable)
if _enable:
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
if self.getFilterOptions().getFilterType() in ['bandpass', 'bandstop']:
self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq()[1])
else:
self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq())
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq())
typeOptions = ["bandpass", "bandstop", "lowpass", "highpass"]
typeOptions = [None, "bandpass", "bandstop", "lowpass", "highpass"]
self.orderLabel = QLabel()
self.orderLabel.setText("Order:")
self.orderSpinBox = QSpinBox()
self.orderSpinBox.setRange(2, 10)
self.orderSpinBox.setEnabled(_enable)
self.selectTypeLabel = QLabel()
self.selectTypeLabel.setText("Select filter type:")
self.selectTypeCombo = QComboBox()
@ -358,6 +370,7 @@ class FilterOptionsDialog(QDialog):
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
def updateUi(self):
if self.selectTypeCombo.currentText() not in ['bandpass', 'bandstop']:
self.freqminLabel.setText("cutoff:")