• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python filemanip.list_to_filename函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nipype.utils.filemanip.list_to_filename函数的典型用法代码示例。如果您正苦于以下问题:Python list_to_filename函数的具体用法?Python list_to_filename怎么用?Python list_to_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了list_to_filename函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:ChadCumba,项目名称:nipype,代码行数:12,代码来源:utils.py


示例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
开发者ID:ChadCumba,项目名称:nipype,代码行数:26,代码来源:base.py


示例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
开发者ID:neurospin,项目名称:caps-clinfmri,代码行数:28,代码来源:spm.py


示例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
开发者ID:chaselgrove,项目名称:nipype,代码行数:26,代码来源:preprocess.py


示例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
开发者ID:schwarty,项目名称:nipype,代码行数:16,代码来源:rapidart.py


示例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)
开发者ID:Conxz,项目名称:nipype,代码行数:34,代码来源:rsfmri_vol_surface_preprocessing_nipy.py


示例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)
开发者ID:neurospin,项目名称:caps-clinfmri,代码行数:8,代码来源:spm.py


示例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
开发者ID:schwarty,项目名称:nipype,代码行数:10,代码来源:io.py


示例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)
开发者ID:JohnGriffiths,项目名称:nipype,代码行数:10,代码来源:rsfmri_vol_surface_preprocessing.py


示例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)
开发者ID:Neurita,项目名称:pypes,代码行数:55,代码来源:filter.py


示例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)
开发者ID:Conxz,项目名称:nipype,代码行数:11,代码来源:rsfmri_vol_surface_preprocessing_nipy.py


示例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
开发者ID:armaneshaghi,项目名称:DCMPy,代码行数:54,代码来源:io.py


示例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
开发者ID:danginsburg,项目名称:nipype,代码行数:15,代码来源:model.py


示例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
开发者ID:chaselgrove,项目名称:nipype,代码行数:15,代码来源:preprocess.py


示例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)
开发者ID:danginsburg,项目名称:nipype,代码行数:16,代码来源:engine.py


示例16: rename

def rename(in_files, suffix=None):
    """Rename all the files in `in_files` adding the `suffix` keeping its
    extension and basedir."""
    import os.path as path
    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)):
        base, name, ext = split_filename(filename)
        if suffix is None:
            new_name = name + ('_%03d' % idx) + ext
        else:
            new_name = name + suffix + ext

        out_files.append(path.join(base, new_name))

    return list_to_filename(out_files)
开发者ID:Neurita,项目名称:pypes,代码行数:17,代码来源:files.py


示例17: _make_matlab_command

 def _make_matlab_command(self, content):
     """validates spm options and generates job structure
     if mfile is True uses matlab .m file
     else generates a job structure and saves in .mat
     """
     if isdefined(self.inputs.mask_image):
         # SPM doesn't handle explicit masking properly, especially
         # when you want to use the entire mask image
         postscript = "load SPM;\n"
         postscript += "SPM.xM.VM = spm_vol('%s');\n" % list_to_filename(self.inputs.mask_image)
         postscript += "SPM.xM.I = 0;\n"
         postscript += "SPM.xM.T = [];\n"
         postscript += "SPM.xM.TH = ones(size(SPM.xM.TH))*(%s);\n" % self.inputs.mask_threshold
         postscript += "SPM.xM.xs = struct('Masking', 'explicit masking only');\n"
         postscript += "save SPM SPM;\n"
     else:
         postscript = None
     return super(Level1Design, self)._make_matlab_command(content, postscript=postscript)
开发者ID:colinbuchanan,项目名称:nipype,代码行数:18,代码来源:model.py


