本文整理汇总了Python中nipype.utils.filemanip.list_to_filename函数的典型用法代码示例。如果您正苦于以下问题:Python list_to_filename函数的具体用法?Python list_to_filename怎么用?Python list_to_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了list_to_filename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _format_arg
def _format_arg(self, opt, spec, val):
"""Convert input to appropriate format for spm
"""
if opt == 'in_files':
return scans_for_fnames(filename_to_list(val))
if opt == 'target':
return scans_for_fname(filename_to_list(val))
if opt == 'deformation':
return np.array([list_to_filename(val)], dtype=object)
if opt == 'deformation_field':
return np.array([list_to_filename(val)], dtype=object)
return val
示例2: _list_outputs
def _list_outputs(self):
outputs = self.output_spec().get()
subjects_dir = self.inputs.subjects_dir
subject_path = op.join(subjects_dir, self.inputs.subject_id)
output_traits = self._outputs()
mesh_paths = []
for k in outputs.keys():
if k != 'mesh_files':
val = self._get_files(subject_path, k,
output_traits.traits()[k].loc,
output_traits.traits()[k].altkey)
if val:
value_list = list_to_filename(val)
if isinstance(value_list, list):
out_files = []
for value in value_list:
out_files.append(op.abspath(value))
elif isinstance(value_list, str):
out_files = op.abspath(value_list)
else:
raise TypeError
outputs[k] = out_files
if not k.rfind('surface') == -1:
mesh_paths.append(out_files)
outputs['mesh_files'] = mesh_paths
return outputs
示例3: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
jobtype = self.inputs.jobtype
if jobtype.startswith('est'):
outputs['normalization_parameters'] = []
for imgf in filename_to_list(self.inputs.source):
outputs['normalization_parameters'].append(fname_presuffix(imgf, suffix='_sn.mat', use_ext=False))
outputs['normalization_parameters'] = list_to_filename(outputs['normalization_parameters'])
if self.inputs.jobtype == "estimate":
if isdefined(self.inputs.apply_to_files):
outputs['normalized_files'] = self.inputs.apply_to_files
outputs['normalized_source'] = self.inputs.source
elif 'write' in self.inputs.jobtype:
outputs['normalized_files'] = []
if isdefined(self.inputs.apply_to_files):
filelist = filename_to_list(self.inputs.apply_to_files)
for f in filelist:
if isinstance(f, list):
run = [fname_presuffix(in_f, prefix=self.inputs.out_prefix) for in_f in f]
else:
run = [fname_presuffix(f, prefix=self.inputs.out_prefix)]
outputs['normalized_files'].extend(run)
if isdefined(self.inputs.source):
outputs['normalized_source'] = fname_presuffix(self.inputs.source, prefix=self.inputs.out_prefix)
return outputs
示例4: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
jobtype = self.inputs.jobtype
if jobtype.startswith("est"):
outputs["normalization_parameters"] = []
for imgf in filename_to_list(self.inputs.source):
outputs["normalization_parameters"].append(fname_presuffix(imgf, suffix="_sn.mat", use_ext=False))
outputs["normalization_parameters"] = list_to_filename(outputs["normalization_parameters"])
if self.inputs.jobtype == "estimate":
if isdefined(self.inputs.apply_to_files):
outputs["normalized_files"] = self.inputs.apply_to_files
outputs["normalized_source"] = self.inputs.source
elif "write" in self.inputs.jobtype:
outputs["normalized_files"] = []
if isdefined(self.inputs.apply_to_files):
for imgf in filename_to_list(self.inputs.apply_to_files):
outputs["normalized_files"].append(fname_presuffix(imgf, prefix="w"))
if isdefined(self.inputs.source):
outputs["normalized_source"] = []
for imgf in filename_to_list(self.inputs.source):
outputs["normalized_source"].append(fname_presuffix(imgf, prefix="w"))
return outputs
示例5: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
outputs['outlier_files'] = []
outputs['intensity_files'] = []
outputs['statistic_files'] = []
for i,f in enumerate(filename_to_list(self.inputs.realigned_files)):
outlierfile,intensityfile,statsfile, _ = self._get_output_filenames(f,os.getcwd())
outputs['outlier_files'].insert(i,outlierfile)
outputs['intensity_files'].insert(i,intensityfile)
outputs['statistic_files'].insert(i,statsfile)
outputs['outlier_files'] = list_to_filename(outputs['outlier_files'])
outputs['intensity_files'] = list_to_filename(outputs['intensity_files'])
outputs['statistic_files'] = list_to_filename(outputs['statistic_files'])
return outputs
示例6: 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)
示例7: _format_arg
def _format_arg(self, opt, spec, val):
"""Convert input to appropriate format for SPM
"""
if opt in ['in_files']:
return scans_for_fnames(filename_to_list(val), keep4d=False)
if opt == 'deformation_field':
return np.array([list_to_filename(val)], dtype=object)
return super(ApplyDeformationField, self)._format_arg(opt, spec, val)
示例8: _list_outputs
def _list_outputs(self):
subjects_dir = self.inputs.subjects_dir
subject_path = os.path.join(subjects_dir, self.inputs.subject_id)
output_traits = self._outputs()
outputs = output_traits.get()
for k in outputs.keys():
val = self._get_files(subject_path, k, output_traits.traits()[k].loc, output_traits.traits()[k].altkey)
if val:
outputs[k] = list_to_filename(val)
return outputs
示例9: get_names
def get_names(files, suffix):
"""Generate appropriate names for output files
"""
from nipype.utils.filemanip import (split_filename, filename_to_list,
list_to_filename)
out_names = []
for filename in files:
_, name, _ = split_filename(filename)
out_names.append(name + suffix)
return list_to_filename(out_names)
示例10: bandpass_filter
def bandpass_filter(files, lowpass_freq=0.1, highpass_freq=0.01, tr=2):
"""Bandpass filter the input files
Parameters
----------
files: list of str
List 4d nifti file paths.
lowpass_freq: float
Cutoff frequency for the low pass filter (in Hz).
highpass_freq: float
Cutoff frequency for the high pass filter (in Hz).
tr: float
The repetition time in seconds. The inverse of sampling rate (in Hz).
"""
import os
import nibabel as nb
import numpy as np
from nipype.utils.filemanip import (filename_to_list,
list_to_filename,
split_filename)
fs = 1./tr
out_files = []
for filename in filename_to_list(files):
path, name, ext = split_filename(filename)
out_file = os.path.join(os.getcwd(), name + '_bandpassed' + 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)
示例11: rename
def rename(in_files, suffix=None):
from nipype.utils.filemanip import (filename_to_list, split_filename,
list_to_filename)
out_files = []
for idx, filename in enumerate(filename_to_list(in_files)):
_, name, ext = split_filename(filename)
if suffix is None:
out_files.append(name + ('_%03d' % idx) + ext)
else:
out_files.append(name + suffix + ext)
return list_to_filename(out_files)
示例12: _list_outputs
def _list_outputs(self):
# infields are mandatory, however I could not figure out how to set 'mandatory' flag dynamically
# hence manual check
if self._infields:
for key in self._infields:
value = getattr(self.inputs, key)
if not isdefined(value):
msg = "%s requires a value for input '%s' because it was listed in 'infields'" % \
(self.__class__.__name__, key)
outputs = {}
subject_id = self.inputs.subject_id
tp, group, pid = subject_id.split('_')
for key, args in self.inputs.template_args.items():
outputs[key] = []
template = self.inputs.template
if hasattr(self.inputs, 'field_template') and \
isdefined(self.inputs.field_template) and \
key in self.inputs.field_template:
template = self.inputs.field_template[key]
if isdefined(self.inputs.base_directory):
template = os.path.join(
os.path.abspath(self.inputs.base_directory), template)
else:
template = os.path.abspath(template)
if (('concatenated_fmri.nii.gz' not in template) and ('filled_t1' not in template)):
template = template % (tp, group, key, pid,
key, tp, pid)
elif 'concatenated_fmri.nii.gz' in template:
template = template % (tp, group, key, pid)
elif 'filled_t1' in template:
template = template %( tp, group, pid, tp,
group, pid, tp, pid)
filelist = glob.glob(template)
if len(filelist) == 0:
msg = 'output key: %s template: %s returned no files' % (
key, template)
if self.inputs.raise_on_empty:
raise IOError(msg)
else:
warn(msg)
else:
if self.inputs.sort_filelist:
filelist = human_order_sorted(filelist)
outputs[key] = list_to_filename(filelist)
if any([val is None for val in outputs[key]]):
outputs[key] = []
if len(outputs[key]) == 0:
outputs[key] = None
elif len(outputs[key]) == 1:
outputs[key] = outputs[key][0]
return outputs
示例13: _list_outputs
def _list_outputs(self):
#TODO: figure out file names and get rid off the globs
outputs = self._outputs().get()
root = self._get_design_root(list_to_filename(self.inputs.fsf_file))
design_file = glob(os.path.join(os.getcwd(), '%s*.mat' % root))
assert len(design_file) == 1, 'No mat file generated by FEAT Model'
outputs['design_file'] = design_file[0]
con_file = glob(os.path.join(os.getcwd(), '%s*.con' % root))
assert len(con_file) == 1, 'No con file generated by FEAT Model'
outputs['con_file'] = con_file[0]
fcon_file = glob(os.path.join(os.getcwd(), '%s*.fts' % root))
if fcon_file:
assert len(fcon_file) == 1, 'No fts file generated by FEAT Model'
outputs['fcon_file'] = fcon_file[0]
return outputs
示例14: _format_arg
def _format_arg(self, opt, spec, val):
"""Convert input to appropriate format for spm
"""
if opt == "template":
return scans_for_fname(filename_to_list(val))
if opt == "source":
return scans_for_fname(filename_to_list(val))
if opt == "apply_to_files":
return scans_for_fnames(filename_to_list(val))
if opt == "parameter_file":
return np.array([list_to_filename(val)], dtype=object)
if opt in ["write_wrap"]:
if len(val) != 3:
raise ValueError("%s must have 3 elements" % opt)
return val
示例15: _copyfiles_to_wd
def _copyfiles_to_wd(self, outdir, execute):
""" copy files over and change the inputs"""
if hasattr(self._interface,'_get_filecopy_info'):
for info in self._interface._get_filecopy_info():
files = self.inputs.get().get(info['key'])
if not isdefined(files):
continue
if files:
infiles = filename_to_list(files)
if execute:
newfiles = copyfiles(infiles, [outdir], copy=info['copy'])
else:
newfiles = fnames_presuffix(infiles, newpath=outdir)
if not isinstance(files, list):
newfiles = list_to_filename(newfiles)
setattr(self.inputs, info['key'], newfiles)