Merge branch 'develop' of ariadne.geophysik.ruhr-uni-bochum.de:/data/git/pylot into develop
This commit is contained in:
commit
c353c24283
80
QtPyLoT.py
80
QtPyLoT.py
@ -81,7 +81,7 @@ from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
|||||||
getDataType, ComparisonDialog, TuneAutopicker, PylotParaBox
|
getDataType, ComparisonDialog, TuneAutopicker, PylotParaBox
|
||||||
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, MultiThread
|
||||||
from pylot.core.util.version import get_git_version as _getVersionString
|
from pylot.core.util.version import get_git_version as _getVersionString
|
||||||
|
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info.major == 3:
|
||||||
@ -1838,6 +1838,36 @@ class MainWindow(QMainWindow):
|
|||||||
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
||||||
self.tap.fill_tabs(picked=True)
|
self.tap.fill_tabs(picked=True)
|
||||||
|
|
||||||
|
# def autoPick(self):
|
||||||
|
# self.autosave = QFileDialog().getExistingDirectory(caption='Select autoPyLoT output')
|
||||||
|
# if not os.path.exists(self.autosave):
|
||||||
|
# QMessageBox.warning(self, "PyLoT Warning",
|
||||||
|
# "No autoPyLoT output declared!")
|
||||||
|
# return
|
||||||
|
# self.listWidget = QListWidget()
|
||||||
|
# self.setDirty(True)
|
||||||
|
# self.logDockWidget = QDockWidget("AutoPickLog", self)
|
||||||
|
# self.logDockWidget.setObjectName("LogDockWidget")
|
||||||
|
# self.logDockWidget.setAllowedAreas(
|
||||||
|
# Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
|
||||||
|
# self.logDockWidget.setWidget(self.listWidget)
|
||||||
|
# self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)
|
||||||
|
# self.addListItem('Loading default values from PyLoT-input file %s'
|
||||||
|
# % self.infile)
|
||||||
|
# autopick_parameter = self._inputs
|
||||||
|
# self.addListItem(str(autopick_parameter))
|
||||||
|
# receventid = self.get_current_event_path()
|
||||||
|
# self.thread = AutoPickThread(parent=self,
|
||||||
|
# func=autoPyLoT,
|
||||||
|
# infile=self.infile,
|
||||||
|
# fnames=self.fnames,
|
||||||
|
# eventid=receventid,
|
||||||
|
# savepath=self.autosave)
|
||||||
|
|
||||||
|
# self.thread.message.connect(self.addListItem)
|
||||||
|
# self.thread.start()
|
||||||
|
# self.thread.finished.connect(self.finalizeAutoPick)
|
||||||
|
|
||||||
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):
|
||||||
@ -1852,26 +1882,44 @@ class MainWindow(QMainWindow):
|
|||||||
Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
|
Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
|
||||||
self.logDockWidget.setWidget(self.listWidget)
|
self.logDockWidget.setWidget(self.listWidget)
|
||||||
self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)
|
self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)
|
||||||
self.addListItem('Loading default values from PyLoT-input file %s'
|
# self.addListItem('Loading default values from PyLoT-input file %s'
|
||||||
% self.infile)
|
# % self.infile)
|
||||||
autopick_parameter = self._inputs
|
|
||||||
self.addListItem(str(autopick_parameter))
|
|
||||||
receventid = self.get_current_event_path()
|
|
||||||
self.thread = AutoPickThread(parent=self,
|
|
||||||
func=autoPyLoT,
|
|
||||||
infile=self.infile,
|
|
||||||
fnames=self.fnames,
|
|
||||||
eventid=receventid,
|
|
||||||
savepath=self.autosave)
|
|
||||||
|
|
||||||
self.thread.message.connect(self.addListItem)
|
stations = []
|
||||||
self.thread.start()
|
# catch all station names
|
||||||
self.thread.finished.connect(self.finalizeAutoPick)
|
for trace in self.data.getWFData():
|
||||||
|
station = trace.stats.station
|
||||||
|
if not station in stations:
|
||||||
|
stations.append(station)
|
||||||
|
|
||||||
|
mp_args = []
|
||||||
|
# create input_dict for each station in a list for multiprocessing.Pool iteration
|
||||||
|
for station in stations:
|
||||||
|
args = {'parameter': self._inputs,
|
||||||
|
'station': station,
|
||||||
|
'fnames': 'None',
|
||||||
|
'eventid': self.get_current_event_path (),
|
||||||
|
'iplot': 0,
|
||||||
|
'fig_dict': None,
|
||||||
|
'locflag': 0}
|
||||||
|
mp_args.append(args)
|
||||||
|
|
||||||
|
self.mp_thread = MultiThread (self, autoPyLoT, args=mp_args,
|
||||||
|
ncores=0,
|
||||||
|
progressText='Picking event...',
|
||||||
|
pb_widget=None,
|
||||||
|
redirect_stdout=True)
|
||||||
|
|
||||||
|
self.addListItem(str(self._inputs))
|
||||||
|
|
||||||
|
self.mp_thread.message.connect(self.addListItem)
|
||||||
|
self.mp_thread.start()
|
||||||
|
self.mp_thread.finished.connect(self.finalizeAutoPick)
|
||||||
|
|
||||||
def finalizeAutoPick(self):
|
def finalizeAutoPick(self):
|
||||||
self.drawPicks(picktype='auto')
|
self.drawPicks(picktype='auto')
|
||||||
self.draw()
|
self.draw()
|
||||||
self.thread.quit()
|
self.mp_thread.quit()
|
||||||
|
|
||||||
def addPicks(self, station, picks, type='manual'):
|
def addPicks(self, station, picks, type='manual'):
|
||||||
stat_picks = self.getPicksOnStation(station, type)
|
stat_picks = self.getPicksOnStation(station, type)
|
||||||
|
@ -66,6 +66,8 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
station = input_dict['station']
|
station = input_dict['station']
|
||||||
if input_dict.has_key('fnames'):
|
if input_dict.has_key('fnames'):
|
||||||
fnames = input_dict['fnames']
|
fnames = input_dict['fnames']
|
||||||
|
if input_dict.has_key('eventid'):
|
||||||
|
eventid = input_dict['eventid']
|
||||||
if input_dict.has_key('iplot'):
|
if input_dict.has_key('iplot'):
|
||||||
iplot = input_dict['iplot']
|
iplot = input_dict['iplot']
|
||||||
if input_dict.has_key('locflag'):
|
if input_dict.has_key('locflag'):
|
||||||
@ -155,7 +157,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
events = []
|
events = []
|
||||||
events.append(os.path.join(datapath,
|
events.append(os.path.join(datapath,
|
||||||
parameter['database'],
|
parameter['database'],
|
||||||
parameter['eventID']))
|
eventid))
|
||||||
|
|
||||||
if not events:
|
if not events:
|
||||||
print('autoPyLoT: No events given. Return!')
|
print('autoPyLoT: No events given. Return!')
|
||||||
|
@ -1 +1 @@
|
|||||||
f86f-dirty
|
f135-dirty
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys, os
|
import sys, os
|
||||||
|
import multiprocessing
|
||||||
from PySide.QtCore import QThread, Signal, Qt
|
from PySide.QtCore import QThread, Signal, Qt
|
||||||
from PySide.QtGui import QDialog, QProgressBar, QLabel, QHBoxLayout
|
from PySide.QtGui import QDialog, QProgressBar, QLabel, QHBoxLayout, QPushButton
|
||||||
|
|
||||||
|
|
||||||
class AutoPickThread(QThread):
|
class AutoPickThread(QThread):
|
||||||
@ -69,6 +70,76 @@ class Thread(QThread):
|
|||||||
print('Exception: {}, file: {}, line: {}'.format(exc_type, fname, exc_tb.tb_lineno))
|
print('Exception: {}, file: {}, line: {}'.format(exc_type, fname, exc_tb.tb_lineno))
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
|
|
||||||
|
# def __del__(self):
|
||||||
|
# self.wait()
|
||||||
|
|
||||||
|
def showProgressbar(self):
|
||||||
|
if self.progressText:
|
||||||
|
|
||||||
|
# generate widget if not given in init
|
||||||
|
if not self.pb_widget:
|
||||||
|
self.pb_widget = QDialog(self.parent())
|
||||||
|
self.pb_widget.setWindowFlags(Qt.SplashScreen)
|
||||||
|
self.pb_widget.setModal(True)
|
||||||
|
|
||||||
|
# add button
|
||||||
|
delete_button = QPushButton('X')
|
||||||
|
delete_button.clicked.connect(self.exit)
|
||||||
|
hl = QHBoxLayout()
|
||||||
|
pb = QProgressBar()
|
||||||
|
pb.setRange(0, 0)
|
||||||
|
hl.addWidget(pb)
|
||||||
|
hl.addWidget(QLabel(self.progressText))
|
||||||
|
hl.addWidget(delete_button)
|
||||||
|
self.pb_widget.setLayout(hl)
|
||||||
|
self.pb_widget.show()
|
||||||
|
|
||||||
|
def hideProgressbar(self):
|
||||||
|
if self.pb_widget:
|
||||||
|
self.pb_widget.hide()
|
||||||
|
|
||||||
|
def write(self, text):
|
||||||
|
self.message.emit(text)
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MultiThread(QThread):
|
||||||
|
finished = Signal(str)
|
||||||
|
message = Signal(str)
|
||||||
|
|
||||||
|
def __init__(self, parent, func, args, ncores=0,
|
||||||
|
progressText=None, pb_widget=None, redirect_stdout=False):
|
||||||
|
QThread.__init__(self, parent)
|
||||||
|
self.func = func
|
||||||
|
self.args = args
|
||||||
|
self.ncores = ncores
|
||||||
|
self.progressText = progressText
|
||||||
|
self.pb_widget = pb_widget
|
||||||
|
self.redirect_stdout = redirect_stdout
|
||||||
|
self.finished.connect(self.hideProgressbar)
|
||||||
|
self.showProgressbar()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# if self.redirect_stdout:
|
||||||
|
# sys.stdout = self
|
||||||
|
# #try:
|
||||||
|
if not self.ncores:
|
||||||
|
self.ncores = multiprocessing.cpu_count()
|
||||||
|
pool = multiprocessing.Pool(self.ncores)
|
||||||
|
self.data = pool.map_async(self.func, self.args, callback=self.emitDone)
|
||||||
|
#self.data = pool.apply_async(self.func, self.shotlist, callback=self.emitDone) #emit each time returned
|
||||||
|
pool.close()
|
||||||
|
self._executed = True
|
||||||
|
# except Exception as e:
|
||||||
|
# self._executed = False
|
||||||
|
# self._executedError = e
|
||||||
|
# exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
# fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||||
|
# print('Exception: {}, file: {}, line: {}'.format(exc_type, fname, exc_tb.tb_lineno))
|
||||||
|
sys.stdout = sys.__stdout__
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
@ -96,3 +167,7 @@ class Thread(QThread):
|
|||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def emitDone(self, result):
|
||||||
|
print('emitDone!')
|
||||||
|
self.finished.emit('Done thread!')
|
||||||
|
self.hideProgressbar()
|
||||||
|
Loading…
Reference in New Issue
Block a user