3
d                @   s  d Z ddlZddljZddlZddlZddlm	Z	m
Z
mZ ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZmZmZ G d
d deZ G dd deZ!G dd deZ"G dd deZ#G dd deZ$G dd deZ%G dd deZ&G dd deZ'G dd deZ(G dd deZ)G dd deZ*G d d! d!eZ+G d"d# d#eZ,G d$d% d%eZ-G d&d' d'eZ.G d(d) d)eZ/G d*d+ d+eZ0G d,d- d-eZ1G d.d/ d/eZ2G d0d1 d1eZ3G d2d3 d3eZ4G d4d5 d5eZ5G d6d7 d7eZ6G d8d9 d9eZ7G d:d; d;eZ8G d<d= d=eZ9G d>d? d?eZ:G d@dA dAeZ;G dBdC dCeZ<G dDdE dEeZ=G dFdG dGeZ>G dHdI dIeZ?G dJdK dKeZ@G dLdM dMeZAG dNdO dOeZBG dPdQ dQeZCG dRdS dSeZDG dTdU dUeZEG dVdW dWeZFG dXdY dYeZGG dZd[ d[eZHG d\d] d]eZIG d^d_ d_eZJG d`da daeZKG dbdc dceZLG ddde deeZMG dfdg dgeZNG dhdi dieZOG djdk dkeZPG dldm dmeZQG dndo doeZRG dpdq dqeZSG drds dseZTG dtdu dueZUG dvdw dweZVG dxdy dyeZWG dzd{ d{eZXG d|d} d}eZYG d~d deZZG dd deZ[G dd deZ\G dd deZ]G dd deZ^G dd deZ_G dd deZ`G dd deZaG dd deZbG dd deZcG dd deZdG dd deZeG dd deZfG dd deZgG dd deZhG dd deZiG dd deZjG dd deZkG dd deZlG dd deZmG dd deZnG dd deZoG dd deZpG dd deZqG dd deZrG dd deZsG dd deZtG dd deZudS )zAFNI utility interfaces.    N   )	load_json	save_jsonsplit_filename   )CommandLineInputSpecCommandLine	DirectoryTraitedSpectraits	isdefinedFileInputMultiObjectInputMultiPath	UndefinedStr)BibTeX   )AFNICommandBaseAFNICommandAFNICommandInputSpecAFNICommandOutputSpecAFNIPythonCommandInputSpecAFNIPythonCommandc               @   sl   e Zd ZedddddddZedddddddZed	d
ddZejdddZ	ejdddZ
ejdddZdS )ABoverlapInputSpeczinput file Az%sr   TF)descargstrposition	mandatoryexistscopyfilezinput file Br   zcollect output to a filez
 |& tee %sr   )r   r   r   z consider input datasets as masksz-no_automask)r   r   z5be as quiet as possible (without being entirely mute)z-quietz+print out some progress reports (to stderr)z-verbN)__name__
__module____qualname__r   	in_file_a	in_file_bout_filer   BoolZno_automaskquietverb r-   r-   >/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/afni/utils.pyr   #   s*   

r   c               @   s   e Zd ZdZdZeZeZdS )	ABoverlapa  Output (to screen) is a count of various things about how
    the automasks of datasets A and B overlap or don't overlap.

    For complete details, see the `3dABoverlap Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dABoverlap.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> aboverlap = afni.ABoverlap()
    >>> aboverlap.inputs.in_file_a = 'functional.nii'
    >>> aboverlap.inputs.in_file_b = 'structural.nii'
    >>> aboverlap.inputs.out_file =  'out.mask_ae_overlap.txt'
    >>> aboverlap.cmdline
    '3dABoverlap functional.nii structural.nii  |& tee out.mask_ae_overlap.txt'
    >>> res = aboverlap.run()  # doctest: +SKIP

    Z3dABoverlapN)	r$   r%   r&   __doc___cmdr   
input_specr   output_specr-   r-   r-   r.   r/   @   s   r/   c               @   s   e Zd ZedddddddZeddd	d
ddZejdddZejdddZ	ejdddZ
ejdddgdZejdddgdZdS )AFNItoNIFTIInputSpeczinput file to 3dAFNItoNIFTIz%sr   TF)r   r   r   r   r   r    z%s.niizoutput image file namez
-prefix %sin_file)name_templater   r   name_source
hash_fileszForce the output dataset to be 32-bit floats. This option should be used when the input AFNI dataset has different float scale factors for different sub-bricks, an option that NIfTI-1.1 does not support.z-float)r   r   zDo NOT write an AFNI extension field into the output file. Only use this option if needed. You can also use the 'nifti_tool' program to strip extensions from a file.z-purezlWhen writing the AFNI extension field, remove text notes that might contain subject identifying information.z-denotez5Give the new dataset the input datasets AFNI ID code.z-oldidnewid)r   r   xorzRGive the new dataset a new AFNI ID code, to distinguish it from the input dataset.z-newidoldidNr#   )r$   r%   r&   r   r5   r)   r   r*   Zfloat_ZpureZdenoter;   r9   r-   r-   r-   r.   r4   Y   s<   
r4   c                   s6   e Zd ZdZdZeZeZdddZ	 fddZ
  ZS )	AFNItoNIFTIac  Converts AFNI format files to NIFTI format. This can also convert 2D or
    1D data, which you can numpy.squeeze() to remove extra dimensions.

    For complete details, see the `3dAFNItoNIFTI Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAFNItoNIFTI.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> a2n = afni.AFNItoNIFTI()
    >>> a2n.inputs.in_file = 'afni_output.3D'
    >>> a2n.inputs.out_file =  'afni_output.nii'
    >>> a2n.cmdline
    '3dAFNItoNIFTI -prefix afni_output.nii afni_output.3D'
    >>> res = a2n.run()  # doctest: +SKIP

    Z3dAFNItoNIFTINc             C   s4   t |\}}}|j dkr"|d7 }tjj||| S )N.nii.nii.gz.1d.1D)r=   r>   r?   r@   )r   lowerospathjoin)selfvaluenamerC   baseextr-   r-   r.   _overload_extension   s    zAFNItoNIFTI._overload_extensionc                s   t jjtt| j|S )N)rB   rC   abspathsuperr<   _gen_filename)rE   rG   )	__class__r-   r.   rM      s    zAFNItoNIFTI._gen_filename)N)r$   r%   r&   r0   r1   r4   r2   r   r3   rJ   rM   __classcell__r-   r-   )rN   r.   r<      s   
r<   c               @   sH   e Zd ZeddddddZejdddZed	d
ddZej	dddZ
dS )AutoboxInputSpecTz	-input %sz
input fileF)r   r   r   r   r    z-npad %dz1Number of extra voxels to pad on each side of box)r   r   z
-prefix %sr5   z
%s_autobox)r   r7   r6   z-noclustzDon't do any clustering to find box. Any non-zero voxel will be preserved in the cropped volume. The default method uses some clustering to find the cropping box, and will clip off small isolated blobs.N)r$   r%   r&   r   r5   r   Intpaddingr)   r*   Zno_clusteringr-   r-   r-   r.   rP      s   
rP   c               @   sF   e Zd Zej Zej Zej Zej Zej Z	ej Z
eddZdS )AutoboxOutputSpeczoutput file)r   N)r$   r%   r&   r   rQ   Zx_minZx_maxZy_minZy_maxZz_minZz_maxr   r)   r-   r-   r-   r.   rS      s   rS   c                   s.   e Zd ZdZdZeZeZd fdd	Z	  Z
S )Autoboxa2  Computes size of a box that fits around the volume.
    Also can be used to crop the volume to that box.

    For complete details, see the `3dAutobox Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAutobox.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> abox = afni.Autobox()
    >>> abox.inputs.in_file = 'structural.nii'
    >>> abox.inputs.padding = 5
    >>> abox.cmdline
    '3dAutobox -input structural.nii -prefix structural_autobox -npad 5'
    >>> res = abox.run()  # doctest: +SKIP

    Z	3dAutoboxNc                sf   t t| j||}d}xJ|jjdD ]:}tj||}|r$|j  |jf  fdd j	 D  q$W |S )Nzvx=(?P<x_min>-?\d+)\.\.(?P<x_max>-?\d+)  y=(?P<y_min>-?\d+)\.\.(?P<y_max>-?\d+)  z=(?P<z_min>-?\d+)\.\.(?P<z_max>-?\d+)
c                s   i | ]}t  | |qS r-   )int).0k)dr-   r.   
<dictcomp>   s    z-Autobox.aggregate_outputs.<locals>.<dictcomp>)
rL   rT   aggregate_outputsstderrsplitresearch	groupdictZ	trait_setkeys)rE   runtimeneeded_outputsoutputspatternlinem)rN   )rY   r.   r[      s    "zAutobox.aggregate_outputs)NN)r$   r%   r&   r0   r1   rP   r2   rS   r3   r[   rO   r-   r-   )rN   r.   rT      s
   rT   c               @   s   e Zd ZeddddddZeddddd	Zejd
dddZejdddZ	ejdddZ
ejdddZejdddZejdddZejejejejdddZdS )BrickStatInputSpeczinput file to 3dmaskavez%sr   T)r   r   r   r   r   z7-mask dset = use dset as mask to include/exclude voxelsz-mask %sr   )r   r   r   r   z"print the minimum value in datasetz-min)r   r   r   z5read the whole dataset to find the min and max valuesz-slow)r   r   z&print the maximum value in the datasetz-maxz#print the mean value in the datasetz-meanz&print the sum of values in the datasetz-sumz!print the variance in the datasetz-varzxp0 ps p1 write the percentile values starting at p0% and ending at p1% at a step of ps%. only one sub-brick is accepted.z-percentile %.3f %.3f %.3fNr#   )r$   r%   r&   r   r5   maskr   r*   minZslowmaxmeansumvarTupleFloatZ
percentiler-   r-   r-   r.   rh      s2   
rh   c               @   s   e Zd ZejddZdS )BrickStatOutputSpecoutput)r   N)r$   r%   r&   r   rp   min_valr-   r-   r-   r.   rq     s   rq   c               @   s&   e Zd ZdZdZeZeZdddZ	dS )	BrickStatay  Computes maximum and/or minimum voxel values of an input dataset.
    TODO Add optional arguments.

    For complete details, see the `3dBrickStat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dBrickStat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> brickstat = afni.BrickStat()
    >>> brickstat.inputs.in_file = 'functional.nii'
    >>> brickstat.inputs.mask = 'skeleton_mask.nii.gz'
    >>> brickstat.inputs.min = True
    >>> brickstat.cmdline
    '3dBrickStat -min -mask skeleton_mask.nii.gz functional.nii'
    >>> res = brickstat.run()  # doctest: +SKIP

    Z3dBrickStatNc             C   s   | j  }tjjtj d}|d krPyt|d }W q tk
rL   | j jS X ng }xV|j	j
dD ]F}|rb|j
 }t|dkr|jdd |D  qb|jdd |D  qbW t|dkr|d }t|t|d	 ||_|S )
Nzstat_result.jsonstatrU   r   c             S   s   g | ]}t |qS r-   )float)rW   valr-   r-   r.   
<listcomp>A  s    z/BrickStat.aggregate_outputs.<locals>.<listcomp>c             S   s   g | ]}t |qS r-   )rv   )rW   rw   r-   r-   r.   rx   C  s    r   )ru   )Z_outputsrB   rC   rD   getcwdr   IOErrorrunrd   stdoutr]   lenappendextendr   dictrs   )rE   rb   rc   rd   outfilers   rf   valuesr-   r-   r.   r[   0  s&    zBrickStat.aggregate_outputs)NN)
r$   r%   r&   r0   r1   rh   r2   rq   r3   r[   r-   r-   r-   r.   rt     s
   rt   c               @   sJ   e Zd Zejejedddejddfddddd	d
dZedddZ	dS )BucketInputSpecTF)r   r    z'%s')r   z%s%s)Zartstrr   z%sa  List of tuples of input datasets and subbrick selection strings
as described in more detail in the following afni help string
Input dataset specified using one of these forms:
``prefix+view``, ``prefix+view.HEAD``, or ``prefix+view.BRIK``.
You can also add a sub-brick selection list after the end of the
dataset name.  This allows only a subset of the sub-bricks to be
included into the output (by default, all of the input dataset
is copied into the output).  A sub-brick selection list looks like
one of the following forms::

    fred+orig[5]                     ==> use only sub-brick #5
    fred+orig[5,9,17]                ==> use #5, #9, and #17
    fred+orig[5..8]     or [5-8]     ==> use #5, #6, #7, and #8
    fred+orig[5..13(2)] or [5-13(2)] ==> use #5, #7, #9, #11, and #13