示例18: _list_outputs

    def _list_outputs(self):
        """Find the files and expose them as interface outputs."""
        outputs = {}
        info = dict([(k, v) for k, v in list(self.inputs.__dict__.items())
                     if k in self._infields])

        # check if the crumb is not absolute or if in info we have the parameter for the base directory
        if not self._crumb.isabs():
            first_arg_name, _ = self._crumb._first_open_arg()
            if first_arg_name not in info:
                raise KeyError('Crumb path is not absolute and could not find input for {}.'.format(first_arg_name))
            elif not op.isabs(info[first_arg_name]):
                raise IOError('Expected an absolute path for {} argument in {} but got {}.'.format(first_arg_name,
                                                                                                   self._crumb,
                                                                                                   info[first_arg_name],
                                                                                                   ))
        force_lists = self.inputs.force_lists
        if isinstance(force_lists, bool):
            force_lists = self._outfields if force_lists else []
        bad_fields = set(force_lists) - set(self._outfields)
        if bad_fields:
            bad_fields = ", ".join(list(bad_fields))
            plural = "s" if len(bad_fields) > 1 else ""
            verb = "were" if len(bad_fields) > 1 else "was"
            msg = ("The field%s '%s' %s set in 'force_lists' and not in "
                   "'templates'.") % (plural, bad_fields, verb)
            raise ValueError(msg)

        # loop over the crumb arguments to fill self_crumb
        crumb_info = {k: v for k, v in info.items() if k in self._crumb.open_args()}
        ocrumb = self._crumb.replace(**crumb_info)

        # check again if crumb path is absolute
        if not ocrumb.isabs():
            raise ValueError('Expected a Crumb with an absolute path, got {}.'.format(ocrumb))

        if not ocrumb.exists():
            raise IOError('Expected an existing Crumb path, got {}.'.format(ocrumb))

        # loop over all the ouput items and fill them with the info in templates
        for field, template in self._templates.items():

            # Fill in the template and glob for files
            focrumb  = ocrumb.replace(**dict(template))

            if list(focrumb.open_args()):
                raise ValueError('Expected a full specification of the Crumb path by now, got {}.'.format(focrumb))

            filelist = [cr.path for cr in focrumb.unfold()]
            # Handle the case where nothing matched
            if not filelist:
                msg = "No files were found unfolding %s crumb path: %s" % (
                    field, focrumb)
                if self.inputs.raise_on_empty:
                    raise IOError(msg)
                else:
                    warn(msg)

            # Possibly sort the list
            if self.inputs.sort_filelist:
                filelist = human_order_sorted(filelist)

            # Handle whether this must be a list or not
            if field not in force_lists:
                filelist = list_to_filename(filelist)

            outputs[field] = filelist

            # add the crumb argument values for output
            for arg_name in focrumb.all_args():
                outputs[arg_name] = focrumb[arg_name][0]

        return outputs
开发者ID:Neurita,项目名称:pypes,代码行数:73,代码来源:crumb.py


示例19: _list_outputs

    def _list_outputs(self):
        # infields are mandatory, however I could not figure out
        # how to set 'mandatory' flag dynamically, hence manual check

        cache_dir = self.inputs.cache_dir or tempfile.gettempdir()

        if self.inputs.config:
            xnat = pyxnat.Interface(config=self.inputs.config)
        else:
            xnat = pyxnat.Interface(self.inputs.server,
                                    self.inputs.user,
                                    self.inputs.pwd,
                                    cache_dir
                                    )

        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)
                           )
                    raise ValueError(msg)

        outputs = {}
        for key, args in self.inputs.query_template_args.items():
            outputs[key] = []
            template = self.inputs.query_template
            if hasattr(self.inputs, 'field_template') and \
                    isdefined(self.inputs.field_template) and \
                    self.inputs.field_template.has_key(key):
                template = self.inputs.field_template[key]
            if not args:
                file_objects = xnat.select(template).get('obj')
                if file_objects == []:
                    raise IOError('Template %s returned no files' \
                                      % template
                                  )
                outputs[key] = list_to_filename(
                                        [str(file_object.get())
                                         for file_object in file_objects
                                         if file_object.exists()
                                        ])
            for argnum, arglist in enumerate(args):
                maxlen = 1
                for arg in arglist:
                    if isinstance(arg, str) and hasattr(self.inputs, arg):
                        arg = getattr(self.inputs, arg)
                    if isinstance(arg, list):
                        if (maxlen > 1) and (len(arg) != maxlen):
                            raise ValueError('incompatible number '
                                             'of arguments for %s' % key
                                             )
                        if len(arg)>maxlen:
                            maxlen = len(arg)
                outfiles = []
                for i in range(maxlen):
                    argtuple = []
                    for arg in arglist:
                        if isinstance(arg, str) and \
                                hasattr(self.inputs, arg):
                            arg = getattr(self.inputs, arg)
                        if isinstance(arg, list):
                            argtuple.append(arg[i])
                        else:
                            argtuple.append(arg)
                    if argtuple:
                        target = template % tuple(argtuple)
                        file_objects = xnat.select(target).get('obj')

                        if file_objects == []:
                            raise IOError('Template %s '
                                          'returned no files' % target
                                          )

                        outfiles = list_to_filename(
                            [str(file_object.get())
                             for file_object in file_objects
                             if file_object.exists()
                             ]
                            )
                    else:
                        file_objects = xnat.select(template).get('obj')

                        if file_objects == []:
                            raise IOError('Template %s '
                                          'returned no files' % template
                                          )

                        outfiles = list_to_filename(
                            [str(file_object.get())
                             for file_object in file_objects
                             if file_object.exists()
                             ]
                            )

                    outputs[key].insert(i,outfiles)
            if len(outputs[key]) == 0:
                outputs[key] = None
#.........这里部分代码省略.........
开发者ID:Sahand-Babapoor,项目名称:nipype,代码行数:101,代码来源:io.py


示例20: selectN

 def selectN(files, N=1):
     from nipype.utils.filemanip import filename_to_list, list_to_filename
     return list_to_filename(filename_to_list(files)[:N])
开发者ID:satra,项目名称:rscourse,代码行数:3,代码来源:rsfmri_conn_spm_preprocessing.py



注:本文中的nipype.utils.filemanip.list_to_filename函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python filemanip.split_f函数代码示例发布时间:2022-05-27
下一篇:
Python filemanip.fname_presuffix函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap