[add] updates to jackknife from GUI (WIP, experimental)
This commit is contained in:
parent
ed994e987f
commit
a5097e1da6
38
QtPyLoT.py
38
QtPyLoT.py
@ -79,7 +79,7 @@ from pylot.core.util.event import Event
|
|||||||
from pylot.core.io.location import create_creation_info, create_event
|
from pylot.core.io.location import create_creation_info, create_event
|
||||||
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
||||||
WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
||||||
getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg
|
getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, JackknifeWidget
|
||||||
from pylot.core.util.map_projection import map_projection
|
from pylot.core.util.map_projection import map_projection
|
||||||
from pylot.core.util.structure import DATASTRUCTURE
|
from pylot.core.util.structure import DATASTRUCTURE
|
||||||
from pylot.core.util.thread import Thread, Worker
|
from pylot.core.util.thread import Thread, Worker
|
||||||
@ -1815,16 +1815,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.listWidget.addItem(text)
|
self.listWidget.addItem(text)
|
||||||
self.listWidget.scrollToBottom()
|
self.listWidget.scrollToBottom()
|
||||||
|
|
||||||
def tune_autopicker(self):
|
def init_fig_dict(self):
|
||||||
'''
|
|
||||||
Initiates TuneAutopicker widget use to interactively
|
|
||||||
tune parameters for autopicking algorithm.
|
|
||||||
'''
|
|
||||||
# figures and canvas have to be iniated from the main GUI
|
|
||||||
# thread to prevent handling of QPixmap objects outside of
|
|
||||||
# the main thread
|
|
||||||
self.fig_dict = {}
|
self.fig_dict = {}
|
||||||
self.canvas_dict = {}
|
|
||||||
self.fig_keys = [
|
self.fig_keys = [
|
||||||
'mainFig',
|
'mainFig',
|
||||||
'aicFig',
|
'aicFig',
|
||||||
@ -1837,11 +1829,27 @@ class MainWindow(QMainWindow):
|
|||||||
'el_S2pick',
|
'el_S2pick',
|
||||||
'refSpick',
|
'refSpick',
|
||||||
'aicARHfig',
|
'aicARHfig',
|
||||||
|
'jackknife',
|
||||||
|
'wadati'
|
||||||
]
|
]
|
||||||
for key in self.fig_keys:
|
for key in self.fig_keys:
|
||||||
fig = Figure()
|
fig = Figure()
|
||||||
self.fig_dict[key] = fig
|
self.fig_dict[key] = fig
|
||||||
|
|
||||||
|
def init_canvas_dict(self):
|
||||||
|
self.canvas_dict = {}
|
||||||
|
for key in self.fig_keys:
|
||||||
|
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
||||||
|
|
||||||
|
def tune_autopicker(self):
|
||||||
|
'''
|
||||||
|
Initiates TuneAutopicker widget use to interactively
|
||||||
|
tune parameters for autopicking algorithm.
|
||||||
|
'''
|
||||||
|
# figures and canvas have to be iniated from the main GUI
|
||||||
|
# thread to prevent handling of QPixmap objects outside of
|
||||||
|
# the main thread
|
||||||
|
self.init_fig_dict()
|
||||||
#if not self.tap:
|
#if not self.tap:
|
||||||
# init TuneAutopicker object
|
# init TuneAutopicker object
|
||||||
self.tap = TuneAutopicker(self)
|
self.tap = TuneAutopicker(self)
|
||||||
@ -1860,8 +1868,7 @@ class MainWindow(QMainWindow):
|
|||||||
'''
|
'''
|
||||||
Create and fill TuneAutopicker tabs with figure canvas.
|
Create and fill TuneAutopicker tabs with figure canvas.
|
||||||
'''
|
'''
|
||||||
for key in self.fig_keys:
|
self.init_canvas_dict()
|
||||||
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
|
||||||
self.tap.fill_tabs(picked=True)
|
self.tap.fill_tabs(picked=True)
|
||||||
|
|
||||||
def autoPick(self):
|
def autoPick(self):
|
||||||
@ -1883,12 +1890,14 @@ class MainWindow(QMainWindow):
|
|||||||
# self.addListItem('Loading default values from PyLoT-input file %s'
|
# self.addListItem('Loading default values from PyLoT-input file %s'
|
||||||
# % self.infile)
|
# % self.infile)
|
||||||
|
|
||||||
|
self.init_fig_dict()
|
||||||
|
|
||||||
args = {'parameter': self._inputs,
|
args = {'parameter': self._inputs,
|
||||||
'station': 'all',
|
'station': 'all',
|
||||||
'fnames': 'None',
|
'fnames': 'None',
|
||||||
'eventid': self.get_current_event_path(),
|
'eventid': self.get_current_event_path(),
|
||||||
'iplot': 0,
|
'iplot': 0,
|
||||||
'fig_dict': None,
|
'fig_dict': self.fig_dict,
|
||||||
'locflag': 0}
|
'locflag': 0}
|
||||||
|
|
||||||
self.mp_thread = QtCore.QThreadPool()
|
self.mp_thread = QtCore.QThreadPool()
|
||||||
@ -1916,6 +1925,9 @@ class MainWindow(QMainWindow):
|
|||||||
event.addAutopicks(result)
|
event.addAutopicks(result)
|
||||||
self.drawPicks(picktype='auto')
|
self.drawPicks(picktype='auto')
|
||||||
self.draw()
|
self.draw()
|
||||||
|
self.init_canvas_dict()
|
||||||
|
jkw = JackknifeWidget(self, self.canvas_dict['jackknife'])
|
||||||
|
jkw.show()
|
||||||
|
|
||||||
def addPicks(self, station, picks, type='manual'):
|
def addPicks(self, station, picks, type='manual'):
|
||||||
stat_picks = self.getPicksOnStation(station, type)
|
stat_picks = self.getPicksOnStation(station, type)
|
||||||
|
@ -76,13 +76,14 @@ def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None,
|
|||||||
pick.pop('station')
|
pick.pop('station')
|
||||||
all_onsets[station] = pick
|
all_onsets[station] = pick
|
||||||
|
|
||||||
return all_onsets
|
#return all_onsets
|
||||||
|
|
||||||
# quality control
|
# quality control
|
||||||
# median check and jackknife on P-onset times
|
# median check and jackknife on P-onset times
|
||||||
jk_checked_onsets = checkPonsets(all_onsets, mdttolerance, iplot)
|
jk_checked_onsets = checkPonsets(all_onsets, mdttolerance, 1, fig_dict)
|
||||||
|
return jk_checked_onsets
|
||||||
# check S-P times (Wadati)
|
# check S-P times (Wadati)
|
||||||
return wadaticheck(jk_checked_onsets, wdttolerance, iplot)
|
return wadaticheck(jk_checked_onsets, wdttolerance, iplot, fig_dict)
|
||||||
|
|
||||||
|
|
||||||
def call_autopickstation(input_tuple):
|
def call_autopickstation(input_tuple):
|
||||||
|
@ -564,7 +564,7 @@ def select_for_phase(st, phase):
|
|||||||
return sel_st
|
return sel_st
|
||||||
|
|
||||||
|
|
||||||
def wadaticheck(pickdic, dttolerance, iplot):
|
def wadaticheck(pickdic, dttolerance, iplot=0, fig_dict=None):
|
||||||
'''
|
'''
|
||||||
Function to calculate Wadati-diagram from given P and S onsets in order
|
Function to calculate Wadati-diagram from given P and S onsets in order
|
||||||
to detect S pick outliers. If a certain S-P time deviates by dttolerance
|
to detect S pick outliers. If a certain S-P time deviates by dttolerance
|
||||||
@ -794,7 +794,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fi
|
|||||||
return returnflag
|
return returnflag
|
||||||
|
|
||||||
|
|
||||||
def checkPonsets(pickdic, dttolerance, iplot):
|
def checkPonsets(pickdic, dttolerance, iplot=0, fig_dict=None):
|
||||||
'''
|
'''
|
||||||
Function to check statistics of P-onset times: Control deviation from
|
Function to check statistics of P-onset times: Control deviation from
|
||||||
median (maximum adjusted deviation = dttolerance) and apply pseudo-
|
median (maximum adjusted deviation = dttolerance) and apply pseudo-
|
||||||
@ -816,17 +816,19 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
|||||||
# search for good quality P picks
|
# search for good quality P picks
|
||||||
Ppicks = []
|
Ppicks = []
|
||||||
stations = []
|
stations = []
|
||||||
for key in pickdic:
|
for station in pickdic:
|
||||||
if pickdic[key]['P']['weight'] < 4:
|
if pickdic[station]['P']['weight'] < 4:
|
||||||
# add P onsets to list
|
# add P onsets to list
|
||||||
UTCPpick = UTCDateTime(pickdic[key]['P']['mpp'])
|
UTCPpick = UTCDateTime(pickdic[station]['P']['mpp'])
|
||||||
Ppicks.append(UTCPpick.timestamp)
|
Ppicks.append(UTCPpick.timestamp)
|
||||||
stations.append(key)
|
stations.append(station)
|
||||||
|
|
||||||
# apply jackknife bootstrapping on variance of P onsets
|
# apply jackknife bootstrapping on variance of P onsets
|
||||||
print("###############################################")
|
print("###############################################")
|
||||||
print("checkPonsets: Apply jackknife bootstrapping on P-onset times ...")
|
print("checkPonsets: Apply jackknife bootstrapping on P-onset times ...")
|
||||||
[xjack, PHI_pseudo, PHI_sub] = jackknife(Ppicks, 'VAR', 1)
|
[xjack, PHI_pseudo, PHI_sub] = jackknife(Ppicks, 'VAR', 1)
|
||||||
|
if not xjack:
|
||||||
|
return
|
||||||
# get pseudo variances smaller than average variances
|
# get pseudo variances smaller than average variances
|
||||||
# (times safety factor), these picks passed jackknife test
|
# (times safety factor), these picks passed jackknife test
|
||||||
ij = np.where(PHI_pseudo <= 5 * xjack)
|
ij = np.where(PHI_pseudo <= 5 * xjack)
|
||||||
@ -870,21 +872,30 @@ def checkPonsets(pickdic, dttolerance, iplot):
|
|||||||
checkedonsets = pickdic
|
checkedonsets = pickdic
|
||||||
|
|
||||||
if iplot > 0:
|
if iplot > 0:
|
||||||
p1, = plt.plot(np.arange(0, len(Ppicks)), Ppicks, 'ro', markersize=14)
|
if fig_dict:
|
||||||
if len(badstations) < 1 and len(badjkstations) < 1:
|
fig = fig_dict['jackknife']
|
||||||
p2, = plt.plot(np.arange(0, len(Ppicks)), Ppicks, 'go', markersize=14)
|
plt_flag = 0
|
||||||
else:
|
else:
|
||||||
p2, = plt.plot(igood, np.array(Ppicks)[igood], 'go', markersize=14)
|
fig = plt.figure()
|
||||||
p3, = plt.plot([0, len(Ppicks) - 1], [pmedian, pmedian], 'g',
|
plt_flag = 1
|
||||||
linewidth=2)
|
ax = fig.add_subplot(111)
|
||||||
for i in range(0, len(Ppicks)):
|
|
||||||
plt.text(i, Ppicks[i] + 0.01, '{0}'.format(stations[i]))
|
|
||||||
|
|
||||||
plt.xlabel('Number of P Picks')
|
ax.plot(np.arange(0, len(Ppicks)), Ppicks, 'ro', markersize=14)
|
||||||
plt.ylabel('Onset Time [s] from 1.1.1970')
|
if len(badstations) < 1 and len(badjkstations) < 1:
|
||||||
plt.legend([p1, p2, p3], ['Skipped P Picks', 'Good P Picks', 'Median'],
|
ax.plot(np.arange(0, len(Ppicks)), Ppicks, 'go', markersize=14, label='Skipped P Picks')
|
||||||
loc='best')
|
else:
|
||||||
plt.title('Jackknifing and Median Tests on P Onsets')
|
ax.plot(igood, np.array(Ppicks)[igood], 'go', markersize=14, label='Good P Picks')
|
||||||
|
ax.plot([0, len(Ppicks) - 1], [pmedian, pmedian], 'g',
|
||||||
|
linewidth=2, label='Median')
|
||||||
|
for i in range(0, len(Ppicks)):
|
||||||
|
ax.text(i, Ppicks[i] + 0.01, '{0}'.format(stations[i]))
|
||||||
|
|
||||||
|
ax.set_xlabel('Number of P Picks')
|
||||||
|
ax.set_ylabel('Onset Time [s] from 1.1.1970')
|
||||||
|
ax.legend()
|
||||||
|
ax.set_title('Jackknifing and Median Tests on P Onsets')
|
||||||
|
if plt_flag:
|
||||||
|
fig.show()
|
||||||
|
|
||||||
return checkedonsets
|
return checkedonsets
|
||||||
|
|
||||||
@ -913,13 +924,13 @@ def jackknife(X, phi, h):
|
|||||||
PHI_sub = None
|
PHI_sub = None
|
||||||
|
|
||||||
# determine number of subgroups
|
# determine number of subgroups
|
||||||
g = len(X) / h
|
|
||||||
|
|
||||||
if type(g) is not int:
|
if len(X) % h:
|
||||||
print("jackknife: Cannot divide quantity X in equal sized subgroups!")
|
print("jackknife: Cannot divide quantity X in equal sized subgroups!")
|
||||||
print("Choose another size for subgroups!")
|
print("Choose another size for subgroups!")
|
||||||
return PHI_jack, PHI_pseudo, PHI_sub
|
return PHI_jack, PHI_pseudo, PHI_sub
|
||||||
else:
|
else:
|
||||||
|
g = int(len(X) / h)
|
||||||
# estimator of undisturbed spot check
|
# estimator of undisturbed spot check
|
||||||
if phi == 'MEA':
|
if phi == 'MEA':
|
||||||
phi_sc = np.mean(X)
|
phi_sc = np.mean(X)
|
||||||
|
@ -2011,6 +2011,17 @@ class PhasePlotWidget(FigureCanvas):
|
|||||||
super(PhasePlotWidget, self).__init__(self.fig)
|
super(PhasePlotWidget, self).__init__(self.fig)
|
||||||
|
|
||||||
|
|
||||||
|
class JackknifeWidget(QWidget):
|
||||||
|
'''
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, parent, canvas):
|
||||||
|
QtGui.QWidget.__init__(self, parent, 1)
|
||||||
|
self.main_layout = QtGui.QVBoxLayout()
|
||||||
|
self.setLayout(self.main_layout)
|
||||||
|
self.main_layout.addWidget(canvas)
|
||||||
|
|
||||||
|
|
||||||
class TuneAutopicker(QWidget):
|
class TuneAutopicker(QWidget):
|
||||||
update = QtCore.Signal(str)
|
update = QtCore.Signal(str)
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user