try to make filtering work
This commit is contained in:
parent
b953377c58
commit
addb8ae815
48
QtPyLoT.py
48
QtPyLoT.py
@ -34,7 +34,7 @@ from obspy.core import UTCDateTime
|
|||||||
|
|
||||||
from pylot.core.read import Data, FilterOptions
|
from pylot.core.read import Data, FilterOptions
|
||||||
from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \
|
from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \
|
||||||
checkurl, FormatError, layoutStationButtons, FilterOptionsDialog, \
|
checkurl, FormatError, FilterOptionsDialog, \
|
||||||
NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \
|
NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \
|
||||||
DatastructureError
|
DatastructureError
|
||||||
from pylot.core.util.structure import DATASTRUCTURE
|
from pylot.core.util.structure import DATASTRUCTURE
|
||||||
@ -62,8 +62,6 @@ class MainWindow(QMainWindow):
|
|||||||
self.fnames = None
|
self.fnames = None
|
||||||
self.dataStructure = DATASTRUCTURE[
|
self.dataStructure = DATASTRUCTURE[
|
||||||
settings.value("data/Structure", None)]()
|
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.seismicPhase = str(settings.value("phase", "P"))
|
||||||
self.dispComponent = str(settings.value("plotting/dispComponent", "Z"))
|
self.dispComponent = str(settings.value("plotting/dispComponent", "Z"))
|
||||||
if settings.value("data/dataRoot", None) is None:
|
if settings.value("data/dataRoot", None) is None:
|
||||||
@ -72,14 +70,9 @@ class MainWindow(QMainWindow):
|
|||||||
settings.setValue("data/dataRoot", dirname)
|
settings.setValue("data/dataRoot", dirname)
|
||||||
settings.sync()
|
settings.sync()
|
||||||
|
|
||||||
# initialize filter parameter
|
self.filteroptions = {}
|
||||||
filterOptionsP = FILTERDEFAULTS['P']
|
|
||||||
filterOptionsS = FILTERDEFAULTS['S']
|
|
||||||
|
|
||||||
self.filterOptionsP = FilterOptions(**filterOptionsP)
|
# UI has to be set up before(!) children widgets are about to show up
|
||||||
self.filterOptionsS = FilterOptions(**filterOptionsS)
|
|
||||||
|
|
||||||
# UI has to be set up before(!) children widgets are
|
|
||||||
self.setupUi()
|
self.setupUi()
|
||||||
|
|
||||||
# initialize event data
|
# initialize event data
|
||||||
@ -105,6 +98,7 @@ class MainWindow(QMainWindow):
|
|||||||
except:
|
except:
|
||||||
self.startTime = UTCDateTime()
|
self.startTime = UTCDateTime()
|
||||||
|
|
||||||
|
self.setWindowTitle("PyLoT - do seismic processing the python way")
|
||||||
self.setWindowIcon(QIcon(":/icon.ico"))
|
self.setWindowIcon(QIcon(":/icon.ico"))
|
||||||
|
|
||||||
xlab = self.startTime.strftime('seconds since %d %b %Y %H:%M:%S (%Z)')
|
xlab = self.startTime.strftime('seconds since %d %b %Y %H:%M:%S (%Z)')
|
||||||
@ -272,9 +266,8 @@ class MainWindow(QMainWindow):
|
|||||||
action = self.sender()
|
action = self.sender()
|
||||||
if isinstance(action, QAction):
|
if isinstance(action, QAction):
|
||||||
if action.data() is None:
|
if action.data() is None:
|
||||||
filt = "Supported event formats (*.mat *.qml *.xml " \
|
filt = "Supported event formats (*.mat *.qml *.xml *.kor *.evt)"
|
||||||
"*.kor *.evt)"
|
caption = "Open an event file"
|
||||||
caption = 'Select event to open'
|
|
||||||
fname = QFileDialog().getOpenFileName(self,
|
fname = QFileDialog().getOpenFileName(self,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
filter=filt)
|
filter=filt)
|
||||||
@ -399,24 +392,35 @@ class MainWindow(QMainWindow):
|
|||||||
filterOptions=self.getFilterOptions())
|
filterOptions=self.getFilterOptions())
|
||||||
if filterDlg.exec_():
|
if filterDlg.exec_():
|
||||||
filteroptions = filterDlg.getFilterOptions()
|
filteroptions = filterDlg.getFilterOptions()
|
||||||
|
|
||||||
assert isinstance(filteroptions, FilterOptions)
|
assert isinstance(filteroptions, FilterOptions)
|
||||||
self.setFilterOptions(filteroptions)
|
self.setFilterOptions(filteroptions)
|
||||||
|
|
||||||
def getFilterOptions(self):
|
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
|
return self.filteroptions
|
||||||
|
|
||||||
def setFilterOptions(self, filterOptions):
|
def setFilterOptions(self, filterOptions, seismicPhase=None):
|
||||||
cases = {'P': self.filterOptionsP,
|
if seismicPhase is None:
|
||||||
'S': self.filterOptionsS}
|
self.getFilters()[self.getSeismicPhase()] = filterOptions
|
||||||
cases[self.getSeismicPhase()] = filterOptions
|
else:
|
||||||
self.updateFilterOptions()
|
self.getFilters()[seismicPhase] = filterOptions
|
||||||
|
|
||||||
|
|
||||||
def updateFilterOptions(self):
|
def updateFilterOptions(self):
|
||||||
try:
|
try:
|
||||||
self.filteroptions = [self.filterOptionsP
|
settings = QSettings()
|
||||||
if not self.seismicPhase == 'S'
|
if settings.value("filterdefaults", None) is None and not self.getFilters():
|
||||||
else self.filterOptionsS][0]
|
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:
|
except Exception, e:
|
||||||
self.updateStatus('Error ...')
|
self.updateStatus('Error ...')
|
||||||
emsg = QErrorMessage(self)
|
emsg = QErrorMessage(self)
|
||||||
|
@ -174,9 +174,9 @@ class FilterOptions(object):
|
|||||||
Type:\t\t{ftype}\n
|
Type:\t\t{ftype}\n
|
||||||
Frequencies:\t{freq}\n
|
Frequencies:\t{freq}\n
|
||||||
Order:\t\t{order}\n
|
Order:\t\t{order}\n
|
||||||
'''.format(ftype=self.getFilterType,
|
'''.format(ftype=self.getFilterType(),
|
||||||
freq=self.getFreq,
|
freq=self.getFreq(),
|
||||||
order=self.getOrder)
|
order=self.getOrder())
|
||||||
return hrs
|
return hrs
|
||||||
|
|
||||||
def getFreq(self):
|
def getFreq(self):
|
||||||
|
@ -296,33 +296,45 @@ class FilterOptionsDialog(QDialog):
|
|||||||
"""
|
"""
|
||||||
super(FilterOptionsDialog, self).__init__()
|
super(FilterOptionsDialog, self).__init__()
|
||||||
|
|
||||||
if filterOptions is not None and parent.getSeismicPhase() != "P":
|
if parent is not None:
|
||||||
self.filterOptions = filterOptions
|
self.filterOptions = parent.getFilterOptions()
|
||||||
else:
|
else:
|
||||||
self.filterOptions = FilterOptions()
|
self.filterOptions = FilterOptions()
|
||||||
|
|
||||||
|
_enable = True
|
||||||
|
if self.getFilterOptions().getFilterType() is None:
|
||||||
|
_enable = False
|
||||||
|
|
||||||
self.freqminLabel = QLabel()
|
self.freqminLabel = QLabel()
|
||||||
self.freqminLabel.setText("minimum:")
|
self.freqminLabel.setText("minimum:")
|
||||||
self.freqminSpinBox = QDoubleSpinBox()
|
self.freqminSpinBox = QDoubleSpinBox()
|
||||||
self.freqminSpinBox.setRange(5e-7, 1e6)
|
self.freqminSpinBox.setRange(5e-7, 1e6)
|
||||||
self.freqminSpinBox.setDecimals(2)
|
self.freqminSpinBox.setDecimals(2)
|
||||||
self.freqminSpinBox.setSuffix(' Hz')
|
self.freqminSpinBox.setSuffix(' Hz')
|
||||||
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
|
self.freqminSpinBox.setEnabled(_enable)
|
||||||
|
|
||||||
self.freqmaxLabel = QLabel()
|
self.freqmaxLabel = QLabel()
|
||||||
self.freqmaxLabel.setText("maximum:")
|
self.freqmaxLabel.setText("maximum:")
|
||||||
self.freqmaxSpinBox = QDoubleSpinBox()
|
self.freqmaxSpinBox = QDoubleSpinBox()
|
||||||
self.freqmaxSpinBox.setRange(5e-7, 1e6)
|
self.freqmaxSpinBox.setRange(5e-7, 1e6)
|
||||||
self.freqmaxSpinBox.setDecimals(2)
|
self.freqmaxSpinBox.setDecimals(2)
|
||||||
self.freqmaxSpinBox.setSuffix(' Hz')
|
self.freqmaxSpinBox.setSuffix(' Hz')
|
||||||
|
self.freqmaxSpinBox.setEnabled(_enable)
|
||||||
|
if _enable:
|
||||||
|
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
|
||||||
if self.getFilterOptions().getFilterType() in ['bandpass', 'bandstop']:
|
if self.getFilterOptions().getFilterType() in ['bandpass', 'bandstop']:
|
||||||
self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq()[1])
|
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 = QLabel()
|
||||||
self.orderLabel.setText("Order:")
|
self.orderLabel.setText("Order:")
|
||||||
self.orderSpinBox = QSpinBox()
|
self.orderSpinBox = QSpinBox()
|
||||||
self.orderSpinBox.setRange(2, 10)
|
self.orderSpinBox.setRange(2, 10)
|
||||||
|
self.orderSpinBox.setEnabled(_enable)
|
||||||
self.selectTypeLabel = QLabel()
|
self.selectTypeLabel = QLabel()
|
||||||
self.selectTypeLabel.setText("Select filter type:")
|
self.selectTypeLabel.setText("Select filter type:")
|
||||||
self.selectTypeCombo = QComboBox()
|
self.selectTypeCombo = QComboBox()
|
||||||
@ -358,6 +370,7 @@ class FilterOptionsDialog(QDialog):
|
|||||||
self.buttonBox.accepted.connect(self.accept)
|
self.buttonBox.accepted.connect(self.accept)
|
||||||
self.buttonBox.rejected.connect(self.reject)
|
self.buttonBox.rejected.connect(self.reject)
|
||||||
|
|
||||||
|
|
||||||
def updateUi(self):
|
def updateUi(self):
|
||||||
if self.selectTypeCombo.currentText() not in ['bandpass', 'bandstop']:
|
if self.selectTypeCombo.currentText() not in ['bandpass', 'bandstop']:
|
||||||
self.freqminLabel.setText("cutoff:")
|
self.freqminLabel.setText("cutoff:")
|
||||||
|
Loading…
Reference in New Issue
Block a user