From a28008c996b5ff37ebee5edc6a07e7d5bd6c63d5 Mon Sep 17 00:00:00 2001 From: salma Date: Thu, 23 Mar 2017 17:31:40 +0100 Subject: [PATCH 1/3] added afni 3dUnifize to utils --- nipype/interfaces/afni/__init__.py | 2 +- nipype/interfaces/afni/utils.py | 110 +++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/afni/__init__.py b/nipype/interfaces/afni/__init__.py index dfc0d794f5..6e6b8af925 100644 --- a/nipype/interfaces/afni/__init__.py +++ b/nipype/interfaces/afni/__init__.py @@ -20,4 +20,4 @@ from .utils import (AFNItoNIFTI, Autobox, BrickStat, Calc, Copy, Eval, FWHMx, MaskTool, Merge, Notes, Refit, Resample, TCat, TStat, To3D, - ZCutUp,) + Unifize, ZCutUp,) diff --git a/nipype/interfaces/afni/utils.py b/nipype/interfaces/afni/utils.py index 94a9378c2a..932974094d 100644 --- a/nipype/interfaces/afni/utils.py +++ b/nipype/interfaces/afni/utils.py @@ -1230,6 +1230,116 @@ class To3D(AFNICommand): output_spec = AFNICommandOutputSpec +class UnifizeInputSpec(AFNICommandInputSpec): + in_file = File( + desc='input file to 3dUnifize', + argstr='-input %s', + position=-1, + mandatory=True, + exists=True, + copyfile=False) + out_file = File( + name_template='%s_unif', + desc='output image file name', + argstr='-prefix %s', + name_source='in_file') + t2 = traits.Bool( + desc='Treat the input as if it were T2-weighted, rather than ' + 'T1-weighted. This processing is done simply by inverting ' + 'the image contrast, processing it as if that result were ' + 'T1-weighted, and then re-inverting the results ' + 'counts of voxel overlap, i.e., each voxel will contain the ' + 'number of masks that it is set in.', + argstr='-T2') + gm = traits.Bool( + desc='Also scale to unifize \'gray matter\' = lower intensity voxels ' + '(to aid in registering images from different scanners).', + argstr='-GM') + urad = traits.Float( + desc='Sets the radius (in voxels) of the ball used for the sneaky ' + 'trick. Default value is 18.3, and should be changed ' + 'proportionally if the dataset voxel size differs significantly ' + 'from 1 mm.', + argstr='-Urad %s') + ssave = File( + name_template='%s_scale', + desc='output file name to save the scale factor used at each voxel ', + argstr='-ssave %s') + no_duplo = traits.Bool( + desc='Do NOT use the \'duplo down\' step; this can be useful for ' + 'lower resolution datasets.', + argstr='-noduplo') + epi = traits.Bool( + desc='Assume the input dataset is a T2 (or T2*) weighted EPI time ' + 'series. After computing the scaling, apply it to ALL volumes ' + '(TRs) in the input dataset. That is, a given voxel will be ' + 'scaled by the same factor at each TR. ' + 'This option also implies \'-noduplo\' and \'-T2\'.' + 'This option turns off \'-GM\' if you turned it on.', + argstr='-EPI', + requires=['no_duplo', 't2'], + xor=['gm']) + + +class UnifizeOutputSpec(TraitedSpec): + out_file = File(desc='unifized file', + exists=True) + + +class Unifize(AFNICommand): + """3dUnifize - for uniformizing image intensity + + * The input dataset is supposed to be a T1-weighted volume, + possibly already skull-stripped (e.g., via 3dSkullStrip). + However, this program can be a useful step to take BEFORE + 3dSkullStrip, since the latter program can fail if the input + volume is strongly shaded -- 3dUnifize will (mostly) remove + such shading artifacts. + + * The output dataset has the white matter (WM) intensity approximately + uniformized across space, and scaled to peak at about 1000. + + * The output dataset is always stored in float format! + + * If the input dataset has more than 1 sub-brick, only sub-brick + #0 will be processed! + + * Want to correct EPI datasets for nonuniformity? + You can try the new and experimental [Mar 2017] '-EPI' option. + + * Method: Obi-Wan's personal variant of Ziad's sneaky trick. + (If you want to know what his trick is, you'll have to ask him, or + read Obi-Wan's source code [which is a world of ecstasy and exaltation], + or just read all the way to the end of this help output.) + + * The principal motive for this program is for use in an image + registration script, and it may or may not be useful otherwise. + + * This program replaces the older (and very different) 3dUniformize, + which is no longer maintained and may sublimate at any moment. + (In other words, we do not recommend the use of 3dUniformize.) + + For complete details, see the `3dUnifize Documentation. + `_ + + Examples + ======== + + >>> from nipype.interfaces import afni + >>> unifize = afni.Unifize() + >>> unifize.inputs.in_file = 't1.nii' + >>> unifize.inputs.out_file = 't1_unifized.nii' + >>> unifize.cmdline # doctest: +ALLOW_UNICODE + '3dUnifize -prefix t1_unifized.nii -input t1.nii' + >>> res = unifize.run() # doctest: +SKIP + + """ + + _cmd = '3dUnifize' + input_spec = UnifizeInputSpec + output_spec = UnifizeOutputSpec + + class ZCutUpInputSpec(AFNICommandInputSpec): in_file = File( desc='input file to 3dZcutup', From 1d77af81a3cf6de6e35a12f2d0a0b54fb0283bb2 Mon Sep 17 00:00:00 2001 From: salma Date: Fri, 24 Mar 2017 16:42:04 +0100 Subject: [PATCH 2/3] fix failing doctest --- nipype/interfaces/afni/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nipype/interfaces/afni/utils.py b/nipype/interfaces/afni/utils.py index 932974094d..3e6857d088 100644 --- a/nipype/interfaces/afni/utils.py +++ b/nipype/interfaces/afni/utils.py @@ -1327,10 +1327,10 @@ class Unifize(AFNICommand): >>> from nipype.interfaces import afni >>> unifize = afni.Unifize() - >>> unifize.inputs.in_file = 't1.nii' - >>> unifize.inputs.out_file = 't1_unifized.nii' + >>> unifize.inputs.in_file = 'structural.nii' + >>> unifize.inputs.out_file = 'structural_unifized.nii' >>> unifize.cmdline # doctest: +ALLOW_UNICODE - '3dUnifize -prefix t1_unifized.nii -input t1.nii' + '3dUnifize -prefix structural_unifized.nii -input structural.nii' >>> res = unifize.run() # doctest: +SKIP """ From 2ad6fe0817e8b638e3b0b44878faff086e12ccd5 Mon Sep 17 00:00:00 2001 From: salma Date: Fri, 7 Apr 2017 15:07:31 +0200 Subject: [PATCH 3/3] rename and add scale file to template fix website typo remove afni jokes --- nipype/interfaces/afni/utils.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/nipype/interfaces/afni/utils.py b/nipype/interfaces/afni/utils.py index 3e6857d088..2ebedeec5b 100644 --- a/nipype/interfaces/afni/utils.py +++ b/nipype/interfaces/afni/utils.py @@ -1239,10 +1239,8 @@ class UnifizeInputSpec(AFNICommandInputSpec): exists=True, copyfile=False) out_file = File( - name_template='%s_unif', desc='output image file name', - argstr='-prefix %s', - name_source='in_file') + argstr='-prefix %s') t2 = traits.Bool( desc='Treat the input as if it were T2-weighted, rather than ' 'T1-weighted. This processing is done simply by inverting ' @@ -1261,8 +1259,7 @@ class UnifizeInputSpec(AFNICommandInputSpec): 'proportionally if the dataset voxel size differs significantly ' 'from 1 mm.', argstr='-Urad %s') - ssave = File( - name_template='%s_scale', + scale_file = File( desc='output file name to save the scale factor used at each voxel ', argstr='-ssave %s') no_duplo = traits.Bool( @@ -1282,8 +1279,8 @@ class UnifizeInputSpec(AFNICommandInputSpec): class UnifizeOutputSpec(TraitedSpec): - out_file = File(desc='unifized file', - exists=True) + scale_file = File(desc='scale factor file') + out_file = File(desc='unifized file', exists=True) class Unifize(AFNICommand): @@ -1307,11 +1304,6 @@ class Unifize(AFNICommand): * Want to correct EPI datasets for nonuniformity? You can try the new and experimental [Mar 2017] '-EPI' option. - * Method: Obi-Wan's personal variant of Ziad's sneaky trick. - (If you want to know what his trick is, you'll have to ask him, or - read Obi-Wan's source code [which is a world of ecstasy and exaltation], - or just read all the way to the end of this help output.) - * The principal motive for this program is for use in an image registration script, and it may or may not be useful otherwise. @@ -1320,7 +1312,7 @@ class Unifize(AFNICommand): (In other words, we do not recommend the use of 3dUniformize.) For complete details, see the `3dUnifize Documentation. - `_ + `_ Examples ========