|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
| 3 | +# vi: set ft=python sts=4 ts=4 sw=4 et: |
| 4 | +"""This module provides interfaces for workbench CIFTI commands""" |
| 5 | +from __future__ import (print_function, division, unicode_literals, |
| 6 | + absolute_import) |
| 7 | + |
| 8 | +from ..base import (TraitedSpec, File, traits, CommandLineInputSpec) |
| 9 | +from .base import WBCommand |
| 10 | +from ... import logging |
| 11 | + |
| 12 | +iflogger = logging.getLogger('nipype.interface') |
| 13 | + |
| 14 | + |
| 15 | +class CiftiSmoothInputSpec(CommandLineInputSpec): |
| 16 | + in_file = File( |
| 17 | + exists=True, |
| 18 | + mandatory=True, |
| 19 | + argstr="%s", |
| 20 | + position=0, |
| 21 | + desc="The input CIFTI file") |
| 22 | + sigma_surf = traits.Float( |
| 23 | + mandatory=True, |
| 24 | + argstr="%s", |
| 25 | + position=1, |
| 26 | + desc="the sigma for the gaussian surface smoothing kernel, in mm") |
| 27 | + sigma_vol = traits.Float( |
| 28 | + mandatory=True, |
| 29 | + argstr="%s", |
| 30 | + position=2, |
| 31 | + desc="the sigma for the gaussian volume smoothing kernel, in mm") |
| 32 | + direction = traits.Enum( |
| 33 | + "ROW", |
| 34 | + "COLUMN", |
| 35 | + mandatory=True, |
| 36 | + argstr="%s", |
| 37 | + position=3, |
| 38 | + desc="which dimension to smooth along, ROW or COLUMN") |
| 39 | + out_file = File( |
| 40 | + name_source=["in_file"], |
| 41 | + name_template="smoothed_%s.nii", |
| 42 | + keep_extension=True, |
| 43 | + argstr="%s", |
| 44 | + position=4, |
| 45 | + desc="The output CIFTI") |
| 46 | + left_surf = File( |
| 47 | + exists=True, |
| 48 | + mandatory=True, |
| 49 | + position=5, |
| 50 | + argstr="-left-surface %s", |
| 51 | + desc="Specify the left surface to use") |
| 52 | + left_corrected_areas = File( |
| 53 | + exists=True, |
| 54 | + position=6, |
| 55 | + argstr="-left-corrected-areas %s", |
| 56 | + desc="vertex areas (as a metric) to use instead of computing them from " |
| 57 | + "the left surface.") |
| 58 | + right_surf = File( |
| 59 | + exists=True, |
| 60 | + mandatory=True, |
| 61 | + position=7, |
| 62 | + argstr="-right-surface %s", |
| 63 | + desc="Specify the right surface to use") |
| 64 | + right_corrected_areas = File( |
| 65 | + exists=True, |
| 66 | + position=8, |
| 67 | + argstr="-right-corrected-areas %s", |
| 68 | + desc="vertex areas (as a metric) to use instead of computing them from " |
| 69 | + "the right surface") |
| 70 | + cerebellum_surf = File( |
| 71 | + exists=True, |
| 72 | + position=9, |
| 73 | + argstr="-cerebellum-surface %s", |
| 74 | + desc="specify the cerebellum surface to use") |
| 75 | + cerebellum_corrected_areas = File( |
| 76 | + exists=True, |
| 77 | + position=10, |
| 78 | + requires=["cerebellum_surf"], |
| 79 | + argstr="cerebellum-corrected-areas %s", |
| 80 | + desc="vertex areas (as a metric) to use instead of computing them from " |
| 81 | + "the cerebellum surface") |
| 82 | + cifti_roi = File( |
| 83 | + exists=True, |
| 84 | + position=11, |
| 85 | + argstr="-cifti-roi %s", |
| 86 | + desc="CIFTI file for ROI smoothing") |
| 87 | + fix_zeros_vol = traits.Bool( |
| 88 | + position=12, |
| 89 | + argstr="-fix-zeros-volume", |
| 90 | + desc="treat values of zero in the volume as missing data") |
| 91 | + fix_zeros_surf = traits.Bool( |
| 92 | + position=13, |
| 93 | + argstr="-fix-zeros-surface", |
| 94 | + desc="treat values of zero on the surface as missing data") |
| 95 | + merged_volume = traits.Bool( |
| 96 | + position=14, |
| 97 | + argstr="-merged-volume", |
| 98 | + desc="smooth across subcortical structure boundaries") |
| 99 | + |
| 100 | + |
| 101 | +class CiftiSmoothOutputSpec(TraitedSpec): |
| 102 | + out_file = File(exists=True, desc="output CIFTI file") |
| 103 | + |
| 104 | + |
| 105 | +class CiftiSmooth(WBCommand): |
| 106 | + """ |
| 107 | + Smooth a CIFTI file |
| 108 | +
|
| 109 | + The input cifti file must have a brain models mapping on the chosen |
| 110 | + dimension, columns for .dtseries, and either for .dconn. By default, |
| 111 | + data in different structures is smoothed independently (i.e., "parcel |
| 112 | + constrained" smoothing), so volume structures that touch do not smooth |
| 113 | + across this boundary. Specify ``merged_volume`` to ignore these |
| 114 | + boundaries. Surface smoothing uses the ``GEO_GAUSS_AREA`` smoothing method. |
| 115 | +
|
| 116 | + The ``*_corrected_areas`` options are intended for when it is unavoidable |
| 117 | + to smooth on group average surfaces, it is only an approximate correction |
| 118 | + for the reduction of structure in a group average surface. It is better |
| 119 | + to smooth the data on individuals before averaging, when feasible. |
| 120 | +
|
| 121 | + The ``fix_zeros_*`` options will treat values of zero as lack of data, and |
| 122 | + not use that value when generating the smoothed values, but will fill |
| 123 | + zeros with extrapolated values. The ROI should have a brain models |
| 124 | + mapping along columns, exactly matching the mapping of the chosen |
| 125 | + direction in the input file. Data outside the ROI is ignored. |
| 126 | +
|
| 127 | + >>> from nipype.interfaces.workbench import CiftiSmooth |
| 128 | + >>> smooth = CiftiSmooth() |
| 129 | + >>> smooth.inputs.in_file = 'sub-01_task-rest.dtseries.nii' |
| 130 | + >>> smooth.inputs.sigma_surf = 4 |
| 131 | + >>> smooth.inputs.sigma_vol = 4 |
| 132 | + >>> smooth.inputs.direction = 'COLUMN' |
| 133 | + >>> smooth.inputs.right_surf = 'sub-01.R.midthickness.32k_fs_LR.surf.gii' |
| 134 | + >>> smooth.inputs.left_surf = 'sub-01.L.midthickness.32k_fs_LR.surf.gii' |
| 135 | + >>> smooth.cmdline |
| 136 | + 'wb_command -cifti-smoothing sub-01_task-rest.dtseries.nii 4.0 4.0 COLUMN \ |
| 137 | + smoothed_sub-01_task-rest.dtseries.nii \ |
| 138 | + -left-surface sub-01.L.midthickness.32k_fs_LR.surf.gii \ |
| 139 | + -right-surface sub-01.R.midthickness.32k_fs_LR.surf.gii' |
| 140 | + """ |
| 141 | + input_spec = CiftiSmoothInputSpec |
| 142 | + output_spec = CiftiSmoothOutputSpec |
| 143 | + _cmd = 'wb_command -cifti-smoothing' |
0 commit comments