本文整理汇总了Python中nipype.interfaces.base.CommandLine类的典型用法代码示例。如果您正苦于以下问题:Python CommandLine类的具体用法?Python CommandLine怎么用?Python CommandLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DICOM2animatedGIF_sidebyside
def DICOM2animatedGIF_sidebyside(dcmdir_l, dcmdir_r, outputpath, slice_i, suffix):
dcmio = DicomIO.DicomIO()
dwidcm_l = dcmio.ReadDICOM_frames(dcmdir_l)
dwidcm_r = dcmio.ReadDICOM_frames(dcmdir_r)
# Write all frames of slice into set of png files
for frame_i in range(len(dwidcm_l)):
slice_l = dwidcm_l[frame_i][slice_i].pixel_array.T
slice_r = dwidcm_r[frame_i][slice_i].pixel_array.T
dimx = slice_l.shape[0]
dimy = slice_l.shape[1]
newImg1 = PIL.Image.new('L', (dimx*2, dimy))
pixels1 = newImg1.load()
for i in range (0, dimx):
for j in range (0, dimy):
pixels1[i, j] = float(slice_l[i, j])
pixels1[dimx+i, j] = float(slice_r[i, j])
#pixels1[i, j] = float(slice[i, j]) * dwidcm[frame_i][slice_i].RescaleSlope + dwidcm[frame_i][slice_i].RescaleIntercept
newImg1.save((outputpath + '_' + ('%02d' % frame_i) + '.png'),'PNG')
cmd = CommandLine('convert -delay 25 -loop 0 %s_*.png %s_%s.gif' % (outputpath, outputpath, suffix))
cmd.run()
for frame_i in range(len(dwidcm_l)):
os.remove((outputpath + '_' + ('%02d' % frame_i) + '.png'))
print "convert (ImageMagick):" + cmd.cmd
return (outputpath + '.gif')
示例2: _submit_batchtask
def _submit_batchtask(self, scriptfile, node):
cmd = CommandLine('qsub', environ=os.environ.data)
qsubargs = ''
if self._qsub_args:
qsubargs = self._qsub_args
if node._hierarchy:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._hierarchy,
node._id))
else:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._id))
cmd.inputs.args = '%s -N %s %s'%(qsubargs,
jobname,
scriptfile)
oldlevel = iflogger.level
iflogger.setLevel(logging.getLevelName('CRITICAL'))
tries = 0
while True:
try:
result = cmd.run()
except Exception, e:
if tries<self._max_tries:
tries += 1
sleep(self._retry_timeout) # sleep 2 seconds and try again.
else:
iflogger.setLevel(oldlevel)
raise RuntimeError('\n'.join((('Could not submit pbs task'
' for node %s') % node._id,
str(e))))
else:
break
示例3: geodesic_depth
def geodesic_depth(command, surface_file):
"""
Measure "travel depth" of each vertex in a surface mesh.
(Calls Joachim Giard's C++ code)
Parameters
----------
command : travel depth C++ executable command
surface_file : ``vtk file``
Returns
-------
depth_file: string
vtk file with geodesic depth per vertex of mesh
"""
import os
from nipype.interfaces.base import CommandLine
depth_file = os.path.join(os.getcwd(),
os.path.splitext(os.path.basename(surface_file))[0] + '.geodesic_depth.vtk')
cli = CommandLine(command = command)
cli.inputs.args = ' '.join([surface_file, depth_file])
cli.cmdline
cli.run()
if not os.path.exists(depth_file):
raise(IOError(depth_file + " not found"))
return depth_file
示例4: dicom2nrrd
def dicom2nrrd(dicomdir, out_prefix, out_suffix):
import os
from nipype.interfaces.base import CommandLine
cmd = CommandLine('DWIConvert --inputDicomDirectory %s --outputVolume %s/%s/%s%s.nrrd' % (dicomdir, experiment_dir,out_prefix,out_prefix,out_suffix))
print "DICOM->NRRD:" + cmd.cmd
cmd.run()
return os.path.abspath('%s/%s/%s%s.nrrd' % (experiment_dir,out_prefix,out_prefix,out_suffix))
示例5: _grab_xml
def _grab_xml(self, module):
cmd = CommandLine(command = "Slicer3", args="--launch %s --xml"%module)
ret = cmd.run()
if ret.runtime.returncode == 0:
return xml.dom.minidom.parseString(ret.runtime.stdout)
else:
raise Exception(cmd.cmdline + " failed:\n%s"%ret.runtime.stderr)
示例6: _submit_batchtask
def _submit_batchtask(self, scriptfile, node):
cmd = CommandLine('bsub', environ=os.environ.data,
terminal_output='allatonce')
path = os.path.dirname(scriptfile)
bsubargs = ''
if self._bsub_args:
bsubargs = self._bsub_args
if 'bsub_args' in node.plugin_args:
if 'overwrite' in node.plugin_args and\
node.plugin_args['overwrite']:
bsubargs = node.plugin_args['bsub_args']
else:
bsubargs += (" " + node.plugin_args['bsub_args'])
if '-o' not in bsubargs: # -o outfile
bsubargs = '%s -o %s' % (bsubargs, scriptfile + ".log")
if '-e' not in bsubargs:
bsubargs = '%s -e %s' % (bsubargs, scriptfile + ".log") # -e error file
if node._hierarchy:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._hierarchy,
node._id))
else:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._id))
jobnameitems = jobname.split('.')
jobnameitems.reverse()
jobname = '.'.join(jobnameitems)
cmd.inputs.args = '%s -J %s sh %s' % (bsubargs,
jobname,
scriptfile) # -J job_name_spec
logger.debug('bsub ' + cmd.inputs.args)
oldlevel = iflogger.level
iflogger.setLevel(logging.getLevelName('CRITICAL'))
tries = 0
while True:
try:
result = cmd.run()
except Exception as e:
if tries < self._max_tries:
tries += 1
sleep(
self._retry_timeout) # sleep 2 seconds and try again.
else:
iflogger.setLevel(oldlevel)
raise RuntimeError('\n'.join((('Could not submit lsf task'
' for node %s') % node._id,
str(e))))
else:
break
iflogger.setLevel(oldlevel)
# retrieve lsf taskid
match = re.search('<(\d*)>', result.runtime.stdout)
if match:
taskid = int(match.groups()[0])
else:
raise ScriptError("Can't parse submission job output id: %s" %
result.runtime.stdout)
self._pending[taskid] = node.output_dir()
logger.debug('submitted lsf task: %d for node %s' % (taskid, node._id))
return taskid
示例7: area
def area(command, surface_file):
"""
Measure area of each vertex in a surface mesh.
(Calls Joachim Giard's C++ code)
Parameters
----------
command : string
Voronoi-based surface area C++ executable command
surface_file : string
vtk file with surface mesh
Returns
-------
area_file: string
vtk file with surface area per vertex of mesh
"""
import os
from nipype.interfaces.base import CommandLine
area_file = os.path.join(os.getcwd(),
os.path.splitext(os.path.basename(surface_file))[0] + '.area.vtk')
cli = CommandLine(command = command)
cli.inputs.args = ' '.join([surface_file, area_file])
cli.cmdline
cli.run()
if not os.path.exists(area_file):
raise(IOError(area_file + " not found"))
return area_file
示例8: _submit_batchtask
def _submit_batchtask(self, scriptfile, node):
cmd = CommandLine('qsub', environ=dict(os.environ),
terminal_output='allatonce')
path = os.path.dirname(scriptfile)
qsubargs = ''
if self._qsub_args:
qsubargs = self._qsub_args
if 'qsub_args' in node.plugin_args:
if 'overwrite' in node.plugin_args and \
node.plugin_args['overwrite']:
qsubargs = node.plugin_args['qsub_args']
else:
qsubargs += (" " + node.plugin_args['qsub_args'])
if '-o' not in qsubargs:
qsubargs = '%s -o %s' % (qsubargs, path)
if '-e' not in qsubargs:
qsubargs = '%s -e %s' % (qsubargs, path)
if node._hierarchy:
jobname = '.'.join((dict(os.environ)['LOGNAME'],
node._hierarchy,
node._id))
else:
jobname = '.'.join((dict(os.environ)['LOGNAME'],
node._id))
jobnameitems = jobname.split('.')
jobnameitems.reverse()
jobname = '.'.join(jobnameitems)
jobname = qsub_sanitize_job_name(jobname)
cmd.inputs.args = '%s -N %s %s' % (qsubargs,
jobname,
scriptfile)
oldlevel = iflogger.level
iflogger.setLevel(logging.getLevelName('CRITICAL'))
tries = 0
result = list()
while True:
try:
result = cmd.run()
except Exception as e:
if tries < self._max_tries:
tries += 1
time.sleep(
self._retry_timeout) # sleep 2 seconds and try again.
else:
iflogger.setLevel(oldlevel)
raise RuntimeError('\n'.join((('Could not submit sge task'
' for node %s') % node._id,
str(e))))
else:
break
iflogger.setLevel(oldlevel)
# retrieve sge taskid
lines = [line for line in result.runtime.stdout.split('\n') if line]
taskid = int(re.match("Your job ([0-9]*) .* has been submitted",
lines[-1]).groups()[0])
self._pending[taskid] = node.output_dir()
self._refQstatSubstitute.add_startup_job(taskid, cmd.cmdline)
logger.debug('submitted sge task: %d for node %s with %s' %
(taskid, node._id, cmd.cmdline))
return taskid
示例9: elastix
def elastix(input_file, target_file, mask_file, output_prefix, output_sub_prefix, param_rigid, param_BSpline):
from os.path import abspath as opap
from nipype.interfaces.base import CommandLine
from nipype.utils.filemanip import split_filename
import shutil
import glob
import os
out_dir = experiment_dir + os.sep + output_prefix + os.sep + output_sub_prefix
# Create output directory if it does not exist
if os.path.exists(out_dir):
print "rmtree: " + out_dir
shutil.rmtree(out_dir)
print "creating: " + out_dir
os.makedirs(out_dir)
cmd = CommandLine(
(
"/Users/eija/Documents/SW/Elastix/elastix_sources_v4.7/bin/bin/elastix -f %s -m %s -out %s -p %s -p %s -threads 8"
)
% (target_file, input_file, out_dir, param_rigid, param_BSpline)
)
print "elastix: " + cmd.cmd
cmd.run()
resultfiles = glob.glob(out_dir + os.sep + "result.*.tiff")
return resultfiles
示例10: _is_pending
def _is_pending(self, taskid):
cmd = CommandLine('qstat')
cmd.inputs.args = '-j %d'%taskid
# check sge task
result = cmd.run(ignore_exception=True)
if result.runtime.stdout.startswith('='):
return True
return False
示例11: _is_pending
def _is_pending(self, taskid):
cmd = CommandLine("qstat")
cmd.inputs.args = "%s" % taskid
# check pbs task
result = cmd.run(ignore_exception=True)
if "Unknown Job Id" in result.runtime.stderr:
return False
return True
示例12: area
def area(command, surface_file, verbose=False):
"""
Measure area of each vertex in a surface mesh.
(Calls Joachim Giard's C++ code)
Parameters
----------
command : string
Voronoi-based surface area C++ executable command
surface_file : string
vtk file with surface mesh
verbose : bool
print statements?
Returns
-------
area_file: string
vtk file with surface area per vertex of mesh
Examples
--------
>>> import os
>>> import numpy as np
>>> from mindboggle.shapes.surface_shapes import area
>>> from mindboggle.mio.vtks import read_scalars
>>> from mindboggle.mio.fetch_data import prep_tests
>>> urls, fetch_data = prep_tests()
>>> surface_file = fetch_data(urls['left_pial'], '', '.vtk')
>>> verbose = False
>>> ccode_path = os.environ['vtk_cpp_tools']
>>> command = os.path.join(ccode_path, 'area', 'PointAreaMain')
>>> area_file = area(command, surface_file, verbose)
>>> scalars, name = read_scalars(area_file)
>>> np.allclose(scalars[0:8],
... [0.48270401731, 0.39661528543, 0.57813454792, 0.70574099571,
... 0.84318527207, 0.57642554119, 0.66942016035, 0.70629953593])
True
"""
import os
from nipype.interfaces.base import CommandLine
basename = os.path.splitext(os.path.basename(surface_file))[0]
area_file = os.path.join(os.getcwd(), basename + '.area.vtk')
args = ' '.join([surface_file, area_file])
if verbose:
print("{0} {1}".format(command, args))
cli = CommandLine(command=command)
cli.inputs.args = args
cli.terminal_output = 'file'
cli.run()
if not os.path.exists(area_file):
raise IOError(area_file + " not found")
return area_file
示例13: _submit_batchtask
def _submit_batchtask(self, scriptfile, node):
"""
This is more or less the _submit_batchtask from sge.py with flipped variable
names, different command line switches, and different output formatting/processing
"""
cmd = CommandLine('sbatch', environ=os.environ.data,
terminal_output='allatonce')
path = os.path.dirname(scriptfile)
sbatch_args = ''
if self._sbatch_args:
sbatch_args = self._sbatch_args
if 'sbatch_args' in node.plugin_args:
if 'overwrite' in node.plugin_args and\
node.plugin_args['overwrite']:
sbatch_args = node.plugin_args['sbatch_args']
else:
sbatch_args += (" " + node.plugin_args['sbatch_args'])
if '-o' not in sbatch_args:
sbatch_args = '%s -o %s' % (sbatch_args, os.path.join(path, 'slurm-%j.out'))
if '-e' not in sbatch_args:
sbatch_args = '%s -e %s' % (sbatch_args, os.path.join(path, 'slurm-%j.out'))
if '-p' not in sbatch_args:
sbatch_args = '%s -p normal' % (sbatch_args)
if '-n' not in sbatch_args:
sbatch_args = '%s -n 16' % (sbatch_args)
if '-t' not in sbatch_args:
sbatch_args = '%s -t 1:00:00' % (sbatch_args)
if node._hierarchy:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._hierarchy,
node._id))
else:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._id))
jobnameitems = jobname.split('.')
jobnameitems.reverse()
jobname = '.'.join(jobnameitems)
cmd.inputs.args = '%s -J %s %s' % (sbatch_args,
jobname,
scriptfile)
oldlevel = iflogger.level
iflogger.setLevel(logging.getLevelName('CRITICAL'))
tries = 0
while True:
try:
result = cmd.run()
except Exception, e:
if tries < self._max_tries:
tries += 1
sleep(self._retry_timeout) # sleep 2 seconds and try again.
else:
iflogger.setLevel(oldlevel)
raise RuntimeError('\n'.join((('Could not submit sbatch task'
' for node %s') % node._id,
str(e))))
else:
break
示例14: _submit_batchtask
def _submit_batchtask(self, scriptfile, node):
cmd = CommandLine('condor_qsub', environ=os.environ.data,
terminal_output='allatonce')
path = os.path.dirname(scriptfile)
qsubargs = ''
if self._qsub_args:
qsubargs = self._qsub_args
if 'qsub_args' in node.plugin_args:
if 'overwrite' in node.plugin_args and\
node.plugin_args['overwrite']:
qsubargs = node.plugin_args['qsub_args']
else:
qsubargs += (" " + node.plugin_args['qsub_args'])
if self._qsub_args:
qsubargs = self._qsub_args
if '-o' not in qsubargs:
qsubargs = '%s -o %s' % (qsubargs, path)
if '-e' not in qsubargs:
qsubargs = '%s -e %s' % (qsubargs, path)
if node._hierarchy:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._hierarchy,
node._id))
else:
jobname = '.'.join((os.environ.data['LOGNAME'],
node._id))
jobnameitems = jobname.split('.')
jobnameitems.reverse()
jobname = '.'.join(jobnameitems)
cmd.inputs.args = '%s -N %s %s' % (qsubargs,
jobname,
scriptfile)
oldlevel = iflogger.level
iflogger.setLevel(logging.getLevelName('CRITICAL'))
tries = 0
while True:
try:
result = cmd.run()
except Exception as e:
if tries < self._max_tries:
tries += 1
sleep(self._retry_timeout) # sleep 2 seconds and try again.
else:
iflogger.setLevel(oldlevel)
raise RuntimeError('\n'.join((('Could not submit condor '
'cluster'
' for node %s') % node._id,
str(e))))
else:
break
iflogger.setLevel(oldlevel)
# retrieve condor clusterid
taskid = int(result.runtime.stdout.split(' ')[2])
self._pending[taskid] = node.output_dir()
logger.debug('submitted condor cluster: %d for node %s' % (taskid,
node._id))
return taskid
示例15: tar_cmd
def tar_cmd(infile):
""" given a ipped tar archive, untars"""
cwd = os.getcwd()
pth, nme = os.path.split(infile)
os.chdir(pth)
cl = CommandLine('tar xfvz %s'%(infile))
cout = cl.run()
os.chdir(cwd)
return pth