Merge branch 'tap_thread' into develop

This commit is contained in:
Marcel Paffrath 2017-05-17 13:27:03 +02:00
commit b97f79c31d
10 changed files with 1122 additions and 532 deletions

View File

@ -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")
@ -548,17 +556,6 @@ class MainWindow(QMainWindow):
self.drawPicks(picktype=type)
self.draw()
def getCurrentEvent(self):
for event in self.project.eventlist:
if event.path == self.getCurrentEventPath():
return event
def getCurrentEventPath(self):
return str(self.eventBox.currentText().split('|')[0]).strip()
def getLastEvent(self):
return self.recentfiles[0]
def add_recentfile(self, event):
self.recentfiles.insert(0, event)
@ -596,16 +593,29 @@ class MainWindow(QMainWindow):
else:
return
def getWFFnames_from_eventlist(self):
def getWFFnames_from_eventbox(self, eventlist=None, eventbox=None):
if self.dataStructure:
searchPath = self.dataStructure.expandDataPath()
directory = self.getCurrentEventPath()
self.fnames = [os.path.join(directory, f) for f in os.listdir(directory)]
directory = self.getCurrentEventPath(eventbox)
fnames = [os.path.join(directory, f) for f in os.listdir(directory)]
else:
raise DatastructureError('not specified')
if not self.fnames:
return None
return self.fnames
return fnames
def getCurrentEvent(self, eventlist=None, eventbox=None):
if not eventlist:
eventlist = self.project.eventlist
if not eventbox:
eventbox = self.eventBox
index = eventbox.currentIndex()
return eventbox.itemData(index)
def getCurrentEventPath(self, eventbox=None):
if not eventbox:
eventbox = self.eventBox
return str(eventbox.currentText().split('|')[0]).strip()
def getLastEvent(self):
return self.recentfiles[0]
def add_events(self):
if not self.project:
@ -628,13 +638,13 @@ class MainWindow(QMainWindow):
def createEventBox(self):
qcb = QComboBox()
palette = qcb.palette()
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight,
QtGui.QBrush(QtGui.QColor(0,0,127,127)))
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight,
QtGui.QBrush(QtGui.QColor(0,0,127,127)))
# change highlight color:
# palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight,
# QtGui.QBrush(QtGui.QColor(0,0,127,127)))
# palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight,
# QtGui.QBrush(QtGui.QColor(0,0,127,127)))
qcb.setPalette(palette)
return qcb
def init_events(self, new=False):
nitems = self.eventBox.count()
@ -643,7 +653,7 @@ class MainWindow(QMainWindow):
self.clearWaveformDataPlot()
return
self.eventBox.setEnabled(True)
self.fill_eventbox()
self.fill_eventbox(self.eventBox)
if new:
self.eventBox.setCurrentIndex(0)
else:
@ -651,8 +661,14 @@ class MainWindow(QMainWindow):
self.refreshEvents()
tabindex = self.tabs.currentIndex()
def fill_eventbox(self):
index=self.eventBox.currentIndex()
def fill_eventbox(self, eventBox=None, select_events='all'):
'''
:param: select_events, can be 'all', 'ref'
:type: str
'''
if not eventBox:
eventBox = self.eventBox
index=eventBox.currentIndex()
tv=QtGui.QTableView()
header = tv.horizontalHeader()
header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
@ -661,16 +677,17 @@ class MainWindow(QMainWindow):
tv.verticalHeader().hide()
tv.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.eventBox.setView(tv)
self.eventBox.clear()
model = self.eventBox.model()
eventBox.setView(tv)
eventBox.clear()
model = eventBox.model()
plmax=0
#set maximum length of path string
for event in self.project.eventlist:
pl = len(event.path)
if pl > plmax:
plmax=pl
for event in self.project.eventlist:
for id, event in enumerate(self.project.eventlist):
event_path = event.path
event_npicks = 0
event_nautopicks = 0
@ -681,11 +698,11 @@ class MainWindow(QMainWindow):
event_ref = event.isRefEvent()
event_test = event.isTestEvent()
text = '{path:{plen}} | manual: [{p:3d}] | auto: [{a:3d}]'
text = text.format(path=event_path,
plen=plmax,
p=event_npicks,
a=event_nautopicks)
# text = '{path:{plen}} | manual: [{p:3d}] | auto: [{a:3d}]'
# text = text.format(path=event_path,
# plen=plmax,
# p=event_npicks,
# a=event_nautopicks)
item_path = QtGui.QStandardItem('{path:{plen}}'.format(path=event_path, plen=plmax))
item_nmp = QtGui.QStandardItem(str(event_npicks))
@ -714,8 +731,17 @@ class MainWindow(QMainWindow):
# item2.setForeground(QtGui.QColor('black'))
# item2.setFont(font)
itemlist = [item_path, item_nmp, item_nap, item_ref, item_test, item_notes]
if event_test and select_events == 'ref':
for item in itemlist:
item.setEnabled(False)
model.appendRow(itemlist)
self.eventBox.setCurrentIndex(index)
if not event.path == self.eventBox.itemText(id):
message = ('Path missmatch creating eventbox.\n'
'{} unequal {}.'
.format(event.path, self.eventBox.itemText(id)))
raise ValueError(message)
eventBox.setItemData(id, event)
eventBox.setCurrentIndex(index)
def filename_from_action(self, action):
if action.data() is None:
@ -886,6 +912,7 @@ class MainWindow(QMainWindow):
self.refreshTabs()
def refreshTabs(self):
plotted=False
if self._eventChanged[0] or self._eventChanged[1]:
event = self.getCurrentEvent()
if not event.picks:
@ -901,19 +928,25 @@ class MainWindow(QMainWindow):
if len(self.project.eventlist) > 0:
if self._eventChanged[0]:
self.newWFplot()
plotted=True
if self.tabs.currentIndex() == 1:
if self._eventChanged[1]:
self.refresh_array_map()
if not plotted and self._eventChanged[0]:
self.newWFplot(False)
if self.tabs.currentIndex() == 2:
self.init_event_table()
def newWFplot(self):
self.loadWaveformDataThread()
self._eventChanged[0] = False
def newWFplot(self, plot=True):
self.loadWaveformDataThread(plot)
if plot:
self._eventChanged[0] = False
def loadWaveformDataThread(self):
wfd_thread = Thread(self, self.loadWaveformData, progressText='Reading data input...')
wfd_thread.finished.connect(self.plotWaveformDataThread)
def loadWaveformDataThread(self, plot=True):
wfd_thread = Thread(self, self.loadWaveformData,
progressText='Reading data input...')
if plot:
wfd_thread.finished.connect(self.plotWaveformDataThread)
wfd_thread.start()
def loadWaveformData(self):
@ -924,7 +957,8 @@ class MainWindow(QMainWindow):
# ans = self.data.setWFData(self.getWFFnames())
# else:
# ans = False
self.data.setWFData(self.getWFFnames_from_eventlist())
self.fnames = self.getWFFnames_from_eventbox(self.project.eventlist)
self.data.setWFData(self.fnames)
self._stime = full_range(self.get_data().getWFData())[0]
def connectWFplotEvents(self):
@ -981,7 +1015,8 @@ class MainWindow(QMainWindow):
self.draw()
def plotWaveformDataThread(self):
wfp_thread = Thread(self, self.plotWaveformData, progressText='Plotting waveform data...')
wfp_thread = Thread(self, self.plotWaveformData,
progressText='Plotting waveform data...')
wfp_thread.finished.connect(self.finishWaveformDataPlot)
wfp_thread.start()
@ -1113,7 +1148,7 @@ class MainWindow(QMainWindow):
station = self.getStationName(wfID)
self.update_status('picking on station {0}'.format(station))
data = self.get_data().getWFData()
pickDlg = PickDlg(self, infile=self.getinfile(),
pickDlg = PickDlg(self, parameter=self._inputs,
data=data.select(station=station),
station=station,
picks=self.getPicksOnStation(station, 'manual'),
@ -1122,6 +1157,7 @@ class MainWindow(QMainWindow):
self.setDirty(True)
self.update_status('picks accepted ({0})'.format(station))
replot = self.addPicks(station, pickDlg.getPicks())
self.getCurrentEvent().setPick(station, pickDlg.getPicks())
if replot:
self.plotWaveformData()
self.drawPicks()
@ -1141,6 +1177,40 @@ class MainWindow(QMainWindow):
self.listWidget.addItem(text)
self.listWidget.scrollToBottom()
def tune_autopicker(self):
self.fig_dict = {}
self.canvas_dict = {}
self.fig_keys = [
'mainFig',
'aicFig',
'slength',
'checkZ4s',
'refPpick',
'el_Ppick',
'fm_picker',
'el_S1pick',
'el_S2pick',
'refSpick',
'aicARHfig',
]
for key in self.fig_keys:
fig = Figure()
self.fig_dict[key] = fig
if not self.tap:
self.tap = TuneAutopicker(self)
self.update_autopicker()
self.tap.update.connect(self.update_autopicker)
self.tap.figure_tabs.setCurrentIndex(0)
else:
self.tap.fill_eventbox()
self.tap.show()
def update_autopicker(self):
for key in self.fig_dict.keys():
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
self.tap.fill_tabs(picked=True)
def autoPick(self):
self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
if not os.path.exists(self.autosave):
@ -1354,19 +1424,34 @@ 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
# refresh with new picks here!!!
self.array_map.refresh_drawings(self.picks)
self.array_map.refresh_drawings(self.getCurrentEvent().getPicks())
self._eventChanged[1] = False
def init_event_table(self, index=2):
def init_event_table(self, tabindex=2):
def set_enabled(item, enabled=True, checkable=False):
if enabled and not checkable:
item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
@ -1397,12 +1482,12 @@ class MainWindow(QMainWindow):
event.setTestEvent(True)
elif column == 4 and not item_test.checkState():
event.setTestEvent(False)
self.fill_eventbox()
self.fill_eventbox(self.eventBox)
elif column == 5:
#update event notes
notes = table[row][5].text()
event.addNotes(notes)
self.fill_eventbox()
self.fill_eventbox(self.eventBox)
if hasattr(self, 'qtl'):
self.qtl.setParent(None)
@ -1467,7 +1552,7 @@ class MainWindow(QMainWindow):
self.qtl.cellChanged[int, int].connect(cell_changed)
self.events_layout.addWidget(self.qtl)
self.tabs.setCurrentIndex(index)
self.tabs.setCurrentIndex(tabindex)
def read_metadata_thread(self, fninv):
self.rm_thread = Thread(self, read_metadata, arg=fninv, progressText='Reading metadata...')
@ -1656,7 +1741,7 @@ class MainWindow(QMainWindow):
self.createNewProject(exists=True)
def draw(self):
self.fill_eventbox()
self.fill_eventbox(self.eventBox)
self.getPlotWidget().draw()
def setDirty(self, value):
@ -1696,10 +1781,18 @@ class Project(object):
return
for item in eventlist:
event = Event(item)
if not event in self.eventlist:
if not event.path in self.getPaths():
self.eventlist.append(event)
else:
print('Skipping event with path {}. Already part of project.'.format(event.path))
self.setDirty()
def getPaths(self):
paths = []
for event in self.eventlist:
paths.append(event.path)
return paths
def setDirty(self):
self.dirty = True
@ -1752,18 +1845,12 @@ class Event(object):
'''
def __init__(self, path):
self.path = path
self.autopicks = None
self.picks = None
self.notes = None
self.autopicks = {}
self.picks = {}
self.notes = ''
self._testEvent = False
self._refEvent = False
def addPicks(self, picks):
self.picks = picks
def addAutopicks(self, autopicks):
self.autopicks = autopicks
def addNotes(self, notes):
self.notes = notes
@ -1783,7 +1870,43 @@ class Event(object):
def setTestEvent(self, bool):
self._testEvent = bool
if bool: self._refEvent = False
def addPicks(self, picks):
for station in picks:
self.picks[station] = picks[station]
def addAutopicks(self, autopicks):
for station in autopicks:
self.autopicks[station] = autopicks[station]
def setPick(self, station, pick):
if pick:
self.picks[station] = pick
def setPicks(self, picks):
self.picks = picks
def getPick(self, station):
if station in self.picks.keys():
return self.picks[station]
def getPicks(self):
return self.picks
def setAutopick(self, station, autopick):
if autopick:
self.autopicks[station] = autopick
def setAutopicks(self, autopicks):
self.autopicks = autopicks
def getAutopick(self, station):
if station in self.autopicks.keys():
return self.autopicks[station]
def getAutopicks(self):
return self.autopicks
class getExistingDirectories(QFileDialog):
def __init__(self, *args):

View File

@ -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(input_dict=None, parameter=None, inputfile=None, fnames=None, savepath=None, station='all', iplot=0):
"""
Determine phase onsets automatically utilizing the automatic picking
algorithms by Kueperkoch et al. 2010/2012.
@ -55,6 +55,21 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
***********************************'''.format(version=_getVersionString())
print(splash)
locflag = 1
if input_dict:
if input_dict.has_key('parameter'):
parameter = input_dict['parameter']
if input_dict.has_key('fig_dict'):
fig_dict = input_dict['fig_dict']
if input_dict.has_key('station'):
station = input_dict['station']
if input_dict.has_key('fnames'):
fnames = input_dict['fnames']
if input_dict.has_key('iplot'):
iplot = input_dict['iplot']
if input_dict.has_key('locflag'):
locflag = input_dict['locflag']
if not parameter:
if inputfile:
parameter = AutoPickParameter(inputfile)
@ -93,8 +108,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
datastructure.setExpandFields(exf)
# check if default location routine NLLoc is available
if parameter['nllocbin']:
locflag = 1
if parameter['nllocbin'] and locflag:
# get NLLoc-root path
nllocroot = parameter.get('nllocroot')
# get path to NLLoc executable
@ -158,15 +172,20 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
now.minute)
parameter.setParam(eventID=evID)
wfdat = data.getWFData() # all available streams
if not station == 'all':
wfdat = wfdat.select(station=station)
if not wfdat:
print('Could not find station {}. STOP!'.format(station))
return
wfdat = remove_underscores(wfdat)
metadata = read_metadata(parameter.get('invdir'))
corr_dat = restitute_data(wfdat.copy(), *metadata)
print('Working on event %s' % event)
print(data)
print('Working on event %s. Stations: %s' % (event, station))
print(wfdat)
##########################################################
# !automated picking starts here!
picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot)
picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
##########################################################
# locating
if locflag == 1:
@ -233,7 +252,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
print("autoPyLoT: Number of maximum iterations reached, stop iterative picking!")
break
print("autoPyLoT: Starting with iteration No. %d ..." % nlloccounter)
picks, _ = iteratepicker(wfdat, nllocfile, picks, badpicks, parameter)
picks = iteratepicker(wfdat, nllocfile, picks, badpicks, parameter, fig_dict=fig_dict)
# write phases to NLLoc-phase file
nll.export(picks, phasefile, parameter)
# remove actual NLLoc-location file to keep only the last
@ -317,7 +336,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
The Python picking and Location Tool\n
************************************'''.format(version=_getVersionString())
print(endsp)
return picks, mainFig
return picks
if __name__ == "__main__":
@ -344,4 +363,5 @@ if __name__ == "__main__":
cla = parser.parse_args()
picks, mainFig = autoPyLoT(str(cla.inputfile), str(cla.fnames), str(cla.spath))
picks, mainFig = autoPyLoT(inputfile=str(cla.inputfile),
fnames=str(cla.fnames), savepath=str(cla.spath))

View File

@ -1 +1 @@
dc65-dirty
55bc-dirty

View File

@ -47,47 +47,12 @@ class AutoPickParameter(object):
self.__init_default_paras()
self.__init_subsettings()
self.__filename = fnin
parFileCont = {}
self._verbosity = verbosity
self._parFileCont = {}
# io from parsed arguments alternatively
for key, val in kwargs.items():
parFileCont[key] = val
if self.__filename is not None:
inputFile = open(self.__filename, 'r')
else:
return
try:
lines = inputFile.readlines()
for line in lines:
parspl = line.split('\t')[:2]
parFileCont[parspl[0].strip()] = parspl[1]
except IndexError as e:
if verbosity > 0:
self._printParameterError(e)
inputFile.seek(0)
lines = inputFile.readlines()
for line in lines:
if not line.startswith(('#', '%', '\n', ' ')):
parspl = line.split('#')[:2]
parFileCont[parspl[1].strip()] = parspl[0].strip()
for key, value in parFileCont.items():
try:
val = int(value)
except:
try:
val = float(value)
except:
if len(value.split(' ')) > 1:
vallist = value.strip().split(' ')
val = []
for val0 in vallist:
val0 = float(val0)
val.append(val0)
else:
val = str(value.strip())
parFileCont[key] = val
self.__parameter = parFileCont
self._parFileCont[key] = val
self.from_file()
if fnout:
self.export2File(fnout)
@ -186,15 +151,64 @@ class AutoPickParameter(object):
if not is_type == expect_type and not is_type == tuple:
message = 'Type check failed for param: {}, is type: {}, expected type:{}'
message = message.format(param, is_type, expect_type)
raise TypeError(message)
print(Warning(message))
def setParam(self, param, value):
def setParamKV(self, param, value):
self.__setitem__(param, value)
def setParam(self, **kwargs):
for key in kwargs:
self.__setitem__(key, kwargs[key])
@staticmethod
def _printParameterError(errmsg):
print('ParameterError:\n non-existent parameter %s' % errmsg)
def reset_defaults(self):
defaults = self.get_defaults()
for param in defaults:
self.setParamKV(param, defaults[param]['value'])
def from_file(self, fnin=None):
if not fnin:
if self.__filename is not None:
fnin = self.__filename
else:
return
inputFile = open(fnin, 'r')
try:
lines = inputFile.readlines()
for line in lines:
parspl = line.split('\t')[:2]
self._parFileCont[parspl[0].strip()] = parspl[1]
except IndexError as e:
if self._verbosity > 0:
self._printParameterError(e)
inputFile.seek(0)
lines = inputFile.readlines()
for line in lines:
if not line.startswith(('#', '%', '\n', ' ')):
parspl = line.split('#')[:2]
self._parFileCont[parspl[1].strip()] = parspl[0].strip()
for key, value in self._parFileCont.items():
try:
val = int(value)
except:
try:
val = float(value)
except:
if len(value.split(' ')) > 1:
vallist = value.strip().split(' ')
val = []
for val0 in vallist:
val0 = float(val0)
val.append(val0)
else:
val = str(value.strip())
self._parFileCont[key] = val
self.__parameter = self._parFileCont
def export2File(self, fnout):
fid_out = open(fnout, 'w')
lines = []

View File

@ -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
@ -75,7 +74,7 @@ def call_autopickstation(input_tuple):
return autopickstation(wfstream, pickparam, verbose, iplot=0)
def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
"""
:param wfstream: `~obspy.core.stream.Stream` containing waveform
:type wfstream: obspy.core.stream.Stream
@ -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,12 @@ 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
if fig_dict:
fig = fig_dict[key]
else:
fig = None
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig=fig_dict[key])
##############################################################
if aicpick.getpick() is not None:
# check signal length to detect spuriously picked noise peaks
@ -252,9 +252,14 @@ 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)
if fig_dict:
fig = fig_dict[key]
else:
fig = None
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength / 2,
nfacsl, minpercent, iplot,
fig)
else:
# filter and taper horizontal traces
trH1_filt = edat.copy()
@ -269,10 +274,14 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
trH2_filt.taper(max_percentage=0.05, type='hann')
zne += trH1_filt
zne += trH2_filt
key = 'slenght'
Pflag, fig_dict[key] = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength,
nfacsl, minpercent, iplot)
if fig_dict:
fig = fig_dict['slength']
else:
fig = None
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength,
nfacsl, minpercent, iplot,
fig)
if Pflag == 1:
# check for spuriously picked S onset
@ -283,9 +292,12 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
if verbose: print(msg)
else:
if iplot>1:
key = 'checkZ4S'
Pflag, fig_dict[key] = checkZ4S(zne, aicpick.getpick(), zfac,
tsnrz[3], iplot)
if fig_dict:
fig = fig_dict['checkZ4s']
else:
fig = None
Pflag = checkZ4S(zne, aicpick.getpick(), zfac,
tsnrz[3], iplot, fig)
if Pflag == 0:
Pmarker = 'SinsteadP'
Pweight = 9
@ -332,19 +344,24 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
'correctly: maybe the algorithm name ({algoP}) is ' \
'corrupted'.format(
algoP=algoP)
if fig_dict:
fig = fig_dict['refPpick']
else:
fig = None
refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP,
aicpick.getpick())
key = 'refPpick'
fig_dict[key] = refPpick.fig
aicpick.getpick(), fig)
mpickP = refPpick.getpick()
#############################################################
if mpickP is not None:
# quality assessment
# 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)
if fig_dict:
fig = fig_dict['el_Ppick']
else:
fig = None
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
mpickP, iplot, fig=fig)
else:
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
mpickP, iplot)
@ -369,8 +386,11 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
# certain quality required
if Pweight <= minfmweight and SNRP >= minFMSNR:
if iplot:
key = 'fm_picker'
FM, fig_dict[key] = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
if fig_dict:
fig = fig_dict['fm_picker']
else:
fig = None
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot, fig)
else:
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
else:
@ -471,10 +491,12 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
##############################################################
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
# of class AutoPicking
if fig_dict:
fig = fig_dict['aicARHfig']
else:
fig = None
aicarhpick = AICPicker(haiccf, tsnrh, pickwinS, iplot, None,
aictsmoothS)
key = 'aicARHfig'
fig_dict[key] = aicarhpick.fig
aictsmoothS, fig=fig)
###############################################################
# go on with processing if AIC onset passes quality control
if (aicarhpick.getSlope() >= minAICSslope and
@ -528,10 +550,12 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
addnoise) # instance of ARHcf
# get refined onset time from CF2 using class Picker
if fig_dict:
fig = fig_dict['refSpick']
else:
fig = None
refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS,
tsmoothS, aicarhpick.getpick())
key = 'refSpick'
fig_dict[key] = refSpick.fig
tsmoothS, aicarhpick.getpick(), fig)
mpickS = refSpick.getpick()
#############################################################
if mpickS is not None:
@ -539,10 +563,14 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
# get earliest/latest possible pick and symmetrized uncertainty
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)
if fig_dict:
fig = fig_dict['el_S1pick']
else:
fig = None
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
tsnrh,
mpickS, iplot,
fig=fig)
else:
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
tsnrh,
@ -550,10 +578,14 @@ 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)
if fig_dict:
fig = fig_dict['el_S2pick']
else:
fig = None
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
tsnrh,
mpickS, iplot,
fig=fig)
else:
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
tsnrh,
@ -649,7 +681,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)
@ -700,7 +735,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
if len(edat[0]) > 1 and len(ndat[0]) > 1 and Sflag == 1:
# plot horizontal traces
ax2 = fig.add_subplot(312)
ax2 = fig.add_subplot(3,1,2,sharex=ax1)
th1data = np.arange(0,
trH1_filt.stats.npts /
trH1_filt.stats.sampling_rate,
@ -749,7 +784,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0):
ax2.set_ylabel('Normalized Counts')
#fig.suptitle(trH1_filt.stats.starttime)
ax3 = fig.add_subplot(313)
ax3 = fig.add_subplot(3,1,3, sharex=ax1)
th2data = np.arange(0,
trH2_filt.stats.npts /
trH2_filt.stats.sampling_rate,
@ -792,8 +827,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,10 +873,10 @@ 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):
def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter, fig_dict=None):
'''
Repicking of bad onsets. Uses theoretical onset times from NLLoc-location file.
@ -918,7 +951,7 @@ def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter):
print("zfac: %f => %f" % (zfac_old, pickparameter.get('zfac')))
# repick station
newpicks, fig = autopickstation(wf2pick, pickparameter)
newpicks = autopickstation(wf2pick, pickparameter, fig_dict=fig_dict)
# replace old dictionary with new one
picks[badpicks[i][0]] = newpicks
@ -933,4 +966,4 @@ def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter):
pickparameter.setParam(noisefactor=noisefactor_old)
pickparameter.setParam(zfac=zfac_old)
return picks, fig
return picks

View File

@ -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,8 @@ class AutoPicker(object):
self.setaus(aus)
self.setTsmooth(Tsmooth)
self.setpick1(Pick1)
self.fig = self.calcPick()
self.fig = fig
self.calcPick()
def __str__(self):
return '''\n\t{name} object:\n
@ -152,7 +153,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 +227,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 +239,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 +256,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')
@ -262,27 +268,33 @@ class AICPicker(AutoPicker):
ax1.plot([self.Pick, self.Pick], [-0.1, 0.5], 'b', linewidth=2, label='AIC-Pick')
ax1.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax1.set_yticks([])
ax1.set_title(self.Data[0].stats.station)
ax1.legend()
if self.Pick is not None:
ax2 = fig.add_subplot(212)
ax2 = fig.add_subplot(2,1,2, sharex=ax1)
ax2.plot(self.Tcf, x, 'k', label='Data')
ax2.plot(self.Tcf[inoise], self.Data[0].data[inoise], label='Noise Window')
ax2.plot(self.Tcf[isignal], self.Data[0].data[isignal], 'r', label='Signal Window')
ax2.plot(self.Tcf[islope], dataslope, 'g--', label='Slope Window')
ax1.axvspan(self.Tcf[inoise[0]],self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax1.axvspan(self.Tcf[isignal[0]],self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
ax1.axvspan(self.Tcf[islope[0]],self.Tcf[islope[-1]], color='g', alpha=0.2, lw=0, label='Slope Window')
ax2.axvspan(self.Tcf[inoise[0]],self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax2.axvspan(self.Tcf[isignal[0]],self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
ax2.axvspan(self.Tcf[islope[0]],self.Tcf[islope[-1]], color='g', alpha=0.2, lw=0, label='Slope Window')
ax2.plot(self.Tcf[islope], datafit, 'g', linewidth=2, label='Slope')
ax2.set_title('Station %s, SNR=%7.2f, Slope= %12.2f counts/s' % (self.Data[0].stats.station,
ax1.set_title('Station %s, SNR=%7.2f, Slope= %12.2f counts/s' % (self.Data[0].stats.station,
self.SNR, self.slope))
ax2.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax2.set_ylabel('Counts')
ax2.set_yticks([])
ax2.legend()
else:
ax1.set_title(self.Data[0].stats.station)
if self.Pick == None:
print('AICPicker: Could not find minimum, picking window too short?')
return fig
return
class PragPicker(AutoPicker):
@ -375,7 +387,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 +400,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!')

View File

@ -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,11 +104,12 @@ 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')
ax.plot(t[isignal], x[isignal], 'r', label='Signal Window')
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax.axvspan(t[isignal[0]], t[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
ax.plot([t[0], t[int(len(t)) - 1]], [nlevel, nlevel], '--k', label='Noise Level')
ax.plot(t[isignal[zc]], np.zeros(len(zc)), '*g',
markersize=14, label='Zero Crossings')
@ -127,13 +128,10 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False):
X[0].stats.station)
ax.legend()
if iplot:
return EPick, LPick, PickError, fig
else:
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=None):
'''
Function to derive first motion (polarity) of given phase onset Pick.
Calculation is based on zero crossings determined within time window pickwin
@ -278,7 +276,8 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None):
print ("fmpicker: Found polarity %s" % FM)
if iplot > 1:
fig = plt.figure()#iplot)
if not fig:
fig = plt.figure()#iplot)
ax1 = fig.add_subplot(211)
ax1.plot(t, xraw, 'k')
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick')
@ -292,7 +291,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None):
ax1.set_title('First-Motion Determination, %s, Unfiltered Data' % Xraw[
0].stats.station)
ax2=fig.add_subplot(212)
ax2=fig.add_subplot(2,1,2, sharex=ax1)
ax2.set_title('First-Motion Determination, Filtered Data')
ax2.plot(t, xfilt, 'k')
ax2.plot([Pick, Pick], [max(xfilt), -max(xfilt)], 'b',
@ -305,10 +304,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None):
ax2.set_xlabel('Time [s] since %s' % Xraw[0].stats.starttime)
ax2.set_yticks([])
if iplot:
return FM, fig
else:
return FM
return FM
def crossings_nonzero_all(data):
@ -620,7 +616,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=None):
'''
Function to detect spuriously picked noise peaks.
Uses RMS trace of all 3 components (if available) to determine,
@ -692,11 +688,12 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
returnflag = 0
if iplot == 2:
fig = plt.figure()#iplot)
if not fig:
fig = plt.figure()#iplot)
ax = fig.add_subplot(111)
ax.plot(t, rms, 'k', label='RMS Data')
ax.plot(t[inoise], rms[inoise], 'c', label='RMS Noise Window')
ax.plot(t[isignal], rms[isignal], 'r', label='RMS Signal Window')
ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax.axvspan(t[isignal[0]], t[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
ax.plot([t[isignal[0]], t[isignal[len(isignal) - 1]]],
[minsiglevel, minsiglevel], 'g', linewidth=2, label='Minimum Signal Level')
ax.plot([pick, pick], [min(rms), max(rms)], 'b', linewidth=2, label='Onset')
@ -706,7 +703,7 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
ax.set_title('Check for Signal Length, Station %s' % X[0].stats.station)
ax.set_yticks([])
return returnflag, fig
return returnflag
def checkPonsets(pickdic, dttolerance, iplot):
@ -868,7 +865,7 @@ def jackknife(X, phi, h):
return PHI_jack, PHI_pseudo, PHI_sub
def checkZ4S(X, pick, zfac, checkwin, iplot):
def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None):
'''
Function to compare energy content of vertical trace with
energy content of horizontal traces to detect spuriously
@ -962,14 +959,14 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
edat[0].stats.delta)
tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate,
ndat[0].stats.delta)
fig = plt.figure()
if not fig:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(tz, z / max(z), 'k')
ax.plot(tz[isignal], z[isignal] / max(z), 'r')
ax.axvspan(tz[isignal[0]], tz[isignal[-1]], color='b', alpha=0.2,
lw=0, label='Signal Window')
ax.plot(te, edat[0].data / max(edat[0].data) + 1, 'k')
ax.plot(te[isignal], edat[0].data[isignal] / max(edat[0].data) + 1, 'r')
ax.plot(tn, ndat[0].data / max(ndat[0].data) + 2, 'k')
ax.plot(tn[isignal], ndat[0].data[isignal] / max(ndat[0].data) + 2, 'r')
ax.plot([tz[isignal[0]], tz[isignal[len(isignal) - 1]]],
[minsiglevel / max(z), minsiglevel / max(z)], 'g',
linewidth=2, label='Minimum Signal Level')
@ -980,7 +977,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
ax.set_title('CheckZ4S, Station %s' % zdat[0].stats.station)
ax.legend()
return returnflag, fig
return returnflag
if __name__ == '__main__':