Sub-brick indexes start at 0.  You can use the character '$'
to indicate the last sub-brick in a dataset; for example, you
can select every third sub-brick by using the selection list
``fred+orig[0..$(3)]``
N.B.: The sub-bricks are output in the order specified, which may
not be the order in the original datasets.  For example, using
``fred+orig[0..$(2),1..$(2)]``
will cause the sub-bricks in fred+orig to be output into the
new dataset in an interleaved fashion. Using ``fred+orig[$..0]``
will reverse the order of the sub-bricks in the output.
N.B.: Bucket datasets have multiple sub-bricks, but do NOT have
a time dimension.  You can input sub-bricks from a 3D+time dataset
into a bucket dataset.  You can use the '3dinfo' program to see
how many sub-bricks a 3D+time or a bucket dataset contains.
N.B.: In non-bucket functional datasets (like the 'fico' datasets
output by FIM, or the 'fitt' datasets output by 3dttest), sub-brick
``[0]`` is the 'intensity' and sub-brick [1] is the statistical parameter
used as a threshold.  Thus, to create a bucket dataset using the
intensity from dataset A and the threshold from dataset B, and
calling the output dataset C, you would type::

    3dbucket -prefix C -fbuc 'A+orig[0]' -fbuc 'B+orig[1]

)r   r   r   r   z
-prefix %sZbuck)r   r6   Nr#   )
r$   r%   r&   r   Listro   r   r   r5   r)   r-   r-   r-   r.   r   M  s   (r   c                   s,   e Zd ZdZdZeZeZ fddZ	  Z
S )Bucketa  Concatenate sub-bricks from input datasets into one big
    'bucket' dataset.

    .. danger::

        Using this program, it is possible to create a dataset that
        has different basic datum types for different sub-bricks
        (e.g., shorts for brick 0, floats for brick 1).
        Do NOT do this!  Very few AFNI programs will work correctly
        with such datasets!

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> bucket = afni.Bucket()
    >>> bucket.inputs.in_file = [('functional.nii',"{2..$}"), ('functional.nii',"{1}")]
    >>> bucket.inputs.out_file = 'vr_base'
    >>> bucket.cmdline
    "3dbucket -prefix vr_base functional.nii'{2..$}' functional.nii'{1}'"
    >>> res = bucket.run()  # doctest: +SKIP

    See Also
    --------
    For complete details, see the `3dbucket Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dbucket.html>`__.

    Z3dbucketc                s6   |dkr"|j djdd |D  S tt| j|||S )Nr5    c             S   s$   g | ]}|d  d |d  d qS )r   'r   r-   )rW   ir-   r-   r.   rx     s    z&Bucket._format_arg.<locals>.<listcomp>)r   rD   rL   r   _format_arg)rE   rG   specrF   )rN   r-   r.   r     s    zBucket._format_arg)r$   r%   r&   r0   r1   r   r2   r   r3   r   rO   r-   r-   )rN   r.   r     s
   r   c               @   s   e Zd ZeddddddZeddddd	Zedd
ddd	ZedddddZedddddZ	e
jddgdZe
jddgdZe
jddZe
jdddZedd dZd!S )"CalcInputSpeczinput file to 3dcalcz-a %sr   T)r   r   r   r   r   zoperand file to 3dcalcz-b %sr   )r   r   r   r   z-c %sr   z%s_calczoutput image file namez
-prefix %sr'   )r6   r   r   r7   exprz
-expr "%s"r   )r   r   r   r   zstart index for in_file_astop_idx)r   requireszstop index for in_file_a	start_idxzvolume index for in_file_a)r   zoverwrite outputz
-overwrite)r   r   zother options N)r$   r%   r&   r   r'   r(   	in_file_cr)   r   r   r   rQ   r   r   
single_idxr*   	overwriteotherr-   r-   r-   r.   r     s*   r   c                   s:   e Zd ZdZdZeZeZ fddZ	d fdd	Z
  ZS )	Calca+  This program does voxel-by-voxel arithmetic on 3D datasets.

    For complete details, see the `3dcalc Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcalc.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> calc = afni.Calc()
    >>> calc.inputs.in_file_a = 'functional.nii'
    >>> calc.inputs.in_file_b = 'functional2.nii'
    >>> calc.inputs.expr='a*b'
    >>> calc.inputs.out_file =  'functional_calc.nii.gz'
    >>> calc.inputs.outputtype = 'NIFTI'
    >>> calc.cmdline  # doctest: +ELLIPSIS
    '3dcalc -a functional.nii -b functional2.nii -expr "a*b" -prefix functional_calc.nii.gz'
    >>> res = calc.run()  # doctest: +SKIP

    >>> from nipype.interfaces import afni
    >>> calc = afni.Calc()
    >>> calc.inputs.in_file_a = 'functional.nii'
    >>> calc.inputs.expr = '1'
    >>> calc.inputs.out_file = 'rm.epi.all1'
    >>> calc.inputs.overwrite = True
    >>> calc.cmdline
    '3dcalc -a functional.nii -expr "1" -prefix rm.epi.all1 -overwrite'
    >>> res = calc.run() # doctest: +SKIP

    Z3dcalcc                sj   |dkrV|j | }t| jjr6|d| jj| jjf 7 }t| jjrR|d| jj 7 }|S tt| j|||S )Nr'   z[%d..%d]z[%d])	r   r   inputsr   r   r   rL   r   r   )rE   rG   
trait_specrF   arg)rN   r-   r.   r     s    
zCalc._format_argNc                s   t t| jddS )z*Skip the arguments without argstr metadatar   r   r   )skip)r   r   r   )rL   r   _parse_inputs)rE   r   )rN   r-   r.   r     s    zCalc._parse_inputs)N)r$   r%   r&   r0   r1   r   r2   r   r3   r   r   rO   r-   r-   )rN   r.   r     s   
r   c               @   s  e Zd Zejeddddd.dZeddddd/dd
ZejdddZ	ejdddZ
ejddddddddddddgdZejdddZejdd dZejd!d"d#ddddgd$Zejd%d&d#ddddgd$Zejd'd(d#ddddgd$Zejd)d*d#ddddgd$Zejd+d#ddddgd,Zd-S )0CatInputSpecT)r   z%sr   )r   r   r   z> %sz	catout.1dzoutput (concatenated) file namer   )r   rF   
usedefaultr   r   r   z7Omit columns that are identically constant from output.z	-nonconst)r   r   zKeep only columns that are marked as 'free' in the 3dAllineate header from '-1Dparam_save'. If there is no such header, all columns are kept.z	-nonfixedrV   nicedoubleZfintZcintz-form %szspecify data type for output.out_intout_nice
out_doubleout_fintout_cint)r   r   r:   z8Stack the columns of the resultant matrix in the output.z-stackzPApply the same column/row selection string to all filenames on the command line.z-sel %sz!specifiy int data type for outputz-i
out_format)r   r   r:   z"specifiy nice data type for outputz-nz$specifiy double data type for outputz-dz0specifiy int, rounded down, data type for outputz-fz.specifiy int, rounded up, data type for output)r   r:   Nr"   r#   )r$   r%   r&   r   r   r   in_filesr)   r*   Z	omitconstZkeepfreeEnumr   stackr   selr   r   r   r   r   r-   r-   r-   r.   r     s^   
r   c               @   s   e Zd ZdZdZeZeZdS )Cata  1dcat takes as input one or more 1D files, and writes out a 1D file
    containing the side-by-side concatenation of all or a subset of the
    columns from the input files.

    For complete details, see the `1dcat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/1dcat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> cat1d = afni.Cat()
    >>> cat1d.inputs.sel = "'[0,2]'"
    >>> cat1d.inputs.in_files = ['f1.1D', 'f2.1D']
    >>> cat1d.inputs.out_file = 'catout.1d'
    >>> cat1d.cmdline
    "1dcat -sel '[0,2]' f1.1D f2.1D > catout.1d"
    >>> res = cat1d.run()  # doctest: +SKIP

    Z1dcatN)	r$   r%   r&   r0   r1   r   r2   r   r3   r-   r-   r-   r.   r   7  s   r   c            	   @   s   e Zd Zejejej ej dddddZedddd	d
dddZ	ej
ddddgdZej
ddddgdZej
ddddgdZdS )CatMatvecInputSpecz.list of tuples of mfiles and associated opkeysTz%sr   )r   r   r   r   z > %sz%s_cat.aff12.1Dr5   Fz&File to write concattenated matvecs tor   )r   r6   r7   keep_extensionr   r   r   zindicates that the resulting matrix willbe written to outfile in the 'MATRIX(...)' format (FORM 3).This feature could be used, with clever scripting, to inputa matrix directly on the command line to program 3dWarp.z-MATRIXoneline	fourxfour)r   r   r:   zTindicates that the resulting matrixwill simply be written as 12 numbers on one line.z-ONELINEmatrixzgOutput matrix in augmented form (last row is 0 0 0 1)This option does not work with -MATRIX or -ONELINEz-4x4Nr"   r#   )r$   r%   r&   r   r   ro   r   r5   r   r)   r*   r   r   r   r-   r-   r-   r.   r   Q  s4   r   c                   s,   e Zd ZdZdZeZeZ fddZ	  Z
S )	CatMatveca#  Catenates 3D rotation+shift matrix+vector transformations.

    For complete details, see the `cat_matvec Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/cat_matvec.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> cmv = afni.CatMatvec()
    >>> cmv.inputs.in_file = [('structural.BRIK::WARP_DATA','I')]
    >>> cmv.inputs.out_file = 'warp.anat.Xat.1D'
    >>> cmv.cmdline
    'cat_matvec structural.BRIK::WARP_DATA -I  > warp.anat.Xat.1D'
    >>> res = cmv.run()  # doctest: +SKIP

    Z
cat_matvecc                s0   |dkrdj dd |D S tt| j|||S )Nr5   r   c             s   s&   | ]\}}|rd ||f n|V  qdS )z%s -%sNr-   )rW   ZmfileZopkeyr-   r-   r.   	<genexpr>  s    z(CatMatvec._format_arg.<locals>.<genexpr>)rD   rL   r   r   )rE   rG   r   rF   )rN   r-   r.   r     s    zCatMatvec._format_arg)r$   r%   r&   r0   r1   r   r2   r   r3   r   rO   r-   r-   )rN   r.   r   x  s
   r   c            	   @   s   e Zd ZedddddddZeddddd	d
ddZeddddZejdddZ	ej
ej ej ej fdddZejdddZejejdddZejdddZdS )CenterMassInputSpeczinput file to 3dCMz%sr   T)r   r   r   r   r   r    r5   z	%s_cm.outFzFile to write center of mass toz> %sr   )r7   r6   r8   r   r   r   r   zFOnly voxels with nonzero values in the provided mask will be averaged.z-mask %s)r   r   r   zGenerate the mask automaticallyz	-automask)r   r   zAfter computing the center of mass, set the origin fields in the header so that the center of mass will be at (x,y,z) in DICOM coords.z-set %f %f %fz,Output values as (i,j,k) in local orienationz
-local_ijkzCompute center of mass for each blob with voxel value of v0, v1, v2, etc. This option is handy for getting ROI centers of mass.z-roi_vals %szkDon't bother listing the values of ROIs you want: The program will find all of them and produce a full listz	-all_roisNr"   r#   )r$   r%   r&   r   r5   cm_file	mask_filer   r*   automaskro   rp   Zset_cmZ	local_ijkr   rQ   Zroi_valsZall_roisr-   r-   r-   r.   r     sB   
r   c               @   sF   e Zd ZedddZeddZejejej	 ej	 ej	 ddZ
dS )CenterMassOutputSpecTzoutput file)r   r   z(file with the center of mass coordinates)r   zcenter of massN)r$   r%   r&   r   r)   r   r   r   ro   rp   cmr-   r-   r-   r.   r     s
   
r   c                   s,   e Zd ZdZdZeZeZ fddZ	  Z
S )
CenterMassa  Computes center of mass using 3dCM command

    .. note::

      By default, the output is (x,y,z) values in DICOM coordinates. But
      as of Dec, 2016, there are now command line switches for other options.


    For complete details, see the `3dCM Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dCM.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> cm = afni.CenterMass()
    >>> cm.inputs.in_file = 'structural.nii'
    >>> cm.inputs.cm_file = 'cm.txt'
    >>> cm.inputs.roi_vals = [2, 10]
    >>> cm.cmdline
    '3dCM -roi_vals 2 10 structural.nii > cm.txt'
    >>> res = 3dcm.run()  # doctest: +SKIP

    Z3dCMc                s^   t t| j }tjj| jj|d< tjj| jj|d< t	j
|d dd}dd |D |d< |S )Nr)   r   r   )Zndminc             S   s   g | ]}t |qS r-   )tuple)rW   sr-   r-   r.   rx     s    z,CenterMass._list_outputs.<locals>.<listcomp>r   )rL   r   _list_outputsrB   rC   rK   r   r5   r   nploadtxt)rE   rd   sout)rN   r-   r.   r     s    zCenterMass._list_outputs)r$   r%   r&   r0   r1   r   r2   r   r3   r   rO   r-   r-   )rN   r.   r     s
   r   c               @   sB   e Zd ZeddddddZeddddd	ZejddddddZdS )ConvertDsetInputSpeczinput file to ConvertDsetz	-input %sr   T)r   r   r   r   r   zoutput file for ConvertDsetz
