WIP restructuring fig_dict to be created inside Qt Main Thread

This commit is contained in:
Marcel Paffrath 2017-05-11 17:15:20 +02:00
parent d1354a33b1
commit f58d17be14
8 changed files with 156 additions and 89 deletions

View File

@ -41,6 +41,13 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
import numpy as np import numpy as np
from obspy import UTCDateTime from obspy import UTCDateTime
try:
from matplotlib.backends.backend_qt4agg import FigureCanvas
except ImportError:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from pylot.core.analysis.magnitude import RichterMagnitude, MomentMagnitude from pylot.core.analysis.magnitude import RichterMagnitude, MomentMagnitude
from pylot.core.io.data import Data from pylot.core.io.data import Data
from pylot.core.io.inputs import FilterOptions, AutoPickParameter from pylot.core.io.inputs import FilterOptions, AutoPickParameter
@ -59,7 +66,7 @@ from pylot.core.util.utils import fnConstructor, getLogin, \
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, PropertiesDlg, HelpForm, createAction, PickDlg, \ WaveformWidget, PropertiesDlg, HelpForm, createAction, PickDlg, \
getDataType, ComparisonDialog getDataType, ComparisonDialog, TuneAutopicker
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 AutoPickThread, Thread from pylot.core.util.thread import AutoPickThread, Thread
@ -90,6 +97,7 @@ class MainWindow(QMainWindow):
self._inputs = AutoPickParameter(infile) self._inputs = AutoPickParameter(infile)
self.project = Project() self.project = Project()
self.tap = None
self.array_map = None self.array_map = None
self._metadata = None self._metadata = None
self._eventChanged = [False, False] self._eventChanged = [False, False]
@ -416,9 +424,9 @@ class MainWindow(QMainWindow):
self.addActions(componentToolBar, componentActions) self.addActions(componentToolBar, componentActions)
self.auto_pick = self.createAction(parent=self, text='autoPick', self.auto_pick = self.createAction(parent=self, text='autoPick',
slot=self.autoPick, shortcut='Alt+Ctrl+A', slot=self.tune_autopicker, shortcut='Alt+Ctrl+A',
icon=auto_icon, tip='Automatically pick' icon=auto_icon, tip='Tune autopicking algorithm.')
' the displayed waveforms.')
self.auto_pick.setEnabled(False) self.auto_pick.setEnabled(False)
autoPickToolBar = self.addToolBar("autoPyLoT") autoPickToolBar = self.addToolBar("autoPyLoT")
@ -1141,6 +1149,26 @@ class MainWindow(QMainWindow):
self.listWidget.addItem(text) self.listWidget.addItem(text)
self.listWidget.scrollToBottom() self.listWidget.scrollToBottom()
def tune_autopicker(self):
self.fig_dict = {
'mainFig':,
'aicFig':,
'slength':,
'checkZ4s':,
'refPpick':,
'el_Ppick':,
'fm_picker':,
'el_S1pick':,
'el_S2pick':,
'refSpick':,
'aicARHfig',
}
ap = self._inputs
if not self.tap:
self.tap = TuneAutopicker(ap, self.fig_dict, self)
self.tap.show()
def autoPick(self): def autoPick(self):
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output') self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
if not os.path.exists(self.autosave): if not os.path.exists(self.autosave):
@ -1354,11 +1382,26 @@ class MainWindow(QMainWindow):
self.get_metadata() self.get_metadata()
if not self.metadata: if not self.metadata:
return return
self.am_figure = Figure()
self.am_canvas = FigureCanvas(self.am_figure)
self.am_toolbar = NavigationToolbar(self.am_canvas, self)
self.array_map = map_projection(self) self.array_map = map_projection(self)
#self.array_map_thread()
self.array_layout.addWidget(self.array_map) self.array_layout.addWidget(self.array_map)
self.tabs.setCurrentIndex(index) self.tabs.setCurrentIndex(index)
self.refresh_array_map() self.refresh_array_map()
def array_map_thread(self):
self.amt = Thread(self, self.array_map.init_map, arg=None, progressText='Generating map...')
self.amt.finished.connect(self.finish_array_map)
self.amt.start()
def finish_array_map(self):
self.array_map = self.amt.data
self.array_layout.addWidget(self.array_map)
#self.tabs.setCurrentIndex(index)
#self.refresh_array_map()
def refresh_array_map(self): def refresh_array_map(self):
if not self.array_map: if not self.array_map:
return return

