[add] --ncores flag added to autoPyLoT call, also enabled in GUI widget
This commit is contained in:
parent
90006809a5
commit
154e7b459f
32
autoPyLoT.py
32
autoPyLoT.py
@ -34,7 +34,7 @@ __version__ = _getVersionString()
|
|||||||
|
|
||||||
|
|
||||||
def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, eventid=None, savepath=None, station='all',
|
def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, eventid=None, savepath=None, station='all',
|
||||||
iplot=0):
|
iplot=0, ncores=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.
|
||||||
@ -48,6 +48,16 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
.. rubric:: Example
|
.. rubric:: Example
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if ncores == 1:
|
||||||
|
sp_info = 'autoPyLoT is running serial on 1 cores.'
|
||||||
|
else:
|
||||||
|
if ncores == 0:
|
||||||
|
ncores_readable = 'all available'
|
||||||
|
else:
|
||||||
|
ncores_readable = ncores
|
||||||
|
sp_info = 'autoPyLoT is running in parallel on {} cores.'.format(ncores_readable)
|
||||||
|
|
||||||
splash = '''************************************\n
|
splash = '''************************************\n
|
||||||
*********autoPyLoT starting*********\n
|
*********autoPyLoT starting*********\n
|
||||||
The Python picking and Location Tool\n
|
The Python picking and Location Tool\n
|
||||||
@ -57,9 +67,13 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
L. Kueperkoch (BESTEC GmbH, Landau i. d. Pfalz)\n
|
L. Kueperkoch (BESTEC GmbH, Landau i. d. Pfalz)\n
|
||||||
S. Wehling-Benatelli (Ruhr-Universitaet Bochum)\n
|
S. Wehling-Benatelli (Ruhr-Universitaet Bochum)\n
|
||||||
M. Paffrath (Ruhr-Universitaet Bochum)\n
|
M. Paffrath (Ruhr-Universitaet Bochum)\n
|
||||||
***********************************'''.format(version=_getVersionString())
|
|
||||||
|
{sp}
|
||||||
|
***********************************'''.format(version=_getVersionString(),
|
||||||
|
sp=sp_info)
|
||||||
print(splash)
|
print(splash)
|
||||||
|
|
||||||
|
|
||||||
parameter = real_None(parameter)
|
parameter = real_None(parameter)
|
||||||
inputfile = real_None(inputfile)
|
inputfile = real_None(inputfile)
|
||||||
eventid = real_None(eventid)
|
eventid = real_None(eventid)
|
||||||
@ -84,7 +98,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
if not parameter:
|
if not parameter:
|
||||||
if inputfile:
|
if inputfile:
|
||||||
parameter = PylotParameter(inputfile)
|
parameter = PylotParameter(inputfile)
|
||||||
iplot = parameter['iplot']
|
#iplot = parameter['iplot']
|
||||||
else:
|
else:
|
||||||
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
|
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
|
||||||
print('Using default input file {}'.format(infile))
|
print('Using default input file {}'.format(infile))
|
||||||
@ -216,7 +230,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
wfdat = remove_underscores(wfdat)
|
wfdat = remove_underscores(wfdat)
|
||||||
metadata = read_metadata(parameter.get('invdir'))
|
metadata = read_metadata(parameter.get('invdir'))
|
||||||
print("Restitute data ...")
|
print("Restitute data ...")
|
||||||
corr_dat = restitute_data(wfdat.copy(), *metadata)
|
corr_dat = restitute_data(wfdat.copy(), *metadata, ncores=ncores)
|
||||||
if not corr_dat and locflag:
|
if not corr_dat and locflag:
|
||||||
locflag = 2
|
locflag = 2
|
||||||
print('Working on event %s. Stations: %s' % (event, station))
|
print('Working on event %s. Stations: %s' % (event, station))
|
||||||
@ -226,9 +240,9 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
if input_dict:
|
if input_dict:
|
||||||
if 'fig_dict' in input_dict:
|
if 'fig_dict' in input_dict:
|
||||||
fig_dict = input_dict['fig_dict']
|
fig_dict = input_dict['fig_dict']
|
||||||
picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
|
picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict, ncores=ncores)
|
||||||
else:
|
else:
|
||||||
picks = autopickevent(wfdat, parameter, iplot=iplot)
|
picks = autopickevent(wfdat, parameter, iplot=iplot, ncores=ncores)
|
||||||
##########################################################
|
##########################################################
|
||||||
# locating
|
# locating
|
||||||
if locflag > 0:
|
if locflag > 0:
|
||||||
@ -442,6 +456,9 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument('-s', '-S', '--spath', type=str,
|
parser.add_argument('-s', '-S', '--spath', type=str,
|
||||||
action='store',
|
action='store',
|
||||||
help='''optional, save path for autoPyLoT output''')
|
help='''optional, save path for autoPyLoT output''')
|
||||||
|
parser.add_argument('-c', '-C', '--ncores', type=int,
|
||||||
|
action='store', default=0,
|
||||||
|
help='''optional, number of CPU cores used for parallel processing (default: all available)''')
|
||||||
# parser.add_argument('-v', '-V', '--version', action='version',
|
# parser.add_argument('-v', '-V', '--version', action='version',
|
||||||
# version='autoPyLoT ' + __version__,
|
# version='autoPyLoT ' + __version__,
|
||||||
# help='show version information and exit')
|
# help='show version information and exit')
|
||||||
@ -449,4 +466,5 @@ if __name__ == "__main__":
|
|||||||
cla = parser.parse_args()
|
cla = parser.parse_args()
|
||||||
|
|
||||||
picks = autoPyLoT(inputfile=str(cla.inputfile), fnames=str(cla.fnames),
|
picks = autoPyLoT(inputfile=str(cla.inputfile), fnames=str(cla.fnames),
|
||||||
eventid=str(cla.eventid), savepath=str(cla.spath))
|
eventid=str(cla.eventid), savepath=str(cla.spath),
|
||||||
|
ncores=cla.ncores)
|
||||||
|
@ -21,7 +21,7 @@ from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker, \
|
|||||||
from pylot.core.util.utils import getPatternLine, gen_Pool
|
from pylot.core.util.utils import getPatternLine, gen_Pool
|
||||||
|
|
||||||
|
|
||||||
def autopickevent(data, param, iplot=0, fig_dict=None):
|
def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0):
|
||||||
stations = []
|
stations = []
|
||||||
all_onsets = {}
|
all_onsets = {}
|
||||||
input_tuples = []
|
input_tuples = []
|
||||||
@ -50,7 +50,7 @@ def autopickevent(data, param, iplot=0, fig_dict=None):
|
|||||||
print('iPlot Flag active: NO MULTIPROCESSING possible.')
|
print('iPlot Flag active: NO MULTIPROCESSING possible.')
|
||||||
return all_onsets
|
return all_onsets
|
||||||
|
|
||||||
pool = gen_Pool()
|
pool = gen_Pool(ncores)
|
||||||
result = pool.map(call_autopickstation, input_tuples)
|
result = pool.map(call_autopickstation, input_tuples)
|
||||||
pool.close()
|
pool.close()
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ def restitute_trace(input_tuple):
|
|||||||
return tr, remove_trace
|
return tr, remove_trace
|
||||||
|
|
||||||
|
|
||||||
def restitute_data(data, invtype, inobj, unit='VEL', force=False):
|
def restitute_data(data, invtype, inobj, unit='VEL', force=False, ncores=0):
|
||||||
"""
|
"""
|
||||||
takes a data stream and a path_to_inventory and returns the corrected
|
takes a data stream and a path_to_inventory and returns the corrected
|
||||||
waveform data stream
|
waveform data stream
|
||||||
@ -293,7 +293,7 @@ def restitute_data(data, invtype, inobj, unit='VEL', force=False):
|
|||||||
input_tuples.append((tr, invtype, inobj, unit, force))
|
input_tuples.append((tr, invtype, inobj, unit, force))
|
||||||
data.remove(tr)
|
data.remove(tr)
|
||||||
|
|
||||||
pool = gen_Pool()
|
pool = gen_Pool(ncores)
|
||||||
result = pool.map(restitute_trace, input_tuples)
|
result = pool.map(restitute_trace, input_tuples)
|
||||||
pool.close()
|
pool.close()
|
||||||
|
|
||||||
|
@ -33,10 +33,14 @@ def getindexbounds(f, eta):
|
|||||||
return mi, l, u
|
return mi, l, u
|
||||||
|
|
||||||
|
|
||||||
def gen_Pool(ncores='max'):
|
def gen_Pool(ncores=0):
|
||||||
|
'''
|
||||||
|
:param ncores: number of CPU cores for multiprocessing.Pool, if ncores == 0 use all available
|
||||||
|
:return: multiprocessing.Pool object
|
||||||
|
'''
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
if ncores == 'max':
|
if ncores == 0:
|
||||||
ncores = multiprocessing.cpu_count()
|
ncores = multiprocessing.cpu_count()
|
||||||
|
|
||||||
pool = multiprocessing.Pool(ncores)
|
pool = multiprocessing.Pool(ncores)
|
||||||
|
@ -2869,7 +2869,6 @@ class AutoPickDlg(QDialog):
|
|||||||
maxcores = multiprocessing.cpu_count()
|
maxcores = multiprocessing.cpu_count()
|
||||||
self.sb_ncores.setMinimum(1)
|
self.sb_ncores.setMinimum(1)
|
||||||
self.sb_ncores.setMaximum(maxcores)
|
self.sb_ncores.setMaximum(maxcores)
|
||||||
self.sb_ncores.setEnabled(False) # not yet implemented in autoPyLoT
|
|
||||||
self.layout_ncores.addWidget(self.label_ncores)
|
self.layout_ncores.addWidget(self.label_ncores)
|
||||||
self.layout_ncores.addWidget(self.sb_ncores)
|
self.layout_ncores.addWidget(self.sb_ncores)
|
||||||
self.layout_ncores.setStretch(0, 1)
|
self.layout_ncores.setStretch(0, 1)
|
||||||
@ -2903,7 +2902,7 @@ class AutoPickDlg(QDialog):
|
|||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.exportParameter()
|
self.exportParameter()
|
||||||
self.job_widget.start(self.pp_export)
|
self.job_widget.start(self.pp_export, self.sb_ncores.value())
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
||||||
|
|
||||||
@ -2931,7 +2930,7 @@ class Submit2Grid(QWidget):
|
|||||||
default_command = 'qsub -l low -cwd -q TARGET_MACHINE -pe mpi-fu NCORES'
|
default_command = 'qsub -l low -cwd -q TARGET_MACHINE -pe mpi-fu NCORES'
|
||||||
self.textedit.setText(default_command)
|
self.textedit.setText(default_command)
|
||||||
|
|
||||||
def start(self, pp_export):
|
def start(self, pp_export, ncores=None):
|
||||||
self.genShellScript(pp_export)
|
self.genShellScript(pp_export)
|
||||||
self.execute_script()
|
self.execute_script()
|
||||||
|
|
||||||
@ -2966,12 +2965,14 @@ class SubmitLocal(QWidget):
|
|||||||
def start(self):
|
def start(self):
|
||||||
print('subprocess Popen')
|
print('subprocess Popen')
|
||||||
|
|
||||||
def start(self, pp_export):
|
def start(self, pp_export, ncores):
|
||||||
self.execute_command(pp_export)
|
self.execute_command(pp_export, ncores)
|
||||||
|
|
||||||
def execute_command(self, pp_export):
|
def execute_command(self, pp_export, ncores):
|
||||||
command = self.script_fn
|
command = self.script_fn
|
||||||
command.append(pp_export)
|
command.append(pp_export)
|
||||||
|
command.append('--ncores')
|
||||||
|
command.append(str(ncores))
|
||||||
cmd_str = str()
|
cmd_str = str()
|
||||||
for item in command:
|
for item in command:
|
||||||
cmd_str += item + ' '
|
cmd_str += item + ' '
|
||||||
|
Loading…
Reference in New Issue
Block a user