-prefix %sr   )r   r   r   r   nimlniml_ascniml_bi1D1Dp1Dptgiigii_ascgii_b64	gii_b64gzzoutput typez-o_%sr   )r   r   r   r   Nr"   r#   )
r   r   r   r   r   r   r   r   r   r   )	r$   r%   r&   r   r5   r)   r   r   Zout_typer-   r-   r-   r.   r     s4            r   c               @   s$   e Zd ZdZd ZeZeZdd Z	dS )ConvertDseta  Converts a surface dataset from one format to another.

    For complete details, see the `ConvertDset Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/ConvertDset.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> convertdset = afni.ConvertDset()
    >>> convertdset.inputs.in_file = 'lh.pial_converted.gii'
    >>> convertdset.inputs.out_type = 'niml_asc'
    >>> convertdset.inputs.out_file = 'lh.pial_converted.niml.dset'
    >>> convertdset.cmdline
    'ConvertDset -o_niml_asc -input lh.pial_converted.gii -prefix lh.pial_converted.niml.dset'
    >>> res = convertdset.run()  # doctest: +SKIP

    c             C   s"   | j  j }tj| jj|d< |S )Nr)   )r3   getoprK   r   r)   )rE   rd   r-   r-   r.   r   2  s    zConvertDset._list_outputsN)
r$   r%   r&   r0   r1   r   r2   r   r3   r   r-   r-   r-   r.   r     s
   r   c               @   s@   e Zd ZedddddddZeddddd
dZejdddZdS )CopyInputSpeczinput file to 3dcopyz%sr   TF)r   r   r   r   r   r    z%s_copyzoutput image file namer   r5   )r6   r   r   r   r7   zprint progress reportsz-verb)r   r   Nr"   r#   )	r$   r%   r&   r   r5   r)   r   r*   verboser-   r-   r-   r.   r   8  s   r   c               @   s   e Zd ZdZdZeZeZdS )Copyao  Copies an image of one type to an image of the same
    or different type using 3dcopy command

    For complete details, see the `3dcopy Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcopy.html>`__

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> copy3d = afni.Copy()
    >>> copy3d.inputs.in_file = 'functional.nii'
    >>> copy3d.cmdline
    '3dcopy functional.nii functional_copy'
    >>> res = copy3d.run()  # doctest: +SKIP

    >>> from copy import deepcopy
    >>> copy3d_2 = deepcopy(copy3d)
    >>> copy3d_2.inputs.outputtype = 'NIFTI'
    >>> copy3d_2.cmdline
    '3dcopy functional.nii functional_copy.nii'
    >>> res = copy3d_2.run()  # doctest: +SKIP

    >>> copy3d_3 = deepcopy(copy3d)
    >>> copy3d_3.inputs.outputtype = 'NIFTI_GZ'
    >>> copy3d_3.cmdline
    '3dcopy functional.nii functional_copy.nii.gz'
    >>> res = copy3d_3.run()  # doctest: +SKIP

    >>> copy3d_4 = deepcopy(copy3d)
    >>> copy3d_4.inputs.out_file = 'new_func.nii'
    >>> copy3d_4.cmdline
    '3dcopy functional.nii new_func.nii'
    >>> res = copy3d_4.run()  # doctest: +SKIP

    Z3dcopyN)	r$   r%   r&   r0   r1   r   r2   r   r3   r-   r-   r-   r.   r   K  s   #r   c               @   s   e Zd Zeje ddd"dZeddd#dZedd	d
Zej	ej
 ej
 fddd
Zejddd
Zejddd
Zejddd
Zejddd
Zejddd
Zejddd
Zejddd
Zejddd
Zejddd
Zejdd d
Zd!S )$DotInputSpecz5list of input files, possibly with subbrick selectorsz%s ...r   )r   r   r   zcollect output to a filez
 |& tee %sr   zUse this dataset as a maskz-mask %s)r   r   zyMeans to further restrict the voxels from 'mset' so thatonly those mask values within this range (inclusive) willbe used.z-mrange %s %szCRemove the mean from each volume prior to computing the correlationz-demeanz-Return the correlation coefficient (default).z-docorz"Return the dot product (unscaled).z-dodotz\Return the least square fit coefficients {{a,b}} so that dset2 is approximately a + b\*dset1z-docoefztReturn the 6 numbers xbar=<x> ybar=<y> <(x-xbar)^2> <(y-ybar)^2> <(x-xbar)(y-ybar)> and the correlation coefficient.z-dosumsz6Return the Dice coefficient (the Sorensen-Dice index).z-dodicez,Return eta-squared (Cohen, NeuroImage 2008).z-doeta2zACompute the whole matrix. A waste of time, but handy for parsing.z-fullzPrint sub-brick labels to help identify what is being correlated. This option is useful whenyou have more than 2 sub-bricks at input.z-show_labelszCompute upper triangular matrixz-upperNr"   r#   )r$   r%   r&   r   r   r   r   r)   ri   ro   rp   Zmranger*   demeanZdocorZdodotZdocoefZdosumsZdodiceZdoeta2fullZshow_labelsupperr-   r-   r-   r.   r   u  sD   


r   c               @   s   e Zd ZdZdZeZeZdS )Dota  Correlation coefficient between sub-brick pairs.
    All datasets in in_files list will be concatenated.
    You can use sub-brick selectors in the file specification.

    .. warning::

        This program is not efficient when more than two subbricks are input.

    For complete details, see the `3ddot Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3ddot.html>`_

    >>> from nipype.interfaces import afni
    >>> dot = afni.Dot()
    >>> dot.inputs.in_files = ['functional.nii[0]', 'structural.nii']
    >>> dot.inputs.dodice = True
    >>> dot.inputs.out_file = 'out.mask_ae_dice.txt'
    >>> dot.cmdline
    '3dDot -dodice functional.nii[0]  structural.nii   |& tee out.mask_ae_dice.txt'
    >>> res = copy3d.run()  # doctest: +SKIP

    Z3dDotN)	r$   r%   r&   r0   r1   r   r2   r   r3   r-   r-   r-   r.   r     s   r   c               @   s   e Zd ZedddddddZedd"d	d
ZejddddddZej	dddddgdZ
ej	dddddgdZej	dddddgdZejdddddgdZej	ddd Zd!S )#Edge3InputSpeczinput file to 3dedge3z	-input %sr   TF)r   r   r   r   r   r    zoutput image file namer   z
-prefix %s)r   r   r   byteshortrv   z	-datum %szJspecify data type for output. Valid types are 'byte', 'short' and 'float'.)r   r   z9Force scaling of the output to the maximum integer range.z-fscalegscalenscalescale_floats)r   r   r:   z[Same as '-fscale', but also forces each output sub-brick to to get the same scaling factor.z-gscalefscalez9Don't do any scaling on output to byte or short datasets.z-nscaleaP  Multiply input by VAL, but only if the input datum is float. This is needed when the input dataset has a small range, like 0 to 2.0 for instance. With such a range, very few edges are detected due to what I suspect to be truncation problems. Multiplying such a dataset by 10000 fixes the problem and the scaling is undone at the output.z-scale_floats %fz)Print out some information along the way.z-verbose)r   r   Nr#   )r$   r%   r&   r   r5   r)   r   r   datumr*   r   r   r   rp   r   r   r-   r-   r-   r.   r     s@   r   c               @   s<   e Zd ZdZdZeZeZe	ddgde	ddgdgZ
dS )Edge3a;  Does 3D Edge detection using the library 3DEdge
    by Gregoire Malandain.

    For complete details, see the `3dedge3 Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dedge3.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> edge3 = afni.Edge3()
    >>> edge3.inputs.in_file = 'functional.nii'
    >>> edge3.inputs.out_file = 'edges.nii'
    >>> edge3.inputs.datum = 'byte'
    >>> edge3.cmdline
    '3dedge3 -input functional.nii -datum byte -prefix edges.nii'
    >>> res = edge3.run()  # doctest: +SKIP

    Z3dedge3z@article{Deriche1987,
author={R. Deriche},
title={Optimal edge detection using recursive filtering},
journal={International Journal of Computer Vision},
volume={2},'
pages={167-187},
year={1987},
}method)entrytagsa,  @article{MongaDericheMalandainCocquerez1991,
    author={O. Monga, R. Deriche, G. Malandain, J.P. Cocquerez},
    title={Recursive filtering and edge tracking: two primary tools for 3D edge detection},
    journal={Image and vision computing},
    volume={9},'
    pages={203-214},
    year={1991},
}N)r$   r%   r&   r0   r1   r   r2   r   r3   r   _referencesr-   r-   r-   r.   r     s   		r   c               @   s   e Zd ZeddddddZeddddd	Zedd
ddd	ZedddddZej	dddZ
edddddZejddgdZejddgdZejddZedd dZd!S )"EvalInputSpeczinput file to 1devalz-a %sr   T)r   r   r   r   r   zoperand file to 1devalz-b %sr   )r   r   r   r   z-c %sr   z%s_calczoutput image file namez
-prefix %sr'   )r6   r   r   r7   zoutput in 1Dz-1D)r   r   r   z
-expr "%s"r   )r   r   r   r   zstart index for in_file_ar   )r   r   zstop index for in_file_ar   zvolume index for in_file_a)r   zother optionsr   N)r$   r%   r&   r   r'   r(   r   r)   r   r*   Zout1Dr   r   rQ   r   r   r   r   r-   r-   r-   r.   r   +  s*   r   c                   s:   e Zd ZdZdZeZeZ fddZ	d fdd	Z
  ZS )	Evala  Evaluates an expression that may include columns of data from one or
    more text files.

    For complete details, see the `1deval Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/1deval.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> eval = afni.Eval()
    >>> eval.inputs.in_file_a = 'seed.1D'
    >>> eval.inputs.in_file_b = 'resp.1D'
    >>> eval.inputs.expr = 'a*b'
    >>> eval.inputs.out1D = True
    >>> eval.inputs.out_file =  'data_calc.1D'
    >>> eval.cmdline
    '1deval -a seed.1D -b resp.1D -expr "a*b" -1D -prefix data_calc.1D'
    >>> res = eval.run()  # doctest: +SKIP

    Z1devalc                sj   |dkrV|j | }t| jjr6|d| jj| jjf 7 }t| jjrR|d| jj 7 }|S tt| j|||S )Nr'   z[%d..%d]z[%d])	r   r   r   r   r   r   rL   r   r   )rE   rG   r   rF   r   )rN   r-   r.   r   a  s    
zEval._format_argNc                s   t t| jddS )z*Skip the arguments without argstr metadatar   r   r   )r   )r   r   r   )rL   r   r   )rE   r   )rN   r-   r.   r   k  s    zEval._parse_inputs)N)r$   r%   r&   r0   r1   r   r2   r   r3   r   r   rO   r-   r-   )rN   r.   r   G  s   
r   c            	   @   s*  e Zd ZedddddZedddd3d	d
dZedddd	ddZeddddZej	d	ddddZ
ejej	 ej d	ddgdddZej	d	ddgddZej	d	ddd Zed!dd"d	d#dZej	d$d%gd&dZej	d'd(gd)dZej	d*d+d Zej	d,d-d Zejej	 e ejedd.ej d	dd/d0d1Zd2S )4FWHMxInputSpeczinput datasetz	-input %sT)r   r   r   r   z> %sr5   z%s_fwhmx.outr   Fzoutput file)r   r7   r6   r   r   r   z-out %sz%s_subbricks.outz&output file listing the subbricks FWHM)r   r7   r6   r   r   z(use only voxels that are nonzero in maskz-mask %s)r   r   r   z	-automaskz1compute a mask from THIS dataset, a la 3dAutomask)r   r   r   z-detrenddemedzinstead of demed (0th order detrending), detrend to the specified order.  If order is not given, the program picks q=NT/30. -detrend disables -demed, and includes -unif.)defaultr   r:   r   r   z-demeddetrendzIf the input dataset has more than one sub-brick (e.g., has a time axis), then subtract the median of each voxel's time series before processing FWHM. This will tend to remove intrinsic spatial structure and leave behind the noise.)r   r:   r   z-unifzIf the input dataset has more than one sub-brick, then normalize each voxel's time series to have the same MAD before processing FWHM.)r   r   z-detprefix %sz
%s_detrendz&Save the detrended file into a datasetz-geomarithzif in_file has more than one sub-brick, compute the final estimate as the geometric mean of the individual sub-brick FWHM estimatesz-arithgeomzif in_file has more than one sub-brick, compute the final estimate as the arithmetic mean of the individual sub-brick FWHM estimatesz-combinez.combine the final measurements along each axisz-compatz#be compatible with the older 3dFWHM)r   z-acfz$computes the spatial autocorrelation)r   r   r   r   Nr#   )r$   r%   r&   r   r5   r)   out_subbricksri   r   r*   r   EitherrQ   r   r   Zunifout_detrendr   r   combinecompatro   rp   acfr-   r-   r-   r.   r   p  s   
r   c               @   s   e Zd ZedddZedddZeddZejej	ej
 ej
 ej
 ej	ej
 ej
 ej
 ej
 ddZejej	ej
 ej
 ej
 ej	ej
 ej
 ej
 ej
 ddZedd	dZd
S )FWHMxOutputSpecTzoutput file)r   r   zoutput file (subbricks)zoutput file, detrended)r   zFWHM along each axiszfitted ACF model parameterszoutput acf fileN)r$   r%   r&   r   r)   r   r   r   r   ro   rp   fwhm	acf_paramout_acfr-   r-   r-   r.   r     s   
r   c                   s\   e Zd ZdZdZeZeZe	ddgdgZ
dZd fdd		Z fd
dZ fddZ  ZS )FWHMxa  
    Unlike the older 3dFWHM, this program computes FWHMs for all sub-bricks
    in the input dataset, each one separately.  The output for each one is
    written to the file specified by '-out'.  The mean (arithmetic or geometric)
    of all the FWHMs along each axis is written to stdout.  (A non-positive
    output value indicates something bad happened; e.g., FWHM in z is meaningless
    for a 2D dataset; the estimation method computed incoherent intermediate results.)

    For complete details, see the `3dFWHMx Documentation.
    <https://afni.nimh.nih.gov/pub../pub/dist/doc/program_help/3dFWHMx.html>`_

    (Classic) METHOD:

      * Calculate ratio of variance of first differences to data variance.
      * Should be the same as 3dFWHM for a 1-brick dataset.
        (But the output format is simpler to use in a script.)


    .. note:: IMPORTANT NOTE [AFNI > 16]

      A completely new method for estimating and using noise smoothness values is
      now available in 3dFWHMx and 3dClustSim. This method is implemented in the
      '-acf' options to both programs.  'ACF' stands for (spatial) AutoCorrelation
      Function, and it is estimated by calculating moments of differences out to
      a larger radius than before.

      Notably, real FMRI data does not actually have a Gaussian-shaped ACF, so the
      estimated ACF is then fit (in 3dFWHMx) to a mixed model (Gaussian plus
      mono-exponential) of the form

        .. math::

          ACF(r) = a * exp(-r*r/(2*b*b)) + (1-a)*exp(-r/c)


      where :math:`r` is the radius, and :math:`a, b, c` are the fitted parameters.
      The apparent FWHM from this model is usually somewhat larger in real data
      than the FWHM estimated from just the nearest-neighbor differences used
      in the 'classic' analysis.

      The longer tails provided by the mono-exponential are also significant.
      3dClustSim has also been modified to use the ACF model given above to generate
      noise random fields.

    .. note:: TL;DR or summary

      The take-awaymessage is that the 'classic' 3dFWHMx and
      3dClustSim analysis, using a pure Gaussian ACF, is not very correct for
      FMRI data -- I cannot speak for PET or MEG data.

    .. warning::

      Do NOT use 3dFWHMx on the statistical results (e.g., '-bucket') from
      3dDeconvolve or 3dREMLfit!!!  The function of 3dFWHMx is to estimate
      the smoothness of the time series NOISE, not of the statistics. This
      proscription is especially true if you plan to use 3dClustSim next!!

    .. note:: Recommendations

      * For FMRI statistical purposes, you DO NOT want the FWHM to reflect
        the spatial structure of the underlying anatomy.  Rather, you want
        the FWHM to reflect the spatial structure of the noise.  This means
        that the input dataset should not have anatomical (spatial) structure.
      * One good form of input is the output of '3dDeconvolve -errts', which is
        the dataset of residuals left over after the GLM fitted signal model is
        subtracted out from each voxel's time series.
      * If you don't want to go to that much trouble, use '-detrend' to approximately
        subtract out the anatomical spatial structure, OR use the output of 3dDetrend
        for the same purpose.
      * If you do not use '-detrend', the program attempts to find non-zero spatial
        structure in the input, and will print a warning message if it is detected.

    .. note:: Notes on -demend

      * I recommend this option, and it is not the default only for historical
        compatibility reasons.  It may become the default someday.
      * It is already the default in program 3dBlurToFWHM. This is the same detrending
        as done in 3dDespike; using 2*q+3 basis functions for q > 0.
      * If you don't use '-detrend', the program now [Aug 2010] checks if a large number
        of voxels are have significant nonzero means. If so, the program will print a
        warning message suggesting the use of '-detrend', since inherent spatial
        structure in the image will bias the estimation of the FWHM of the image time
        series NOISE (which is usually the point of using 3dFWHMx).

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> fwhm = afni.FWHMx()
    >>> fwhm.inputs.in_file = 'functional.nii'
    >>> fwhm.cmdline
    '3dFWHMx -input functional.nii -out functional_subbricks.out > functional_fwhmx.out'
    >>> res = fwhm.run()  # doctest: +SKIP

    Z3dFWHMxz@article{CoxReynoldsTaylor2016,author={R.W. Cox, R.C. Reynolds, and P.A. Taylor},title={AFNI and clustering: false positive rates redux},journal={bioRxiv},year={2016},}r   )r   r   TNc                s0   | j js|d krg }|dg7 }tt| j|dS )Nr   )r   )r   r   rL   r   r   )rE   r   )rN   r-   r.   r   O  s
    