View File

@ -29,7 +29,7 @@ from pylot.core.util.version import get_git_version as _getVersionString
__version__ = _getVersionString() __version__ = _getVersionString()
def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=0): def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=0, fig_dict=None):
""" """
Determine phase onsets automatically utilizing the automatic picking Determine phase onsets automatically utilizing the automatic picking
algorithms by Kueperkoch et al. 2010/2012. algorithms by Kueperkoch et al. 2010/2012.
@ -166,7 +166,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
print(data) print(data)
########################################################## ##########################################################
# !automated picking starts here! # !automated picking starts here!
picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot) picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
########################################################## ##########################################################
# locating # locating
if locflag == 1: if locflag == 1:

View File

@ -1 +1 @@
dc65-dirty d135-dirty

View File

@ -21,10 +21,9 @@ from pylot.core.util.utils import getPatternLine, gen_Pool
from pylot.core.io.data import Data from pylot.core.io.data import Data
def autopickevent(data, param, iplot=0): def autopickevent(data, param, iplot=0, fig_dict=None):
stations = [] stations = []
all_onsets = {} all_onsets = {}
fig_dict = {}
input_tuples = [] input_tuples = []
# get some parameters for quality control from # get some parameters for quality control from
@ -45,22 +44,22 @@ def autopickevent(data, param, iplot=0):
if not iplot: if not iplot:
input_tuples.append((topick, param, apverbose)) input_tuples.append((topick, param, apverbose))
if iplot>0: if iplot>0:
all_onsets[station], fig_dict[station] = autopickstation(topick, param, verbose=apverbose, iplot=iplot) all_onsets[station] = autopickstation(topick, param, verbose=apverbose, iplot=iplot, fig_dict=fig_dict)
if iplot>0: if iplot>0:
print('iPlot Flag active: NO MULTIPROCESSING possible.') print('iPlot Flag active: NO MULTIPROCESSING possible.')
return all_onsets, fig_dict # changing structure of autopicking and figure generation MP MP return all_onsets
pool = gen_Pool() pool = gen_Pool()
result = pool.map(call_autopickstation, input_tuples) result = pool.map(call_autopickstation, input_tuples)
pool.close() pool.close()
for pick, fig_dict in result: for pick in result:
station = pick['station'] station = pick['station']
pick.pop('station') pick.pop('station')
all_onsets[station] = pick all_onsets[station] = pick
return all_onsets, fig_dict # changing structure of autopicking and figure generation MP MP return all_onsets
# quality control # quality control
# median check and jackknife on P-onset times # median check and jackknife on P-onset times
@ -172,8 +171,6 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
Ao = None # Wood-Anderson peak-to-peak amplitude Ao = None # Wood-Anderson peak-to-peak amplitude
picker = 'auto' # type of picks picker = 'auto' # type of picks
fig_dict = {}
# split components # split components
zdat = wfstream.select(component="Z") zdat = wfstream.select(component="Z")
if len(zdat) == 0: # check for other components if len(zdat) == 0: # check for other components
@ -235,9 +232,8 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
############################################################## ##############################################################
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker # get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
# of class AutoPicking # of class AutoPicking
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP)
key = 'aicFig' key = 'aicFig'
fig_dict[key] = aicpick.fig aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig_dict[key])
############################################################## ##############################################################
if aicpick.getpick() is not None: if aicpick.getpick() is not None:
# check signal length to detect spuriously picked noise peaks # check signal length to detect spuriously picked noise peaks
@ -252,9 +248,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
'{1}'.format(minsiglength, minsiglength / 2) '{1}'.format(minsiglength, minsiglength / 2)
if verbose: print(msg) if verbose: print(msg)
key = 'slength' key = 'slength'
Pflag, fig_dict[key] = checksignallength(zne, aicpick.getpick(), tsnrz, Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength / 2, minsiglength / 2,
nfacsl, minpercent, iplot) nfacsl, minpercent, iplot,
fig_dict[key])
else: else:
# filter and taper horizontal traces # filter and taper horizontal traces
trH1_filt = edat.copy() trH1_filt = edat.copy()
@ -270,9 +267,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
zne += trH1_filt zne += trH1_filt
zne += trH2_filt zne += trH2_filt
key = 'slenght' key = 'slenght'
Pflag, fig_dict[key] = checksignallength(zne, aicpick.getpick(), tsnrz, Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength, minsiglength,
nfacsl, minpercent, iplot) nfacsl, minpercent, iplot,
fig_dict[key])
if Pflag == 1: if Pflag == 1:
# check for spuriously picked S onset # check for spuriously picked S onset
@ -284,8 +282,8 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
else: else:
if iplot>1: if iplot>1:
key = 'checkZ4S' key = 'checkZ4S'
Pflag, fig_dict[key] = checkZ4S(zne, aicpick.getpick(), zfac, Pflag = checkZ4S(zne, aicpick.getpick(), zfac,
tsnrz[3], iplot) tsnrz[3], iplot, fig_dict[key])
if Pflag == 0: if Pflag == 0:
Pmarker = 'SinsteadP' Pmarker = 'SinsteadP'
Pweight = 9 Pweight = 9
@ -332,10 +330,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
'correctly: maybe the algorithm name ({algoP}) is ' \ 'correctly: maybe the algorithm name ({algoP}) is ' \
'corrupted'.format( 'corrupted'.format(
algoP=algoP) algoP=algoP)
refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP,
aicpick.getpick())
key = 'refPpick' key = 'refPpick'
fig_dict[key] = refPpick.fig refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP,
aicpick.getpick(), fig_dict[key])
mpickP = refPpick.getpick() mpickP = refPpick.getpick()
############################################################# #############################################################
if mpickP is not None: if mpickP is not None:
@ -343,8 +340,8 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
# get earliest/latest possible pick and symmetrized uncertainty # get earliest/latest possible pick and symmetrized uncertainty
if iplot: if iplot:
key = 'el_Ppick' key = 'el_Ppick'
epickP, lpickP, Perror, fig_dict[key] = earllatepicker(z_copy, nfacP, tsnrz, epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
mpickP, iplot) mpickP, iplot, fig_dict[key])
else: else:
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz, epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
mpickP, iplot) mpickP, iplot)
@ -370,7 +367,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
if Pweight <= minfmweight and SNRP >= minFMSNR: if Pweight <= minfmweight and SNRP >= minFMSNR:
if iplot: if iplot:
key = 'fm_picker' key = 'fm_picker'
FM, fig_dict[key] = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot) FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot, fig_dict[key])
else: else:
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot) FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
else: else:
@ -471,10 +468,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
############################################################## ##############################################################
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker # get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
# of class AutoPicking # of class AutoPicking
aicarhpick = AICPicker(haiccf, tsnrh, pickwinS, iplot, None,
aictsmoothS)
key = 'aicARHfig' key = 'aicARHfig'
fig_dict[key] = aicarhpick.fig aicarhpick = AICPicker(haiccf, tsnrh, pickwinS, iplot, None,
aictsmoothS, fig_dict[key])
############################################################### ###############################################################
# go on with processing if AIC onset passes quality control # go on with processing if AIC onset passes quality control
if (aicarhpick.getSlope() >= minAICSslope and if (aicarhpick.getSlope() >= minAICSslope and
@ -528,10 +524,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
addnoise) # instance of ARHcf addnoise) # instance of ARHcf
# get refined onset time from CF2 using class Picker # get refined onset time from CF2 using class Picker
refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS,
tsmoothS, aicarhpick.getpick())
key = 'refSpick' key = 'refSpick'
fig_dict[key] = refSpick.fig refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS,
tsmoothS, aicarhpick.getpick(), fig_dict[key])
mpickS = refSpick.getpick() mpickS = refSpick.getpick()
############################################################# #############################################################
if mpickS is not None: if mpickS is not None:
@ -540,9 +535,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
h_copy[0].data = trH1_filt.data h_copy[0].data = trH1_filt.data
if iplot: if iplot:
key = 'el_S1pick' key = 'el_S1pick'
epickS1, lpickS1, Serror1, fig_dict[key] = earllatepicker(h_copy, nfacS, epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
mpickS, iplot) mpickS, iplot,
fig_dict[key])
else: else:
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS, epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
@ -551,9 +547,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
h_copy[0].data = trH2_filt.data h_copy[0].data = trH2_filt.data
if iplot: if iplot:
key = 'el_S2pick' key = 'el_S2pick'
epickS2, lpickS2, Serror2, fig_dict[key] = earllatepicker(h_copy, nfacS, epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
mpickS, iplot) mpickS, iplot,
fig_dict[key])
else: else:
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS, epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
@ -649,7 +646,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
############################################################## ##############################################################
if iplot > 0: if iplot > 0:
# plot vertical trace # plot vertical trace
if not fig_dict:
fig = plt.figure() fig = plt.figure()
else:
fig = fig_dict['mainFig']
ax1 = fig.add_subplot(311) ax1 = fig.add_subplot(311)
tdata = np.arange(0, zdat[0].stats.npts / tr_filt.stats.sampling_rate, tdata = np.arange(0, zdat[0].stats.npts / tr_filt.stats.sampling_rate,
tr_filt.stats.delta) tr_filt.stats.delta)
@ -792,8 +792,6 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
ax3.set_xlabel('Time [s] after %s' % tr_filt.stats.starttime) ax3.set_xlabel('Time [s] after %s' % tr_filt.stats.starttime)
ax3.set_ylabel('Normalized Counts') ax3.set_ylabel('Normalized Counts')
ax3.set_title(trH2_filt.stats.channel) ax3.set_title(trH2_filt.stats.channel)
key = 'mainFig'
fig_dict[key] = fig
########################################################################## ##########################################################################
# calculate "real" onset times # calculate "real" onset times
if lpickP is not None and lpickP == mpickP: if lpickP is not None and lpickP == mpickP:
@ -840,7 +838,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
snrdb=SNRSdB, weight=Sweight, fm=None, picker=picker, Ao=Ao) snrdb=SNRSdB, weight=Sweight, fm=None, picker=picker, Ao=Ao)
# merge picks into returning dictionary # merge picks into returning dictionary
picks = dict(P=ppick, S=spick, station=zdat[0].stats.station) picks = dict(P=ppick, S=spick, station=zdat[0].stats.station)
return picks, fig_dict return picks
def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter): def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter):

