当前位置: 首页>>代码示例>>Python>>正文


Python filemanip.fname_presuffix方法代码示例

本文整理汇总了Python中nipype.utils.filemanip.fname_presuffix方法的典型用法代码示例。如果您正苦于以下问题:Python filemanip.fname_presuffix方法的具体用法?Python filemanip.fname_presuffix怎么用?Python filemanip.fname_presuffix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nipype.utils.filemanip的用法示例。


在下文中一共展示了filemanip.fname_presuffix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        import nibabel as nib
        from nipype.utils.filemanip import fname_presuffix

        bold_img = nib.load(self.inputs.timeseries_file)
        bold_mask_img = nib.load(self.inputs.mask_file)

        bold_data = bold_img.get_fdata()
        bold_mask = bold_mask_img.get_fdata().astype(bool)

        outliers = is_outlier(bold_data[bold_mask].T, thresh=self.inputs.threshold)

        out = fname_presuffix(self.inputs.timeseries_file, suffix='_censored')

        bold_img.__class__(bold_data[..., ~outliers],
                           bold_img.affine, bold_img.header).to_filename(out)

        self._results['censored_file'] = out
        self._results['outliers'] = outliers

        return runtime 
开发者ID:HBClab,项目名称:NiBetaSeries,代码行数:23,代码来源:nilearn.py

示例2: apply_lut

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def apply_lut(in_dseg, lut, newpath=None):
    """Map the input discrete segmentation to a new label set (lookup table, LUT)."""
    import numpy as np
    import nibabel as nb
    from nipype.utils.filemanip import fname_presuffix

    if newpath is None:
        from os import getcwd
        newpath = getcwd()

    out_file = fname_presuffix(in_dseg, suffix='_dseg', newpath=newpath)
    lut = np.array(lut, dtype='int16')

    segm = nb.load(in_dseg)
    hdr = segm.header.copy()
    hdr.set_data_dtype('int16')
    segm.__class__(lut[np.asanyarray(segm.dataobj, dtype=int)].astype('int16'),
                   segm.affine, hdr).to_filename(out_file)

    return out_file 
开发者ID:nipreps,项目名称:smriprep,代码行数:22,代码来源:misc.py

示例3: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):

        in_file = nb.load(self.inputs.in_file)
        wm_mask = nb.load(self.inputs.wm_mask).get_data()
        wm_mask[wm_mask < 0.9] = 0
        wm_mask[wm_mask > 0] = 1
        wm_mask = wm_mask.astype(np.uint8)

        if self.inputs.erodemsk:
            # Create a structural element to be used in an opening operation.
            struc = nd.generate_binary_structure(3, 2)
            # Perform an opening operation on the background data.
            wm_mask = nd.binary_erosion(wm_mask, structure=struc).astype(np.uint8)

        data = in_file.get_data()
        data *= 1000.0 / np.median(data[wm_mask > 0])

        out_file = fname_presuffix(
            self.inputs.in_file, suffix="_harmonized", newpath="."
        )
        in_file.__class__(data, in_file.affine, in_file.header).to_filename(out_file)

        self._results["out_file"] = out_file

        return runtime 
开发者ID:poldracklab,项目名称:mriqc,代码行数:27,代码来源:anatomical.py

示例4: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        ext = ".nii.gz" if self.inputs.compress else ".nii"
        self._results["out_file"] = fname_presuffix(
            self.inputs.in_files[0],
            suffix="_merged" + ext,
            newpath=runtime.cwd,
            use_ext=False,
        )
        new_nii = concat_imgs(self.inputs.in_files, dtype=self.inputs.dtype)

        if isdefined(self.inputs.header_source):
            src_hdr = nb.load(self.inputs.header_source).header
            new_nii.header.set_xyzt_units(t=src_hdr.get_xyzt_units()[-1])
            new_nii.header.set_zooms(
                list(new_nii.header.get_zooms()[:3]) + [src_hdr.get_zooms()[3]]
            )

        new_nii.to_filename(self._results["out_file"])

        return runtime 
开发者ID:nipreps,项目名称:niworkflows,代码行数:22,代码来源:nilearn.py