zFWHMx._parse_inputsc                s   |dkr:|dkr|j S |dkr"d S t|tr:|j d|  S |dkr|dkrP|j S |dkrbd| _d S t|trz|j d|  S t|ttfr|j d | S tt| j	|||S )Nr   TFz %dr   z %s %fr   )
r   
isinstancerV   _acfr   strbytesrL   r   r   )rE   rG   r   rF   )rN   r-   r.   r   V  s$    

zFWHMx._format_argc                s  t t| j }| jjrXtj| jj\}}d|krFtj|\}}|| }|d  |7  < nt|d< t	j
|d }|jdkrt|dd d f |d< nt||d< | jr|jdkstdt| t|d |d	< tjd
|d< t| jjttfrtj| jj|d< |S )Nz.gzr   r)      r   r   zWrong number of elements in %sr   r   z
3dFWHMx.1Dr   )rL   r   r   r   r   r   splitextr5   r   r   r   sizer   r   AssertionErrorr   rK   r   r   r   )rE   rd   fnamerI   _ext2r   )rN   r-   r.   r   k  s&    
zFWHMx._list_outputs)N)r$   r%   r&   r0   r1   r   r2   r   r3   r   r   r   r   r   r   rO   r-   r-   )rN   r.   r     s   ^r   c               @   s   e Zd Zedddd1ddZedddd2ddZejejej	dd	d
ej
 ejej	dejej
 ej
 ej
 ddddZddddddddddddddgZeej	eddddZeddd d!Zejd"d#d$gd%Zedd&d'd(gd)Zed*d+d,d-dd.d/Zd0S )3LocalBistatInputSpecTz%sr   zFilename of the first image)r   r   r   r   r   r   zFilename of the second imageSPHERERHDDTOHDRECTa
  The region around each voxel that will be extracted for the statistics calculation. Possible regions are: 'SPHERE', 'RHDD' (rhombic dodecahedron), 'TOHD' (truncated octahedron) with a given radius in mm or 'RECT' (rectangular block) with dimensions to specify in mm.z-nbhd '%s(%s)')r   r   r   ZpearsonZspearmanZquadrantZmutinfoZnormutiZjointentZ	hellingerZcrUZcrMZcrAZL2slopeZL1slopenumALLaj  Statistics to compute. Possible names are:

  * pearson  = Pearson correlation coefficient
  * spearman = Spearman correlation coefficient
  * quadrant = Quadrant correlation coefficient
  * mutinfo  = Mutual Information
  * normuti  = Normalized Mutual Information
  * jointent = Joint entropy
  * hellinger= Hellinger metric
  * crU      = Correlation ratio (Unsymmetric)
  * crM      = Correlation ratio (symmetrized by Multiplication)
  * crA      = Correlation ratio (symmetrized by Addition)
  * L2slope  = slope of least-squares (L2) linear regression of
               the data from dataset1 vs. the dataset2
               (i.e., d2 = a + b*d1 ==> this is 'b')
  * L1slope  = slope of least-absolute-sum (L1) linear
               regression of the data from dataset1 vs.
               the dataset2
  * num      = number of the values in the region:
               with the use of -mask or -automask,
               the size of the region around any given
               voxel will vary; this option lets you
               map that size.
  * ALL      = all of the above, in that order

More than one option can be used.z-stat %s...zmask image file name. Voxels NOT in the mask will not be used in the neighborhood of any voxel. Also, a voxel NOT in the mask will have its statistic(s) computed as zero (0).z-mask %s)r   r   r   z*Compute the mask as in program 3dAutomask.z	-automaskweight_file)r   r   r:   zPFile name of an image to use as a weight.  Only applies to 'pearson' statistics.z
-weight %sr   )r   r   r   r:   zOutput dataset.z
-prefix %sin_file1z	%s_bistatr   )r   r   r7   r6   r   r   Nr"   r#   )r$   r%   r&   r   r  Zin_file2r   r   ro   r   rp   neighborhood_stat_namesr   ru   r   r*   r   r  r)   r-   r-   r-   r.   r     sv   

r   c                   s,   e Zd ZdZdZeZeZ fddZ	  Z
S )LocalBistata   3dLocalBistat - computes statistics between 2 datasets, at each voxel,
    based on a local neighborhood of that voxel.

    For complete details, see the `3dLocalBistat Documentation.
    <https://afni.nimh.nih.gov/pub../pub/dist/doc/program_help/3dLocalBistat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> bistat = afni.LocalBistat()
    >>> bistat.inputs.in_file1 = 'functional.nii'
    >>> bistat.inputs.in_file2 = 'structural.nii'
    >>> bistat.inputs.neighborhood = ('SPHERE', 1.2)
    >>> bistat.inputs.stat = 'pearson'
    >>> bistat.inputs.outputtype = 'NIFTI'
    >>> bistat.cmdline
    "3dLocalBistat -prefix functional_bistat.nii -nbhd 'SPHERE(1.2)' -stat pearson functional.nii structural.nii"
    >>> res = automask.run()  # doctest: +SKIP

    Z3dLocalBistatc                s8   |dkr$|d dkr$dd|d  f}t t| j|||S )Nr  r   r  z%s,%s,%sr   )rL   r
  r   )rE   rG   r   rF   )rN   r-   r.   r     s    zLocalBistat._format_arg)r$   r%   r&   r0   r1   r   r2   r   r3   r   rO   r-   r-   )rN   r.   r
    s
   r
  c               @   s  e Zd ZeddddHddZejejejdddej	 ejejd	ejej	 ej	 ej	 dd
ddZ
dddddddddddddddddddgZeejejeejejd ejej	ej	ej	dd!d"dZedd#d$d%Zejd&d'd(Zejd)d*d(Zejej	ejej	ej	ej	d+d,d-gd.d/Zejej	ejej	ej	ej	d0d-d1gd2d/Zej	d3d,d1gd4d/Zejd5d6d7d8d9d,gd:d;Zejd<d=d>Zejd?d@d(ZedAdBdCdDddEdFZdGS )ILocalstatInputSpecTz%sr   zinput dataset)r   r   r   r   r   r   r  r  r  a
  The region around each voxel that will be extracted for the statistics calculation. Possible regions are: 'SPHERE', 'RHDD' (rhombic dodecahedron), 'TOHD' (truncated octahedron) with a given radius in mm or 'RECT' (rectangular block) with dimensions to specify in mm.z-nbhd '%s(%s)')r   r   r   rl   Zstdevrn   ZcvarZmedianZMADrj   rk   Zabsmaxr  rm   ZFWHMZFWHMbarZrankZfrankZP2skewr  ZmMP2sZmmMP2sperca  statistics to compute. Possible names are:

 * mean   = average of the values
 * stdev  = standard deviation
 * var    = variance (stdev\*stdev)
 * cvar   = coefficient of variation = stdev/fabs(mean)
 * median = median of the values
 * MAD    = median absolute deviation
 * min    = minimum
 * max    = maximum
 * absmax = maximum of the absolute values
 * num    = number of the values in the region:
            with the use of -mask or -automask,
            the size of the region around any given
            voxel will vary; this option lets you
            map that size.  It may be useful if you
            plan to compute a t-statistic (say) from
            the mean and stdev outputs.
 * sum    = sum of the values in the region
 * FWHM   = compute (like 3dFWHM) image smoothness
            inside each voxel's neighborhood.  Results
            are in 3 sub-bricks: FWHMx, FHWMy, and FWHMz.
            Places where an output is -1 are locations
            where the FWHM value could not be computed
            (e.g., outside the mask).
 * FWHMbar= Compute just the average of the 3 FWHM values
            (normally would NOT do this with FWHM also).
 * perc:P0:P1:Pstep =
            Compute percentiles between P0 and P1 with a
            step of Pstep.
            Default P1 is equal to P0 and default P2 = 1
 * rank   = rank of the voxel's intensity
 * frank  = rank / number of voxels in neighborhood
 * P2skew = Pearson's second skewness coefficient
             3 \* (mean - median) / stdev
 * ALL    = all of the above, in that order
            (except for FWHMbar and perc).
 * mMP2s  = Exactly the same output as:
            median, MAD, P2skew,
            but a little faster
 * mmMP2s = Exactly the same output as:
            mean, median, MAD, P2skew

More than one option can be used.z-stat %s...zMask image file name. Voxels NOT in the mask will not be used in the neighborhood of any voxel. Also, a voxel NOT in the mask will have its statistic(s) computed as zero (0) unless the parameter 'nonmask' is set to true.z-mask %s)r   r   r   z*Compute the mask as in program 3dAutomask.z	-automask)r   r   zVoxels not in the mask WILL have their local statistics
computed from all voxels in their neighborhood that ARE in
the mask. For instance, this option can be used to compute the
average local white matter time series, even at non-WM
voxels.z-use_nonmaskz-reduce_grid %sreduce_restore_gridreduce_max_voxa  Compute output on a grid that is reduced by the specified factors. If a single value is passed, output is resampled to the specified isotropic grid. Otherwise, the 3 inputs describe the reduction in the X, Y, and Z directions. This option speeds up computations at the expense of resolution. It should only be used when the nbhd is quite large with respect to the input's resolution, and the resultant stats are expected to be smooth.)r   r:   r   z-reduce_restore_grid %sreduce_gridz=Like reduce_grid, but also resample output back to inputgrid.z-reduce_max_vox %sz~Like reduce_restore_grid, but automatically set Rx Ry Rz sothat the computation grid is at a resolution of nbhd/MAX_VOXvoxels.NNLiCuBkz-grid_rmode %sa  Interpolant to use when resampling the output with thereduce_restore_grid option. The resampling method string RESAM should come from the set {'NN', 'Li', 'Cu', 'Bk'}. These stand for 'Nearest Neighbor', 'Linear', 'Cubic', and 'Blocky' interpolation, respectively.)r   r   r   z-quietz-Stop the highly informative progress reports.)r   r   z*overwrite output file if it already existsz
-overwritezOutput dataset.z
-prefix %sr5   z%s_localstatr   )r   r   r7   r6   r   r   Nr#   )r$   r%   r&   r   r5   r   r   ro   r   rp   r  r	  r   ru   r   r*   r   Znonmaskr  r  r  Z
grid_rmoder+   r   r)   r-   r-   r-   r.   r    s   -
	

r  c                   s,   e Zd ZdZdZeZeZ fddZ	  Z
S )	LocalstataY  3dLocalstat - computes statistics at each voxel,
    based on a local neighborhood of that voxel.

    For complete details, see the `3dLocalstat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dLocalstat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> localstat = afni.Localstat()
    >>> localstat.inputs.in_file = 'functional.nii'
    >>> localstat.inputs.mask_file = 'skeleton_mask.nii.gz'
    >>> localstat.inputs.neighborhood = ('SPHERE', 45)
    >>> localstat.inputs.stat = 'mean'
    >>> localstat.inputs.nonmask = True
    >>> localstat.inputs.outputtype = 'NIFTI_GZ'
    >>> localstat.cmdline
    "3dLocalstat -prefix functional_localstat.nii -mask skeleton_mask.nii.gz -nbhd 'SPHERE(45.0)' -use_nonmask -stat mean functional.nii"
    >>> res = localstat.run()  # doctest: +SKIP

    Z3dLocalstatc                sr   |dkr$|d dkr$dd|d  f}|dkr:dd |D }|d	ksJ|d
