WIP restructuring fig_dict to be created inside Qt Main Thread
This commit is contained in:
parent
d1354a33b1
commit
f58d17be14
51
QtPyLoT.py
51
QtPyLoT.py
@ -41,6 +41,13 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
|
||||
import numpy as np
|
||||
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.io.data import Data
|
||||
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.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
||||
WaveformWidget, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
||||
getDataType, ComparisonDialog
|
||||
getDataType, ComparisonDialog, TuneAutopicker
|
||||
from pylot.core.util.map_projection import map_projection
|
||||
from pylot.core.util.structure import DATASTRUCTURE
|
||||
from pylot.core.util.thread import AutoPickThread, Thread
|
||||
@ -90,6 +97,7 @@ class MainWindow(QMainWindow):
|
||||
self._inputs = AutoPickParameter(infile)
|
||||
|
||||
self.project = Project()
|
||||
self.tap = None
|
||||
self.array_map = None
|
||||
self._metadata = None
|
||||
self._eventChanged = [False, False]
|
||||
@ -416,9 +424,9 @@ class MainWindow(QMainWindow):
|
||||
self.addActions(componentToolBar, componentActions)
|
||||
|
||||
self.auto_pick = self.createAction(parent=self, text='autoPick',
|
||||
slot=self.autoPick, shortcut='Alt+Ctrl+A',
|
||||
icon=auto_icon, tip='Automatically pick'
|
||||
' the displayed waveforms.')
|
||||
slot=self.tune_autopicker, shortcut='Alt+Ctrl+A',
|
||||
icon=auto_icon, tip='Tune autopicking algorithm.')
|
||||
|
||||
self.auto_pick.setEnabled(False)
|
||||
|
||||
autoPickToolBar = self.addToolBar("autoPyLoT")
|
||||
@ -1141,6 +1149,26 @@ class MainWindow(QMainWindow):
|
||||
self.listWidget.addItem(text)
|
||||
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):
|
||||
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
|
||||
if not os.path.exists(self.autosave):
|
||||
@ -1354,11 +1382,26 @@ class MainWindow(QMainWindow):
|
||||
self.get_metadata()
|
||||
if not self.metadata:
|
||||
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_thread()
|
||||
self.array_layout.addWidget(self.array_map)
|
||||
self.tabs.setCurrentIndex(index)
|
||||
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):
|
||||
if not self.array_map:
|
||||
return
|
||||
|
@ -29,7 +29,7 @@ from pylot.core.util.version import get_git_version as _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
|
||||
algorithms by Kueperkoch et al. 2010/2012.
|
||||
@ -166,7 +166,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
|
||||
print(data)
|
||||
##########################################################
|
||||
# !automated picking starts here!
|
||||
picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot)
|
||||
picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
|
||||
##########################################################
|
||||
# locating
|
||||
if locflag == 1:
|
||||
|
@ -1 +1 @@
|
||||
dc65-dirty
|
||||
d135-dirty
|
||||
|
@ -21,10 +21,9 @@ from pylot.core.util.utils import getPatternLine, gen_Pool
|
||||
from pylot.core.io.data import Data
|
||||
|
||||
|
||||
def autopickevent(data, param, iplot=0):
|
||||
def autopickevent(data, param, iplot=0, fig_dict=None):
|
||||
stations = []
|
||||
all_onsets = {}
|
||||
fig_dict = {}
|
||||
input_tuples = []
|
||||
|
||||
# get some parameters for quality control from
|
||||
@ -45,22 +44,22 @@ def autopickevent(data, param, iplot=0):
|
||||
if not iplot:
|
||||
input_tuples.append((topick, param, apverbose))
|
||||
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:
|
||||
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()
|
||||
result = pool.map(call_autopickstation, input_tuples)
|
||||
pool.close()
|
||||
|
||||
for pick, fig_dict in result:
|
||||
for pick in result:
|
||||
station = pick['station']
|
||||
pick.pop('station')
|
||||
all_onsets[station] = pick
|
||||
|
||||
return all_onsets, fig_dict # changing structure of autopicking and figure generation MP MP
|
||||
return all_onsets
|
||||
|
||||
# quality control
|
||||
# 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
|
||||
picker = 'auto' # type of picks
|
||||
|
||||
fig_dict = {}
|
||||
|
||||
# split components
|
||||
zdat = wfstream.select(component="Z")
|
||||
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
|
||||
# of class AutoPicking
|
||||
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP)
|
||||
key = 'aicFig'
|
||||
fig_dict[key] = aicpick.fig
|
||||
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig_dict[key])
|
||||
##############################################################
|
||||
if aicpick.getpick() is not None:
|
||||
# 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)
|
||||
if verbose: print(msg)
|
||||
key = 'slength'
|
||||
Pflag, fig_dict[key] = checksignallength(zne, aicpick.getpick(), tsnrz,
|
||||
minsiglength / 2,
|
||||
nfacsl, minpercent, iplot)
|
||||
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
|
||||
minsiglength / 2,
|
||||
nfacsl, minpercent, iplot,
|
||||
fig_dict[key])
|
||||
else:
|
||||
# filter and taper horizontal traces
|
||||
trH1_filt = edat.copy()
|
||||
@ -270,9 +267,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
zne += trH1_filt
|
||||
zne += trH2_filt
|
||||
key = 'slenght'
|
||||
Pflag, fig_dict[key] = checksignallength(zne, aicpick.getpick(), tsnrz,
|
||||
minsiglength,
|
||||
nfacsl, minpercent, iplot)
|
||||
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
|
||||
minsiglength,
|
||||
nfacsl, minpercent, iplot,
|
||||
fig_dict[key])
|
||||
|
||||
if Pflag == 1:
|
||||
# check for spuriously picked S onset
|
||||
@ -284,8 +282,8 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
else:
|
||||
if iplot>1:
|
||||
key = 'checkZ4S'
|
||||
Pflag, fig_dict[key] = checkZ4S(zne, aicpick.getpick(), zfac,
|
||||
tsnrz[3], iplot)
|
||||
Pflag = checkZ4S(zne, aicpick.getpick(), zfac,
|
||||
tsnrz[3], iplot, fig_dict[key])
|
||||
if Pflag == 0:
|
||||
Pmarker = 'SinsteadP'
|
||||
Pweight = 9
|
||||
@ -332,10 +330,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
'correctly: maybe the algorithm name ({algoP}) is ' \
|
||||
'corrupted'.format(
|
||||
algoP=algoP)
|
||||
refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP,
|
||||
aicpick.getpick())
|
||||
key = 'refPpick'
|
||||
fig_dict[key] = refPpick.fig
|
||||
refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP,
|
||||
aicpick.getpick(), fig_dict[key])
|
||||
mpickP = refPpick.getpick()
|
||||
#############################################################
|
||||
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
|
||||
if iplot:
|
||||
key = 'el_Ppick'
|
||||
epickP, lpickP, Perror, fig_dict[key] = earllatepicker(z_copy, nfacP, tsnrz,
|
||||
mpickP, iplot)
|
||||
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
|
||||
mpickP, iplot, fig_dict[key])
|
||||
else:
|
||||
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
|
||||
mpickP, iplot)
|
||||
@ -370,7 +367,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
if Pweight <= minfmweight and SNRP >= minFMSNR:
|
||||
if iplot:
|
||||
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:
|
||||
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
|
||||
else:
|
||||
@ -471,10 +468,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
##############################################################
|
||||
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
|
||||
# of class AutoPicking
|
||||
aicarhpick = AICPicker(haiccf, tsnrh, pickwinS, iplot, None,
|
||||
aictsmoothS)
|
||||
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
|
||||
if (aicarhpick.getSlope() >= minAICSslope and
|
||||
@ -528,10 +524,9 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
addnoise) # instance of ARHcf
|
||||
|
||||
# get refined onset time from CF2 using class Picker
|
||||
refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS,
|
||||
tsmoothS, aicarhpick.getpick())
|
||||
key = 'refSpick'
|
||||
fig_dict[key] = refSpick.fig
|
||||
refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS,
|
||||
tsmoothS, aicarhpick.getpick(), fig_dict[key])
|
||||
mpickS = refSpick.getpick()
|
||||
#############################################################
|
||||
if mpickS is not None:
|
||||
@ -540,9 +535,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
h_copy[0].data = trH1_filt.data
|
||||
if iplot:
|
||||
key = 'el_S1pick'
|
||||
epickS1, lpickS1, Serror1, fig_dict[key] = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot)
|
||||
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot,
|
||||
fig_dict[key])
|
||||
else:
|
||||
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
@ -551,9 +547,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
h_copy[0].data = trH2_filt.data
|
||||
if iplot:
|
||||
key = 'el_S2pick'
|
||||
epickS2, lpickS2, Serror2, fig_dict[key] = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot)
|
||||
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
mpickS, iplot,
|
||||
fig_dict[key])
|
||||
else:
|
||||
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
|
||||
tsnrh,
|
||||
@ -649,7 +646,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
|
||||
##############################################################
|
||||
if iplot > 0:
|
||||
# plot vertical trace
|
||||
fig = plt.figure()
|
||||
if not fig_dict:
|
||||
fig = plt.figure()
|
||||
else:
|
||||
fig = fig_dict['mainFig']
|
||||
ax1 = fig.add_subplot(311)
|
||||
tdata = np.arange(0, zdat[0].stats.npts / tr_filt.stats.sampling_rate,
|
||||
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_ylabel('Normalized Counts')
|
||||
ax3.set_title(trH2_filt.stats.channel)
|
||||
key = 'mainFig'
|
||||
fig_dict[key] = fig
|
||||
##########################################################################
|
||||
# calculate "real" onset times
|
||||
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)
|
||||
# merge picks into returning dictionary
|
||||
picks = dict(P=ppick, S=spick, station=zdat[0].stats.station)
|
||||
return picks, fig_dict
|
||||
return picks
|
||||
|
||||
|
||||
def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter):
|
||||
|
@ -34,7 +34,7 @@ class AutoPicker(object):
|
||||
|
||||
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
|
||||
:type: `~pylot.core.pick.CharFuns.CharacteristicFunction` object
|
||||
@ -72,7 +72,7 @@ class AutoPicker(object):
|
||||
self.setaus(aus)
|
||||
self.setTsmooth(Tsmooth)
|
||||
self.setpick1(Pick1)
|
||||
self.fig = self.calcPick()
|
||||
self.fig = fig
|
||||
|
||||
def __str__(self):
|
||||
return '''\n\t{name} object:\n
|
||||
@ -152,7 +152,6 @@ class AICPicker(AutoPicker):
|
||||
self.Pick = None
|
||||
self.slope = None
|
||||
self.SNR = None
|
||||
fig = None
|
||||
# find NaN's
|
||||
nn = np.isnan(self.cf)
|
||||
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('Choose longer slope determination window!')
|
||||
if self.iplot > 1:
|
||||
fig = plt.figure() #self.iplot) ### WHY? MP MP
|
||||
if not self.fig:
|
||||
fig = plt.figure() #self.iplot) ### WHY? MP MP
|
||||
else:
|
||||
fig = self.fig
|
||||
ax = fig.add_subplot(111)
|
||||
x = self.Data[0].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_yticks([])
|
||||
ax.set_title(self.Data[0].stats.station)
|
||||
return fig
|
||||
return
|
||||
islope = islope[0][0:imax]
|
||||
dataslope = self.Data[0].data[islope]
|
||||
# calculate slope as polynomal fit of order 1
|
||||
@ -253,7 +255,10 @@ class AICPicker(AutoPicker):
|
||||
self.slope = None
|
||||
|
||||
if self.iplot > 1:
|
||||
fig = plt.figure()#self.iplot)
|
||||
if not self.fig:
|
||||
fig = plt.figure()#self.iplot)
|
||||
else:
|
||||
fig = self.fig
|
||||
ax1 = fig.add_subplot(211)
|
||||
x = self.Data[0].data
|
||||
ax1.plot(self.Tcf, x / max(x), 'k', label='(HOS-/AR-) Data')
|
||||
@ -282,7 +287,7 @@ class AICPicker(AutoPicker):
|
||||
if self.Pick == None:
|
||||
print('AICPicker: Could not find minimum, picking window too short?')
|
||||
|
||||
return fig
|
||||
return
|
||||
|
||||
|
||||
class PragPicker(AutoPicker):
|
||||
@ -375,7 +380,10 @@ class PragPicker(AutoPicker):
|
||||
pickflag = 0
|
||||
|
||||
if self.getiplot() > 1:
|
||||
fig = plt.figure()#self.getiplot())
|
||||
if not self.fig:
|
||||
fig = plt.figure()#self.getiplot())
|
||||
else:
|
||||
fig = self.fig
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(Tcfpick, cfipick, 'k', label='CF')
|
||||
ax.plot(Tcfpick, cfsmoothipick, 'r', label='Smoothed CF')
|
||||
@ -385,7 +393,7 @@ class PragPicker(AutoPicker):
|
||||
ax.set_yticks([])
|
||||
ax.set_title(self.Data[0].stats.station)
|
||||
ax.legend()
|
||||
return fig
|
||||
return
|
||||
|
||||
else:
|
||||
print('PragPicker: No initial onset time given! Check input!')
|
||||
|
@ -14,7 +14,7 @@ import numpy as np
|
||||
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)
|
||||
as reasonable uncertainties. Latest possible pick is based on noise level,
|
||||
@ -104,7 +104,8 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False):
|
||||
PickError = symmetrize_error(diffti_te, diffti_tl)
|
||||
|
||||
if iplot > 1:
|
||||
fig = plt.figure()#iplot)
|
||||
if not fig:
|
||||
fig = plt.figure()#iplot)
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(t, x, 'k', label='Data')
|
||||
ax.plot(t[inoise], x[inoise], label='Noise Window')
|
||||
@ -133,7 +134,7 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False):
|
||||
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.
|
||||
Calculation is based on zero crossings determined within time window pickwin
|
||||
@ -620,7 +621,7 @@ def wadaticheck(pickdic, dttolerance, iplot):
|
||||
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.
|
||||
Uses RMS trace of all 3 components (if available) to determine,
|
||||
|
@ -12,41 +12,44 @@ from pylot.core.util.widgets import PickDlg
|
||||
plt.interactive(False)
|
||||
|
||||
class map_projection(QtGui.QWidget):
|
||||
def __init__(self, mainwindow, figure=None):
|
||||
def __init__(self, parent, figure=None):
|
||||
'''
|
||||
:param: picked, can be False, auto, manual
|
||||
:value: str
|
||||
'''
|
||||
QtGui.QWidget.__init__(self)
|
||||
self.pyl_mainwindow = mainwindow
|
||||
self.parser = mainwindow.metadata[1]
|
||||
self._parent = parent
|
||||
self.parser = parent.metadata[1]
|
||||
self.picks = None
|
||||
self.picks_dict = None
|
||||
self.figure = figure
|
||||
self.init_graphics()
|
||||
self.init_basemap(projection='mill', resolution='l')
|
||||
self.init_map()
|
||||
#self.show()
|
||||
|
||||
def init_map(self):
|
||||
self.init_stations()
|
||||
self.init_lat_lon_dimensions()
|
||||
self.init_lat_lon_grid()
|
||||
self.init_basemap(projection='mill', resolution='l')
|
||||
self.init_x_y_dimensions()
|
||||
self.connectSignals()
|
||||
self.draw_everything()
|
||||
#self.show()
|
||||
|
||||
def onpick(self, event):
|
||||
ind = event.ind
|
||||
if ind == []:
|
||||
return
|
||||
data = self.pyl_mainwindow.get_data().getWFData()
|
||||
data = self._parent.get_data().getWFData()
|
||||
for index in ind:
|
||||
station=str(self.station_names[index])
|
||||
try:
|
||||
pickDlg = PickDlg(self, infile=self.pyl_mainwindow.getinfile(),
|
||||
pickDlg = PickDlg(self, infile=self._parent.getinfile(),
|
||||
data=data.select(station=station),
|
||||
station=station,
|
||||
picks=self.pyl_mainwindow.getPicksOnStation(station, 'manual'),
|
||||
autopicks=self.pyl_mainwindow.getPicksOnStation(station, 'auto'))
|
||||
pyl_mw = self.pyl_mainwindow
|
||||
picks=self._parent.getPicksOnStation(station, 'manual'),
|
||||
autopicks=self._parent.getPicksOnStation(station, 'auto'))
|
||||
pyl_mw = self._parent
|
||||
if pickDlg.exec_():
|
||||
pyl_mw.setDirty(True)
|
||||
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)
|
||||
|
||||
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.setLayout(self.main_box)
|
||||
|
||||
@ -85,17 +99,8 @@ class map_projection(QtGui.QWidget):
|
||||
self.top_row.addWidget(self.comboBox_phase)
|
||||
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.toolbar = NavigationToolbar(self.canvas, self)
|
||||
self.main_box.addWidget(self.toolbar)
|
||||
self.figure = fig
|
||||
|
||||
def init_stations(self):
|
||||
def get_station_names_lat_lon(parser):
|
||||
@ -187,7 +192,6 @@ class map_projection(QtGui.QWidget):
|
||||
self.basemap = basemap
|
||||
self.figure.tight_layout()
|
||||
|
||||
|
||||
def init_lat_lon_grid(self):
|
||||
def get_lat_lon_axis(lat, lon):
|
||||
steplat = (max(lat)-min(lat))/250
|
||||
|
@ -1,4 +1,4 @@
|
||||
[]# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
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, \
|
||||
demeanTrace, isSorted, findComboBoxIndex, clims
|
||||
from autoPyLoT import autoPyLoT
|
||||
from pylot.core.util.thread import Thread
|
||||
import icons_rc
|
||||
|
||||
def getDataType(parent):
|
||||
@ -1270,11 +1271,12 @@ class PickDlg(QDialog):
|
||||
|
||||
|
||||
class TuneAutopicker(QWidget):
|
||||
def __init__(self, ap, parent=None):
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
def __init__(self, ap, fig_dict, parent=None):
|
||||
QtGui.QWidget.__init__(self, parent, 1)
|
||||
self.ap = ap
|
||||
self.station = 'AH11'
|
||||
self.fd = None
|
||||
self.parent = parent
|
||||
self.station = 'AH11' ############# justs for testing
|
||||
self.fig_dict = fig_dict
|
||||
self.layout = QtGui.QHBoxLayout()
|
||||
self.parameter_layout = QtGui.QVBoxLayout()
|
||||
self.setLayout(self.layout)
|
||||
@ -1282,6 +1284,9 @@ class TuneAutopicker(QWidget):
|
||||
self.add_parameter()
|
||||
self.add_buttons()
|
||||
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):
|
||||
self.main_tabs = QtGui.QTabWidget()
|
||||
@ -1302,13 +1307,20 @@ class TuneAutopicker(QWidget):
|
||||
self.parameter_layout.addWidget(self.pick_button)
|
||||
|
||||
def call_picker(self):
|
||||
self.parameters.update_params()
|
||||
picks, fig_dict = autoPyLoT(self.ap, fnames='None', iplot=2)
|
||||
self.pb_thread = Thread(self, self._hover, arg=None, progressText='Picking trace...')
|
||||
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.fd = fig_dict[self.station]
|
||||
self.init_figure_tabs()
|
||||
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):
|
||||
self.layout.setStretch(0, 3)
|
||||
self.layout.setStretch(1, 1)
|
||||
@ -1788,6 +1800,7 @@ class AutoPickParaBox(QtGui.QWidget):
|
||||
value = self.getValue(box)
|
||||
self.ap.checkValue(param, value)
|
||||
self.ap.setParam(param, value)
|
||||
return self.ap
|
||||
|
||||
def getValue(self, box):
|
||||
if type(box) == QtGui.QLineEdit:
|
||||
|
Loading…
Reference in New Issue
Block a user