示例5: _enhance_t2_contrast

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _enhance_t2_contrast(in_file, newpath=None, offset=0.5):
    """
    Enhance the T2* contrast of an EPI dataset.

    Performs a logarithmic transformation of intensity that
    effectively splits brain and background and makes the
    overall distribution more Gaussian.
    """
    out_file = fname_presuffix(in_file, suffix="_t1enh", newpath=newpath)
    nii = nb.load(in_file)
    data = nii.get_fdata()
    maxd = data.max()
    newdata = np.log(offset + data / maxd)
    newdata -= newdata.min()
    newdata *= maxd / newdata.max()
    nii = nii.__class__(newdata, nii.affine, nii.header)
    nii.to_filename(out_file)
    return out_file 
开发者ID:nipreps,项目名称:niworkflows,代码行数:20,代码来源:nilearn.py

示例6: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        gii = nb.load(self.inputs.in_file)
        data = gii.darrays[0].data

        if self.inputs.itk_lps:  # ITK: flip X and Y around 0
            data[:, :2] *= -1

        # antsApplyTransformsToPoints requires 5 cols with headers
        csvdata = np.hstack((data, np.zeros((data.shape[0], 3))))

        out_file = fname_presuffix(
            self.inputs.in_file, newpath=runtime.cwd, use_ext=False, suffix="points.csv"
        )
        np.savetxt(
            out_file,
            csvdata,
            delimiter=",",
            header="x,y,z,t,label,comment",
            fmt=["%.5f"] * 4 + ["%d"] * 2,
        )
        self._results["out_file"] = out_file
        return runtime 
开发者ID:nipreps,项目名称:niworkflows,代码行数:24,代码来源:surf.py

示例7: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        out_file = fname_presuffix(
            self.inputs.in_file,
            suffix="_motion.tsv",
            newpath=runtime.cwd,
            use_ext=False,
        )
        data = np.loadtxt(self.inputs.in_file)
        np.savetxt(
            out_file,
            data,
            delimiter="\t",
            header="\t".join(self.inputs.columns),
            comments="",
        )

        self._results["out_file"] = out_file
        return runtime 
开发者ID:nipreps,项目名称:niworkflows,代码行数:20,代码来源:utils.py

示例8: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        if self.inputs.out_file is None:
            self._results["out_file"] = fname_presuffix(
                self.inputs.metadata_files[0],
                suffix="_compcor.svg",
                use_ext=False,
                newpath=runtime.cwd,
            )
        else:
            self._results["out_file"] = self.inputs.out_file
        compcor_variance_plot(
            metadata_files=self.inputs.metadata_files,
            metadata_sources=self.inputs.metadata_sources,
            output_file=self._results["out_file"],
            varexp_thresh=self.inputs.variance_thresholds,
        )
        return runtime 
开发者ID:nipreps,项目名称:niworkflows,代码行数:19,代码来源:plotting.py

示例9: _mat2itk

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _mat2itk(args):
    from nipype.interfaces.c3 import C3dAffineTool
    from nipype.utils.filemanip import fname_presuffix

    in_file, in_ref, in_src, index, newpath = args
    # Generate a temporal file name
    out_file = fname_presuffix(in_file, suffix="_itk-%05d.txt" % index, newpath=newpath)

    # Run c3d_affine_tool
    C3dAffineTool(
        transform_file=in_file,
        reference_file=in_ref,
        source_file=in_src,
        fsl2ras=True,
        itk_transform=out_file,
        resource_monitor=False,
    ).run()
    transform = "#Transform %d\n" % index
    with open(out_file) as itkfh:
        transform += "".join(itkfh.readlines()[2:])

    return (index, transform) 
开发者ID:nipreps,项目名称:niworkflows,代码行数:24,代码来源:itk.py

示例10: demean

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def demean(in_file, in_mask, only_mask=False, newpath=None):
    """Demean ``in_file`` within the mask defined by ``in_mask``."""
    import os
    import numpy as np
    import nibabel as nb
    from nipype.utils.filemanip import fname_presuffix

    out_file = fname_presuffix(in_file, suffix="_demeaned", newpath=os.getcwd())
    nii = nb.load(in_file)
    msk = np.asanyarray(nb.load(in_mask).dataobj)
    data = nii.get_fdata()
    if only_mask:
        data[msk > 0] -= np.median(data[msk > 0])
    else:
        data -= np.median(data[msk > 0])
    nb.Nifti1Image(data, nii.affine, nii.header).to_filename(out_file)
    return out_file 