kr^t |dkr^d| }tt| j|||S )Nr  r   r  z%s,%s,%sr   ru   c             S   s(   g | ] }t |d kr d|d  n|qS )r   zperc:%s:%s:%sr   )r}   )rW   vr-   r-   r.   rx     s    z)Localstat._format_arg.<locals>.<listcomp>r  r  r   z%s %s %s)r}   rL   r  r   )rE   rG   r   rF   )rN   r-   r.   r     s    zLocalstat._format_arg)r$   r%   r&   r0   r1   r  r2   r   r3   r   rO   r-   r-   )rN   r.   r    s
   r  c               @   s   e Zd Zeeddddd+dddZedd	d
ddZejddddZ	ej
ddddddZedddZedddZejdddZejdddZejd d!dZejd"d#dZed$d%d&gd'Zejd(d)dZd*S ),MaskToolInputSpecT)r   z"input file or files to 3dmask_toolz	-input %sr   F)r   r   r   r   r    z%s_maskzoutput image file namez
-prefix %sr5   )r6   r   r   r7   zInstead of created a binary 0/1 mask dataset, create one with counts of voxel overlap, i.e., each voxel will contain the number of masks that it is set in.z-countr   )r   r   r   r   r   rv   z	-datum %szspecify data type for output.)r   r   zhUse this option to dilate and/or erode datasets as they are read. ex. '5 -5' to dilate and erode 5 timesz-dilate_inputs %s)r   r   z6dilate and/or erode combined mask at the given levels.z-dilate_results %szWhen combining masks (across datasets and sub-bricks), use this option to restrict the result to a certain fraction of the set of volumesz-frac %sz"intersection, this means -frac 1.0z-interzunion, this means -frac 0z-unionzkThis option can be used to fill holes in the resulting mask, i.e. after all other processing has been done.z-fill_holeszfill holes only in the given directions. This option is for use with -fill holes. should be a single string that specifies 1-3 of the axes using {x,y,z} labels (i.e. dataset axis order), or using the labels in {R,L,A,P,I,S}.z-fill_dirs %s
fill_holes)r   r   r   z#specify verbosity level, for 0 to 3z-verb %sNr#   )r$   r%   r&   r   r   r5   r)   r   r*   countr   r   r   Zdilate_inputsZdilate_resultsrp   fracZinterunionr  Z	fill_dirsrQ   r   r-   r-   r-   r.   r    sR   
r  c               @   s   e Zd ZedddZdS )MaskToolOutputSpecz	mask fileT)r   r   N)r$   r%   r&   r   r)   r-   r-   r-   r.   r  &  s   r  c               @   s   e Zd ZdZdZeZeZdS )MaskToola'  3dmask_tool - for combining/dilating/eroding/filling masks

    For complete details, see the `3dmask_tool Documentation.
    <https://afni.nimh.nih.gov/pub../pub/dist/doc/program_help/3dmask_tool.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> masktool = afni.MaskTool()
    >>> masktool.inputs.in_file = 'functional.nii'
    >>> masktool.inputs.outputtype = 'NIFTI'
    >>> masktool.cmdline
    '3dmask_tool -prefix functional_mask.nii -input functional.nii'
    >>> res = automask.run()  # doctest: +SKIP

    Z3dmask_toolN)	r$   r%   r&   r0   r1   r  r2   r  r3   r-   r-   r-   r.   r  *  s   r  c               @   sT   e Zd ZeeddddddddZedd	d
ddZejdddZ	ej
ddddZdS )MergeInputSpeczinput file to 3dmergeT)r   r   z%sr   F)r   r   r   r    z%s_mergezoutput image file namez
-prefix %sr   )r6   r   r   r7   z*apply options to all sub-bricks in datasetz-doall)r   r   zFWHM blur value (mm)z-1blur_fwhm %dmm)r   r   ZunitsNr#   )r$   r%   r&   r   r   r   r)   r   r*   ZdoallrQ   Zblurfwhmr-   r-   r-   r.   r  A  s   

r  c               @   s   e Zd ZdZdZeZeZdS )Mergeac  Merge or edit volumes using AFNI 3dmerge command

    For complete details, see the `3dmerge Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dmerge.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> merge = afni.Merge()
    >>> merge.inputs.in_files = ['functional.nii', 'functional2.nii']
    >>> merge.inputs.blurfwhm = 4
    >>> merge.inputs.doall = True
    >>> merge.inputs.out_file = 'e7.nii'
    >>> merge.cmdline
    '3dmerge -1blur_fwhm 4 -doall -prefix e7.nii functional.nii functional2.nii'
    >>> res = merge.run()  # doctest: +SKIP

    Z3dmergeN)	r$   r%   r&   r0   r1   r  r2   r   r3   r-   r-   r-   r.   r  W  s   r  c               @   st   e Zd ZedddddddZeddd	Zed
ddgdZedddgdZe	j
ddd	Ze	jddd	Zeddd	ZdS )NotesInputSpeczinput file to 3dNotesz%sr   TF)r   r   r   r   r   r    znote to addz-a "%s")r   r   znote to add to historyz-h "%s"rep_history)r   r   r:   z"note with which to replace historyz-HH "%s"add_historyzdelete note number numz-d %dz"print to stdout the expanded notesz-seszoutput image file nameNr#   )r$   r%   r&   r   r5   r   addr"  r!  r   rQ   deleter*   Zsesr)   r-   r-   r-   r.   r   p  s"   
r   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )Notesak  A program to add, delete, and show notes for AFNI datasets.

    For complete details, see the `3dNotes Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNotes.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> notes = afni.Notes()
    >>> notes.inputs.in_file = 'functional.HEAD'
    >>> notes.inputs.add = 'This note is added.'
    >>> notes.inputs.add_history = 'This note is added to history.'
    >>> notes.cmdline
    '3dNotes -a "This note is added." -h "This note is added to history." functional.HEAD'
    >>> res = notes.run()  # doctest: +SKIP

    Z3dNotesc             C   s$   | j  j }tjj| jj|d< |S )Nr)   )r3   r   rB   rC   rK   r   r5   )rE   rd   r-   r-   r.   r     s    zNotes._list_outputsN)
r$   r%   r&   r0   r1   r   r2   r   r3   r   r-   r-   r-   r.   r%    s
   r%  c               @   sP   e Zd ZeedddddddZeedddddd	Zed
dddddgdZdS )NwarpAdjustInputSpecT)r      z	-nwarp %szList of input 3D warp datasets)minlenr   r   r   z
-source %szList of input 3D datasets to be warped by the adjusted warp datasets.  There must be exactly as many of these datasets as there are input warps.)r(  r   r   zOutput mean dataset, only needed if in_files are also given. The output dataset will be on the common grid shared by the source datasets.z
-prefix %sr   z%s_NwarpAdjust)r   r   r7   r6   r   r   N)r$   r%   r&   r   r   Zwarpsr   r)   r-   r-   r-   r.   r&    s$   r&  c                   s6   e Zd ZdZdZeZeZd fdd	Z	dd Z
  ZS )	NwarpAdjusta  This program takes as input a bunch of 3D warps, averages them,
    and computes the inverse of this average warp.  It then composes
    each input warp with this inverse average to 'adjust' the set of
    warps.  Optionally, it can also read in a set of 1-brick datasets
    corresponding to the input warps, and warp each of them, and average
    those.

    For complete details, see the `3dNwarpAdjust Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpAdjust.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> adjust = afni.NwarpAdjust()
    >>> adjust.inputs.warps = ['func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz', 'func2anat_InverseWarp.nii.gz']
    >>> adjust.cmdline
    '3dNwarpAdjust -nwarp func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz func2anat_InverseWarp.nii.gz'
    >>> res = adjust.run()  # doctest: +SKIP

    Z3dNwarpAdjustNc                s0   | j js|d krg }|dg7 }tt| j|dS )Nr)   )r   )r   r   rL   r)  r   )rE   r   )rN   r-   r.   r     s
    
zNwarpAdjust._parse_inputsc             C   s   | j  j }| jjr| jjr2tjj| jj|d< nXtjj| jjd }t	j
|\}}d|krrt	j
|\}}|| }tjj|d | |d< |S )Nr)   r   z.gzZ_NwarpAdjust)r3   r   r   r   r)   rB   rC   rK   basenamer   r   )rE   rd   r*  Zbasename_noextrI   r   r-   r-   r.   r     s    zNwarpAdjust._list_outputs)N)r$   r%   r&   r0   r1   r&  r2   r   r3   r   r   rO   r-   r-   )rN   r.   r)    s   r)  c               @   s   e Zd ZejeddejeddddddZejddddZ	ej
d	d
dZeddddZejddddddddddddddZejdddddddddddddZeddd d!d"Zej
d#d$dZej
d%d&d'gd(Zej
d)d*d+gd(Zd,S )-NwarpApplyInputSpecT)r   z
-source %sz=the name of the dataset to be warped can be multiple datasets)r   r   r   zWthe name of the warp dataset. multiple warps can be concatenated (make sure they exist)z	-nwarp %s)r   r   r   z;After the warp specified in '-nwarp' is computed, invert itz-iwarp)r   r   z=the name of the master dataset, which defines the output gridz
-master %s)r   r   r   wsinc5r  ZnearestneighbourZnearestneighborlinearZ	trilinearZcubicZtricubicquinticZ
triquinticz/defines interpolation method to use during warpz
-interp %s)r   r   r   zHspecify a different interpolation method than might be used for the warpz-ainterp %sz%s_Nwarpzoutput image file namez
-prefix %sr5   )r6   r   r   r7   zVWrite output dataset using 16-bit short integers, rather than the usual 32-bit floats.z-shortzdon't be verbose :(z-quietr,   )r   r   r:   zbe extra verbose :)z-verbr+   N)r$   r%   r&   r   r   r   r   r5   StringZwarpr*   inv_warpmasterr   interpZainterpr)   r   r+   r,   r-   r-   r-   r.   r+    sl   r+  c               @   s   e Zd ZdZdZeZeZdS )
NwarpApplya  Program to apply a nonlinear 3D warp saved from 3dQwarp
    (or 3dNwarpCat, etc.) to a 3D dataset, to produce a warped
    version of the source dataset.

    For complete details, see the `3dNwarpApply Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpApply.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> nwarp = afni.NwarpApply()
    >>> nwarp.inputs.in_file = 'Fred+orig'
    >>> nwarp.inputs.master = 'NWARP'
    >>> nwarp.inputs.warp = "'Fred_WARP+tlrc Fred.Xaff12.1D'"
    >>> nwarp.cmdline
    "3dNwarpApply -source Fred+orig -interp wsinc5 -master NWARP -prefix Fred+orig_Nwarp -nwarp 'Fred_WARP+tlrc Fred.Xaff12.1D'"
    >>> res = nwarp.run()  # doctest: +SKIP

    Z3dNwarpApplyN)	r$   r%   r&   r0   r1   r+  r2   r   r3   r-   r-   r-   r.   r3  7  s   r3  c            	   @   s   e Zd Zejeje ejejdddde ddddd	Z	ej
d
ddZejdddZejdddddddZejdddZedddddZejdddZdS ) NwarpCatInputSpecIDENTZINVZSQRTZSQRTINVz3list of tuples of 3D warps and associated functionsTz%sr   )r   r   r   r   zAstring to attach to the output dataset as its atlas space marker.z	-space %s)r   r   z#invert the final warp before outputz-iwarpr,  r-  r.  zHspecify a different interpolation method than might be used for the warpz
-interp %s)r   r   r   zPad the nonlinear warps by the given number of voxels voxels in all directions. The warp displacements are extended by linear extrapolation from the faces of the input grid..z	-expad %dz%s_NwarpCatzoutput image file namez
-prefix %sr   )r6   r   r   r7   z
be verbosez-verbNr#   )r$   r%   r&   r   r   r   r   ro   r   r   r/  spacer*   r0  r2  rQ   Zexpadr)   r,   r-   r-   r-   r.   r4  Q  s6   r4  c                   s<   e Zd ZdZdZeZeZ fddZ	dd Z
dd Z  ZS )	NwarpCata
  Catenates (composes) 3D warps defined on a grid, OR via a matrix.

    .. note::

      * All transformations are from DICOM xyz (in mm) to DICOM xyz.

      * Matrix warps are in files that end in '.1D' or in '.txt'.  A matrix
        warp file should have 12 numbers in it, as output (for example), by
        '3dAllineate -1Dmatrix_save'.

      * Nonlinear warps are in dataset files (AFNI .HEAD/.BRIK or NIfTI .nii)
        with 3 sub-bricks giving the DICOM order xyz grid displacements in mm.

      * If all the input warps are matrices, then the output is a matrix
        and will be written to the file 'prefix.aff12.1D'.
        Unless the prefix already contains the string '.1D', in which case
        the filename is just the prefix.

      * If 'prefix' is just 'stdout', then the output matrix is written
        to standard output.
        In any of these cases, the output format is 12 numbers in one row.

      * If any of the input warps are datasets, they must all be defined on
        the same 3D grid!
        And of course, then the output will be a dataset on the same grid.
        However, you can expand the grid using the '-expad' option.

      * The order of operations in the final (output) warp is, for the
        case of 3 input warps:

            OUTPUT(x) = warp3( warp2( warp1(x) ) )

       That is, warp1 is applied first, then warp2, et cetera.
       The 3D x coordinates are taken from each grid location in the
       first dataset defined on a grid.

    For complete details, see the `3dNwarpCat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpCat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> nwarpcat = afni.NwarpCat()
    >>> nwarpcat.inputs.in_files = ['Q25_warp+tlrc.HEAD', ('IDENT', 'structural.nii')]
    >>> nwarpcat.inputs.out_file = 'Fred_total_WARP'
    >>> nwarpcat.cmdline
    "3dNwarpCat -interp wsinc5 -prefix Fred_total_WARP Q25_warp+tlrc.HEAD 'IDENT(structural.nii)'"
    >>> res = nwarpcat.run()  # doctest: +SKIP

    Z
