本文整理汇总了Python中nipype.utils.filemanip.copyfile函数的典型用法代码示例。如果您正苦于以下问题:Python copyfile函数的具体用法?Python copyfile怎么用?Python copyfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copyfile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_copyfallback
def test_copyfallback():
if os.name is not 'posix':
return
orig_img, orig_hdr = _temp_analyze_files()
pth, imgname = os.path.split(orig_img)
pth, hdrname = os.path.split(orig_hdr)
try:
fatfs = TempFATFS()
except IOError:
warnings.warn('Fuse mount failed. copyfile fallback tests skipped.')
else:
with fatfs as fatdir:
tgt_img = os.path.join(fatdir, imgname)
tgt_hdr = os.path.join(fatdir, hdrname)
for copy in (True, False):
for use_hardlink in (True, False):
copyfile(orig_img, tgt_img, copy=copy,
use_hardlink=use_hardlink)
yield assert_true, os.path.exists(tgt_img)
yield assert_true, os.path.exists(tgt_hdr)
yield assert_false, os.path.islink(tgt_img)
yield assert_false, os.path.islink(tgt_hdr)
yield assert_false, os.path.samefile(orig_img, tgt_img)
yield assert_false, os.path.samefile(orig_hdr, tgt_hdr)
os.unlink(tgt_img)
os.unlink(tgt_hdr)
finally:
os.unlink(orig_img)
os.unlink(orig_hdr)
开发者ID:DimitriPapadopoulos,项目名称:nipype,代码行数:29,代码来源:test_filemanip.py
示例2: sink_mask_file
def sink_mask_file(in_file, orig_file, out_dir):
import os
from nipype.utils.filemanip import fname_presuffix, copyfile
os.makedirs(out_dir, exist_ok=True)
out_file = fname_presuffix(orig_file, suffix='_mask', newpath=out_dir)
copyfile(in_file, out_file, copy=True, use_hardlink=True)
return out_file
开发者ID:oesteban,项目名称:preprocessing-workflow,代码行数:7,代码来源:generate_reference_mask.py
示例3: _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
示例4: test_copyfile
def test_copyfile():
orig_img, orig_hdr = _temp_analyze_files()
pth, fname = os.path.split(orig_img)
new_img = os.path.join(pth, 'newfile.img')
new_hdr = os.path.join(pth, 'newfile.hdr')
copyfile(orig_img, new_img)
yield assert_true, os.path.exists(new_img)
yield assert_true, os.path.exists(new_hdr)
os.unlink(new_img)
os.unlink(new_hdr)
# final cleanup
os.unlink(orig_img)
os.unlink(orig_hdr)
开发者ID:agramfort,项目名称:nipype,代码行数:13,代码来源:test_filemanip.py
示例5: _list_outputs
def _list_outputs(self):
"""Execute this module.
"""
outdir = self.inputs.base_directory
if not isdefined(outdir):
outdir = '.'
outdir = os.path.abspath(outdir)
if isdefined(self.inputs.container):
outdir = os.path.join(outdir, self.inputs.container)
if not os.path.exists(outdir):
os.makedirs(outdir)
for key,files in self.inputs._outputs.items():
iflogger.debug("key: %s files: %s"%(key, str(files)))
files = filename_to_list(files)
outfiles = []
tempoutdir = outdir
for d in key.split('.'):
if d[0] == '@':
continue
tempoutdir = os.path.join(tempoutdir,d)
# flattening list
if isinstance(files, list):
if isinstance(files[0], list):
files = [item for sublist in files for item in sublist]
for src in filename_to_list(files):
src = os.path.abspath(src)
if os.path.isfile(src):
dst = self._get_dst(src)
dst = os.path.join(tempoutdir, dst)
dst = self._substitute(dst)
path,_ = os.path.split(dst)
if not os.path.exists(path):
os.makedirs(path)
iflogger.debug("copyfile: %s %s"%(src, dst))
copyfile(src, dst, copy=True)
elif os.path.isdir(src):
dst = self._get_dst(os.path.join(src,''))
dst = os.path.join(tempoutdir, dst)
dst = self._substitute(dst)
path,_ = os.path.split(dst)
if not os.path.exists(path):
os.makedirs(path)
if os.path.exists(dst):
iflogger.debug("removing: %s"%dst)
shutil.rmtree(dst)
iflogger.debug("copydir: %s %s"%(src, dst))
shutil.copytree(src, dst)
return None
开发者ID:danginsburg,项目名称:nipype,代码行数:50,代码来源:io.py
示例6: _run_interface
def _run_interface(self, runtime):
if self.inputs.initialization == "PriorProbabilityImages":
priors_directory = os.path.join(os.getcwd(), "priors")
if not os.path.exists(priors_directory):
os.makedirs(priors_directory)
_, _, ext = split_filename(self.inputs.prior_probability_images[0])
for i, f in enumerate(self.inputs.prior_probability_images):
target = os.path.join(priors_directory,
'priorProbImages%02d' % (i + 1) + ext)
if not (os.path.exists(target) and os.path.realpath(target) == os.path.abspath(f)):
copyfile(os.path.abspath(f), os.path.join(priors_directory,
'priorProbImages%02d' % (i + 1) + ext))
runtime = super(Atropos, self)._run_interface(runtime)
return runtime
开发者ID:FNNDSC,项目名称:nipype,代码行数:14,代码来源:segment.py
示例7: convert_rawdata
def convert_rawdata(base_directory, input_dir, out_prefix):
os.environ['UNPACK_MGH_DTI'] = '0'
file_list = os.listdir(input_dir)
# If RAWDATA folder contains one (and only one) gunzipped nifti file -> copy it
first_file = os.path.join(input_dir, file_list[0])
if len(file_list) == 1 and first_file.endswith('nii.gz'):
copyfile(first_file, os.path.join(base_directory, 'NIFTI', out_prefix+'.nii.gz'), False, False, 'content') # intelligent copy looking at input's content
else:
mem = Memory(base_dir=os.path.join(base_directory,'NIPYPE'))
mri_convert = mem.cache(fs.MRIConvert)
res = mri_convert(in_file=first_file, out_file=os.path.join(base_directory, 'NIFTI', out_prefix + '.nii.gz'))
if len(res.outputs.get()) == 0:
return False
return True
开发者ID:LTS5,项目名称:cmp_nipype,代码行数:16,代码来源:common.py
示例8: _copy_any
def _copy_any(src, dst):
src_isgz = src.endswith('.gz')
dst_isgz = dst.endswith('.gz')
if src_isgz == dst_isgz:
copyfile(src, dst, copy=True, use_hardlink=True)
return False # Make sure we do not reuse the hardlink later
# Unlink target (should not exist)
if os.path.exists(dst):
os.unlink(dst)
src_open = gzip.open if src_isgz else open
dst_open = gzip.open if dst_isgz else open
with src_open(src, 'rb') as f_in:
with dst_open(dst, 'wb') as f_out:
copyfileobj(f_in, f_out)
return True
开发者ID:ZhifangYe,项目名称:fmriprep,代码行数:17,代码来源:bids.py
示例9: _run_interface
def _run_interface(self, runtime):
out_file = self._gen_outfilename()
src_file = self.inputs.src_file
ref_file = self.inputs.ref_file
# Collect orientation infos
# "orientation" => 3 letter acronym defining orientation
src_orient = fs.utils.ImageInfo(in_file=src_file).run().outputs.orientation
ref_orient = fs.utils.ImageInfo(in_file=ref_file).run().outputs.orientation
# "convention" => RADIOLOGICAL/NEUROLOGICAL
src_conv = fsl.Orient(in_file=src_file, get_orient=True).run().outputs.orient
ref_conv = fsl.Orient(in_file=ref_file, get_orient=True).run().outputs.orient
if src_orient == ref_orient:
# no reorientation needed
copyfile(src_file, out_file, False, False, "content")
return runtime
else:
if src_conv != ref_conv:
# if needed, match convention (radiological/neurological) to reference
tmpsrc = os.path.join(os.path.dirname(src_file), "tmp_" + os.path.basename(src_file))
fsl.SwapDimensions(in_file=src_file, new_dims=("-x", "y", "z"), out_file=tmpsrc).run()
fsl.Orient(in_file=tmpsrc, swap_orient=True).run()
else:
# If conventions match, just use the original source
tmpsrc = src_file
tmp2 = os.path.join(os.path.dirname(src_file), "tmp.nii.gz")
map_orient = {"L": "RL", "R": "LR", "A": "PA", "P": "AP", "S": "IS", "I": "SI"}
fsl.SwapDimensions(
in_file=tmpsrc,
new_dims=(map_orient[ref_orient[0]], map_orient[ref_orient[1]], map_orient[ref_orient[2]]),
out_file=tmp2,
).run()
shutil.move(tmp2, out_file)
# Only remove the temporary file if the conventions did not match. Otherwise,
# we end up removing the output.
if tmpsrc != src_file:
os.remove(tmpsrc)
return runtime
开发者ID:JohnGriffiths,项目名称:cmp_nipype,代码行数:45,代码来源:common.py
示例10: inject_skullstripped
def inject_skullstripped(subjects_dir, subject_id, skullstripped):
mridir = op.join(subjects_dir, subject_id, 'mri')
t1 = op.join(mridir, 'T1.mgz')
bm_auto = op.join(mridir, 'brainmask.auto.mgz')
bm = op.join(mridir, 'brainmask.mgz')
if not op.exists(bm_auto):
img = nb.load(t1)
mask = nb.load(skullstripped)
bmask = new_img_like(mask, mask.get_data() > 0)
resampled_mask = resample_to_img(bmask, img, 'nearest')
masked_image = new_img_like(img, img.get_data() * resampled_mask.get_data())
masked_image.to_filename(bm_auto)
if not op.exists(bm):
copyfile(bm_auto, bm, copy=True, use_hardlink=True)
return subjects_dir, subject_id
开发者ID:ZhifangYe,项目名称:fmriprep,代码行数:18,代码来源:freesurfer.py
示例11: index
def index(self, config):
fig_dir = 'figures'
subject_dir = self.root.split('/')[-1]
subject = re.search('^(?P<subject_id>sub-[a-zA-Z0-9]+)$', subject_dir).group()
svg_dir = os.path.join(self.out_dir, 'fmriprep', subject, fig_dir)
os.makedirs(svg_dir, exist_ok=True)
reportlet_list = list(sorted([str(f) for f in Path(self.root).glob('**/*.*')]))
for subrep_cfg in config:
reportlets = []
for reportlet_cfg in subrep_cfg['reportlets']:
rlet = Reportlet(**reportlet_cfg)
for src in reportlet_list:
ext = src.split('.')[-1]
if rlet.file_pattern.search(src):
contents = None
if ext == 'html':
with open(src) as fp:
contents = fp.read().strip()
elif ext == 'svg':
fbase = os.path.basename(src)
copyfile(src, os.path.join(svg_dir, fbase),
copy=True, use_hardlink=True)
contents = os.path.join(subject, fig_dir, fbase)
if contents:
rlet.source_files.append(src)
rlet.contents.append(contents)
if rlet.source_files:
reportlets.append(rlet)
if reportlets:
sub_report = SubReport(
subrep_cfg['name'], reportlets=reportlets,
title=subrep_cfg.get('title'))
self.sections.append(order_by_run(sub_report))
error_dir = os.path.join(self.out_dir, "fmriprep", subject, 'log', self.run_uuid)
if os.path.isdir(error_dir):
self.index_error_dir(error_dir)
开发者ID:ZhifangYe,项目名称:fmriprep,代码行数:42,代码来源:reports.py
示例12: _run_interface
def _run_interface(self, runtime):
out_file = self._gen_outfilename()
src_file = self.inputs.src_file
ref_file = self.inputs.ref_file
# Collect orientation infos
# "orientation" => 3 letter acronym defining orientation
src_orient = fs.utils.ImageInfo(in_file=src_file).run().outputs.orientation
ref_orient = fs.utils.ImageInfo(in_file=ref_file).run().outputs.orientation
# "convention" => RADIOLOGICAL/NEUROLOGICAL
src_conv = fsl.Orient(in_file=src_file, get_orient=True).run().outputs.orient
ref_conv = fsl.Orient(in_file=ref_file, get_orient=True).run().outputs.orient
if src_orient == ref_orient:
# no reorientation needed
copyfile(src_file,out_file,False, False, 'content')
return runtime
else:
if src_conv != ref_conv:
# if needed, match convention (radiological/neurological) to reference
tmpsrc = os.path.join(os.path.dirname(src_file), 'tmp_' + os.path.basename(src_file))
fsl.SwapDimensions(in_file=src_file, new_dims=('-x','y','z'), out_file=tmpsrc).run()
fsl.Orient(in_file=tmpsrc, swap_orient=True).run()
else:
# If conventions match, just use the original source
tmpsrc = src_file
tmp2 = os.path.join(os.path.dirname(src_file), 'tmp.nii.gz')
map_orient = {'L':'RL','R':'LR','A':'PA','P':'AP','S':'IS','I':'SI'}
fsl.SwapDimensions(in_file=tmpsrc, new_dims=(map_orient[ref_orient[0]],map_orient[ref_orient[1]],map_orient[ref_orient[2]]), out_file=tmp2).run()
shutil.move(tmp2, out_file)
# Only remove the temporary file if the conventions did not match. Otherwise,
# we end up removing the output.
if tmpsrc != src_file:
os.remove(tmpsrc)
return runtime
开发者ID:LTS5,项目名称:cmp_nipype,代码行数:41,代码来源:common.py
示例13: _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
示例14: test_linkchain
def test_linkchain():
if os.name is not 'posix':
return
orig_img, orig_hdr = _temp_analyze_files()
pth, fname = os.path.split(orig_img)
new_img1 = os.path.join(pth, 'newfile1.img')
new_hdr1 = os.path.join(pth, 'newfile1.hdr')
new_img2 = os.path.join(pth, 'newfile2.img')
new_hdr2 = os.path.join(pth, 'newfile2.hdr')
new_img3 = os.path.join(pth, 'newfile3.img')
new_hdr3 = os.path.join(pth, 'newfile3.hdr')
copyfile(orig_img, new_img1)
yield assert_true, os.path.islink(new_img1)
yield assert_true, os.path.islink(new_hdr1)
copyfile(new_img1, new_img2, copy=True)
yield assert_false, os.path.islink(new_img2)
yield assert_false, os.path.islink(new_hdr2)
yield assert_false, os.path.samefile(orig_img, new_img2)
yield assert_false, os.path.samefile(orig_hdr, new_hdr2)
copyfile(new_img1, new_img3, copy=True, use_hardlink=True)
yield assert_false, os.path.islink(new_img3)
yield assert_false, os.path.islink(new_hdr3)
yield assert_true, os.path.samefile(orig_img, new_img3)
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)
os.unlink(new_img1)
os.unlink(new_hdr1)
os.unlink(new_img2)
os.unlink(new_hdr2)
os.unlink(new_img3)
os.unlink(new_hdr3)
# final cleanup
os.unlink(orig_img)
os.unlink(orig_hdr)
开发者ID:DimitriPapadopoulos,项目名称:nipype,代码行数:33,代码来源:test_filemanip.py
示例15: _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
示例16: index
def index(self, config):
fig_dir = 'figures'
subject = 'sub-{}'.format(self.subject_id)
svg_dir = self.out_dir / subject / fig_dir
svg_dir.mkdir(parents=True, exist_ok=True)
reportlet_list = list(sorted([str(f) for f in Path(self.root).glob('**/*.*')]))
for subrep_cfg in config:
reportlets = []
for reportlet_cfg in subrep_cfg['reportlets']:
rlet = Reportlet(**reportlet_cfg)
for src in reportlet_list:
ext = src.split('.')[-1]
if rlet.file_pattern.search(src):
contents = None
if ext == 'html':
with open(src) as fp:
contents = fp.read().strip()
elif ext == 'svg':
fbase = Path(src).name
copyfile(src, str(svg_dir / fbase),
copy=True, use_hardlink=True)
contents = str(Path(subject) / fig_dir / fbase)
if contents:
rlet.source_files.append(src)
rlet.contents.append(contents)
if rlet.source_files:
reportlets.append(rlet)
if reportlets:
sub_report = SubReport(
subrep_cfg['name'], reportlets=reportlets,
title=subrep_cfg.get('title'))
self.sections.append(order_by_run(sub_report))
error_dir = self.out_dir / self.packagename / subject / 'log' / self.run_uuid
if error_dir.is_dir():
self.index_error_dir(error_dir)
开发者ID:poldracklab,项目名称:niworkflows,代码行数:40,代码来源:reports.py
示例17: test_masking
def test_masking(input_fname, expected_fname):
bold_reference_wf = init_bold_reference_wf(omp_nthreads=1)
bold_reference_wf.inputs.inputnode.bold_file = input_fname
# Reconstruct base_fname from above
dirname, basename = os.path.split(input_fname)
dsname = os.path.basename(dirname)
reports_dir = Path(os.getenv('FMRIPREP_REGRESSION_REPORTS', ''))
newpath = reports_dir / dsname
out_fname = fname_presuffix(basename, suffix='_masks.svg', use_ext=False,
newpath=str(newpath))
newpath.mkdir(parents=True, exist_ok=True)
mask_diff_plot = pe.Node(ROIsPlot(colors=['limegreen'], levels=[0.5]),
name='mask_diff_plot')
mask_diff_plot.inputs.in_mask = expected_fname
mask_diff_plot.inputs.out_report = out_fname
outputnode = bold_reference_wf.get_node('outputnode')
bold_reference_wf.connect([
(outputnode, mask_diff_plot, [('ref_image', 'in_file'),
('bold_mask', 'in_rois')])
])
res = bold_reference_wf.run(plugin='MultiProc')
combine_masks = [node for node in res.nodes if node.name.endswith('combine_masks')][0]
overlap = symmetric_overlap(expected_fname,
combine_masks.result.outputs.out_file)
mask_dir = reports_dir / 'fmriprep_bold_mask' / dsname
mask_dir.mkdir(parents=True, exist_ok=True)
copyfile(combine_masks.result.outputs.out_file,
fname_presuffix(basename, suffix='_mask',
use_ext=True, newpath=str(mask_dir)),
copy=True)
assert overlap > 0.95, input_fname
开发者ID:oesteban,项目名称:preprocessing-workflow,代码行数:37,代码来源:test_util.py
示例18: copytree
try:
os.makedirs(dst)
except OSError, why:
if 'File exists' in why:
pass
else:
raise why
errors = []
for name in names:
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if os.path.isdir(srcname):
copytree(srcname, dstname)
else:
copyfile(srcname, dstname, True)
except (IOError, os.error), why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Exception, err:
errors.extend(err.args[0])
if errors:
raise Exception, errors
def add_traits(base, names, trait_type=None):
""" Add traits to a traited class.
All traits are set to Undefined by default
"""
if trait_type is None:
开发者ID:colinbuchanan,项目名称:nipype,代码行数:31,代码来源:io.py
示例19: _run_interface
def _run_interface(self, runtime):
runtime.returncode = 0
_ = copyfile(self.inputs.in_file, os.path.join(os.getcwd(),
self._rename()))
return runtime
开发者ID:Guokr1991,项目名称:nipype,代码行数:5,代码来源:utility.py
示例20: _run_interface
def _run_interface(self, runtime):
_, _, ext = split_filename(self.inputs.tensor_file)
copyfile(self.inputs.tensor_file, os.path.abspath(self.inputs.input_data_prefix + "_tensor" + ext), copy=False)
return super(DTITracker, self)._run_interface(runtime)
开发者ID:agramfort,项目名称:nipype,代码行数:5,代码来源:dti.py
注:本文中的nipype.utils.filemanip.copyfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论