[add] phase defaults for phasesTab
This commit is contained in:
parent
7748a39a72
commit
c644095b5a
@ -2583,7 +2583,8 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def PyLoTprefs(self):
|
def PyLoTprefs(self):
|
||||||
if not self._props:
|
if not self._props:
|
||||||
self._props = PropertiesDlg(self, infile=self.infile)
|
self._props = PropertiesDlg(self, infile=self.infile,
|
||||||
|
inputs=self._inputs)
|
||||||
|
|
||||||
if self._props.exec_():
|
if self._props.exec_():
|
||||||
self.init_wfWidget()
|
self.init_wfWidget()
|
||||||
|
@ -38,6 +38,7 @@ from PySide.QtWebKit import QWebView
|
|||||||
from obspy import Stream, UTCDateTime
|
from obspy import Stream, UTCDateTime
|
||||||
from obspy.core.util import AttribDict
|
from obspy.core.util import AttribDict
|
||||||
from obspy.taup import TauPyModel
|
from obspy.taup import TauPyModel
|
||||||
|
from obspy.taup.utils import get_phase_names
|
||||||
from pylot.core.io.data import Data
|
from pylot.core.io.data import Data
|
||||||
from pylot.core.io.inputs import FilterOptions, PylotParameter
|
from pylot.core.io.inputs import FilterOptions, PylotParameter
|
||||||
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
||||||
@ -48,6 +49,7 @@ from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
|
|||||||
demeanTrace, isSorted, findComboBoxIndex, clims
|
demeanTrace, isSorted, findComboBoxIndex, clims
|
||||||
from autoPyLoT import autoPyLoT
|
from autoPyLoT import autoPyLoT
|
||||||
from pylot.core.util.thread import Thread
|
from pylot.core.util.thread import Thread
|
||||||
|
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info.major == 3:
|
||||||
import icons_rc_3 as icons_rc
|
import icons_rc_3 as icons_rc
|
||||||
elif sys.version_info.major == 2:
|
elif sys.version_info.major == 2:
|
||||||
@ -61,6 +63,7 @@ if pg:
|
|||||||
pg.setConfigOptions(antialias=True)
|
pg.setConfigOptions(antialias=True)
|
||||||
# pg.setConfigOption('leftButtonPan', False)
|
# pg.setConfigOption('leftButtonPan', False)
|
||||||
|
|
||||||
|
|
||||||
def getDataType(parent):
|
def getDataType(parent):
|
||||||
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
||||||
["manual", "automatic"])
|
["manual", "automatic"])
|
||||||
@ -72,6 +75,7 @@ def getDataType(parent):
|
|||||||
|
|
||||||
return type
|
return type
|
||||||
|
|
||||||
|
|
||||||
def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None,
|
def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None,
|
||||||
title=None):
|
title=None):
|
||||||
# try method or data
|
# try method or data
|
||||||
@ -91,6 +95,7 @@ def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None,
|
|||||||
|
|
||||||
return _axes
|
return _axes
|
||||||
|
|
||||||
|
|
||||||
def createAction(parent, text, slot=None, shortcut=None, icon=None,
|
def createAction(parent, text, slot=None, shortcut=None, icon=None,
|
||||||
tip=None, checkable=False):
|
tip=None, checkable=False):
|
||||||
"""
|
"""
|
||||||
@ -109,6 +114,7 @@ def createAction(parent, text, slot=None, shortcut=None, icon=None,
|
|||||||
action.setCheckable(True)
|
action.setCheckable(True)
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
|
||||||
class ComparisonDialog(QDialog):
|
class ComparisonDialog(QDialog):
|
||||||
def __init__(self, c, parent=None):
|
def __init__(self, c, parent=None):
|
||||||
self._data = c
|
self._data = c
|
||||||
@ -736,8 +742,69 @@ class WaveformWidget(FigureCanvas):
|
|||||||
axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
|
axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
|
||||||
|
|
||||||
|
|
||||||
|
class PhaseDefaults(QtGui.QDialog):
|
||||||
|
def __init__(self, parent=None, nrow=10,
|
||||||
|
phase_defaults=['P', 'S'],
|
||||||
|
current_phases=[]):
|
||||||
|
super(PhaseDefaults, self).__init__(parent)
|
||||||
|
self.nrow = nrow
|
||||||
|
self.main_layout = QtGui.QVBoxLayout()
|
||||||
|
self.sub_layout = QtGui.QGridLayout()
|
||||||
|
self.phase_names = phase_defaults
|
||||||
|
self.current_phases = current_phases
|
||||||
|
self.setButtons()
|
||||||
|
self.setupUi()
|
||||||
|
self.connectSignals()
|
||||||
|
self.setWindowTitle('Default Phases')
|
||||||
|
self.selected_phases = []
|
||||||
|
|
||||||
|
def setButtons(self):
|
||||||
|
self._buttonbox = QDialogButtonBox(QDialogButtonBox.Ok |
|
||||||
|
QDialogButtonBox.Cancel)
|
||||||
|
|
||||||
|
def setupUi(self):
|
||||||
|
self.setLayout(self.main_layout)
|
||||||
|
self.main_layout.addLayout(self.sub_layout)
|
||||||
|
self.init_phase_layout()
|
||||||
|
self.main_layout.addWidget(self._buttonbox)
|
||||||
|
|
||||||
|
def connectSignals(self):
|
||||||
|
self._buttonbox.accepted.connect(self.accept)
|
||||||
|
self._buttonbox.rejected.connect(self.reject)
|
||||||
|
|
||||||
|
def init_phase_layout(self):
|
||||||
|
self._checkboxes = {}
|
||||||
|
row = 0
|
||||||
|
column = 0
|
||||||
|
for index, phase in enumerate(self.phase_names):
|
||||||
|
if row > self.nrow:
|
||||||
|
column += 1
|
||||||
|
row = 0
|
||||||
|
checkbox = self.create_phase_box(phase)
|
||||||
|
self.sub_layout.addWidget(checkbox,
|
||||||
|
row, column)
|
||||||
|
self._checkboxes[phase] = checkbox
|
||||||
|
checkbox.setChecked(bool(phase in self.current_phases))
|
||||||
|
row += 1
|
||||||
|
|
||||||
|
def create_phase_box(self, phase_name):
|
||||||
|
checkbox = QtGui.QCheckBox(phase_name)
|
||||||
|
return checkbox
|
||||||
|
|
||||||
|
def update_selected_phases(self):
|
||||||
|
self.selected_phases = []
|
||||||
|
for phase in self.phase_names:
|
||||||
|
if self._checkboxes[phase].isChecked():
|
||||||
|
self.selected_phases.append(phase)
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
self.update_selected_phases()
|
||||||
|
QtGui.QDialog.accept(self)
|
||||||
|
|
||||||
|
|
||||||
class PickDlg(QDialog):
|
class PickDlg(QDialog):
|
||||||
update_picks = QtCore.Signal(dict)
|
update_picks = QtCore.Signal(dict)
|
||||||
|
|
||||||
def __init__(self, parent=None, data=None, station=None, network=None, picks=None,
|
def __init__(self, parent=None, data=None, station=None, network=None, picks=None,
|
||||||
autopicks=None, rotate=False, parameter=None, embedded=False, model='iasp91'):
|
autopicks=None, rotate=False, parameter=None, embedded=False, model='iasp91'):
|
||||||
super(PickDlg, self).__init__(parent)
|
super(PickDlg, self).__init__(parent)
|
||||||
@ -1460,7 +1527,7 @@ class PickDlg(QDialog):
|
|||||||
horiz_comp = find_horizontals(data)
|
horiz_comp = find_horizontals(data)
|
||||||
data = scaleWFData(data, noiselevel * 2.5, horiz_comp)
|
data = scaleWFData(data, noiselevel * 2.5, horiz_comp)
|
||||||
|
|
||||||
x_res = getResolutionWindow(snr, parameter.get('extent'))
|
x_res = getResolutionWindow(snr, parameter.get('inp'))
|
||||||
|
|
||||||
self.setXLims(tuple([ini_pick - x_res, ini_pick + x_res]))
|
self.setXLims(tuple([ini_pick - x_res, ini_pick + x_res]))
|
||||||
traces = self.getTraceID(horiz_comp)
|
traces = self.getTraceID(horiz_comp)
|
||||||
@ -1506,8 +1573,6 @@ class PickDlg(QDialog):
|
|||||||
'Denied', 'setPick: Could not filter waveform: {}'.format(e))
|
'Denied', 'setPick: Could not filter waveform: {}'.format(e))
|
||||||
self.qmb.show()
|
self.qmb.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# get earliest and latest possible pick and symmetric pick error
|
# get earliest and latest possible pick and symmetric pick error
|
||||||
if wfdata[0].stats.channel[2] == 'Z' or wfdata[0].stats.channel[2] == '3':
|
if wfdata[0].stats.channel[2] == 'Z' or wfdata[0].stats.channel[2] == '3':
|
||||||
nfac = parameter.get('nfacP')
|
nfac = parameter.get('nfacP')
|
||||||
@ -1867,6 +1932,7 @@ class TuneAutopicker(QWidget):
|
|||||||
:param: parent
|
:param: parent
|
||||||
:type: QtPyLoT Mainwindow
|
:type: QtPyLoT Mainwindow
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QtGui.QWidget.__init__(self, parent, 1)
|
QtGui.QWidget.__init__(self, parent, 1)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
@ -2268,6 +2334,7 @@ class TuneAutopicker(QWidget):
|
|||||||
class PylotParaBox(QtGui.QWidget):
|
class PylotParaBox(QtGui.QWidget):
|
||||||
accepted = QtCore.Signal(str)
|
accepted = QtCore.Signal(str)
|
||||||
rejected = 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.
|
||||||
@ -2681,16 +2748,17 @@ class PylotParaBox(QtGui.QWidget):
|
|||||||
|
|
||||||
|
|
||||||
class PropertiesDlg(QDialog):
|
class PropertiesDlg(QDialog):
|
||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None, inputs=None):
|
||||||
super(PropertiesDlg, self).__init__(parent)
|
super(PropertiesDlg, self).__init__(parent)
|
||||||
|
|
||||||
self.infile = infile
|
self.infile = infile
|
||||||
|
self.inputs = inputs
|
||||||
|
|
||||||
self.setWindowTitle("PyLoT Properties")
|
self.setWindowTitle("PyLoT Properties")
|
||||||
self.tabWidget = QTabWidget()
|
self.tabWidget = QTabWidget()
|
||||||
self.tabWidget.addTab(InputsTab(self), "Inputs")
|
self.tabWidget.addTab(InputsTab(self), "Inputs")
|
||||||
# self.tabWidget.addTab(OutputsTab(self), "Outputs")
|
# self.tabWidget.addTab(OutputsTab(self), "Outputs")
|
||||||
self.tabWidget.addTab(PhasesTab(self), "Phases")
|
self.tabWidget.addTab(PhasesTab(self, inputs), "Phases")
|
||||||
self.tabWidget.addTab(GraphicsTab(self), "Graphics")
|
self.tabWidget.addTab(GraphicsTab(self), "Graphics")
|
||||||
# self.tabWidget.addTab(LocalisationTab(self), "Loc. Tools")
|
# self.tabWidget.addTab(LocalisationTab(self), "Loc. Tools")
|
||||||
self.tabWidget.addTab(LocalisationTab(self), "NonLinLoc")
|
self.tabWidget.addTab(LocalisationTab(self), "NonLinLoc")
|
||||||
@ -2752,7 +2820,6 @@ class PropertiesDlg(QDialog):
|
|||||||
for values in self._current_values():
|
for values in self._current_values():
|
||||||
self.setValues(values)
|
self.setValues(values)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setValues(tabValues):
|
def setValues(tabValues):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
@ -2858,6 +2925,7 @@ class InputsTab(PropTab):
|
|||||||
"data/Structure": self.structureSelect.setCurrentIndex(index)}
|
"data/Structure": self.structureSelect.setCurrentIndex(index)}
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
class OutputsTab(PropTab):
|
class OutputsTab(PropTab):
|
||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None):
|
||||||
super(OutputsTab, self).__init__(parent)
|
super(OutputsTab, self).__init__(parent)
|
||||||
@ -2889,12 +2957,17 @@ class OutputsTab(PropTab):
|
|||||||
|
|
||||||
|
|
||||||
class PhasesTab(PropTab):
|
class PhasesTab(PropTab):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None, inputs=None):
|
||||||
super(PhasesTab, self).__init__(parent)
|
super(PhasesTab, self).__init__(parent)
|
||||||
|
self.inputs = inputs
|
||||||
|
|
||||||
|
self.Pphases = 'P, Pg, Pn, PmP, P1, P2, P3'
|
||||||
|
self.Sphases = 'S, Sg, Sn, SmS, S1, S2, S3'
|
||||||
|
|
||||||
self.PphasesEdit = QLineEdit()
|
self.PphasesEdit = QLineEdit()
|
||||||
self.SphasesEdit = QLineEdit()
|
self.SphasesEdit = QLineEdit()
|
||||||
|
|
||||||
|
self.pickDefaultsButton = QtGui.QPushButton('Choose default phases...')
|
||||||
PphasesLabel = QLabel("P Phases to pick")
|
PphasesLabel = QLabel("P Phases to pick")
|
||||||
SphasesLabel = QLabel("S Phases to pick")
|
SphasesLabel = QLabel("S Phases to pick")
|
||||||
|
|
||||||
@ -2905,24 +2978,96 @@ class PhasesTab(PropTab):
|
|||||||
self.PphasesEdit.setText("%s" % Pphases)
|
self.PphasesEdit.setText("%s" % Pphases)
|
||||||
self.SphasesEdit.setText("%s" % Sphases)
|
self.SphasesEdit.setText("%s" % Sphases)
|
||||||
|
|
||||||
|
self.main_layout = QtGui.QHBoxLayout()
|
||||||
layout = QGridLayout()
|
layout = QGridLayout()
|
||||||
layout.addWidget(PphasesLabel, 0, 0)
|
layout.addWidget(PphasesLabel, 0, 0)
|
||||||
layout.addWidget(SphasesLabel, 1, 0)
|
layout.addWidget(SphasesLabel, 1, 0)
|
||||||
|
|
||||||
layout.addWidget(self.PphasesEdit, 0, 1)
|
layout.addWidget(self.PphasesEdit, 0, 1)
|
||||||
layout.addWidget(self.SphasesEdit, 1, 1)
|
layout.addWidget(self.SphasesEdit, 1, 1)
|
||||||
self.setLayout(layout)
|
self.main_layout.addLayout(layout)
|
||||||
|
self.main_layout.addWidget(self.pickDefaultsButton)
|
||||||
|
self.setLayout(self.main_layout)
|
||||||
|
|
||||||
|
self.connectSignals()
|
||||||
|
|
||||||
|
def connectSignals(self):
|
||||||
|
self.pickDefaultsButton.clicked.connect(self.get_defaults)
|
||||||
|
|
||||||
|
def get_defaults(self):
|
||||||
|
phases = [p.strip() for p in self.Pphases.split(',')] + [s.strip() for s in self.Sphases.split(',')]
|
||||||
|
p_current = [p.strip() for p in self.PphasesEdit.text().split(',')]
|
||||||
|
s_current = [s.strip() for s in self.SphasesEdit.text().split(',')]
|
||||||
|
|
||||||
|
current_phases = p_current + s_current
|
||||||
|
if self.inputs:
|
||||||
|
parameter = self.inputs
|
||||||
|
if parameter.get('extent') == 'global':
|
||||||
|
# get all default phase names known to obspy.taup
|
||||||
|
# in a list
|
||||||
|
phases = get_phase_names('ttall')
|
||||||
|
phaseDefaults = PhaseDefaults(self, phase_defaults=phases,
|
||||||
|
current_phases=current_phases)
|
||||||
|
if phaseDefaults.exec_():
|
||||||
|
phase_dict = self.sortPhases(phaseDefaults.selected_phases)
|
||||||
|
p_phases=''
|
||||||
|
s_phases=''
|
||||||
|
for index, p in enumerate(phase_dict['P']):
|
||||||
|
p_phases += p
|
||||||
|
if not index == len(phase_dict['P']) - 1:
|
||||||
|
p_phases += ', '
|
||||||
|
for index, s in enumerate(phase_dict['S']):
|
||||||
|
s_phases += s
|
||||||
|
if not index == len(phase_dict['S']) - 1:
|
||||||
|
s_phases += ', '
|
||||||
|
self.PphasesEdit.setText(p_phases)
|
||||||
|
self.SphasesEdit.setText(s_phases)
|
||||||
|
|
||||||
|
def sortPhases(self, phases):
|
||||||
|
sorted_phases = {'P': [],
|
||||||
|
'S': []}
|
||||||
|
# suffix for phase name if not phase identified by last letter (P, p, etc.)
|
||||||
|
alt_PS = ['diff', 'n', 'g', '1', '2', '3'] # alternative suffix
|
||||||
|
for phase in phases:
|
||||||
|
self.loopIdentifyPhase(phase, alt_PS, sorted_phases)
|
||||||
|
return sorted_phases
|
||||||
|
|
||||||
|
def loopIdentifyPhase(self, phase, alt_PS, sorted_phases):
|
||||||
|
phase_copy = phase
|
||||||
|
while not self.identifyPhase(phase_copy):
|
||||||
|
identified = False
|
||||||
|
for alt_suf in alt_PS:
|
||||||
|
if phase_copy.endswith(alt_suf):
|
||||||
|
phase_copy = phase_copy.split(alt_suf)[0]
|
||||||
|
identified = True
|
||||||
|
if not identified:
|
||||||
|
phase_copy = phase_copy[:-1]
|
||||||
|
if len(phase_copy) < 1:
|
||||||
|
print('Warning: Could not identify phase {}!'.format(phase))
|
||||||
|
return
|
||||||
|
sorted_phases[self.identifyPhase(phase_copy)].append(phase)
|
||||||
|
|
||||||
|
def identifyPhase(self, phase):
|
||||||
|
# common phase suffix for P and S
|
||||||
|
common_P = ['P', 'p']
|
||||||
|
common_S = ['S', 's']
|
||||||
|
if phase[-1] in common_P:
|
||||||
|
return 'P'
|
||||||
|
if phase[-1] in common_S:
|
||||||
|
return 'S'
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def getValues(self):
|
def getValues(self):
|
||||||
values = {'p_phases': self.PphasesEdit.text(),
|
p_phases = self.PphasesEdit.text()
|
||||||
's_phases': self.SphasesEdit.text()}
|
s_phases = self.SphasesEdit.text()
|
||||||
|
values = {'p_phases': p_phases,
|
||||||
|
's_phases': s_phases}
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def resetValues(self, infile=None):
|
def resetValues(self, infile=None):
|
||||||
Pphases = 'P, Pg, Pn, PmP, P1, P2, P3'
|
values = {'p_phases': self.PphasesEdit.setText(self.Pphases),
|
||||||
Sphases = 'S, Sg, Sn, SmS, S1, S2, S3'
|
's_phases': self.SphasesEdit.setText(self.Sphases)}
|
||||||
values = {'p_phases': self.PphasesEdit.setText(Pphases),
|
|
||||||
's_phases': self.SphasesEdit.setText(Sphases)}
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user