3dNwarpCatc                s6   |dkr"|j djdd |D  S tt| j|||S )Nr   r   c             S   s6   g | ].}t |tr.d |d  d |d  d n|qS )r   r   (r   z)')r   r   )rW   r  r-   r-   r.   rx     s   z(NwarpCat._format_arg.<locals>.<listcomp>)r   rD   rL   r7  r   )rE   rG   r   rF   )rN   r-   r.   r     s    zNwarpCat._format_argc             C   s&   |dkr"| j | jjd d ddS d S )Nr)   r   Z	_NwarpCat)suffix)
_gen_fnamer   r   )rE   rG   r-   r-   r.   rM     s    zNwarpCat._gen_filenamec             C   sV   | j  j }t| jjr.tjj| jj|d< n$tjj| j| jj	d ddd|d< |S )Nr)   r   z_NwarpCat+tlrcz.HEAD)r9  rI   )
r3   r   r   r   r)   rB   rC   rK   r:  r   )rE   rd   r-   r-   r.   r     s    zNwarpCat._list_outputs)r$   r%   r&   r0   r1   r4  r2   r   r3   r   rM   r   rO   r-   r-   )rN   r.   r7  x  s   2r7  c               @   s   e Zd ZedddddZejdddZejdd	dZ	ejd
ddZ
edddgdZejdddZejej e fdddZejdddZejdddddddZeddd&dgd Zejd!d"dZejd#d$dZd%S )'OneDToolPyInputSpeczinput file to OneDToolz
-infile %sT)r   r   r   r   z'treat the input data as if it has nrunsz-set_nruns %d)r   r   zOtake the temporal derivative of each vector (done as first backward difference)z-derivativez,demean each run (new mean of each run = 0.0)z-demeanz!write the current 1D data to FILEz	-write %sshow_cormat_warnings)r   r   r:   zdisplay the total number of censored TRs  Note : if input is a valid xmat.1D dataset, then the count will come from the header.  Otherwise the input is assumed to be a binary censorfile, and zeros are simply counted.z-show_censor_countzWTuple of motion limit and outfile prefix. need to also set set_nruns -r set_run_lengthsz-censor_motion %f %sz*for each censored TR, also censor previousz-censor_prev_TRcommar6  encodedr   zDdisplay a list of TRs which were not censored in the specified stylez-show_trs_uncensored %szWrite cormat warnings to a filez-show_cormat_warnings |& tee %sr   r)   )r   r   r   r:   z+display column indices for regs of interestz-show_indices_interestz8restrict -show_trs_[un]censored to the given 1-based runz-show_trs_run %dNr#   )r$   r%   r&   r   r5   r   rQ   Z	set_nrunsr*   Z
derivativer   r)   Zshow_censor_countro   rp   censor_motionZcensor_prev_TRr   Zshow_trs_uncensoredr<  Zshow_indices_interestZshow_trs_runr-   r-   r-   r.   r;    sP   




r;  c               @   s   e Zd ZeddZdS )OneDToolPyOutputSpeczoutput of 1D_tool.py)r   N)r$   r%   r&   r   r)   r-   r-   r-   r.   r@  	  s   r@  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )
OneDToolPya  This program is meant to read/manipulate/write/diagnose 1D datasets.
    Input can be specified using AFNI sub-brick[]/time{} selectors.

    >>> from nipype.interfaces import afni
    >>> odt = afni.OneDToolPy()
    >>> odt.inputs.in_file = 'f1.1D'
    >>> odt.inputs.set_nruns = 3
    >>> odt.inputs.demean = True
    >>> odt.inputs.out_file = 'motion_dmean.1D'
    >>> odt.cmdline # doctest: +ELLIPSIS
    'python2 ...1d_tool.py -demean -infile f1.1D -write motion_dmean.1D -set_nruns 3'
     >>> res = odt.run()  # doctest: +SKIPz
1d_tool.pyc             C   s   | j  j }t| jjr2tjjtj | jj|d< t| jj	rXtjjtj | jj	|d< t| jj
rtjjtj | jj
d d |d< |S )Nr)   r   z
_censor.1D)r3   r   r   r   r)   rB   rC   rD   ry   r<  r?  )rE   rd   r-   r-   r.   r   	  s    zOneDToolPy._list_outputsN)
r$   r%   r&   r0   r1   r;  r2   r@  r3   r   r-   r-   r-   r.   rA  
	  s
   rA  c               @   s2  e Zd Zeddd.ddddZejdddZed	d
dZ	edddZ
edddZeddddZejdddZejdddZejdddZejdddZejddddddZejedd ej d!d"dZejej ej d#d$dZejej ej d%d&dZejej ej d'd(dZejd)d*dZejd+d,dZd-S )/RefitInputSpeczinput file to 3drefitz%sr   T)r   r   r   r   r   r    z:replace current transformation matrix with cardinal matrixz
-deoblique)r   r   z x distance for edge voxel offsetz-xorigin %sz y distance for edge voxel offsetz-yorigin %sz z distance for edge voxel offsetz-zorigin %sz-duporigin %szTCopies the xorigin, yorigin, and zorigin values from the header of the given dataset)r   r   r   znew x voxel dimension in mmz-xdel %fznew y voxel dimension in mmz-ydel %fznew z voxel dimension in mmz-zdel %fz8Scale the size of the dataset voxels by the given factorz-xyzscale %fZTLRCZMNIZORIGz	-space %szJAssociates the dataset with a specific template type, e.g. TLRC, MNI, ORIG)r   r   )r   z-atrcopy %s %sa[  Copy AFNI header attribute from the given file into the header of the dataset(s) being modified. For more information on AFNI header attributes, see documentation file README.attributes. More than one '-atrcopy' option can be used. For AFNI advanced users only. Do NOT use -atrcopy or -atrstring with other modification options. See also -copyaux.z-atrstring %s %szCopy the last given string into the dataset(s) being modified, giving it the attribute name given by the last string.To be safe, the last string should be in quotes.z-atrfloat %s %szCreate or modify floating point attributes. The input values may be specified as a single string in quotes or as a 1D filename or string, example '1 0.2 0 0 -0.2 1 0 0 0 0 1 0' or flipZ.1D or '1D:1,0.2,2@0,-0.2,1,2@0,2@0,1,0'z-atrint %s %szCreate or modify integer attributes. The input values may be specified as a single string in quotes or as a 1D filename or string, example '1 0 0 0 0 1 0 0 0 0 1 0' or flipZ.1D or '1D:1,0,2@0,-0,1,2@0,2@0,1,0'z-saveatrz(default) Copy the attributes that are known to AFNI into the dset->dblk structure thereby forcing changes to known attributes to be present in the output. This option only makes sense with -atrcopy.z
-nosaveatrzOpposite of -saveatrNr#   )r$   r%   r&   r   r5   r   r*   Z	deobliquer   ZxoriginZyoriginZzoriginZduporigin_filerp   ZxdelZydelZzdelZxyzscaler   r6  ro   ZatrcopyZ	atrstringZatrfloatZatrintZsaveatrZ	nosaveatrr-   r-   r-   r.   rB  -	  sj   rB  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )Refita3  Changes some of the information inside a 3D dataset's header

    For complete details, see the `3drefit Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3drefit.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> refit = afni.Refit()
    >>> refit.inputs.in_file = 'structural.nii'
    >>> refit.inputs.deoblique = True
    >>> refit.cmdline
    '3drefit -deoblique structural.nii'
    >>> res = refit.run()  # doctest: +SKIP

    >>> refit_2 = afni.Refit()
    >>> refit_2.inputs.in_file = 'structural.nii'
    >>> refit_2.inputs.atrfloat = ("IJK_TO_DICOM_REAL", "'1 0.2 0 0 -0.2 1 0 0 0 0 1 0'")
    >>> refit_2.cmdline
    "3drefit -atrfloat IJK_TO_DICOM_REAL '1 0.2 0 0 -0.2 1 0 0 0 0 1 0' structural.nii"
    >>> res = refit_2.run()  # doctest: +SKIP

    Z3drefitc             C   s$   | j  j }tjj| jj|d< |S )Nr)   )r3   r   rB   rC   rK   r   r5   )rE   rd   r-   r-   r.   r   	  s    zRefit._list_outputsN)
r$   r%   r&   r0   r1   rB  r2   r   r3   r   r-   r-   r-   r.   rC  	  s
   rC  c               @   s   e Zd ZeddddddZedddd	dd
dZejdddZedddZ	ej
dddddgdddZejdddgddZejejejejddgdddZedd d!d"Zejd#d$dZd%S )&ReHoInputSpeczinput datasetz	-inset %sr   T)r   r   r   r   r   zOutput dataset.z
-prefix %sr5   z%s_rehor   )r   r   r7   r6   r   r   z-chi_sqzOutput the Friedman chi-squared value in addition to the Kendall's W. This option is currently compatible only with the AFNI (BRIK/HEAD) output type; the chi-squared value will be the second sub-brick of the output dataset.)r   r   z5Mask within which ReHo should be calculated voxelwisez-mask %s)r   r   facesedgesverticessphere	ellipsoidz
-nneigh %sz
voxels in neighborhood. can be:
``faces`` (for voxel and 6 facewise neighbors, only),
``edges`` (for voxel and 18 face- and edge-wise neighbors),
``vertices`` (for voxel and 26 face-, edge-, and node-wise neighbors).)r:   r   r   z-neigh_RAD %sr  a  \
For additional voxelwise neighborhood control, the
radius R of a desired neighborhood can be put in; R is
a floating point number, and must be >1. Examples of
the numbers of voxels in a given radius are as follows
(you can roughly approximate with the ol' :math:`4\pi\,R^3/3`
thing):

    * R=2.0 -> V=33
    * R=2.3 -> V=57,
    * R=2.9 -> V=93,
    * R=3.1 -> V=123,
    * R=3.9 -> V=251,
    * R=4.5 -> V=389,
    * R=6.1 -> V=949,

but you can choose most any value.)r   r:   r   z#-neigh_X %s -neigh_Y %s -neigh_Z %saX  \
Tuple indicating the x, y, and z radius of an ellipsoid
defining the neighbourhood of each voxel.
The 'hood is then made according to the following relation:
:math:`(i/A)^2 + (j/B)^2 + (k/C)^2 \le 1.`
which will have approx. :math:`V=4 \pi \, A B C/3`. The impetus for
this freedom was for use with data having anisotropic
voxel edge lengths.z-in_rois %szZa set of ROIs, each labelled with distinct integers. ReHo will then be calculated per ROI.)r   r   r   z*overwrite output file if it already existsz
-overwriteN)r$   r%   r&   r   r5   r)   r   r*   Zchi_sqr   r   r  rp   rH  ro   rI  	label_setr   r-   r-   r-   r.   rD  	  sT   
rD  c               @   s"   e Zd ZedddZeddZdS )ReHoOutputSpecTz"Voxelwise regional homogeneity map)r   r   z-Table of labelwise regional homogenity values)r   N)r$   r%   r&   r   r)   out_valsr-   r-   r-   r.   rK  	  s   rK  c                   s8   e Zd ZdZdZeZeZ fddZ	 fddZ
  ZS )ReHoa^  Compute regional homogenity for a given neighbourhood.l,
    based on a local neighborhood of that voxel.

    For complete details, see the `3dReHo Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dReHo.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> reho = afni.ReHo()
    >>> reho.inputs.in_file = 'functional.nii'
    >>> reho.inputs.out_file = 'reho.nii.gz'
    >>> reho.inputs.neighborhood = 'vertices'
    >>> reho.cmdline
    '3dReHo -prefix reho.nii.gz -inset functional.nii -nneigh 27'
    >>> res = reho.run()  # doctest: +SKIP

    Z3dReHoc                s*   t t| j }| jjr&|d d |d< |S )Nr)   z_ROI_reho.valsrL  )rL   rM  r   r   rJ  )rE   rd   )rN   r-   r.   r   
  s    zReHo._list_outputsc                s0   dddd}|dkr|| }t t| j|||S )N         )rE  rF  rG  r  )rL   rM  r   )rE   rG   r   rF   Z_neigh_dict)rN   r-   r.   r   
  s    zReHo._format_arg)r$   r%   r&   r0   r1   rD  r2   rK  r3   r   r   rO   r-   r-   )rN   r.   rM   
  s   rM  c               @   sz   e Zd ZedddddddZeddd	d
dZedddZej	dddddddZ
ejej gd dddZedddZdS )ResampleInputSpeczinput file to 3dresamplez	-inset %sr   TF)r   r   r   r   r   r    z%s_resamplezoutput image file namez
-prefix %sr5   )r6   r   r   r7   znew orientation codez
-orient %s)r   r   r  r  r  r  z	-rmode %szresampling method from set {"NN", "Li", "Cu", "Bk"}. These are for "Nearest Neighbor", "Linear", "Cubic" and "Blocky"interpolation, respectively. Default is NN.)r   r   r   z-dxyz %f %f %fzresample to new dx, dy and dzz
-master %sz&align dataset grid to a reference fileNr#   )r$   r%   r&   r   r5   r)   r   orientationr   r   Zresample_modero   rp   Z
voxel_sizer1  r-   r-   r-   r.   rQ  %
  s2   
rQ  c               @   s   e Zd ZdZdZeZeZdS )ResampleaZ  Resample or reorient an image using AFNI 3dresample command

    For complete details, see the `3dresample Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dresample.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> resample = afni.Resample()
    >>> resample.inputs.in_file = 'functional.nii'
    >>> resample.inputs.orientation= 'RPI'
    >>> resample.inputs.outputtype = 'NIFTI'
    >>> resample.cmdline
    '3dresample -orient RPI -prefix functional_resample.nii -inset functional.nii'
    >>> res = resample.run()  # doctest: +SKIP

    Z
3dresampleN)	r$   r%   r&   r0   r1   rQ  r2   r   r3   r-   r-   r-   r.   rS  H
  s   rS  c               @   sZ   e Zd ZeeddddddddZedd	d
ddZejdddddddZ	ej
dddZdS )TCatInputSpecT)r   zinput file to 3dTcatz %sr   F)r   r   r   r   r    z%s_tcatzoutput image file namez
-prefix %sr   )r6   r   r   r7   r   +z++z-rlt%sa  Remove linear trends in each voxel time series loaded from each input dataset, SEPARATELY. Option -rlt removes the least squares fit of 'a+b*t' to each voxel time series. Option -rlt+ adds dataset mean back in. Option -rlt++ adds overall mean of all dataset timeseries back in.)r   r   r   z,Print out some verbose output as the programz-verb)r   r   Nr#   )r$   r%   r&   r   r   r   r)   r   r   rltr*   r   r-   r-   r-   r.   rT  `
  s*   rT  c               @   s   e Zd ZdZdZeZeZdS )TCata  Concatenate sub-bricks from input datasets into one big 3D+time dataset.

    TODO Replace InputMultiPath in_files with Traits.List, if possible. Current
    version adds extra whitespace.

    For complete details, see the `3dTcat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTcat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> tcat = afni.TCat()
    >>> tcat.inputs.in_files = ['functional.nii', 'functional2.nii']
    >>> tcat.inputs.out_file= 'functional_tcat.nii'
    >>> tcat.inputs.rlt = '+'
    >>> tcat.cmdline
    '3dTcat -rlt+ -prefix functional_tcat.nii functional.nii functional2.nii'
    >>> res = tcat.run()  # doctest: +SKIP

    3dTcatN)	r$   r%   r&   r0   r1   rT  r2   r   r3   r-   r-   r-   r.   rW  
  s   rW  c               @   sV   e Zd Zejejedde ddddddZedd	dd
Z	ej
dddddddZdS )TCatSBInputSpecT)r   zList of tuples of file names and subbrick selectors as strings.Don't forget to protect the single quotes in the subbrick selectorso the contents are protected from the command line interpreter.z%s%s ...r   F)r   r   r   r   r    zoutput image file namez
-prefix %s)r   r   Zgenfiler   rU  z++z-rlt%sa  Remove linear trends in each voxel time series loaded from each input dataset, SEPARATELY. Option -rlt removes the least squares fit of 'a+b*t' to each voxel time series. Option -rlt+ adds dataset mean back in. Option -rlt++ adds overall mean of all dataset timeseries back in.)r   r   r   Nr#   )r$   r%   r&   r   r   ro   r   r   r   r)   r   rV  r-   r-   r-   r.   rY  
  s   rY  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )TCatSubBricka  Hopefully a temporary function to allow sub-brick selection until
    afni file managment is improved.

    For complete details, see the `3dTcat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTcat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> tcsb = afni.TCatSubBrick()
    >>> tcsb.inputs.in_files = [('functional.nii', "'{2..$}'"), ('functional2.nii', "'{2..$}'")]
    >>> tcsb.inputs.out_file= 'functional_tcat.nii'
    >>> tcsb.inputs.rlt = '+'
    >>> tcsb.cmdline
    "3dTcat -rlt+ -prefix functional_tcat.nii functional.nii'{2..$}' functional2.nii'{2..$}' "
    >>> res = tcsb.run()  # doctest: +SKIP

    rX  c             C   s&   |dkr"| j | jjd d ddS d S )Nr)   r   Z_tcat)r9  )r:  r   r   )rE   rG   r-   r-   r.   rM   
  s    zTCatSubBrick._gen_filenameN)
r$   r%   r&   r0   r1   rY  r2   r   r3   rM   r-   r-   r-   r.   rZ  
  s
   rZ  c               @   sJ   e Zd ZedddddddZeddd	d
dZeddddZedddZdS )TStatInputSpeczinput file to 3dTstatz%sr   TF)r   r   r   r   r   r    z%s_tstatzoutput image file namez
-prefix %sr5   )r6   r   r   r7   z	mask filez-mask %s)r   r   r   zselected statistical output)r   r   Nr#   )	r$   r%   r&   r   r5   r)   ri   r   optionsr-   r-   r-   r.   r[  
  s   r[  c               @   s   e Zd ZdZdZeZeZdS )TStata  Compute voxel-wise statistics using AFNI 3dTstat command

    For complete details, see the `3dTstat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTstat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> tstat = afni.TStat()
    >>> tstat.inputs.in_file = 'functional.nii'
    >>> tstat.inputs.args = '-mean'
    >>> tstat.inputs.out_file = 'stats'
    >>> tstat.cmdline
    '3dTstat -mean -prefix stats functional.nii'
    >>> res = tstat.run()  # doctest: +SKIP

    Z3dTstatN)	r$   r%   r&   r0   r1   r[  r2   r   r3   r-   r-   r-   r.   r]  
  s   r]  c               @   s   e Zd ZeddddgdZeddd4d	d	d
Zejdddddddddddddddddddddd d!d"d#d$d%Z	ej
d&d'd(Zej
d)d*d(Zejd+d,d-d.d/d0d(Zed1d2d(Zd3S )5To3DInputSpecz%szoutput image file namez
-prefix %s	in_folder)r6   r   r   r7   z#folder with DICOM images to convertz%s/*.dcmr   T)r   r   r   r   r   ZspgrZfseZepanZanatctZspctZpetZmraZbmapZdiffZomriZabucZfimZfithZficoZfittZfiftZfiztZfictZfibtZfibnZfigtZfiptZfbucz-%sz type of datafile being converted)r   r   zskip the outliers checkz-skip_outliers)r   r   z#assume that Siemens image is mosaicz-assume_dicom_mosaicr   rv   r   complexzset output file datatypez	-datum %szparameters for functional dataz-time:zt %s alt+z2Nr#   )r$   r%   r&   r   r)   r	   r_  r   r   Zfiletyper*   ZskipoutliersZassumemosaicdatatyper   Z
funcparamsr-   r-   r-   r.   r^  
  sb   

r^  c               @   s   e Zd ZdZdZeZeZdS )To3DaS  Create a 3D dataset from 2D image files using AFNI to3d command

    For complete details, see the `to3d Documentation
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> to3d = afni.To3D()
    >>> to3d.inputs.datatype = 'float'
    >>> to3d.inputs.in_folder = '.'
    >>> to3d.inputs.out_file = 'dicomdir.nii'
    >>> to3d.inputs.filetype = 'anat'
    >>> to3d.cmdline  # doctest: +ELLIPSIS
    'to3d -datum float -anat -prefix dicomdir.nii ./*.dcm'
    >>> res = to3d.run()  # doctest: +SKIP

    Zto3dN)	r$   r%   r&   r0   r1   r^  r2   r   r3   r-   r-   r-   r.   rc  6  s   rc  c               @   s   e Zd Zeddd(ddddZeddd	d
ZedddZejddddddZ	ej
dddZej
dddZejdddddZej
dddZejejddejdd ejd!d"d#d$dZejd%d&dZd'S ))UndumpInputSpeczOinput file to 3dUndump, whose geometry will determinethe geometry of the outputz
-master %sr   TF)r   r   r   r   r   r    zoutput image file namez
-prefix %sr5   )r   r   r7   zJmask image file name. Only voxels that are nonzero in the mask can be set.z-mask %s)r   r   r   rv   r   zset output file datatypez	-datum %sz^default value stored in each input voxel that does not have a value supplied in the input filez-dval %fzUvalue, used for each voxel in the output dataset that is NOT listed in the input filez-fval %fZijkZxyzz_Coordinates in the input file as index triples (i, j, k) or spatial coordinates (x, y, z) in mmz-%szradius in mm of the sphere that will be filled about each input (x,y,z) or (i,j,k) voxel. If the radius is not given, or is 0, then each input data line sets the value in only one voxel.z-srad %fRLAPISa  Specifies the coordinate order used by -xyz. The code must be 3 letters, one each from the pairs {R,L} {A,P} {I,S}.  The first letter gives the orientation of the x-axis, the second the orientation of the y-axis, the third the z-axis: R = right-to-left         L = left-to-right A = anterior-to-posterior P = posterior-to-anterior I = inferior-to-superior  S = superior-to-inferior If -orient isn't used, then the coordinate order of the -master (in_file) dataset is used to interpret (x,y,z) inputs.z
-orient %sz^create only the .HEAD file which gets exploited by the AFNI matlab library function New_HEAD.mz
-head_onlyNr#   )r$   r%   r&   r   r5   r)   r   r   r   rb  rp   default_valueZ
fill_valueZcoordinates_specificationZsradro   Zorientr*   Z	head_onlyr-   r-   r-   r.   rd  O  sJ   