View File

@ -34,7 +34,7 @@ class AutoPicker(object):
warnings.simplefilter('ignore') warnings.simplefilter('ignore')
def __init__(self, cf, TSNR, PickWindow, iplot=None, aus=None, Tsmooth=None, Pick1=None): def __init__(self, cf, TSNR, PickWindow, iplot=None, aus=None, Tsmooth=None, Pick1=None, fig=None):
''' '''
:param: cf, characteristic function, on which the picking algorithm is applied :param: cf, characteristic function, on which the picking algorithm is applied
:type: `~pylot.core.pick.CharFuns.CharacteristicFunction` object :type: `~pylot.core.pick.CharFuns.CharacteristicFunction` object
@ -72,7 +72,7 @@ class AutoPicker(object):
self.setaus(aus) self.setaus(aus)
self.setTsmooth(Tsmooth) self.setTsmooth(Tsmooth)
self.setpick1(Pick1) self.setpick1(Pick1)
self.fig = self.calcPick() self.fig = fig
def __str__(self): def __str__(self):
return '''\n\t{name} object:\n return '''\n\t{name} object:\n
@ -152,7 +152,6 @@ class AICPicker(AutoPicker):
self.Pick = None self.Pick = None
self.slope = None self.slope = None
self.SNR = None self.SNR = None
fig = None
# find NaN's # find NaN's
nn = np.isnan(self.cf) nn = np.isnan(self.cf)
if len(nn) > 1: if len(nn) > 1:
@ -227,7 +226,10 @@ class AICPicker(AutoPicker):
print('AICPicker: Maximum for slope determination right at the beginning of the window!') print('AICPicker: Maximum for slope determination right at the beginning of the window!')
print('Choose longer slope determination window!') print('Choose longer slope determination window!')
if self.iplot > 1: if self.iplot > 1:
if not self.fig:
fig = plt.figure() #self.iplot) ### WHY? MP MP fig = plt.figure() #self.iplot) ### WHY? MP MP
else:
fig = self.fig
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
x = self.Data[0].data x = self.Data[0].data
ax.plot(self.Tcf, x / max(x), 'k', legend='(HOS-/AR-) Data') ax.plot(self.Tcf, x / max(x), 'k', legend='(HOS-/AR-) Data')
@ -236,7 +238,7 @@ class AICPicker(AutoPicker):
ax.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime) ax.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax.set_yticks([]) ax.set_yticks([])
ax.set_title(self.Data[0].stats.station) ax.set_title(self.Data[0].stats.station)
return fig return
islope = islope[0][0:imax] islope = islope[0][0:imax]
dataslope = self.Data[0].data[islope] dataslope = self.Data[0].data[islope]
# calculate slope as polynomal fit of order 1 # calculate slope as polynomal fit of order 1
@ -253,7 +255,10 @@ class AICPicker(AutoPicker):
self.slope = None self.slope = None
if self.iplot > 1: if self.iplot > 1:
if not self.fig:
fig = plt.figure()#self.iplot) fig = plt.figure()#self.iplot)
else:
fig = self.fig
ax1 = fig.add_subplot(211) ax1 = fig.add_subplot(211)
x = self.Data[0].data x = self.Data[0].data
ax1.plot(self.Tcf, x / max(x), 'k', label='(HOS-/AR-) Data') ax1.plot(self.Tcf, x / max(x), 'k', label='(HOS-/AR-) Data')
@ -282,7 +287,7 @@ class AICPicker(AutoPicker):
if self.Pick == None: if self.Pick == None:
print('AICPicker: Could not find minimum, picking window too short?') print('AICPicker: Could not find minimum, picking window too short?')
return fig return
class PragPicker(AutoPicker): class PragPicker(AutoPicker):
@ -375,7 +380,10 @@ class PragPicker(AutoPicker):
pickflag = 0 pickflag = 0
if self.getiplot() > 1: if self.getiplot() > 1:
if not self.fig:
fig = plt.figure()#self.getiplot()) fig = plt.figure()#self.getiplot())
else:
fig = self.fig
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(Tcfpick, cfipick, 'k', label='CF') ax.plot(Tcfpick, cfipick, 'k', label='CF')
ax.plot(Tcfpick, cfsmoothipick, 'r', label='Smoothed CF') ax.plot(Tcfpick, cfsmoothipick, 'r', label='Smoothed CF')
@ -385,7 +393,7 @@ class PragPicker(AutoPicker):
ax.set_yticks([]) ax.set_yticks([])
ax.set_title(self.Data[0].stats.station) ax.set_title(self.Data[0].stats.station)
ax.legend() ax.legend()
return fig return
else: else:
print('PragPicker: No initial onset time given! Check input!') print('PragPicker: No initial onset time given! Check input!')

