Skip to content

Commit 8dfc981

Browse files
author
Oscar Esteban
committed
[ENH] Addition of 3dHist from AFNI
1 parent a8956d2 commit 8dfc981

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
Fourier, Allineate, Maskave, SkullStrip, TCat, Fim,
1313
BlurInMask, Autobox, TCorrMap, Bandpass, Retroicor,
1414
TCorrelate, TCorr1D, BrickStat, ROIStats, AutoTcorrelate,
15-
AFNItoNIFTI, Eval, Means)
15+
AFNItoNIFTI, Eval, Means, Histogram)
1616
from .svm import (SVMTest, SVMTrain)

nipype/interfaces/afni/preprocess.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"""
1111

1212
import os
13+
import os.path as op
1314
import re
1415
from warnings import warn
1516

16-
from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec
17+
from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec, Info
1718
from ..base import CommandLineInputSpec, CommandLine, OutputMultiPath
1819
from ..base import (Directory, TraitedSpec,
1920
traits, isdefined, File, InputMultiPath, Undefined)
@@ -2090,3 +2091,64 @@ class Means(AFNICommand):
20902091
_cmd = '3dMean'
20912092
input_spec = MeansInputSpec
20922093
output_spec = AFNICommandOutputSpec
2094+
2095+
2096+
class HistogramInputSpec(CommandLineInputSpec):
2097+
in_file = File(
2098+
desc='input file to 3dHist', argstr='-input %s', position=1, mandatory=True,
2099+
exists=True, copyfile=False)
2100+
out_file = File(
2101+
desc='Write histogram to niml file with this prefix', name_template='%s_hist',
2102+
keep_extension=False, argstr='-prefix %s', name_source=['in_file'])
2103+
showhist = traits.Bool(False, usedefault=True, desc='write a text visual histogram',
2104+
argstr='-showhist')
2105+
out_show = File(
2106+
name_template="%s_hist.out", desc='output image file name', keep_extension=False,
2107+
argstr="> %s", name_source="in_file", position=-1)
2108+
mask = File(desc='matrix to align input file', argstr='-mask %s', exists=True)
2109+
nbin = traits.Int(desc='number of bins', argstr='-nbin %d')
2110+
max_value = traits.Float(argstr='-max %f', desc='maximum intensity value')
2111+
min_value = traits.Float(argstr='-min %f', desc='minimum intensity value')
2112+
bin_width = traits.Float(argstr='-binwidth %f', desc='bin width')
2113+
2114+
class HistogramOutputSpec(TraitedSpec):
2115+
out_file = File(desc='output file', exists=True)
2116+
out_show = File(desc='output visual histogram')
2117+
2118+
2119+
class Histogram(CommandLine):
2120+
"""Computes average of all voxels in the input dataset
2121+
which satisfy the criterion in the options list
2122+
2123+
For complete details, see the `3dHist Documentation.
2124+
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dHist.html>`_
2125+
2126+
Examples
2127+
========
2128+
2129+
>>> from nipype.interfaces import afni as afni
2130+
>>> maskave = afni.Histogram()
2131+
>>> maskave.inputs.in_file = 'functional.nii'
2132+
'3dHist -input functional.nii -prefix functional_hist'
2133+
>>> res = maskave.run() # doctest: +SKIP
2134+
2135+
"""
2136+
2137+
_cmd = '3dHist'
2138+
input_spec = HistogramInputSpec
2139+
output_spec = HistogramOutputSpec
2140+
2141+
def _parse_inputs(self, skip=None):
2142+
if not self.inputs.showhist:
2143+
if skip is None:
2144+
skip = []
2145+
skip += ['out_show']
2146+
return super(Histogram, self)._parse_inputs(skip=skip)
2147+
2148+
2149+
def _list_outputs(self):
2150+
outputs = super(Histogram, self)._list_outputs()
2151+
outputs['out_file'] += '.niml.hist'
2152+
if not self.inputs.showhist:
2153+
outputs['out_show'] = Undefined
2154+
return outputs

0 commit comments

Comments
 (0)