rd  c               @   s   e Zd ZedddZdS )UndumpOutputSpeczassembled fileT)r   r   N)r$   r%   r&   r   r)   r-   r-   r-   r.   rl    s   rl  c               @   s   e Zd ZdZdZeZeZdS )Undumpa(  3dUndump - Assembles a 3D dataset from an ASCII list of coordinates and
    (optionally) values.

     The input file(s) are ASCII files, with one voxel specification per
     line.  A voxel specification is 3 numbers (-ijk or -xyz coordinates),
     with an optional 4th number giving the voxel value.  For example:

     1 2 3
     3 2 1 5
     5.3 6.2 3.7
     // this line illustrates a comment

     The first line puts a voxel (with value given by '-dval') at point
     (1,2,3).  The second line puts a voxel (with value 5) at point (3,2,1).
     The third line puts a voxel (with value given by '-dval') at point
     (5.3,6.2,3.7).  If -ijk is in effect, and fractional coordinates
     are given, they will be rounded to the nearest integers; for example,
     the third line would be equivalent to (i,j,k) = (5,6,4).


    For complete details, see the `3dUndump Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dUndump.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> unndump = afni.Undump()
    >>> unndump.inputs.in_file = 'structural.nii'
    >>> unndump.inputs.out_file = 'structural_undumped.nii'
    >>> unndump.cmdline
    '3dUndump -prefix structural_undumped.nii -master structural.nii'
    >>> res = unndump.run()  # doctest: +SKIP

    Z3dUndumpN)	r$   r%   r&   r0   r1   rd  r2   rl  r3   r-   r-   r-   r.   rm    s   "rm  c               @   s   e Zd Zeddd&ddddZeddd	d
dZejdddZejdddZ	ej
dddZedddZejdddZejddddgdgdZejej
 ej
 ej
 dddZej
dd dZej
d!d"dZejd#d$dZd%S )'UnifizeInputSpeczinput file to 3dUnifizez	-input %sr   TF)r   r   r   r   r   r    z%s_unifizedzoutput image file namez
-prefix %sr5   )r6   r   r   r7   a5  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.z-T2)r   r   ztAlso scale to unifize 'gray matter' = lower intensity voxels (to aid in registering images from different scanners).z-GMzSets 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.z-Urad %sz=output file name to save the scale factor used at each voxel z	-ssave %szSDo NOT use the 'duplo down' step; this can be useful for lower resolution datasets.z-noduploa9  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.z-EPIno_duplot2gm)r   r   r   r:   a  Option for AFNI experts only.Specify the 3 parameters for the algorithm:
R = radius; same as given by option '-Urad', [default=18.3]
b = bottom percentile of normalizing data range, [default=70.0]
r = top percentile of normalizing data range, [default=80.0]
z-rbt %f %f %fzOption for AFNI experts only.Set the upper percentile point used for T2-T1 inversion. Allowed to be anything between 90 and 100 (inclusive), with default to 98.5  (for no good reason).z-T2up %fzOption for AFNI experts only.Set the automask 'clip level fraction'. Must be between 0.1 and 0.9. A small fraction means to make the initial threshold for clipping (a la 3dClipLevel) smaller, which will tend to make the mask larger.  [default=0.1]z
-clfrac %fz"Don't print the progress messages.z-quietNr#   )r$   r%   r&   r   r5   r)   r   r*   rp  rq  rp   Zurad
scale_filero  Zepiro   ZrbtZt2_upZcl_fracr+   r-   r-   r-   r.   rn    sZ   
rn  c               @   s"   e Zd ZeddZedddZdS )UnifizeOutputSpeczscale factor file)r   zunifized fileT)r   r   N)r$   r%   r&   r   rr  r)   r-   r-   r-   r.   rs    s   
rs  c               @   s   e Zd ZdZdZeZeZdS )Unifizea  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.

    * 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.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dUnifize.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> unifize = afni.Unifize()
    >>> unifize.inputs.in_file = 'structural.nii'
    >>> unifize.inputs.out_file = 'structural_unifized.nii'
    >>> unifize.cmdline
    '3dUnifize -prefix structural_unifized.nii -input structural.nii'
    >>> res = unifize.run()  # doctest: +SKIP

    Z	3dUnifizeN)	r$   r%   r&   r0   r1   rn  r2   rs  r3   r-   r-   r-   r.   rt    s   )rt  c               @   s<   e Zd ZedddddddZeddd	d
dZedddZdS )ZCutUpInputSpeczinput file to 3dZcutupz%sr   TF)r   r   r   r   r   r    z	%s_zcutupzoutput image file namez
-prefix %sr5   )r6   r   r   r7   zslice range to keep in outputz-keep %s)r   r   Nr#   )r$   r%   r&   r   r5   r)   r   Zkeepr-   r-   r-   r.   ru  I  s   ru  c               @   s   e Zd ZdZdZeZeZdS )ZCutUpa?  Cut z-slices from a volume using AFNI 3dZcutup command

    For complete details, see the `3dZcutup Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZcutup.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> zcutup = afni.ZCutUp()
    >>> zcutup.inputs.in_file = 'functional.nii'
    >>> zcutup.inputs.out_file = 'functional_zcutup.nii'
    >>> zcutup.inputs.keep= '0 10'
    >>> zcutup.cmdline
    '3dZcutup -keep 0 10 -prefix functional_zcutup.nii functional.nii'
    >>> res = zcutup.run()  # doctest: +SKIP

    Z3dZcutupN)	r$   r%   r&   r0   r1   ru  r2   r   r3   r-   r-   r-   r.   rv  [  s   rv  c               @   sP   e Zd ZedddddddZeddddd	Zejd
dddZej	ddddZ
dS )GCORInputSpecz&input dataset to compute the GCOR overz	-input %sr   TF)r   r   r   r   r   r    z-mask dataset, for restricting the computationz-mask %s)r   r   r   r    r   z
-nfirst %dz'specify number of initial TRs to ignore)r   r   z
-no_demeanz%do not (need to) demean as first stepNr#   )r$   r%   r&   r   r5   ri   r   rQ   Znfirstr*   Z	no_demeanr-   r-   r-   r.   rw  s  s    rw  c               @   s   e Zd ZejddZdS )GCOROutputSpeczglobal correlation value)r   N)r$   r%   r&   r   rp   outr-   r-   r-   r.   rx    s   rx  c                   s4   e Zd ZdZdZeZeZ fddZ	dd Z
  ZS )GCORa!  
    Computes the average correlation between every voxel
    and ever other voxel, over any give mask.


    For complete details, see the `@compute_gcor Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/@compute_gcor.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> gcor = afni.GCOR()
    >>> gcor.inputs.in_file = 'structural.nii'
    >>> gcor.inputs.nfirst = 4
    >>> gcor.cmdline
    '@compute_gcor -nfirst 4 -input structural.nii'
    >>> res = gcor.run()  # doctest: +SKIP

    z@compute_gcorc                sJ   t t| j|}dd |jjdD d }t| dt|tdd   |S )Nc             S   s"   g | ]}|j  jd r|j  qS )zGCOR = )strip
startswith)rW   rf   r-   r-   r.   rx     s   z'GCOR._run_interface.<locals>.<listcomp>rU   r   _gcorzGCOR = r#   )rL   rz  _run_interfacer|   r]   setattrrv   r}   )rE   rb   Z	gcor_line)rN   r-   r.   r~    s    zGCOR._run_interfacec             C   s   dt | diS )Nry  r}  )getattr)rE   r-   r-   r.   r     s    zGCOR._list_outputs)r$   r%   r&   r0   r1   rw  r2   rx  r3   r~  r   rO   r-   r-   )rN   r.   rz    s   rz  c               @   s   e Zd ZedddddddZeddd	d
dZejdddZejddddgdZ	ejddddgdZ
ejddddgdZedddZdS )AxializeInputSpeczinput file to 3daxializez%sr   TF)r   r   r   r   r   r    z%s_axializezoutput image file namez
-prefix %sr5   )r6   r   r   r7   zPrint out a progerss reportz-verb)r   r   z%Do sagittal slice order [-orient ASL]z	-sagittalcoronalaxial)r   r   r:   z%Do coronal slice order  [-orient RSA]z-coronalsagittalzDo axial slice order    [-orient RAI]This is the default AFNI axial order, andis the one currently required by thevolume rendering plugin; this is alsothe default orientation output by thisprogram (hence the program's name).z-axialznew orientation codez
-orient %sNr"   )r$   r%   r&   r   r5   r)   r   r*   r,   r  r  r  r   rR  r-   r-   r-   r.   r    s4   r  c               @   s   e Zd ZdZdZeZeZdS )Axializea?  Read in a dataset and write it out as a new dataset
         with the data brick oriented as axial slices.

    For complete details, see the `3dcopy Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3daxialize.html>`__

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> axial3d = afni.Axialize()
    >>> axial3d.inputs.in_file = 'functional.nii'
    >>> axial3d.inputs.out_file = 'axialized.nii'
    >>> axial3d.cmdline
    '3daxialize -prefix axialized.nii functional.nii'
    >>> res = axial3d.run()  # doctest: +SKIP

    Z
3daxializeN)	r$   r%   r&   r0   r1   r  r2   r   r3   r-   r-   r-   r.   r    s   r  c               @   s|   e Zd ZeeddddddddZedd	d
ddZejddddddZ	ej
dddZej
dddgdZej
dddgdZdS )ZcatInputSpeczinput files to 3dZcatT)r   r   z%sr   F)r   r   r   r    z%s_zcatz+output dataset prefix name (default 'zcat')z
-prefix %sr   )r6   r   r   r7   r   r   rv   z	-datum %szJspecify data type for output. Valid types are 'byte', 'short' and 'float'.)r   r   z5print out some verbositiness as the program proceeds.z-verb)r   r   zForce scaling of the output to the maximum integer range.  This only has effect if the output datum is byte or short (either forced or defaulted). This option is sometimes necessary to eliminate unpleasant truncation artifacts.z-fscaler   )r   r   r:   zDon't do any scaling on output to byte or short datasets. This may be especially useful when operating on mask datasets whose output values are only 0's and 1's.z-nscaler   Nr#   )r$   r%   r&   r   r   r   r)   r   r   r   r*   r,   r   r   r-   r-   r-   r.   r    s6   


r  c               @   s   e Zd ZdZdZeZeZdS )ZcataI  Copies an image of one type to an image of the same
    or different type using 3dZcat command

    For complete details, see the `3dZcat Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZcat.html>`_

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> zcat = afni.Zcat()
    >>> zcat.inputs.in_files = ['functional2.nii', 'functional3.nii']
    >>> zcat.inputs.out_file = 'cat_functional.nii'
    >>> zcat.cmdline
    '3dZcat -prefix cat_functional.nii functional2.nii functional3.nii'
    >>> res = zcat.run()  # doctest: +SKIP

    Z3dZcatN)	r$   r%   r&   r0   r1   r  r2   r   r3   r-   r-   r-   r.   r  #  s   r  c               @   s  e Zd Zeddd1ddddZeddd	d
ZejdddgdZejdddgdZ	ejdddgdZ
ejdddgdZejdddgdZejdddgdZejdddgdZejdddgdZejdddgdZejdd dgdZejd!d"dgdZed#d$d%d&d'd(d)d*d+d,d-d.d/gdZd0S )2ZeropadInputSpeczinput datasetz%sr   TF)r   r   r   r   r   r    Zzeropadz.output dataset prefix name (default 'zeropad')z
-prefix %s)r6   r   r   z,adds 'n' planes of zero at the Inferior edgez-I %ir1  )r   r   r:   z,adds 'n' planes of zero at the Superior edgez-S %iz,adds 'n' planes of zero at the Anterior edgez-A %iz-adds 'n' planes of zero at the Posterior edgez-P %iz(adds 'n' planes of zero at the Left edgez-L %iz)adds 'n' planes of zero at the Right edgez-R %izMadds 'n' planes of zero on EACH of the dataset z-axis (slice-direction) facesz-z %iz~specify that planes should be added or cut symmetrically to make the resulting volume haveN slices in the right-left directionz-RL %izspecify that planes should be added or cut symmetrically to make the resulting volume haveN slices in the anterior-posterior directionz-AP %izspecify that planes should be added or cut symmetrically to make the resulting volume haveN slices in the inferior-superior directionz-IS %izpad counts 'n' are in mm instead of slices, where each 'n' is an integer and at least 'n' mm of slices will be added/removed; e.g., n =  3 and slice thickness = 2.5 mm ==> 2 slices addedz-mma>  match the volume described in dataset 'mset', where mset must have the same orientation and grid spacing as dataset to be padded. the goal of -master is to make the output dataset from 3dZeropad match the spatial 'extents' of mset by adding or subtracting slices as needed. You can't use -I,-S,..., or -mm with -masterz
-master %sri  rj  rg  rh  rf  re  zRLAPISr  Nr#   )r$   r%   r&   r   r   r)   r   rQ   ri  rj  rg  rh  rf  re  r  r  r  r  r*   r  r1  r-   r-   r-   r.   r  ;  sn   








r  c               @   s   e Zd ZdZdZeZeZdS )Zeropada  Adds planes of zeros to a dataset (i.e., pads it out).

    For complete details, see the `3dZeropad Documentation.
    <https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZeropad.html>`__

    Examples
    --------
    >>> from nipype.interfaces import afni
    >>> zeropad = afni.Zeropad()
    >>> zeropad.inputs.in_files = 'functional.nii'
    >>> zeropad.inputs.out_file = 'pad_functional.nii'
    >>> zeropad.inputs.I = 10
    >>> zeropad.inputs.S = 10
    >>> zeropad.inputs.A = 10
    >>> zeropad.inputs.P = 10
    >>> zeropad.inputs.R = 10
    >>> zeropad.inputs.L = 10
    >>> zeropad.cmdline
    '3dZeropad -A 10 -I 10 -L 10 -P 10 -R 10 -S 10 -prefix pad_functional.nii functional.nii'
    >>> res = zeropad.run()  # doctest: +SKIP

    Z	3dZeropadN)	r$   r%   r&   r0   r1   r  r2   r   r3   r-   r-   r-   r.   r    s   r  )vr0   rB   os.pathrC   r   r^   numpyr   Zutils.filemanipr   r   r   rH   r   r   r	   r
   r   r   r   r   r   r   r   Zexternal.duer   r   r   r   r   r   r   r   r/   r4   r<   rP   rS   rT   rh   rq   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r  r  r  r  r  r  r   r%  r&  r)  r+  r3  r4  r7  r;  r@  rA  rB  rC  rD  rK  rM  rQ  rS  rT  rW  rY  rZ  r[  r]  r^  rc  rd  rl  rm  rn  rs  rt  ru  rv  rw  rx  rz  r  r  r  r  r  r  r-   r-   r-   r.   <module>   s   
4 
/!&#55'2@'1	&$*127)[ /j! -'>3D'U9#V#U%# 9C)U0(',Y