开发者ID:nipreps,项目名称:niworkflows,代码行数:19,代码来源:images.py

示例11: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        if isdefined(self.inputs.output_file):
            out_file = self.inputs.output_file
        else:
            out_file = fname_presuffix(
                self.inputs.confounds_file,
                suffix="_expansion.tsv",
                newpath=runtime.cwd,
                use_ext=False,
            )

        confounds_data = pd.read_csv(self.inputs.confounds_file, sep="\t")
        _, confounds_data = parse_formula(
            model_formula=self.inputs.model_formula,
            parent_data=confounds_data,
            unscramble=True,
        )
        confounds_data.to_csv(out_file, sep="\t", index=False, na_rep="n/a")
        self._results["confounds_file"] = out_file
        return runtime 
开发者ID:nipreps,项目名称:niworkflows,代码行数:22,代码来源:confounds.py

示例12: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        img = nb.load(self.inputs.in_file)
        msknii = nb.load(self.inputs.in_mask)
        msk = msknii.get_fdata() > self.inputs.threshold

        self._results["out_file"] = fname_presuffix(
            self.inputs.in_file, suffix="_masked", newpath=runtime.cwd
        )

        if img.dataobj.shape[:3] != msk.shape:
            raise ValueError("Image and mask sizes do not match.")

        if not np.allclose(img.affine, msknii.affine):
            raise ValueError("Image and mask affines are not similar enough.")

        if img.dataobj.ndim == msk.ndim + 1:
            msk = msk[..., np.newaxis]

        masked = img.__class__(img.dataobj * msk, None, img.header)
        masked.to_filename(self._results["out_file"])
        return runtime 
开发者ID:nipreps,项目名称:niworkflows,代码行数:23,代码来源:nibabel.py

示例13: dseg_label

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def dseg_label(in_seg, label, newpath=None):
    """Extract a particular label from a discrete segmentation."""
    from pathlib import Path
    import nibabel as nb
    import numpy as np
    from nipype.utils.filemanip import fname_presuffix

    newpath = Path(newpath or ".")

    nii = nb.load(in_seg)
    data = np.int16(nii.dataobj) == label

    out_file = fname_presuffix(in_seg, suffix="_mask", newpath=str(newpath.absolute()))
    new = nii.__class__(data, nii.affine, nii.header)
    new.set_data_dtype(np.uint8)
    new.to_filename(out_file)
    return out_file 
开发者ID:nipreps,项目名称:niworkflows,代码行数:19,代码来源:images.py

示例14: _select_labels

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _select_labels(in_segm, labels):
    from os import getcwd
    import numpy as np
    import nibabel as nb
    from nipype.utils.filemanip import fname_presuffix

    out_files = []

    cwd = getcwd()
    nii = nb.load(in_segm)
    label_data = np.asanyarray(nii.dataobj).astype("uint8")
    for label in labels:
        newnii = nii.__class__(np.uint8(label_data == label), nii.affine, nii.header)
        newnii.set_data_dtype("uint8")
        out_file = fname_presuffix(in_segm, suffix="_class-%02d" % label, newpath=cwd)
        newnii.to_filename(out_file)
        out_files.append(out_file)
    return out_files 
开发者ID:nipreps,项目名称:niworkflows,代码行数:20,代码来源:ants.py

示例15: _run_interface

# 需要导入模块: from nipype.utils import filemanip [as 别名]
# 或者: from nipype.utils.filemanip import fname_presuffix [as 别名]
def _run_interface(self, runtime):
        import matplotlib
        matplotlib.use('Agg')
        import seaborn as sns
        from matplotlib import pyplot as plt
        sns.set_style('white')
        plt.rcParams['svg.fonttype'] = 'none'
        plt.rcParams['image.interpolation'] = 'nearest'

        data = self._load_data(self.inputs.data)
        out_name = fname_presuffix(self.inputs.data,
                                   suffix='.' + self.inputs.image_type,
                                   newpath=runtime.cwd,
                                   use_ext=False)
        self._visualize(data, out_name)
        self._results['figure'] = out_name
        return runtime 
开发者ID:poldracklab,项目名称:fitlins,代码行数:19,代码来源:visualizations.py


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