View File

@ -14,7 +14,7 @@ import numpy as np
from obspy.core import Stream, UTCDateTime from obspy.core import Stream, UTCDateTime
def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False): def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False, fig=None):
''' '''
Function to derive earliest and latest possible pick after Diehl & Kissling (2009) Function to derive earliest and latest possible pick after Diehl & Kissling (2009)
as reasonable uncertainties. Latest possible pick is based on noise level, as reasonable uncertainties. Latest possible pick is based on noise level,
@ -104,6 +104,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False):
PickError = symmetrize_error(diffti_te, diffti_tl) PickError = symmetrize_error(diffti_te, diffti_tl)
if iplot > 1: if iplot > 1:
if not fig:
fig = plt.figure()#iplot) fig = plt.figure()#iplot)
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(t, x, 'k', label='Data') ax.plot(t, x, 'k', label='Data')
@ -133,7 +134,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False):
return EPick, LPick, PickError return EPick, LPick, PickError
def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None): def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None, fig_dict):
''' '''
Function to derive first motion (polarity) of given phase onset Pick. Function to derive first motion (polarity) of given phase onset Pick.
Calculation is based on zero crossings determined within time window pickwin Calculation is based on zero crossings determined within time window pickwin
@ -620,7 +621,7 @@ def wadaticheck(pickdic, dttolerance, iplot):
return checkedonsets return checkedonsets
def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot): def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot=0, fig_dict=None):
''' '''
Function to detect spuriously picked noise peaks. Function to detect spuriously picked noise peaks.
Uses RMS trace of all 3 components (if available) to determine, Uses RMS trace of all 3 components (if available) to determine,

View File

@ -12,41 +12,44 @@ from pylot.core.util.widgets import PickDlg
plt.interactive(False) plt.interactive(False)
class map_projection(QtGui.QWidget): class map_projection(QtGui.QWidget):
def __init__(self, mainwindow, figure=None): def __init__(self, parent, figure=None):
''' '''
:param: picked, can be False, auto, manual :param: picked, can be False, auto, manual
:value: str :value: str
''' '''
QtGui.QWidget.__init__(self) QtGui.QWidget.__init__(self)
self.pyl_mainwindow = mainwindow self._parent = parent
self.parser = mainwindow.metadata[1] self.parser = parent.metadata[1]
self.picks = None self.picks = None
self.picks_dict = None self.picks_dict = None
self.figure = figure self.figure = figure
self.init_graphics() self.init_graphics()
self.init_basemap(projection='mill', resolution='l')
self.init_map()
#self.show()
def init_map(self):
self.init_stations() self.init_stations()
self.init_lat_lon_dimensions() self.init_lat_lon_dimensions()
self.init_lat_lon_grid() self.init_lat_lon_grid()
self.init_basemap(projection='mill', resolution='l')
self.init_x_y_dimensions() self.init_x_y_dimensions()
self.connectSignals() self.connectSignals()
self.draw_everything() self.draw_everything()
#self.show()
def onpick(self, event): def onpick(self, event):
ind = event.ind ind = event.ind
if ind == []: if ind == []:
return return
data = self.pyl_mainwindow.get_data().getWFData() data = self._parent.get_data().getWFData()
for index in ind: for index in ind:
station=str(self.station_names[index]) station=str(self.station_names[index])
try: try:
pickDlg = PickDlg(self, infile=self.pyl_mainwindow.getinfile(), pickDlg = PickDlg(self, infile=self._parent.getinfile(),
data=data.select(station=station), data=data.select(station=station),
station=station, station=station,
picks=self.pyl_mainwindow.getPicksOnStation(station, 'manual'), picks=self._parent.getPicksOnStation(station, 'manual'),
autopicks=self.pyl_mainwindow.getPicksOnStation(station, 'auto')) autopicks=self._parent.getPicksOnStation(station, 'auto'))
pyl_mw = self.pyl_mainwindow pyl_mw = self._parent
if pickDlg.exec_(): if pickDlg.exec_():
pyl_mw.setDirty(True) pyl_mw.setDirty(True)
pyl_mw.update_status('picks accepted ({0})'.format(station)) pyl_mw.update_status('picks accepted ({0})'.format(station))
@ -67,6 +70,17 @@ class map_projection(QtGui.QWidget):
self.comboBox_phase.currentIndexChanged.connect(self._refresh_drawings) self.comboBox_phase.currentIndexChanged.connect(self._refresh_drawings)
def init_graphics(self): def init_graphics(self):
if not self.figure:
if not hasattr(self._parent, 'am_figure'):
self.figure = plt.figure()
self.toolbar = NavigationToolbar(self.figure.canvas, self)
else:
self.figure = self._parent.am_figure
self.toolbar = self._parent.am_toolbar
self.main_ax = self.figure.add_subplot(111)
self.canvas = self.figure.canvas
self.main_box = QtGui.QVBoxLayout() self.main_box = QtGui.QVBoxLayout()
self.setLayout(self.main_box) self.setLayout(self.main_box)
@ -85,17 +99,8 @@ class map_projection(QtGui.QWidget):
self.top_row.addWidget(self.comboBox_phase) self.top_row.addWidget(self.comboBox_phase)
self.top_row.setStretch(1,1) #set stretch of item 1 to 1 self.top_row.setStretch(1,1) #set stretch of item 1 to 1
if not self.figure:
fig = plt.figure()
else:
fig = self.figure
self.main_ax = fig.add_subplot(111)
self.canvas = fig.canvas
self.main_box.addWidget(self.canvas) self.main_box.addWidget(self.canvas)
self.toolbar = NavigationToolbar(self.canvas, self)
self.main_box.addWidget(self.toolbar) self.main_box.addWidget(self.toolbar)
self.figure = fig
def init_stations(self): def init_stations(self):
def get_station_names_lat_lon(parser): def get_station_names_lat_lon(parser):
@ -187,7 +192,6 @@ class map_projection(QtGui.QWidget):
self.basemap = basemap self.basemap = basemap
self.figure.tight_layout() self.figure.tight_layout()
def init_lat_lon_grid(self): def init_lat_lon_grid(self):
def get_lat_lon_axis(lat, lon): def get_lat_lon_axis(lat, lon):
steplat = (max(lat)-min(lat))/250 steplat = (max(lat)-min(lat))/250

View File

@ -1,4 +1,4 @@
[]# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Wed Mar 19 11:27:35 2014 Created on Wed Mar 19 11:27:35 2014
@ -39,6 +39,7 @@ from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \ 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
import icons_rc import icons_rc
def getDataType(parent): def getDataType(parent):
@ -1270,11 +1271,12 @@ class PickDlg(QDialog):
class TuneAutopicker(QWidget): class TuneAutopicker(QWidget):
def __init__(self, ap, parent=None): def __init__(self, ap, fig_dict, parent=None):
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent, 1)
self.ap = ap self.ap = ap
self.station = 'AH11' self.parent = parent
self.fd = None self.station = 'AH11' ############# justs for testing
self.fig_dict = fig_dict
self.layout = QtGui.QHBoxLayout() self.layout = QtGui.QHBoxLayout()
self.parameter_layout = QtGui.QVBoxLayout() self.parameter_layout = QtGui.QVBoxLayout()
self.setLayout(self.layout) self.setLayout(self.layout)
@ -1282,6 +1284,9 @@ class TuneAutopicker(QWidget):
self.add_parameter() self.add_parameter()
self.add_buttons() self.add_buttons()
self.set_stretch() self.set_stretch()
self.resize(1280, 720)
self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
def init_figure_tabs(self): def init_figure_tabs(self):
self.main_tabs = QtGui.QTabWidget() self.main_tabs = QtGui.QTabWidget()
@ -1302,13 +1307,20 @@ class TuneAutopicker(QWidget):
self.parameter_layout.addWidget(self.pick_button) self.parameter_layout.addWidget(self.pick_button)
def call_picker(self): def call_picker(self):
self.parameters.update_params() self.pb_thread = Thread(self, self._hover, arg=None, progressText='Picking trace...')
picks, fig_dict = autoPyLoT(self.ap, fnames='None', iplot=2) self.pb_thread.start()
self.ap = self.update_params()
picks = autoPyLoT(self.ap, fnames='None', iplot=2, self.fig_dict)
self.main_tabs.setParent(None) self.main_tabs.setParent(None)
self.fd = fig_dict[self.station]
self.init_figure_tabs() self.init_figure_tabs()
self.set_stretch() self.set_stretch()
def update_params(self):
ap = self.parameters.update_params()
if self.parent:
self.parent._inputs = ap
return ap
def set_stretch(self): def set_stretch(self):
self.layout.setStretch(0, 3) self.layout.setStretch(0, 3)
self.layout.setStretch(1, 1) self.layout.setStretch(1, 1)
@ -1788,6 +1800,7 @@ class AutoPickParaBox(QtGui.QWidget):
value = self.getValue(box) value = self.getValue(box)
self.ap.checkValue(param, value) self.ap.checkValue(param, value)
self.ap.setParam(param, value) self.ap.setParam(param, value)
return self.ap
def getValue(self, box): def getValue(self, box):
if type(box) == QtGui.QLineEdit: if type(box) == QtGui.QLineEdit: