本文整理汇总了Python中nipype.interfaces.base.CommandLine.run方法的典型用法代码示例。如果您正苦于以下问题:Python CommandLine.run方法的具体用法?Python CommandLine.run怎么用?Python CommandLine.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nipype.interfaces.base.CommandLine
的用法示例。
在下文中一共展示了CommandLine.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: geodesic_depth
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
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
示例2: dicom2nrrd
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
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))
示例3: DICOM2animatedGIF_sidebyside
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
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')
示例4: area
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
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
示例5: make_cerebellum
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def make_cerebellum(aseg):
cwd = os.getcwd()
pth, nme = os.path.split(aseg)
os.chdir(pth)
cl = CommandLine('fslmaths %s -thr 47 -uthr 47 right_cerebellum'% (aseg))
cout = cl.run()
if not cout.runtime.returncode == 0:
os.chdir(cwd)
print 'Unable to create right cerebellum for %s'%(aseg)
return None
cl2 = CommandLine('fslmaths %s -thr 8 -uthr 8 left_cerebellum'% (aseg))
cout2 = cl2.run()
if not cout2.runtime.returncode == 0:
os.chdir(cwd)
print 'Unable to create left cerebellum for %s'%(aseg)
return None
cl3 = CommandLine('fslmaths left_cerebellum -add right_cerebellum -bin grey_cerebellum')
cout3 = cl3.run()
if not cout3.runtime.returncode == 0:
print 'Unable to create whole cerebellum for %s'%(aseg)
print cout3.runtime.stderr
print cout3.runtime.stdout
return None
cmd = 'rm right_cerebellum.* left_cerebellum.*'
cl4 = CommandLine(cmd)
cout4 = cl4.run()
os.chdir(cwd)
cerebellum = glob('%s/grey_cerebellum.*'%(pth))
return cerebellum[0]
示例6: elastix
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
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
示例7: area
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
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
示例8: travel_depth
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def travel_depth(command, surface_file, verbose=False):
"""
Measure "travel depth" of each vertex in a surface mesh.
(Calls Joachim Giard's C++ code)
Parameters
----------
command : string
travel depth C++ executable command
surface_file : string
vtk file
verbose : bool
print statements?
Returns
-------
depth_file: string
vtk file with travel depth per vertex of mesh
Examples
--------
>>> import os
>>> import numpy as np
>>> from mindboggle.shapes.surface_shapes import travel_depth
>>> 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, 'travel_depth', 'TravelDepthMain')
>>> depth_file = travel_depth(command, surface_file, verbose)
>>> scalars, name = read_scalars(depth_file)
>>> print(np.array_str(np.array(scalars[0:8]), precision=5,
... suppress_small=True))
[ 0.02026 0.06009 0.12859 0.04564 0.00774 0.05284 0.05354 0.01316]
"""
import os
from nipype.interfaces.base import CommandLine
basename = os.path.splitext(os.path.basename(surface_file))[0]
depth_file = os.path.join(os.getcwd(), basename + '.travel_depth.vtk')
args = ' '.join([surface_file, depth_file])
if verbose:
print("{0} {1}".format(command, args))
cli = CommandLine(command=command)
cli.inputs.args = args
cli.cmdline
cli.run()
if not os.path.exists(depth_file):
raise IOError(depth_file + " not found")
return depth_file
示例9: unzip
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def unzip(infile):
gunzipfile, gz = os.path.splitext(infile)
if not 'gz' in gz:
#when running gunzip on file when
return infile
else:
c3 = CommandLine('gunzip %s'%(infile))
c3.run()
return gunzipfile
示例10: gznii2nii
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def gznii2nii(in_file):
import os
import shutil
fileName, fileExtension = os.path.splitext(in_file)
cmd = CommandLine('gunzip -f -k %s.nii.gz' % (fileName))
print "gunzip NII.GZ:" + cmd.cmd
cmd.run()
return os.path.abspath('%s.nii' % (fileName))
示例11: travel_depth
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def travel_depth(command, surface_file, verbose=False):
"""
Measure "travel depth" of each vertex in a surface mesh.
(Calls Joachim Giard's C++ code)
Parameters
----------
command : string
travel depth C++ executable command
surface_file : string
vtk file
verbose : bool
print statements?
Returns
-------
depth_file: string
vtk file with travel depth per vertex of mesh
Examples
--------
>>> import os
>>> import numpy as np
>>> from mindboggle.shapes.surface_shapes import travel_depth
>>> 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, 'travel_depth', 'TravelDepthMain')
>>> depth_file = travel_depth(command, surface_file, verbose)
>>> scalars, name = read_scalars(depth_file)
>>> np.allclose(scalars[0:8], [0.020259869839, 0.06009166489, 0.12858575442, 0.045639221313, 0.007742772964, 0.052839111255, 0.053538904296, 0.013158746337])
True
"""
import os
from nipype.interfaces.base import CommandLine
basename = os.path.splitext(os.path.basename(surface_file))[0]
depth_file = os.path.join(os.getcwd(), basename + '.travel_depth.vtk')
args = ' '.join([surface_file, depth_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(depth_file):
raise IOError(depth_file + " not found")
return depth_file
示例12: nii2nrrd
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def nii2nrrd(filename_nii, filename_bval, filename_bvec, out_prefix, out_suffix):
import os
import shutil
from nipype.interfaces.base import CommandLine
basename = experiment_dir + os.sep + out_prefix + os.sep + out_prefix + out_suffix
cmd = CommandLine('./DWIConvert --inputVolume %s --outputVolume %s.nrrd --conversionMode FSLToNrrd --inputBValues %s --inputBVectors %s' % (filename_nii, basename, filename_bval, filename_bvec))
print "NII->NRRD:" + cmd.cmd
cmd.run()
return os.path.abspath('%s.nrrd' % (basename))
示例13: gunzip
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def gunzip(file):
import os
os.mkdir("./out")
from nipype.interfaces.base import CommandLine
c = CommandLine(command="tar zxvf %s"%file)
c.run()
from nipype.utils.filemanip import split_filename
_,base,_ = split_filename(file)
return os.path.abspath(base)
示例14: geodesic_depth
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def geodesic_depth(command, surface_file, verbose=False):
"""
Estimate geodesic 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``
verbose : bool
print statements?
Returns
-------
depth_file: string
vtk file with geodesic depth per vertex of mesh
Examples
--------
>>> import os
>>> import numpy as np
>>> from mindboggle.shapes.surface_shapes import geodesic_depth
>>> 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, 'geodesic_depth', 'GeodesicDepthMain')
>>> depth_file = geodesic_depth(command, surface_file, verbose)
>>> scalars, name = read_scalars(depth_file)
>>> [np.float("{0:.{1}f}".format(x, 5)) for x in scalars[0:8]]
[0.02026, 0.06009, 0.12859, 0.04564, 0.00774, 0.05284, 0.05354, 0.01316]
"""
import os
from nipype.interfaces.base import CommandLine
basename = os.path.splitext(os.path.basename(surface_file))[0]
depth_file = os.path.join(os.getcwd(), basename + '.geodesic_depth.vtk')
args = ' '.join([surface_file, depth_file])
if verbose:
print("{0} {1}".format(command, args))
cli = CommandLine(command=command)
cli.inputs.args = args
cli.cmdline
cli.run()
if not os.path.exists(depth_file):
raise IOError(depth_file + " not found")
return depth_file
示例15: dtiprep
# 需要导入模块: from nipype.interfaces.base import CommandLine [as 别名]
# 或者: from nipype.interfaces.base.CommandLine import run [as 别名]
def dtiprep(in_file, output_prefix):
from glob import glob
import os
from nipype.interfaces.base import CommandLine
cmd = CommandLine('DTIPrepExec -c -d -f %s -n %s/%s_notes.txt -p %s -w %s/%s.nrrd' % ((experiment_dir + '/' + output_prefix),(experiment_dir + '/' + output_prefix),output_prefix,DTIprep_protocol,experiment_dir,output_prefix))
print "DTIPREP:" + cmd.cmd
cmd.run()
qcfile = experiment_dir + '/' + output_prefix + '/' + output_prefix + '_QCed.nrrd'
xmlfile = experiment_dir + '/' + output_prefix + '/' + output_prefix + '_XMLQCResult.xml'
sumfile = experiment_dir + '/' + output_prefix + '/' + output_prefix + '_QCReport.txt'
return qcfile, xmlfile, sumfile