View File

@ -12,61 +12,83 @@ 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 == []:
button = event.mouseevent.button
if ind == [] or not button == 1:
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, parameter=self._parent._inputs,
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
if pickDlg.exec_():
pyl_mw.setDirty(True)
pyl_mw.update_status('picks accepted ({0})'.format(station))
replot = pyl_mw.addPicks(station, pickDlg.getPicks())
if replot:
pyl_mw.plotWaveformData()
pyl_mw.drawPicks()
pyl_mw.draw()
else:
pyl_mw.drawPicks(station)
pyl_mw.draw()
else:
pyl_mw.update_status('picks discarded ({0})'.format(station))
picks=self._parent.getCurrentEvent().getPick(station),
autopicks=self._parent.getCurrentEvent().getAutopick(station))
except Exception as e:
print('Could not generate Plot for station {st}.\n{er}'.format(st=station, er=e))
message = 'Could not generate Plot for station {st}.\n{er}'.format(st=station, er=e)
self._warn(message)
print(message, e)
pyl_mw = self._parent
#try:
if pickDlg.exec_():
pyl_mw.setDirty(True)
pyl_mw.update_status('picks accepted ({0})'.format(station))
replot = pyl_mw.getCurrentEvent().setPick(station, pickDlg.getPicks())
if replot:
pyl_mw.plotWaveformData()
pyl_mw.drawPicks()
pyl_mw.draw()
else:
pyl_mw.drawPicks(station)
pyl_mw.draw()
else:
pyl_mw.update_status('picks discarded ({0})'.format(station))
# except Exception as e:
# message = 'Could not save picks for station {st}.\n{er}'.format(st=station, er=e)
# self._warn(message)
# print(message, e)
def connectSignals(self):
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)
@ -77,26 +99,17 @@ class map_projection(QtGui.QWidget):
self.comboBox_phase.insertItem(0, 'P')
self.comboBox_phase.insertItem(1, 'S')
# self.comboBox_am = QtGui.QComboBox()
# self.comboBox_am.insertItem(0, 'auto')
# self.comboBox_am.insertItem(1, 'manual')
self.comboBox_am = QtGui.QComboBox()
self.comboBox_am.insertItem(0, 'auto')
self.comboBox_am.insertItem(1, 'manual')
self.top_row.addWidget(QtGui.QLabel('Select a phase: '))
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):
station_names=[]
@ -128,9 +141,13 @@ class map_projection(QtGui.QWidget):
def get_picks_rel(picks):
picks_rel=[]
minp = min(picks)
picks_utc = []
for pick in picks:
if type(pick) is obspy.core.utcdatetime.UTCDateTime:
picks_utc.append(pick)
minp = min(picks_utc)
for pick in picks:
if type(pick) is obspy.core.utcdatetime.UTCDateTime:
pick -= minp
picks_rel.append(pick)
return picks_rel
@ -186,7 +203,6 @@ class map_projection(QtGui.QWidget):
basemap.drawcoastlines()
self.basemap = basemap
self.figure.tight_layout()
def init_lat_lon_grid(self):
def get_lat_lon_axis(lat, lon):
@ -219,8 +235,19 @@ class map_projection(QtGui.QWidget):
self.cid = self.canvas.mpl_connect('pick_event', self.onpick)
def scatter_picked_stations(self):
self.sc_picked = self.basemap.scatter(self.lon_no_nan, self.lat_no_nan, s=50, facecolor='white',
c=self.picks_no_nan, latlon=True, zorder=11, label='Picked')
lon = self.lon_no_nan
lat = self.lat_no_nan
#workaround because of an issue with latlon transformation of arrays with len <3
if len(lon) <= 2 and len(lat) <= 2:
self.sc_picked = self.basemap.scatter(lon[0], lat[0], s=50, facecolor='white',
c=self.picks_no_nan[0], latlon=True, zorder=11, label='Picked')
if len(lon) == 2 and len(lat) == 2:
self.sc_picked = self.basemap.scatter(lon[1], lat[1], s=50, facecolor='white',
c=self.picks_no_nan[1], latlon=True, zorder=11)
else:
self.sc_picked = self.basemap.scatter(lon, lat, s=50, facecolor='white',
c=self.picks_no_nan, latlon=True, zorder=11, label='Picked')
def annotate_ax(self):
self.annotations=[]
@ -248,8 +275,9 @@ class map_projection(QtGui.QWidget):
self.init_picks()
self.init_picks_active()
self.init_stations_active()
self.init_picksgrid()
self.draw_contour_filled()
if len(self.picks_no_nan) >= 3:
self.init_picksgrid()
self.draw_contour_filled()
self.scatter_all_stations()
if self.picks_dict:
self.scatter_picked_stations()
@ -291,4 +319,9 @@ class map_projection(QtGui.QWidget):
for annotation in self.annotations:
annotation.remove()
def _warn(self, message):
self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning,
'Warning', message)
self.qmb.show()

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import sys
from PySide.QtCore import QThread, Signal, Qt
from PySide.QtGui import QDialog, QProgressBar, QLabel, QVBoxLayout
from PySide.QtGui import QDialog, QProgressBar, QLabel, QHBoxLayout
class AutoPickThread(QThread):
@ -39,39 +39,57 @@ class AutoPickThread(QThread):
class Thread(QThread):
def __init__(self, parent, func, arg=None, progressText=None):
message = Signal(str)
def __init__(self, parent, func, arg=None, progressText=None, pb_widget=None, redirect_stdout=False):
QThread.__init__(self, parent)
self.func = func
self.arg = arg
self.progressText = progressText
self.pbdlg = None
self.pb_widget = pb_widget
self.redirect_stdout = redirect_stdout
self.finished.connect(self.hideProgressbar)
self.showProgressbar()
def run(self):
if self.arg:
self.data = self.func(self.arg)
else:
self.data = self.func()
if self.redirect_stdout:
sys.stdout = self
try:
if self.arg:
self.data = self.func(self.arg)
else:
self.data = self.func()
self._executed = True
except Exception as e:
self._executed = False
self._executedError = e
print(e)
sys.stdout = sys.__stdout__
def __del__(self):
self.wait()
def showProgressbar(self):
if self.progressText:
self.pbdlg = QDialog(self.parent())
self.pbdlg.setModal(True)
vl = QVBoxLayout()
if not self.pb_widget:
self.pb_widget = QDialog(self.parent())
self.pb_widget.setWindowFlags(Qt.SplashScreen)
self.pb_widget.setModal(True)
hl = QHBoxLayout()
pb = QProgressBar()
pb.setRange(0, 0)
vl.addWidget(pb)
vl.addWidget(QLabel(self.progressText))
self.pbdlg.setLayout(vl)
self.pbdlg.setWindowFlags(Qt.SplashScreen)
self.pbdlg.show()
hl.addWidget(pb)
hl.addWidget(QLabel(self.progressText))
self.pb_widget.setLayout(hl)
self.pb_widget.show()
def hideProgressbar(self):
if self.pbdlg:
self.pbdlg.hide()
if self.pb_widget:
self.pb_widget.hide()
def write(self, text):
self.message.emit(text)
def flush(self):
pass

File diff suppressed because it is too large Load Diff