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

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(input_dict=None, parameter=None, inputfile=None, fnames=None, savepath=None, station='all', iplot=0):
""" """
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.
@ -55,6 +55,21 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
***********************************'''.format(version=_getVersionString()) ***********************************'''.format(version=_getVersionString())
print(splash) 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 not parameter:
if inputfile: if inputfile:
parameter = AutoPickParameter(inputfile) parameter = AutoPickParameter(inputfile)
@ -93,8 +108,7 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
datastructure.setExpandFields(exf) datastructure.setExpandFields(exf)
# check if default location routine NLLoc is available # check if default location routine NLLoc is available
if parameter['nllocbin']: if parameter['nllocbin'] and locflag:
locflag = 1
# get NLLoc-root path # get NLLoc-root path
nllocroot = parameter.get('nllocroot') nllocroot = parameter.get('nllocroot')
# get path to NLLoc executable # get path to NLLoc executable
@ -158,15 +172,20 @@ def autoPyLoT(parameter=None, inputfile=None, fnames=None, savepath=None, iplot=
now.minute) now.minute)
parameter.setParam(eventID=evID) parameter.setParam(eventID=evID)
wfdat = data.getWFData() # all available streams 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) wfdat = remove_underscores(wfdat)
metadata = read_metadata(parameter.get('invdir')) metadata = read_metadata(parameter.get('invdir'))
corr_dat = restitute_data(wfdat.copy(), *metadata) corr_dat = restitute_data(wfdat.copy(), *metadata)
print('Working on event %s' % event) print('Working on event %s. Stations: %s' % (event, station))
print(data) print(wfdat)
########################################################## ##########################################################
# !automated picking starts here! # !automated picking starts here!
picks, mainFig = autopickevent(wfdat, parameter, iplot=iplot) picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
########################################################## ##########################################################
# locating # locating
if locflag == 1: 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!") print("autoPyLoT: Number of maximum iterations reached, stop iterative picking!")
break break
print("autoPyLoT: Starting with iteration No. %d ..." % nlloccounter) 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 # write phases to NLLoc-phase file
nll.export(picks, phasefile, parameter) nll.export(picks, phasefile, parameter)
# remove actual NLLoc-location file to keep only the last # 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 The Python picking and Location Tool\n
************************************'''.format(version=_getVersionString()) ************************************'''.format(version=_getVersionString())
print(endsp) print(endsp)
return picks, mainFig return picks
if __name__ == "__main__": if __name__ == "__main__":
@ -344,4 +363,5 @@ if __name__ == "__main__":
cla = parser.parse_args() 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_default_paras()
self.__init_subsettings() self.__init_subsettings()
self.__filename = fnin self.__filename = fnin
parFileCont = {} self._verbosity = verbosity
self._parFileCont = {}
# io from parsed arguments alternatively # io from parsed arguments alternatively
for key, val in kwargs.items(): for key, val in kwargs.items():
parFileCont[key] = val self._parFileCont[key] = val
self.from_file()
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
if fnout: if fnout:
self.export2File(fnout) self.export2File(fnout)
@ -186,15 +151,64 @@ class AutoPickParameter(object):
if not is_type == expect_type and not is_type == tuple: if not is_type == expect_type and not is_type == tuple:
message = 'Type check failed for param: {}, is type: {}, expected type:{}' message = 'Type check failed for param: {}, is type: {}, expected type:{}'
message = message.format(param, is_type, expect_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) self.__setitem__(param, value)
def setParam(self, **kwargs):
for key in kwargs:
self.__setitem__(key, kwargs[key])
@staticmethod @staticmethod
def _printParameterError(errmsg): def _printParameterError(errmsg):
print('ParameterError:\n non-existent parameter %s' % 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): def export2File(self, fnout):
fid_out = open(fnout, 'w') fid_out = open(fnout, 'w')
lines = [] lines = []

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

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,8 @@ 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
self.calcPick()
def __str__(self): def __str__(self):
return '''\n\t{name} object:\n return '''\n\t{name} object:\n
@ -152,7 +153,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 +227,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:
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) 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 +239,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 +256,10 @@ class AICPicker(AutoPicker):
self.slope = None self.slope = None
if self.iplot > 1: 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) 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')
@ -262,27 +268,33 @@ class AICPicker(AutoPicker):
ax1.plot([self.Pick, self.Pick], [-0.1, 0.5], 'b', linewidth=2, label='AIC-Pick') 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_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax1.set_yticks([]) ax1.set_yticks([])
ax1.set_title(self.Data[0].stats.station)
ax1.legend() ax1.legend()
if self.Pick is not None: 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, x, 'k', label='Data')
ax2.plot(self.Tcf[inoise], self.Data[0].data[inoise], label='Noise Window') ax1.axvspan(self.Tcf[inoise[0]],self.Tcf[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax2.plot(self.Tcf[isignal], self.Data[0].data[isignal], 'r', label='Signal Window') ax1.axvspan(self.Tcf[isignal[0]],self.Tcf[isignal[-1]], color='b', alpha=0.2, lw=0, label='Signal Window')
ax2.plot(self.Tcf[islope], dataslope, 'g--', label='Slope 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.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)) self.SNR, self.slope))
ax2.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime) ax2.set_xlabel('Time [s] since %s' % self.Data[0].stats.starttime)
ax2.set_ylabel('Counts') ax2.set_ylabel('Counts')
ax2.set_yticks([]) ax2.set_yticks([])
ax2.legend() ax2.legend()
else:
ax1.set_title(self.Data[0].stats.station)
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 +387,10 @@ class PragPicker(AutoPicker):
pickflag = 0 pickflag = 0
if self.getiplot() > 1: 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 = 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 +400,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,11 +104,12 @@ 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:
fig = plt.figure()#iplot) if not fig:
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')
ax.plot(t[inoise], x[inoise], label='Noise Window') ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax.plot(t[isignal], x[isignal], 'r', label='Signal 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[0], t[int(len(t)) - 1]], [nlevel, nlevel], '--k', label='Noise Level')
ax.plot(t[isignal[zc]], np.zeros(len(zc)), '*g', ax.plot(t[isignal[zc]], np.zeros(len(zc)), '*g',
markersize=14, label='Zero Crossings') markersize=14, label='Zero Crossings')
@ -127,13 +128,10 @@ def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealth_mode=False):
X[0].stats.station) X[0].stats.station)
ax.legend() ax.legend()
if iplot: return EPick, LPick, PickError
return EPick, LPick, PickError, fig
else:
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. 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
@ -278,7 +276,8 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=None):
print ("fmpicker: Found polarity %s" % FM) print ("fmpicker: Found polarity %s" % FM)
if iplot > 1: if iplot > 1:
fig = plt.figure()#iplot) if not fig:
fig = plt.figure()#iplot)
ax1 = fig.add_subplot(211) ax1 = fig.add_subplot(211)
ax1.plot(t, xraw, 'k') ax1.plot(t, xraw, 'k')
ax1.plot([Pick, Pick], [max(xraw), -max(xraw)], 'b', linewidth=2, label='Pick') 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[ ax1.set_title('First-Motion Determination, %s, Unfiltered Data' % Xraw[
0].stats.station) 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.set_title('First-Motion Determination, Filtered Data')
ax2.plot(t, xfilt, 'k') ax2.plot(t, xfilt, 'k')
ax2.plot([Pick, Pick], [max(xfilt), -max(xfilt)], 'b', 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_xlabel('Time [s] since %s' % Xraw[0].stats.starttime)
ax2.set_yticks([]) ax2.set_yticks([])
if iplot: return FM
return FM, fig
else:
return FM
def crossings_nonzero_all(data): def crossings_nonzero_all(data):
@ -620,7 +616,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=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,
@ -692,11 +688,12 @@ def checksignallength(X, pick, TSNR, minsiglength, nfac, minpercent, iplot):
returnflag = 0 returnflag = 0
if iplot == 2: if iplot == 2:
fig = plt.figure()#iplot) if not fig:
fig = plt.figure()#iplot)
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(t, rms, 'k', label='RMS Data') ax.plot(t, rms, 'k', label='RMS Data')
ax.plot(t[inoise], rms[inoise], 'c', label='RMS Noise Window') ax.axvspan(t[inoise[0]], t[inoise[-1]], color='y', alpha=0.2, lw=0, label='Noise Window')
ax.plot(t[isignal], rms[isignal], 'r', label='RMS Signal 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]]], ax.plot([t[isignal[0]], t[isignal[len(isignal) - 1]]],
[minsiglevel, minsiglevel], 'g', linewidth=2, label='Minimum Signal Level') [minsiglevel, minsiglevel], 'g', linewidth=2, label='Minimum Signal Level')
ax.plot([pick, pick], [min(rms), max(rms)], 'b', linewidth=2, label='Onset') 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_title('Check for Signal Length, Station %s' % X[0].stats.station)
ax.set_yticks([]) ax.set_yticks([])
return returnflag, fig return returnflag
def checkPonsets(pickdic, dttolerance, iplot): def checkPonsets(pickdic, dttolerance, iplot):
@ -868,7 +865,7 @@ def jackknife(X, phi, h):
return PHI_jack, PHI_pseudo, PHI_sub 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 Function to compare energy content of vertical trace with
energy content of horizontal traces to detect spuriously energy content of horizontal traces to detect spuriously
@ -962,14 +959,14 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
edat[0].stats.delta) edat[0].stats.delta)
tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate, tn = np.arange(0, ndat[0].stats.npts / ndat[0].stats.sampling_rate,
ndat[0].stats.delta) ndat[0].stats.delta)
fig = plt.figure() if not fig:
fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(tz, z / max(z), 'k') 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, 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, 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]]], ax.plot([tz[isignal[0]], tz[isignal[len(isignal) - 1]]],
[minsiglevel / max(z), minsiglevel / max(z)], 'g', [minsiglevel / max(z), minsiglevel / max(z)], 'g',
linewidth=2, label='Minimum Signal Level') 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.set_title('CheckZ4S, Station %s' % zdat[0].stats.station)
ax.legend() ax.legend()
return returnflag, fig return returnflag
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -12,61 +12,83 @@ 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 == []: button = event.mouseevent.button
if ind == [] or not button == 1:
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, parameter=self._parent._inputs,
data=data.select(station=station), data=data.select(station=station),
station=station, station=station,
picks=self.pyl_mainwindow.getPicksOnStation(station, 'manual'), picks=self._parent.getCurrentEvent().getPick(station),
autopicks=self.pyl_mainwindow.getPicksOnStation(station, 'auto')) autopicks=self._parent.getCurrentEvent().getAutopick(station))
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))
except Exception as e: 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): def connectSignals(self):
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)
@ -77,26 +99,17 @@ class map_projection(QtGui.QWidget):
self.comboBox_phase.insertItem(0, 'P') self.comboBox_phase.insertItem(0, 'P')
self.comboBox_phase.insertItem(1, 'S') self.comboBox_phase.insertItem(1, 'S')
# self.comboBox_am = QtGui.QComboBox() self.comboBox_am = QtGui.QComboBox()
# self.comboBox_am.insertItem(0, 'auto') self.comboBox_am.insertItem(0, 'auto')
# self.comboBox_am.insertItem(1, 'manual') self.comboBox_am.insertItem(1, 'manual')
self.top_row.addWidget(QtGui.QLabel('Select a phase: ')) self.top_row.addWidget(QtGui.QLabel('Select a phase: '))
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):
station_names=[] station_names=[]
@ -128,9 +141,13 @@ class map_projection(QtGui.QWidget):
def get_picks_rel(picks): def get_picks_rel(picks):
picks_rel=[] picks_rel=[]
minp = min(picks) picks_utc = []
for pick in picks: for pick in picks:
if type(pick) is obspy.core.utcdatetime.UTCDateTime: 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 pick -= minp
picks_rel.append(pick) picks_rel.append(pick)
return picks_rel return picks_rel
@ -186,7 +203,6 @@ class map_projection(QtGui.QWidget):
basemap.drawcoastlines() basemap.drawcoastlines()
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):
@ -219,8 +235,19 @@ class map_projection(QtGui.QWidget):
self.cid = self.canvas.mpl_connect('pick_event', self.onpick) self.cid = self.canvas.mpl_connect('pick_event', self.onpick)
def scatter_picked_stations(self): def scatter_picked_stations(self):
self.sc_picked = self.basemap.scatter(self.lon_no_nan, self.lat_no_nan, s=50, facecolor='white', lon = self.lon_no_nan
c=self.picks_no_nan, latlon=True, zorder=11, label='Picked') 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): def annotate_ax(self):
self.annotations=[] self.annotations=[]
@ -248,8 +275,9 @@ class map_projection(QtGui.QWidget):
self.init_picks() self.init_picks()
self.init_picks_active() self.init_picks_active()
self.init_stations_active() self.init_stations_active()
self.init_picksgrid() if len(self.picks_no_nan) >= 3:
self.draw_contour_filled() self.init_picksgrid()
self.draw_contour_filled()
self.scatter_all_stations() self.scatter_all_stations()
if self.picks_dict: if self.picks_dict:
self.scatter_picked_stations() self.scatter_picked_stations()
@ -291,4 +319,9 @@ class map_projection(QtGui.QWidget):
for annotation in self.annotations: for annotation in self.annotations:
annotation.remove() 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 -*- # -*- coding: utf-8 -*-
import sys import sys
from PySide.QtCore import QThread, Signal, Qt 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): class AutoPickThread(QThread):
@ -39,39 +39,57 @@ class AutoPickThread(QThread):
class Thread(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) QThread.__init__(self, parent)
self.func = func self.func = func
self.arg = arg self.arg = arg
self.progressText = progressText self.progressText = progressText
self.pbdlg = None self.pb_widget = pb_widget
self.redirect_stdout = redirect_stdout
self.finished.connect(self.hideProgressbar) self.finished.connect(self.hideProgressbar)
self.showProgressbar() self.showProgressbar()
def run(self): def run(self):
if self.arg: if self.redirect_stdout:
self.data = self.func(self.arg) sys.stdout = self
else: try:
self.data = self.func() 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): def __del__(self):
self.wait() self.wait()
def showProgressbar(self): def showProgressbar(self):
if self.progressText: if self.progressText:
self.pbdlg = QDialog(self.parent()) if not self.pb_widget:
self.pbdlg.setModal(True) self.pb_widget = QDialog(self.parent())
vl = QVBoxLayout() self.pb_widget.setWindowFlags(Qt.SplashScreen)
self.pb_widget.setModal(True)
hl = QHBoxLayout()
pb = QProgressBar() pb = QProgressBar()
pb.setRange(0, 0) pb.setRange(0, 0)
vl.addWidget(pb) hl.addWidget(pb)
vl.addWidget(QLabel(self.progressText)) hl.addWidget(QLabel(self.progressText))
self.pbdlg.setLayout(vl) self.pb_widget.setLayout(hl)
self.pbdlg.setWindowFlags(Qt.SplashScreen) self.pb_widget.show()
self.pbdlg.show()
def hideProgressbar(self): def hideProgressbar(self):
if self.pbdlg: if self.pb_widget:
self.pbdlg.hide() 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