本文整理汇总了Python中nipype.utils.filemanip.split_filename函数的典型用法代码示例。如果您正苦于以下问题:Python split_filename函数的具体用法?Python split_filename怎么用?Python split_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_filename函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _run_interface
def _run_interface(self, runtime):
for i in range(1, len(self.inputs.thsamples) + 1):
_, _, ext = split_filename(self.inputs.thsamples[i - 1])
copyfile(self.inputs.thsamples[i - 1],
self.inputs.samples_base_name + "_th%dsamples" % i + ext,
copy=True)
_, _, ext = split_filename(self.inputs.thsamples[i - 1])
copyfile(self.inputs.phsamples[i - 1],
self.inputs.samples_base_name + "_ph%dsamples" % i + ext,
copy=True)
_, _, ext = split_filename(self.inputs.thsamples[i - 1])
copyfile(self.inputs.fsamples[i - 1],
self.inputs.samples_base_name + "_f%dsamples" % i + ext,
copy=True)
if isdefined(self.inputs.target_masks):
f = open("targets.txt", "w")
for target in self.inputs.target_masks:
f.write("%s\n" % target)
f.close()
runtime = super(mapped_ProbTrackX, self)._run_interface(runtime)
if runtime.stderr:
self.raise_exception(runtime)
return runtime
开发者ID:imclab,项目名称:cmp_nipype,代码行数:25,代码来源:tracking.py
示例2: _run_interface
def _run_interface(self, runtime):
for i in range(1, len(self.inputs.thsamples) + 1):
_, _, ext = split_filename(self.inputs.thsamples[i - 1])
copyfile(self.inputs.thsamples[i - 1],
self.inputs.samples_base_name + "_th%dsamples" % i + ext,
copy=False)
_, _, ext = split_filename(self.inputs.thsamples[i - 1])
copyfile(self.inputs.phsamples[i - 1],
self.inputs.samples_base_name + "_ph%dsamples" % i + ext,
copy=False)
_, _, ext = split_filename(self.inputs.thsamples[i - 1])
copyfile(self.inputs.fsamples[i - 1],
self.inputs.samples_base_name + "_f%dsamples" % i + ext,
copy=False)
if isdefined(self.inputs.target_masks):
f = open("targets.txt", "w")
for target in self.inputs.target_masks:
f.write("%s\n" % target)
f.close()
if isinstance(self.inputs.seed, list):
f = open("seeds.txt", "w")
for seed in self.inputs.seed:
if isinstance(seed, list):
f.write("%s\n" % (" ".join([str(s) for s in seed])))
else:
f.write("%s\n" % seed)
f.close()
runtime = super(ProbTrackX, self)._run_interface(runtime)
if runtime.stderr:
self.raise_exception(runtime)
return runtime
开发者ID:carlohamalainen,项目名称:nipype,代码行数:33,代码来源:dti.py
示例3: _run_interface
def _run_interface(self, runtime):
preprocessedfile = self.inputs.preprocessedfile
regfile = self.inputs.regfile
#invert transform matrix
invt = fsl.ConvertXFM()
invt.inputs.in_file = regfile
invt.inputs.invert_xfm = True
invt.inputs.out_file = regfile + '_inv.mat'
invt_result= invt.run()
#define source mask (surface, volume)
input_labels = self.inputs.vol_source+self.inputs.vol_target
sourcemask = get_mask(input_labels, self.inputs.parcfile)
sourcemaskfile = os.path.abspath('sourcemask.nii')
sourceImg = nb.Nifti1Image(sourcemask, None)
nb.save(sourceImg, sourcemaskfile)
#transform anatomical mask to functional space
sourcexfm = fsl.ApplyXfm()
sourcexfm.inputs.in_file = sourcemaskfile
sourcexfm.inputs.in_matrix_file = invt_result.outputs.out_file
_, base, _ = split_filename(sourcemaskfile)
sourcexfm.inputs.out_file = base + '_xfm.nii.gz'
sourcexfm.inputs.reference = preprocessedfile
sourcexfm.inputs.interp = 'nearestneighbour'
sourcexfm.inputs.apply_xfm = True
sourcexfm_result = sourcexfm.run()
#manual source data creation (-mask_source option not yet available in afni)
sourcemask_xfm = nb.load(sourcexfm_result.outputs.out_file).get_data()
inputdata = nb.load(preprocessedfile).get_data()
maskedinput = np.zeros_like(inputdata)
for timepoint in range(inputdata.shape[3]):
maskedinput[:,:,:,timepoint] = np.where(sourcemask_xfm,inputdata[:,:,:,timepoint],0)
maskedinputfile = os.path.abspath('inputfile.nii')
inputImg = nb.Nifti1Image(maskedinput, None)
nb.save(inputImg, maskedinputfile)
##PREPARE TARGET MASK##
#define target mask (surface, volume)
targetmask = get_mask(self.inputs.vol_target, self.inputs.parcfile)
targetmaskfile = os.path.abspath('targetmask.nii')
targetImg = nb.Nifti1Image(targetmask, None)
nb.save(targetImg, targetmaskfile)
#same transform for target
targetxfm = fsl.ApplyXfm()
targetxfm.inputs.in_file = targetmaskfile
targetxfm.inputs.in_matrix_file = invt_result.outputs.out_file
_, base, _ = split_filename(targetmaskfile)
targetxfm.inputs.out_file = base + '_xfm.nii.gz'
targetxfm.inputs.reference = preprocessedfile
targetxfm.inputs.interp = 'nearestneighbour'
targetxfm.inputs.apply_xfm = True
targetxfm_result = targetxfm.run()
return runtime
开发者ID:JanisReinelt,项目名称:pipelines,代码行数:59,代码来源:mask_volume.py
示例4: _run_interface
def _run_interface(self, runtime):
_, _, ext = split_filename(self.inputs.max)
copyfile(self.inputs.max, os.path.abspath(self.inputs.input_data_prefix + "_max" + ext), copy=False)
_, _, ext = split_filename(self.inputs.ODF)
copyfile(self.inputs.ODF, os.path.abspath(self.inputs.input_data_prefix + "_odf" + ext), copy=False)
return super(ODFTracker, self)._run_interface(runtime)
开发者ID:agramfort,项目名称:nipype,代码行数:8,代码来源:odf.py
示例5: _gen_outfilename
def _gen_outfilename(self, ext):
_, name , _ = split_filename(self.inputs.aparc_aseg_file)
if self.inputs.use_freesurfer_LUT:
prefix = 'fsLUT'
elif not self.inputs.use_freesurfer_LUT and isdefined(self.inputs.LUT_file):
lutpath, lutname, lutext = split_filename(self.inputs.LUT_file)
prefix = lutname
return prefix + '_' + name + '.' + ext
开发者ID:colinbuchanan,项目名称:nipype,代码行数:8,代码来源:cmtk.py
示例6: _gen_outfilename
def _gen_outfilename(self, ext):
if ext.endswith("mat") and isdefined(self.inputs.out_matrix_mat_file):
_, name , _ = split_filename(self.inputs.out_matrix_mat_file)
elif isdefined(self.inputs.out_matrix_file):
_, name , _ = split_filename(self.inputs.out_matrix_file)
else:
_, name , _ = split_filename(self.inputs.tract_file)
return name + ext
开发者ID:Alunisiira,项目名称:nipype,代码行数:8,代码来源:cmtk.py
示例7: _gen_filename
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_wmcsfresidual',ext)))
if name == 'outcomp':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_pcs','.txt')))
开发者ID:RanjitK,项目名称:NKI_NYU_Nipype,代码行数:10,代码来源:e_afni.py
示例8: test_split_filename
def test_split_filename():
res = split_filename('foo.nii')
yield assert_equal, res, ('', 'foo', '.nii')
res = split_filename('foo.nii.gz')
yield assert_equal, res, ('', 'foo', '.nii.gz')
res = split_filename('/usr/local/foo.nii.gz')
yield assert_equal, res, ('/usr/local', 'foo', '.nii.gz')
res = split_filename('../usr/local/foo.nii')
yield assert_equal, res, ('../usr/local', 'foo', '.nii')
res = split_filename('/usr/local/foo.a.b.c.d')
yield assert_equal, res, ('/usr/local', 'foo.a.b.c', '.d')
开发者ID:agramfort,项目名称:nipype,代码行数:11,代码来源:test_filemanip.py
示例9: fs_extract_label_rois
def fs_extract_label_rois(subdir, pet, dat, labels):
"""
Uses freesurfer tools to extract
Parameters
-----------
subdir : subjects freesurfer directory
pet : filename of subjects PET volume coreg'd to mri space
dat : filename of dat generated by tkregister mapping pet to mri
labels : filename of subjects aparc+aseg.mgz
Returns
-------
stats_file: file that contains roi stats
label_file : file of volume with label rois in pet space
you can check dat with ...
'tkmedit %s T1.mgz -overlay %s -overlay-reg %s
-fthresh 0.5 -fmid1'%(subject, pet, dat)
"""
pth, nme, ext = split_filename(pet)
pth_lbl, nme_lbl, ext_lbl = split_filename(labels)
stats_file = os.path.join(pth, '%s_%s_stats'%(nme, nme_lbl))
label_file = os.path.join(pth, '%s_%s_.nii.gz'%(nme, nme_lbl))
# Gen label file
cmd = ['mri_label2vol',
'--seg %s/mri/%s'%(subdir, labels),
'--temp %s'%(pet),
'--reg'%(dat),
'--o %s'%(label_file)]
cmd = ' '.join(cmd)
cout = CommandLine(cmd).run()
if not cout.runtime.returncode == 0:
print 'mri_label2vol failed for %s'%(pet)
return None, None
## Get stats
cmd = ['mri_segstats',
'--seg %s'%(label_file),
'--sum %s'%(stats_file),
'--in %s'%(pet),
'--nonempty --ctab',
'/usr/local/freesurfer_x86_64-4.5.0/FreeSurferColorLUT.txt']
cmd = ' '.join(cmd)
cout = CommandLine(cmd).run()
if not cout.runtime.returncode == 0:
print 'mri_segstats failed for %s'%(pet)
return None, None
return stats_file, label_file
开发者ID:cindeem,项目名称:PetProcessing,代码行数:54,代码来源:fs_tools.py
示例10: _list_outputs
def _list_outputs(self):
outputs = self.output_spec().get()
path, name, ext = split_filename(self.inputs.out_stats_file)
if not ext == '.mat':
ext = '.mat'
out_stats_file = op.abspath(name + ext)
outputs["stats_file"] = out_stats_file
path, name, ext = split_filename(self.inputs.out_network_file)
if not ext == '.pck':
ext = '.pck'
out_network_file = op.abspath(name + ext)
outputs["network_file"] = out_network_file
return outputs
开发者ID:GIGA-Consciousness,项目名称:structurefunction,代码行数:13,代码来源:functional.py
示例11: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
out_file = self.inputs.out_file
if not isdefined(out_file):
if isdefined(self.inputs.stat_image2) and (
not isdefined(self.inputs.show_negative_stats)
or not self.inputs.show_negative_stats):
stem = "%s_and_%s" % (split_filename(self.inputs.stat_image)[1],
split_filename(self.inputs.stat_image2)[1])
else:
stem = split_filename(self.inputs.stat_image)[1]
out_file = self._gen_fname(stem, suffix='_overlay')
outputs['out_file'] = os.path.abspath(out_file)
return outputs
开发者ID:dohmatob,项目名称:nipype,代码行数:14,代码来源:utils.py
示例12: z_image
def z_image(image,outliers):
"""Calculates z-score of timeseries removing timpoints with outliers.
Parameters
----------
image :
outliers :
Returns
-------
File : z-image
"""
import numpy as np
import math
import nibabel as nib
from scipy.stats.mstats import zscore
from nipype.utils.filemanip import split_filename
import os
if isinstance(image,list):
image = image[0]
if isinstance(outliers,list):
outliers = outliers[0]
def try_import(fname):
try:
a = np.genfromtxt(fname)
return np.atleast_1d(a).astype(int)
except:
return np.array([]).astype(int)
z_img = os.path.abspath('z_no_outliers_' + split_filename(image)[1] + '.nii.gz')
arts = try_import(outliers)
img = nib.load(image)
data, aff = np.asarray(img.get_data()), img.get_affine()
weights = np.zeros(data.shape, dtype=bool)
for a in arts:
weights[:, :, :, a] = True
data_mask = np.ma.array(data, mask=weights)
z = (data_mask - np.mean(data_mask, axis=3)[:,:,:,None])/np.std(data_mask,axis=3)[:,:,:,None]
final_image = nib.Nifti1Image(z, aff)
final_image.to_filename(z_img)
z_img2 = os.path.abspath('z_' + split_filename(image)[1] + '.nii.gz')
z2 = (data - np.mean(data, axis=3)[:,:,:,None])/np.std(data,axis=3)[:,:,:,None]
final_image = nib.Nifti1Image(z2, aff)
final_image.to_filename(z_img2)
z_img = [z_img, z_img2]
return z_img
开发者ID:shanqing-cai,项目名称:BrainImagingPipelines,代码行数:49,代码来源:utils.py
示例13: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
pth, base, ext = split_filename(self.inputs.template_file)
outputs["normalization_parameter_file"] = os.path.realpath(base + "_2mni.mat")
outputs["normalized_files"] = []
prefix = "w"
if isdefined(self.inputs.modulate) and self.inputs.modulate:
prefix = "m" + prefix
if isdefined(self.inputs.fwhm) and self.inputs.fwhm > 0:
prefix = "s" + prefix
for filename in self.inputs.apply_to_files:
pth, base, ext = split_filename(filename)
outputs["normalized_files"].append(os.path.realpath("%s%s%s" % (prefix, base, ext)))
return outputs
开发者ID:chaselgrove,项目名称:nipype,代码行数:15,代码来源:preprocess.py
示例14: _list_outputs
def _list_outputs(self):
outputs = self.output_spec().get()
# Get the top-level output directory
if not isdefined(self.inputs.glm_dir):
glmdir = os.getcwd()
else:
glmdir = os.path.abspath(self.inputs.glm_dir)
outputs["glm_dir"] = glmdir
# Assign the output files that always get created
outputs["beta_file"] = os.path.join(glmdir, "beta.mgh")
outputs["error_var_file"] = os.path.join(glmdir, "rvar.mgh")
outputs["error_stddev_file"] = os.path.join(glmdir, "rstd.mgh")
outputs["mask_file"] = os.path.join(glmdir, "mask.mgh")
outputs["fwhm_file"] = os.path.join(glmdir, "fwhm.dat")
outputs["dof_file"] = os.path.join(glmdir, "dof.dat")
# Assign the conditional outputs
if isdefined(self.inputs.save_residual) and self.inputs.save_residual:
outputs["error_file"] = os.path.join(glmdir, "eres.mgh")
if isdefined(self.inputs.save_estimate) and self.inputs.save_estimate:
outputs["estimate_file"] = os.path.join(glmdir, "yhat.mgh")
# Get the contrast directory name(s)
if isdefined(self.inputs.contrast):
contrasts = []
for c in self.inputs.contrast:
if split_filename(c)[2] in [".mat", ".dat", ".mtx", ".con"]:
contrasts.append(split_filename(c)[1])
else:
contrasts.append(os.path.split(c)[1])
elif isdefined(self.inputs.one_sample) and self.inputs.one_sample:
contrasts = ["osgm"]
# Add in the contrast images
outputs["sig_file"] = [os.path.join(glmdir, c, "sig.mgh") for c in contrasts]
outputs["ftest_file"] = [os.path.join(glmdir, c, "F.mgh") for c in contrasts]
outputs["gamma_file"] = [os.path.join(glmdir, c, "gamma.mgh") for c in contrasts]
outputs["gamma_var_file"] = [os.path.join(glmdir, c, "gammavar.mgh") for c in contrasts]
# Add in the PCA results, if relevant
if isdefined(self.inputs.pca) and self.inputs.pca:
pcadir = os.path.join(glmdir, "pca-eres")
outputs["spatial_eigenvectors"] = os.path.join(pcadir, "v.mgh")
outputs["frame_eigenvectors"] = os.path.join(pcadir, "u.mtx")
outputs["singluar_values"] = os.path.join(pcadir, "sdiag.mat")
outputs["svd_stats_file"] = os.path.join(pcadir, "stats.dat")
return outputs
开发者ID:dbanda,项目名称:nipype,代码行数:48,代码来源:model.py
示例15: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
_, name, ext = split_filename(self.inputs.out_file)
if not ext == '.cff':
ext = '.cff'
outputs['connectome_file'] = op.abspath(name + ext)
return outputs
开发者ID:Alunisiira,项目名称:nipype,代码行数:7,代码来源:convert.py
示例16: _gen_outfilename
def _gen_outfilename(self):
_, name , _ = split_filename(self.inputs.in_file)
if isdefined(self.inputs.out_filename):
outname = self.inputs.out_filename
else:
outname = name + '_mrconvert.' + self.inputs.extension
return outname
开发者ID:B-Rich,项目名称:nipype,代码行数:7,代码来源:preprocess.py
示例17: test_coreg
def test_coreg():
moving = example_data(infile="functional.nii")
target = example_data(infile="T1.nii")
mat = example_data(infile="trans.mat")
coreg = spmu.CalcCoregAffine(matlab_cmd="mymatlab")
coreg.inputs.target = target
assert_equal(coreg.inputs.matlab_cmd, "mymatlab")
coreg.inputs.moving = moving
assert_equal(isdefined(coreg.inputs.mat), False)
pth, mov, _ = split_filename(moving)
_, tgt, _ = split_filename(target)
mat = os.path.join(pth, "%s_to_%s.mat" % (mov, tgt))
invmat = fname_presuffix(mat, prefix="inverse_")
scrpt = coreg._make_matlab_command(None)
assert_equal(coreg.inputs.mat, mat)
assert_equal(coreg.inputs.invmat, invmat)
开发者ID:stymy,项目名称:nipype,代码行数:16,代码来源:test_utils.py
示例18: bandpass_filter
def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
"""Bandpass filter the input files
Parameters
----------
files: list of 4d nifti files
lowpass_freq: cutoff frequency for the low pass filter (in Hz)
highpass_freq: cutoff frequency for the high pass filter (in Hz)
fs: sampling rate (in Hz)
"""
out_files = []
for filename in filename_to_list(files):
path, name, ext = split_filename(filename)
out_file = os.path.join(os.getcwd(), name + '_bp' + ext)
img = nb.load(filename)
timepoints = img.shape[-1]
F = np.zeros((timepoints))
lowidx = int(timepoints / 2) + 1
if lowpass_freq > 0:
lowidx = np.round(float(lowpass_freq) / fs * timepoints)
highidx = 0
if highpass_freq > 0:
highidx = np.round(float(highpass_freq) / fs * timepoints)
F[highidx:lowidx] = 1
F = ((F + F[::-1]) > 0).astype(int)
data = img.get_data()
if np.all(F == 1):
filtered_data = data
else:
filtered_data = np.real(np.fft.ifftn(np.fft.fftn(data) * F))
img_out = nb.Nifti1Image(filtered_data, img.affine, img.header)
img_out.to_filename(out_file)
out_files.append(out_file)
return list_to_filename(out_files)
开发者ID:Conxz,项目名称:nipype,代码行数:34,代码来源:rsfmri_vol_surface_preprocessing_nipy.py
示例19: test_chained_namesource
def test_chained_namesource():
tmp_infile = setup_file()
tmpd, nme, ext = split_filename(tmp_infile)
pwd = os.getcwd()
os.chdir(tmpd)
class spec2(nib.CommandLineInputSpec):
doo = nib.File(exists=True, argstr="%s", position=1)
moo = nib.File(name_source=['doo'], hash_files=False, argstr="%s",
position=2, name_template='%s_mootpl')
poo = nib.File(name_source=['moo'], hash_files=False,
argstr="%s", position=3)
class TestName(nib.CommandLine):
_cmd = "mycommand"
input_spec = spec2
testobj = TestName()
testobj.inputs.doo = tmp_infile
res = testobj.cmdline
yield assert_true, '%s' % tmp_infile in res
yield assert_true, '%s_mootpl ' % nme in res
yield assert_true, '%s_mootpl_generated' % nme in res
os.chdir(pwd)
teardown_file(tmpd)
开发者ID:vsaase,项目名称:nipype,代码行数:26,代码来源:test_base.py
示例20: _run_interface
def _run_interface(self, runtime):
extracted_networks = []
for i, con in enumerate(self.inputs.in_files):
mycon = cf.load(con)
nets = mycon.get_connectome_network()
for ne in nets:
# here, you might want to skip networks with a given
# metadata information
ne.load()
contitle = mycon.get_connectome_meta().get_title()
ne.set_name( str(i) + ': ' + contitle + ' - ' + ne.get_name() )
ne.set_src(ne.get_name())
extracted_networks.append(ne)
# Add networks to new connectome
newcon = cf.connectome(title = 'All CNetworks', connectome_network = extracted_networks)
# Setting additional metadata
metadata = newcon.get_connectome_meta()
metadata.set_creator('My Name')
metadata.set_email('My Email')
_, name, ext = split_filename(self.inputs.out_file)
if not ext == '.cff':
ext = '.cff'
cf.save_to_cff(newcon, op.abspath(name + ext))
return runtime
开发者ID:Alunisiira,项目名称:nipype,代码行数:28,代码来源:convert.py
注:本文中的nipype.utils.filemanip.split_filename函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论