本文整理汇总了Python中nipype.Node.run方法的典型用法代码示例。如果您正苦于以下问题:Python Node.run方法的具体用法?Python Node.run怎么用?Python Node.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nipype.Node
的用法示例。
在下文中一共展示了Node.run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: nipype_convert
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
""" """
import nipype
if with_prov:
from nipype import config
config.enable_provenance()
from nipype import Node
from nipype.interfaces.dcm2nii import Dcm2niix
item_dicoms = list(map(op.abspath, item_dicoms)) # absolute paths
dicom_dir = op.dirname(item_dicoms[0]) if item_dicoms else None
convertnode = Node(Dcm2niix(), name='convert')
convertnode.base_dir = tmpdir
convertnode.inputs.source_names = item_dicoms
convertnode.inputs.out_filename = op.basename(op.dirname(prefix))
if nipype.__version__.split('.')[0] == '0':
# deprecated since 1.0, might be needed(?) before
convertnode.inputs.terminal_output = 'allatonce'
else:
convertnode.terminal_output = 'allatonce'
convertnode.inputs.bids_format = bids
eg = convertnode.run()
# prov information
prov_file = prefix + '_prov.ttl' if with_prov else None
if prov_file:
safe_copyfile(op.join(convertnode.base_dir,
convertnode.name,
'provenance.ttl'),
prov_file)
return eg, prov_file
示例2: run_freesurfer
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
def run_freesurfer(subject_id, T1_images, subjects_dir, T2_image=None):
"""Run freesurfer, convert to nidm and extract stats
"""
from nipype import freesurfer as fs
from nipype import Node
from fs_dir_to_graph import to_graph
from query_convert_fs_stats import get_collections, process_collection
recon = Node(fs.ReconAll(), name='recon')
recon.inputs.T1_files = T1_images
recon.inputs.subject_id = subject_id
recon.inputs.subjects_dir = subjects_dir
recon.inputs.openmp = 4
if T2_image:
recon.inputs.T2_file = T2_image
recon.base_dir = os.path.abspath(os.path.join('working', subject_id))
results = recon.run()
provgraph = results.provenance
newgraph = to_graph(os.path.join(results.outputs.subjects_dir,
results.outputs.subject_id))
provgraph.add_bundle(newgraph)
provgraph.rdf().serialize('test1.ttl', format='turtle')
results = get_collections(provgraph.rdf())
collections = []
for row in results:
collections.append(str(row[0]))
if len(collections) > 1:
raise ValueError('More than one freesurfer directory collection found')
provgraph, termsrdf = process_collection(provgraph, collections.pop())
rdfgraph = provgraph.rdf() + termsrdf
return provgraph, rdfgraph
示例3: rawdataChecker
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
def rawdataChecker(input_file):
# If the input is a single DCM-file instead of a multi-dim-NifTI, we have to fetch all the other files in the series
if input_file.endswith('.dcm'):
from nipype.interfaces.io import DataFinder
from os import path
from nipype import Node
# Setup a datafinder to find the paths to the specific DICOM files
t1FinderNode = Node(DataFinder(), name = 't1Finder')
t1FinderNode.inputs.match_regex = '.*\.dcm'
t1FinderNode.inputs.root_paths = path.split(input_file)[0]
return t1FinderNode.run().outputs.out_paths
else:
return input_file # If other datatype just return the same path
示例4: run_bet
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
def run_bet(T1_image, workdir):
"""Run freesurfer, convert to nidm and extract stats
"""
from nipype import fsl
from nipype import Node
from fs_dir_to_graph import to_graph
from query_convert_fs_stats import get_collections, process_collection
strip = Node(fsl.BET(), name='skullstripper')
strip.inputs.in_file = T1_image
strip.base_dir = workdir
results = strip.run()
provgraph = results.provenance
return provgraph
示例5: embed_metadata_from_dicoms
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
def embed_metadata_from_dicoms(bids, item_dicoms, outname, outname_bids,
prov_file, scaninfo, tempdirs, with_prov,
min_meta):
"""
Enhance sidecar information file with more information from DICOMs
Parameters
----------
bids
item_dicoms
outname
outname_bids
prov_file
scaninfo
tempdirs
with_prov
min_meta
Returns
-------
"""
from nipype import Node, Function
tmpdir = tempdirs(prefix='embedmeta')
# We need to assure that paths are absolute if they are relative
item_dicoms = list(map(op.abspath, item_dicoms))
embedfunc = Node(Function(input_names=['dcmfiles', 'niftifile', 'infofile',
'bids_info', 'force', 'min_meta'],
output_names=['outfile', 'meta'],
function=embed_nifti),
name='embedder')
embedfunc.inputs.dcmfiles = item_dicoms
embedfunc.inputs.niftifile = op.abspath(outname)
embedfunc.inputs.infofile = op.abspath(scaninfo)
embedfunc.inputs.min_meta = min_meta
if bids:
embedfunc.inputs.bids_info = load_json(op.abspath(outname_bids))
else:
embedfunc.inputs.bids_info = None
embedfunc.inputs.force = True
embedfunc.base_dir = tmpdir
cwd = os.getcwd()
lgr.debug("Embedding into %s based on dicoms[0]=%s for nifti %s",
scaninfo, item_dicoms[0], outname)
try:
if op.lexists(scaninfo):
# TODO: handle annexed file case
if not op.islink(scaninfo):
set_readonly(scaninfo, False)
res = embedfunc.run()
set_readonly(scaninfo)
if with_prov:
g = res.provenance.rdf()
g.parse(prov_file,
format='turtle')
g.serialize(prov_file, format='turtle')
set_readonly(prov_file)
except Exception as exc:
lgr.error("Embedding failed: %s", str(exc))
os.chdir(cwd)
示例6: print
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
# Releasing Mr Loggins...
dangerZone.setLevel('NOTSET')
print('Done!')
return SC_cap_row_filename, SC_dist_row_filename
import numpy as np
debugPath = '/Users/srothmei/Desktop/charite/toronto/Adalberto/debug/'
roi = 68
subid = 'Adalberto'
tracksPath = debugPath
wmBorder_file = debugPath + 'wmborder.npy'
wmborder = np.load(wmBorder_file)
affine_matrix_file = debugPath + 'affine_matrix.npy'
affine_matrix = np.load(affine_matrix_file)
from nipype import Node
from nipype.interfaces.io import DataFinder
tckFinder = Node(DataFinder(match_regex = '.*\.npy', root_paths = tracksPath), name = 'tckFinder')
res = tckFinder.run()
track_files = res.outputs.out_paths
#
compute_connectivity_row(roi, subid, affine_matrix, wmborder, tracksPath, track_files)
示例7: convert
# 需要导入模块: from nipype import Node [as 别名]
# 或者: from nipype.Node import run [as 别名]
def convert(items, anonymizer=None, symlink=True, converter=None):
prov_files = []
tmpdir = mkdtemp()
for item in items:
if isinstance(item[1], (list, tuple)):
outtypes = item[1]
else:
outtypes = [item[1]]
prefix = item[0]
print('Converting %s' % prefix)
dirname = os.path.dirname(prefix + '.ext')
print(dirname)
if not os.path.exists(dirname):
os.makedirs(dirname)
for outtype in outtypes:
print(outtype)
if outtype == 'dicom':
dicomdir = prefix + '_dicom'
if os.path.exists(dicomdir):
shutil.rmtree(dicomdir)
os.mkdir(dicomdir)
for filename in item[2]:
outfile = os.path.join(dicomdir, os.path.split(filename)[1])
if not os.path.islink(outfile):
if symlink:
os.symlink(filename, outfile)
else:
os.link(filename, outfile)
elif outtype in ['nii', 'nii.gz']:
outname = prefix + '.' + outtype
scaninfo = prefix + '_scaninfo.json'
if not os.path.exists(outname):
from nipype import config
config.enable_provenance()
from nipype import Function, Node
from nipype.interfaces.base import isdefined
print converter
if converter == 'mri_convert':
from nipype.interfaces.freesurfer.preprocess import MRIConvert
convertnode = Node(MRIConvert(), name = 'convert')
convertnode.base_dir = tmpdir
if outtype == 'nii.gz':
convertnode.inputs.out_type = 'niigz'
convertnode.inputs.in_file = item[2][0]
convertnode.inputs.out_file = outname
#cmd = 'mri_convert %s %s' % (item[2][0], outname)
#print(cmd)
#os.system(cmd)
res=convertnode.run()
elif converter == 'dcm2nii':
from nipype.interfaces.dcm2nii import Dcm2nii
convertnode = Node(Dcm2nii(), name='convert')
convertnode.base_dir = tmpdir
convertnode.inputs.source_names = item[2]
convertnode.inputs.gzip_output = outtype == 'nii.gz'
convertnode.inputs.terminal_output = 'allatonce'
res = convertnode.run()
if isinstance(res.outputs.converted_files, list):
print("Cannot convert dicom files - series likely has multiple orientations: ", item[2])
continue
else:
shutil.copyfile(res.outputs.converted_files, outname)
if isdefined(res.outputs.bvecs):
outname_bvecs = prefix + '.bvecs'
outname_bvals = prefix + '.bvals'
shutil.copyfile(res.outputs.bvecs, outname_bvecs)
shutil.copyfile(res.outputs.bvals, outname_bvals)
prov_file = prefix + '_prov.ttl'
shutil.copyfile(os.path.join(convertnode.base_dir,
convertnode.name,
'provenance.ttl'),
prov_file)
prov_files.append(prov_file)
embedfunc = Node(Function(input_names=['dcmfiles',
'niftifile',
'infofile',
'force'],
output_names=['outfile',
'meta'],
function=embed_nifti),
name='embedder')
embedfunc.inputs.dcmfiles = item[2]
embedfunc.inputs.niftifile = outname
embedfunc.inputs.infofile = scaninfo
embedfunc.inputs.force = True
embedfunc.base_dir = tmpdir
res = embedfunc.run()
g = res.provenance.rdf()
g.parse(prov_file,
format='turtle')
g.serialize(prov_file, format='turtle')
#out_file, meta_dict = embed_nifti(item[2], outname, force=True)
os.chmod(outname, 0440)
os.chmod(scaninfo, 0440)
os.chmod(prov_file, 0440)
shutil.rmtree(tmpdir)