3
dX                @   s  d Z ddlZddljZddlZddlmZ ddlZddlZ	ddl
mZmZmZmZ ddlmZmZmZmZmZmZmZ dd	l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Z*G d,d- d-eZ+G d.d/ d/eZ,G d0d1 d1eZ-G d2d3 d3eZ.G d4d5 d5eZ/G d6d7 d7eZ0G d8d9 d9eZ1G d:d; d;eZ2G d<d= d=eZ3G d>d? d?eZ4G d@dA dAeZ5G dBdC dCeZ6G dDdE dEeZ7G dFdG dGeZ8G dHdI dIeZ9G dJdK dKeZ:G dLdM dMeZ;G dNdO dOeZ<G dPdQ dQeZ=G dRdS dSeZ>G dTdU dUeZ?G dVdW dWeZ@G dXdY dYeZAG dZd[ d[eZBG d\d] d]eZCG d^d_ d_eZDG d`da daeZEG dbdc dceZFG ddde deeZGG dfdg dgeZHG dhdi dieZIG djdk dkeZJG dldm dmeZKG dndo doeZLG dpdq dqeZMG drds dseZNG dtdu dueZOG dvdw dweZPG dxdy dyeZQG dzd{ d{eZRG d|d} d}eZSG d~d deZTG dd deZUG dd deZVG dd deZWG dd deZXG dd deZYG dd de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 deeZfG dd deZgG dd deZhG dd deeZiG dd dehZjG dd deZkG dd deZlG dd deZmG dd deZnG dd deZodS )zThe fsl module provides classes for interfacing with the `FSL
<http://www.fmrib.ox.ac.uk/fsl/index.html>`_ command line tools.  This
was written to work with FSL version 4.1.4.

Examples
--------
See the docstrings of the individual classes for examples.
    N)glob   )	load_json	save_jsonsplit_filenamefname_presuffix   )traitsTraitedSpecOutputMultiPathFileCommandLineCommandLineInputSpec	isdefined   )
FSLCommandFSLCommandInputSpecInfoc               @   sH   e Zd ZeddddddZedddddddd	dd
	ZejddddZdS )CopyGeomInputSpecTz%sr   zsource image)exists	mandatoryargstrpositiondescr   zdestination imageout_file	dest_file)	r   r   r   r   r   copyfileoutput_namename_sourcename_templatezDo not copy image dimensionsz-dz-1)r   r   r   N)	__name__
__module____qualname__r   in_filer   r	   BoolZignore_dims r%   r%   =/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/fsl/utils.pyr   !   s   r   c               @   s   e Zd ZedddZdS )CopyGeomOutputSpecTzimage with new geometry header)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   r'   5   s   r'   c               @   s   e Zd ZdZdZeZeZdS )CopyGeoma  Use fslcpgeom to copy the header geometry information to another image.
    Copy certain parts of the header information (image dimensions, voxel
    dimensions, voxel dimensions units string, image orientation/origin or
    qform/sform info) from one image to another. Note that only copies from
    Analyze to Analyze or Nifti to Nifti will work properly. Copying from
    different files will result in loss of information or potentially incorrect
    settings.
    Z	fslcpgeomN)	r    r!   r"   __doc___cmdr   
input_specr'   output_specr%   r%   r%   r&   r(   9   s   r(   c               @   sT   e Zd ZeddddddZedddgd	d
dZejdddZedddgd	ddZ	dS )RobustFOVInputSpecTzinput filenamez-i %sr   )r   r   r   r   r   zROI volume output namez-r %sr#   Fz%s_ROI)r   r   r   
hash_filesr   z2size of brain in z-dimension (default 170mm/150mm)z-b %d)r   r   z4Transformation matrix in_file to out_roi output namez-m %sz	%s_to_ROIN)
r    r!   r"   r   r#   out_roir	   IntZ	brainsizeout_transformr%   r%   r%   r&   r-   H   s    
r-   c               @   s$   e Zd ZedddZedddZdS )RobustFOVOutputSpecTzROI volume output name)r   r   z4Transformation matrix in_file to out_roi output nameN)r    r!   r"   r   r/   r1   r%   r%   r%   r&   r2   _   s   r2   c               @   s   e Zd ZdZdZeZeZdS )	RobustFOVzAutomatically crops an image removing lower head and neck.

    Interface is stable 5.0.0 to 5.0.9, but default brainsize changed from
    150mm to 170mm.
    Z	robustfovN)	r    r!   r"   r)   r*   r-   r+   r2   r,   r%   r%   r%   r&   r3   f   s   r3   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Z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ej	dddddZejdddZejdddZdS )ImageMeantsInputSpecTz/input file for computing the average timeseriesz-i %sr   )r   r   r   r   r   zname of output text matrixz-o %sF)r   r   genfiler.   zinput 3D maskz-m %s)r   r   r   z7<x y z>  requested spatial coordinate (instead of mask)z-c %s)r   r   z3use mm instead of voxel coordinates (for -c option)z--usemmz=show all voxel time series (within mask) instead of averagingz	--showallzCcalculate Eigenvariate(s) instead of mean (output will have 0 mean)z--eigr   zselect number of Eigenvariatesz
--order=%d)r   r   
usedefaultz9do not binarise the mask for calculation of Eigenvariatesz--no_binz;output results in transpose format (one row per voxel/mean)z--transposeN)r    r!   r"   r   r#   r   maskr	   Listr0   Zspatial_coordr$   Zuse_mmZshow_allZeigorderZnobinZ	transposer%   r%   r%   r&   r4   r   sB   r4   c               @   s   e Zd ZedddZdS )ImageMeantsOutputSpecTzpath/name of output text matrix)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d Z	dd Z
dS )ImageMeantszUse fslmeants for printing the average timeseries (intensities) to
    the screen (or saves to a file). The average is taken over all voxels
    in the mask (or all voxels in the image if no mask is specified)

    Z	fslmeantsc             C   sV   | j  j }| jj|d< t|d s>| j| jjdddd|d< tjj	|d |d< |S )Nr   _tsz.txtT)suffixextZ
change_ext)
r,   getinputsr   r   
_gen_fnamer#   ospathabspath)selfoutputsr%   r%   r&   _list_outputs   s    zImageMeants._list_outputsc             C   s   |dkr| j  | S d S )Nr   )rG   )rE   namer%   r%   r&   _gen_filename   s    zImageMeants._gen_filenameN)r    r!   r"   r)   r*   r4   r+   r:   r,   rG   rI   r%   r%   r%   r&   r;      s   
r;   c               @   s\   e Zd ZedddddZejdddgddd	Zejddd
gddd	ZedddgdddZ	dS )SmoothInputSpecTz%sr   )r   r   r   r   z-kernel gauss %.03f -fmeanr   fwhmz(gaussian kernel sigma in mm (not voxels))r   r   xorr   r   sigmazCgaussian kernel fwhm, will be converted to sigma in mm (not voxels)r   r#   z	%s_smoothF)r   r   r   r   r.   N)
r    r!   r"   r   r#   r	   FloatrM   rK   smoothed_filer%   r%   r%   r&   rJ      s&   rJ   c               @   s   e Zd ZeddZdS )SmoothOutputSpecT)r   N)r    r!   r"   r   rO   r%   r%   r%   r&   rP      s   rP   c                   s,   e Zd ZdZeZeZdZ fddZ	  Z
S )Smootha  
    Use fslmaths to smooth the image

    Examples
    --------

    Setting the kernel width using sigma:

    >>> sm = Smooth()
    >>> sm.inputs.output_type = 'NIFTI_GZ'
    >>> sm.inputs.in_file = 'functional2.nii'
    >>> sm.inputs.sigma = 8.0
    >>> sm.cmdline # doctest: +ELLIPSIS
    'fslmaths functional2.nii -kernel gauss 8.000 -fmean functional2_smooth.nii.gz'

    Setting the kernel width using fwhm:

    >>> sm = Smooth()
    >>> sm.inputs.output_type = 'NIFTI_GZ'
    >>> sm.inputs.in_file = 'functional2.nii'
    >>> sm.inputs.fwhm = 8.0
    >>> sm.cmdline # doctest: +ELLIPSIS
    'fslmaths functional2.nii -kernel gauss 3.397 -fmean functional2_smooth.nii.gz'

    One of sigma or fwhm must be set:

    >>> from nipype.interfaces.fsl import Smooth
    >>> sm = Smooth()
    >>> sm.inputs.output_type = 'NIFTI_GZ'
    >>> sm.inputs.in_file = 'functional2.nii'
    >>> sm.cmdline #doctest: +ELLIPSIS
    Traceback (most recent call last):
     ...
    ValueError: Smooth requires a value for one of the inputs ...

    fslmathsc                sL   |dkr8t |tjdtjd  }tt| j|||S tt| j|||S )NrK      r   )floatnpsqrtlogsuperrQ   _format_arg)rE   rH   
trait_specvaluerM   )	__class__r%   r&   rY     s    zSmooth._format_arg)r    r!   r"   r)   rJ   r+   rP   r,   r*   rY   __classcell__r%   r%   )r\   r&   rQ      s
   $rQ   c               @   s0   e Zd ZedddddddZejdddd	Zd
S )SliceInputSpecTz%sr   zinput filenameF)r   r   r   r   r   r   r   zoutputs prefix)r   r   r   N)r    r!   r"   r   r#   r	   Strout_base_namer%   r%   r%   r&   r^     s   r^   c               @   s   e Zd ZeeddZdS )SliceOutputSpecT)r   N)r    r!   r"   r   r   	out_filesr%   r%   r%   r&   ra     s   ra   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )SliceaB  Use fslslice to split a 3D file into lots of 2D files (along z-axis).


    Examples
    --------

    >>> from nipype.interfaces.fsl import Slice
    >>> slice = Slice()
    >>> slice.inputs.in_file = 'functional.nii'
    >>> slice.inputs.out_base_name = 'sl'
    >>> slice.cmdline
    'fslslice functional.nii sl'


    Zfslslicec             C   sj   | j  j }tj| jj}d| }t| jjrDtj	j
| jj| }nt| jj|dd}tt||d< |S )a  Create a Bunch which contains all possible files generated
        by running the interface.  Some files are always generated, others
        depending on which ``inputs`` options are set.

        Returns
        -------

        outputs : Bunch object
            Bunch object containing all possible files generated by
            interface object.

            If None, file was not generated
            Else, contains path, filename of generated outputfile

        z_slice_*F)r=   use_extrb   )_outputsr?   r   output_type_to_extr@   output_typer   r`   rB   rC   rD   r   r#   sortedr   )rE   rF   r>   r=   Zfname_templater%   r%   r&   rG   1  s    zSlice._list_outputsN)
r    r!   r"   r)   r*   r^   r+   ra   r,   rG   r%   r%   r%   r&   rc     s
   rc   c               @   sb   e Zd ZejeddddddZejdddd	d
ddddd	Zej	ddddZ
eddddddZdS )MergeInputSpecT)r   z%sr   )r   r   r   txyzaz-%sr   zKdimension along which to merge, optionally set tr input when dimension is t)r   r   r   r   r   z%.2fzYuse to specify TR in seconds (default is 1.00 sec), overrides dimension and sets it to tr)r   r   r   in_filesz	%s_mergedF)r   r   r   r   r.   N)r    r!   r"   r	   r8   r   ro   Enum	dimensionrN   trmerged_filer%   r%   r%   r&   ri   P  s*   ri   c               @   s   e Zd ZeddZdS )MergeOutputSpecT)r   N)r    r!   r"   r   rt   r%   r%   r%   r&   ru   q  s   ru   c                   s,   e Zd ZdZdZeZeZ fddZ	  Z
S )Mergea\  Use fslmerge to concatenate images

    Images can be concatenated across time, x, y, or z dimensions. Across the
    time (t) dimension the TR is set by default to 1 sec.

    Note: to set the TR to a different value, specify 't' for dimension and
    specify the TR value in seconds for the tr input. The dimension will be
    automatically updated to 'tr'.

    Examples
    --------

    >>> from nipype.interfaces.fsl import Merge
    >>> merger = Merge()
    >>> merger.inputs.in_files = ['functional2.nii', 'functional3.nii']
    >>> merger.inputs.dimension = 't'
    >>> merger.inputs.output_type = 'NIFTI_GZ'
    >>> merger.cmdline
    'fslmerge -t functional2_merged.nii.gz functional2.nii functional3.nii'
    >>> merger.inputs.tr = 2.25
    >>> merger.cmdline
    'fslmerge -tr functional2_merged.nii.gz functional2.nii functional3.nii 2.25'


    Zfslmergec                s\   |dkr&| j jdkrtd|j| S |dkrHt| j jr>dS |j| S tt| j|||S )Nrs   rj   z)When TR is specified, dimension must be trr   z-tr)	r@   rr   
ValueErrorr   r   rs   rX   rv   rY   )rE   rH   specr[   )r\   r%   r&   rY     s    

zMerge._format_arg)r    r!   r"   r)   r*   ri   r+   ru   r,   rY   r]   r%   r%   )r\   r&   rv   u  s
   rv   c               @   s   e Zd Ze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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dddddddgZejejejejddeddZdS )ExtractROIInputSpecTz%sr   z
input file)r   r   r   r   r   r   zoutput fileF)r   r   r   r5   r.   z%dr   )r   r   r               rS   	   x_minx_sizey_miny_sizez_minz_sizet_mint_sizez*list of two tuples specifying crop options)r   r   rL   r   N)r    r!   r"   r   r#   roi_filer	   r0   r   r   r   r   r   r   r   r   Z	_crop_xorr8   Tuple	crop_listr%   r%   r%   r&   ry     s4   ry   c               @   s   e Zd ZeddZdS )ExtractROIOutputSpecT)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 fddZ	dd Z
dd Z  ZS )	
ExtractROIa5  Uses FSL Fslroi command to extract region of interest (ROI)
    from an image.

    You can a) take a 3D ROI from a 3D data set (or if it is 4D, the
    same ROI is taken from each time point and a new 4D data set is
    created), b) extract just some time points from a 4D data set, or
    c) control time and space limits to the ROI.  Note that the
    arguments are minimum index and size (not maximum index).  So to
    extract voxels 10 to 12 inclusive you would specify 10 and 3 (not
    10 and 12).


    Examples
    --------

    >>> from nipype.interfaces.fsl import ExtractROI
    >>> from nipype.testing import anatfile
    >>> fslroi = ExtractROI(in_file=anatfile, roi_file='bar.nii', t_min=0,
    ...                     t_size=1)
    >>> fslroi.cmdline == 'fslroi %s bar.nii 0 1' % anatfile
    True


    Zfslroic                s<   |dkr(dj tttttt|g S tt| j|||S )Nr    )joinmapstrsumlistrX   r   rY   )rE   rH   rx   r[   )r\   r%   r&   rY     s     zExtractROI._format_argc             C   sR   | j  j }| jj|d< t|d s:| j| jjdd|d< tjj	|d |d< |S )a  Create a Bunch which contains all possible files generated
        by running the interface.  Some files are always generated, others
        depending on which ``inputs`` options are set.


        Returns
        -------

        outputs : Bunch object
            Bunch object containing all possible files generated by
            interface object.

            If None, file was not generated
            Else, contains path, filename of generated outputfile

        r   Z_roi)r=   )
re   r?   r@   r   r   rA   r#   rB   rC   rD   )rE   rF   r%   r%   r&   rG     s    zExtractROI._list_outputsc             C   s   |dkr| j  | S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI     s    zExtractROI._gen_filename)r    r!   r"   r)   r*   ry   r+   r   r,   rY   rG   rI   r]   r%   r%   )r\   r&   r     s   r   c            
   @   sH   e Zd ZeddddddZejddddZejd	d
dddddddZ	dS )SplitInputSpecTz%sr   zinput filename)r   r   r   r   r   r   zoutputs prefix)r   r   r   rj   rk   rl   rm   z-%sr   z,dimension along which the file will be split)r   r   r   r   N)
r    r!   r"   r   r#   r	   r_   r`   rq   rr   r%   r%   r%   r&   r     s   r   c               @   s   e Zd ZeeddZdS )SplitOutputSpecT)r   N)r    r!   r"   r   r   rb   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 )SplitzaUses FSL Fslsplit command to separate a volume into images in
    time, x, y or z dimension.
    Zfslsplitc             C   s\   | j  j }tj| jj}d}t| jjr6d| jj }tt	t
jjt
j || |d< |S )a  Create a Bunch which contains all possible files generated
        by running the interface.  Some files are always generated, others
        depending on which ``inputs`` options are set.

        Returns
        -------

        outputs : Bunch object
            Bunch object containing all possible files generated by
            interface object.

            If None, file was not generated
            Else, contains path, filename of generated outputfile

        z	vol[0-9]*z%s[0-9]*rb   )re   r?   r   rf   r@   rg   r   r`   rh   r   rB   rC   r   getcwd)rE   rF   r>   Zoutbaser%   r%   r&   rG   &  s    "zSplit._list_outputsN)
r    r!   r"   r)   r*   r   r+   r   r,   rG   r%   r%   r%   r&   r     s
   r   c               @   s   e Zd ZedddddZeddddZedddd	ZedddddZej	dd
ddZ
ej	ddZejdddddddddd	ZdS )ImageMathsInputSpecTz%sr   )r   r   r   r   r   )r   r   r   z-mas %sz-use (following image>0) to mask current image)r   r   r   r   F)r   r   r5   r.   z)string defining the operation, i. e. -add)r   r   r   zout_file suffix)r   charshortintrT   doubleinputz-odt %sz@output datatype, one of (char, short, int, float, double, input)Nrp   )r    r!   r"   r   r#   in_file2	mask_filer   r	   r_   	op_stringr=   rq   Zout_data_typer%   r%   r%   r&   r   ?  s(   r   c               @   s   e Zd ZeddZdS )ImageMathsOutputSpecT)r   N)r    r!   r"   r   r   r%   r%   r%   r&   r   Y  s   r   c                   s>   e Zd ZdZeZeZdZdd Z	d
 fdd	Z
dd	 Z  ZS )
ImageMathsa  Use FSL fslmaths command to allow mathematical manipulation of images
    `FSL info <http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/intro/index.htm#fslutils>`_


    Examples
    --------

    >>> from nipype.interfaces import fsl
    >>> from nipype.testing import anatfile
    >>> maths = fsl.ImageMaths(in_file=anatfile, op_string= '-add 5',
    ...                        out_file='foo_maths.nii')
    >>> maths.cmdline == 'fslmaths %s -add 5 foo_maths.nii' % anatfile
    True


    rR   c             C   s   |dkr| j  | S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI   t  s    zImageMaths._gen_filenameNc                s   t t| jdgdS )Nr=   )skip)rX   r   _parse_inputs)rE   r   )r\   r%   r&   r   y  s    zImageMaths._parse_inputsc             C   sj   d}t | jjr| jj}| j j }| jj|d< t |d sR| j| jj|d|d< tj	j
|d |d< |S )NZ_mathsr   )r=   )r   r@   r=   re   r?   r   rA   r#   rB   rC   rD   )rE   r=   rF   r%   r%   r&   rG   |  s    zImageMaths._list_outputs)N)r    r!   r"   r)   r   r+   r   r,   r*   rI   r   rG   r]   r%   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	d
ZeddddddZejej	ddgddddZ
ejdddgdddZeddddZejdddZejdddZdS ) FilterRegressorInputSpecTz-i %szinput file name (4D image)r   )r   r   r   r   r   z-o %sz&output file name for the filtered datar   F)r   r   r5   r   r.   z-d %sr   zOname of the matrix with time courses (e.g. GLM design or MELODIC mixing matrix))r   r   r   r   r   z-f '%s'
filter_allrz   z2(1-based) column indices to filter out of the data)r   rL   r   r   r   filter_columnsz/use all columns in the design file in denoising)r   r   rL   r   r   z-m %szmask image file name)r   r   r   z--vnz&perform variance-normalization on data)r   r   z--out_vnscalesz1output scaling factors for variance normalizationN)r    r!   r"   r   r#   r   design_filer	   r8   r0   r   r$   r   r7   Zvar_normZout_vnscalesr%   r%   r%   r&   r     sH   r   c               @   s   e Zd ZedddZdS )FilterRegressorOutputSpecTz&output file name for the filtered data)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   r     s   r   c                   s<   e Zd ZdZeZeZdZ fddZ	dd Z
dd Z  ZS )	FilterRegressorzkData de-noising by regressing out part of a design matrix

    Uses simple OLS regression on 4D images
    Zfsl_regfiltc                s   |dkr|j djtt| S |dkrtj| jj}y|jd }W n t	k
rZ   d}Y nX |j djttt
td|d  S tt| j|||S )Nr   ,r   r   )r   r   r   r   rU   Zloadtxtr@   r   shape
IndexErrorr   rangerX   r   rY   )rE   rH   rZ   r[   ZdesignZn_cols)r\   r%   r&   rY     s    
$zFilterRegressor._format_argc             C   sR   | j  j }| jj|d< t|d s:| j| jjdd|d< tjj	|d |d< |S )Nr   Z_regfilt)r=   )
r,   r?   r@   r   r   rA   r#   rB   rC   rD   )rE   rF   r%   r%   r&   rG     s    zFilterRegressor._list_outputsc             C   s   |dkr| j  | S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI     s    zFilterRegressor._gen_filename)r    r!   r"   r)   r   r+   r   r,   r*   rY   rG   rI   r]   r%   r%   )r\   r&   r     s   
r   c               @   s^   e Zd ZejddddZedddddd	Zejddd
ddZ	eddddZ
edddddZdS )ImageStatsInputSpecz-tr   zAgive a separate output line for each 3D volume of a 4D timeseries)r   r   r   Tz%sr   zinput file to generate stats of)r   r   r   r   r   rz   zstring defining the operation, options are applied in order, e.g. -M -l 10 -M will report the non-zero mean, apply a threshold and then report the new nonzero mean)r   r   r   r    zmask file used for option -k %s)r   r   r   z-K %sr   zgenerate seperate n submasks from indexMask, for indexvalues 1..n where n is the maximum index value in indexMask, and generate statistics for each submask)r   r   r   r   N)r    r!   r"   r	   r$   Zsplit_4dr   r#   r_   r   r   Zindex_mask_filer%   r%   r%   r&   r     s*   r   c               @   s   e Zd ZejddZdS )ImageStatsOutputSpeczstats output)r   N)r    r!   r"   r	   ZAnyout_statr%   r%   r%   r&   r     s   r   c                   s6   e Zd ZdZeZeZdZ fddZ	dddZ
  ZS )	
ImageStatsa  Use FSL fslstats command to calculate stats from images
    `FSL info
    <http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/intro/index.htm#fslutils>`_


    Examples
    --------

    >>> from nipype.interfaces.fsl import ImageStats
    >>> from nipype.testing import funcfile
    >>> stats = ImageStats(in_file=funcfile, op_string= '-M')
    >>> stats.cmdline == 'fslstats %s -M'%funcfile
    True


    Zfslstatsc                sX   |dkrdS |dkrDd| j jkrDt| j jr<| j j| j j S tdtt| j|||S )Nr   r   r   z-k %sz,-k %s option in op_string requires mask_file)r@   r   r   r   rw   rX   r   rY   )rE   rH   rZ   r[   )r\   r%   r&   rY      s    zImageStats._format_argNc             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stat
r   c             S   s   g | ]}t |qS r%   )rT   ).0valr%   r%   r&   
<listcomp>:  s    z0ImageStats.aggregate_outputs.<locals>.<listcomp>c             S   s   g | ]}t |qS r%   )rT   )r   r   r%   r%   r&   r   <  s    r   )r   )re   rB   rC   r   r   r   IOErrorrunrF   stdoutsplitlenappendextendr   dictr   )rE   runtimeZneeded_outputsrF   outfiler   linevaluesr%   r%   r&   aggregate_outputs+  s&    zImageStats.aggregate_outputs)NN)r    r!   r"   r)   r   r+   r   r,   r*   rY   r   r]   r%   r%   )r\   r&   r   	  s   r   c               @   s:   e Zd ZejdddZedddddZedddd
dZdS )AvScaleInputSpecFz--allparams)r   Tz%szmat file to readr   )r   r   r   r   r   z(reference file to get center of rotation)r   r   r   r   Nr   rp   )	r    r!   r"   r	   r$   	all_paramr   Zmat_fileZref_filer%   r%   r%   r&   r   D  s   r   c               @   s   e Zd ZejejejddZejejddZejejddZejddZ	ejddZ
ejejejddZejejejddZejd	dZejejd
dZejejddZdS )AvScaleOutputSpeczRotation and Translation Matrix)r   zScales (x,y,z)ZSkewszAverage ScalingZDeterminantzForward Half TransformzBackwards Half Transformz True if LR orientation preservedzrotation anglestranslationsN)r    r!   r"   r	   r8   rN   rotation_translation_matrixscalesskewsaverage_scalingdeterminantforward_half_transformbackward_half_transformr$    left_right_orientation_preserved
rot_anglesr   r%   r%   r%   r&   r   O  s   r   c                   s4   e Zd ZdZeZeZdZ fddZ	dd Z
  ZS )AvScalezUse FSL avscale command to extract info from mat file output of FLIRT

    Examples
    --------

    >>> avscale = AvScale()
    >>> avscale.inputs.mat_file = 'flirt.mat'
    >>> res = avscale.run()  # doctest: +SKIP


    Zavscalec                sd  t t| j|}tjd}|j|jj }i }dd |d j j	dD |d< dd |d j j	d	D |d< d
d |d j j	d	D |d< t
|d j |d< t
|d j |d< |d j dk|d< dd |d j j	dD |d< dd |d j j	dD |d< | jjrTdd |d j j	d	D |d< dd |d j j	d	D |d< t| d| |S )Na\  Rotation & Translation Matrix:\n(?P<rot_tran_mat>[0-9\. \n-]+)[\s\n]*(Rotation Angles \(x,y,z\) \[rads\] = (?P<rot_angles>[0-9\. -]+))?[\s\n]*(Translations \(x,y,z\) \[mm\] = (?P<translations>[0-9\. -]+))?[\s\n]*Scales \(x,y,z\) = (?P<scales>[0-9\. -]+)[\s\n]*Skews \(xy,xz,yz\) = (?P<skews>[0-9\. -]+)[\s\n]*Average scaling = (?P<avg_scaling>[0-9\.-]+)[\s\n]*Determinant = (?P<determinant>[0-9\.-]+)[\s\n]*Left-Right orientation: (?P<lr_orientation>[A-Za-z]+)[\s\n]*Forward half transform =[\s]*\n(?P<fwd_half_xfm>[0-9\. \n-]+)[\s\n]*Backward half transform =[\s]*\n(?P<bwd_half_xfm>[0-9\. \n-]+)[\s\n]*c             S   s$   g | ]}d d |j  jdD qS )c             S   s   g | ]}t |qS r%   )rT   )r   vr%   r%   r&   r     s    z5AvScale._run_interface.<locals>.<listcomp>.<listcomp>r   )stripr   )r   rr%   r%   r&   r     s   z*AvScale._run_interface.<locals>.<listcomp>Zrot_tran_matr   r   c             S   s   g | ]}t |qS r%   )rT   )r   sr%   r%   r&   r     s    r   r   c             S   s   g | ]}t |qS r%   )rT   )r   r   r%   r%   r&   r     s    r   Zavg_scalingr   r   Zlr_orientationZ	preservedr   c             S   s$   g | ]}d d |j  jdD qS )c             S   s   g | ]}t |qS r%   )rT   )r   r   r%   r%   r&   r     s    z5AvScale._run_interface.<locals>.<listcomp>.<listcomp>r   )r   r   )r   r   r%   r%   r&   r     s   Zfwd_half_xfmr   c             S   s$   g | ]}d d |j  jdD qS )c             S   s   g | ]}t |qS r%   )rT   )r   r   r%   r%   r&   r     s    z5AvScale._run_interface.<locals>.<listcomp>.<listcomp>r   )r   r   )r   r   r%   r%   r&   r     s   Zbwd_half_xfmr   c             S   s   g | ]}t |qS r%   )rT   )r   r   r%   r%   r&   r     s    r   c             S   s   g | ]}t |qS r%   )rT   )r   r   r%   r%   r&   r     s    r   _results)rX   r   _run_interfacerecompilesearchr   	groupdictr   r   rT   r@   r   setattr)rE   r   exproutrF   )r\   r%   r&   r   v  s*      
  zAvScale._run_interfacec             C   s   | j S )N)r   )rE   r%   r%   r&   rG     s    zAvScale._list_outputs)r    r!   r"   r)   r   r+   r   r,   r*   r   rG   r]   r%   r%   )r\   r&   r   d  s   2r   c            	   @   s  e Zd ZejddddddZejdddddd	d
ZejddddZe	ddddddZ
d3ZejdddeddZejdddeddZejejejdddeddZe	ddddddZejejejd dd!d"d#Zejd$d%gdd&d'Ze	dd(d)gdd*d+Zejejejd,d-d!d.Ze	d/d4ddd0d1Zd2S )5OverlayInputSpecz$make overlay colors semi-transparentr   z%sT)r   r   r   r6   default_valuerT   r   r   zwrite output with float or int)r   r6   r   r   z!use checkerboard mask for overlayz-cr   )r   r   r   rz   zimage to use as background)r   r   r   r   r   auto_thresh_bgfull_bg_range	bg_threshz,automatically threshold the background imagez-ar{   )r   r   r   rL   r   z"use full range of background imagez-Az	%.3f %.3fz+min and max values for background intensity)r   r   r   rL   r   r|   z%statistical image to overlay in colorr}   z	%.2f %.2fz.min and max values for the statistical overlay)r   r   r   r   z&display negative statistics in overlaystat_image2rS   )r   rL   r   r   r~   show_negative_statsz,second statistical image to overlay in color)r   r   rL   r   r   
   z1min and max values for second statistical overlay)r   r   r   zcombined image volumeF)r   r   r   r5   r.   N)r   r   r   rp   )r    r!   r"   r	   r$   transparencyrq   out_typeZuse_checkerboardr   Zbackground_imageZ_xor_inputsr   r   r   rN   r   
stat_imagestat_threshr   r   Zstat_thresh2r   r%   r%   r%   r&   r     s   r   c               @   s   e Zd ZedddZdS )OverlayOutputSpecTzcombined image volume)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 fddZ	dd Z
dd Z  ZS )	Overlaya  Use FSL's overlay command to combine background and statistical images
        into one volume


    Examples
    --------

    >>> from nipype.interfaces import fsl
    >>> combine = fsl.Overlay()
    >>> combine.inputs.background_image = 'mean_func.nii.gz'
    >>> combine.inputs.auto_thresh_bg = True
    >>> combine.inputs.stat_image = 'zstat1.nii.gz'
    >>> combine.inputs.stat_thresh = (3.5, 10)
    >>> combine.inputs.show_negative_stats = True
    >>> res = combine.run() #doctest: +SKIP


    Zoverlayc                sr   |dkr|rdS dS |dkr,|dkr(dS dS |dkr^d| j j| j jd d
 | j jd	 d f S tt| j|||S )Nr   10r   rT   r   z%s %.2f %.2fr   r   rp   rp   )r@   r   r   rX   r   rY   )rE   rH   rx   r[   )r\   r%   r&   rY   &  s    zOverlay._format_argc             C   s   | j  j }| jj}t|st| jjrft| jj s@| jj rfdt| jjd t| jjd f }nt| jjd }| j	|dd}t
jj||d< |S )Nz	%s_and_%sr   Z_overlay)r=   r   )re   r?   r@   r   r   r   r   r   r   rA   rB   rC   rD   )rE   rF   r   Zstemr%   r%   r&   rG   9  s    
zOverlay._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI   K  s    zOverlay._gen_filename)r    r!   r"   r)   r*   r   r+   r   r,   rY   rG   rI   r]   r%   r%   )r\   r&   r     s   r   c            
   @   sN  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edddddZ	ej
ejejddddZejddddZejddddZejddddZejddddddZd@Zejd$d%d&d'd(ed)gd*d+Zejd,d-d.dZejd'd/ed0d1Zejd'd2ed3gd4d+Zejd'd5ed3gd6d+ZejdAd7d8dZedBddd9d:d;Zejd<d=d>dZd?S )CSlicerInputSpecTr   z%szinput volume)r   r   r   r   r   r   zDvolume to display edge overlay for (useful for checking registration)r   r   r   r   r   z-Lzdisplay slice number)r   r   r   r6   r   rz   z-l %sz9use different colour map from that stored in nifti headerr{   z-i %.3f %.3fz"min and max intensities to display)r   r   r   r|   z-e %.3fzuse threshold for edgesr}   z-tz)produce semi-transparent (dithered) edgesrS   z-nz-use nearest neighbor interpolation for outputr~   zlabel left-right orientation)r   r   r6   r   r   single_slicemiddle_slices	all_axialsample_axialrk   rl   rm   r   z-%sslice_numberz6output picture of single slice in the x, y, or z plane)r   r   rL   requiresr      z-%dzslice number to save in picturez-az9output picture of mid-sagittal, axial, and coronal slices)r   r   rL   r   z-Aimage_widthz(output all axial slices into one picturez-S %dz,output every n axial slices into one picturez%dzmax picture widthzpicture to writeF)r   r5   r   r   r.   r   z-s %fzimage scaleN)r   r   r   r   r   rp   )r    r!   r"   r   r#   Zimage_edgesr	   r$   label_slicesZ
colour_mapr   rN   Zintensity_rangeZthreshold_edgesZdither_edgesZnearest_neighbourshow_orientationZ_xor_optionsrq   r   r0   r   r   r   r   r   r   Zscalingr%   r%   r%   r&   r   Q  s   r   c               @   s   e Zd ZedddZdS )SlicerOutputSpecTzpicture to write)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 fddZ	dd Z
dd Z  ZS )	Slicera  Use FSL's slicer command to output a png image from a volume.


    Examples
    --------

    >>> from nipype.interfaces import fsl
    >>> from nipype.testing import example_data
    >>> slice = fsl.Slicer()
    >>> slice.inputs.in_file = example_data('functional.nii')
    >>> slice.inputs.all_axial = True
    >>> slice.inputs.image_width = 750
    >>> res = slice.run() #doctest: +SKIP


    Zslicerc                s>   |dkr|rdS dS n|dkr*|r&dS dS t t| j|||S )Nr   r   z-ur   z-L)rX   r   rY   )rE   rH   rx   r[   )r\   r%   r&   rY     s    zSlicer._format_argc             C   sB   | j  j }| jj}t|s.| j| jjdd}tjj	||d< |S )Nz.png)r>   r   )
re   r?   r@   r   r   rA   r#   rB   rC   rD   )rE   rF   r   r%   r%   r&   rG     s    zSlicer._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI     s    zSlicer._gen_filename)r    r!   r"   r)   r*   r   r+   r   r,   rY   rG   rI   r]   r%   r%   )r\   r&   r     s   r   c               @   s0  e Zd ZejeddejedddddddZejdd,d	d
Z	ejdd-dd
Z
ejejejdd.dd
ZejdddZeddddZejejejejdddZejddd/dZejddd0dZejejejdd1dd
Zejdd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ed'dd(d)d*Zd+S )2PlotTimeSeriesInputSpecT)r   z%sr   z<file or list of files with columns of timecourse information)r   r   r   r   z
--start=%d
plot_rangez!first column from in-file to plot)r   rL   r   z--finish=%dz!final column from in-file to plot
plot_startplot_finishz/first and last columns from the in-file to plotz
plot title)r   r   z--legend=%szlegend file)r   r   r   zlabel or list of labelsz--ymin=%.2fzminumum y valuey_range)r   r   rL   z--ymax=%.2fzmaximum y valuer   y_maxzmin and max y axis valuesz-u %dz:scaling units for x-axis (between 1 and length of in file))r   r6   r   r   zplot image height and widthz--precision=%dzprecision of x-axis labelsz--scizswitch on scientific notationz-o %szimage to writeF)r   r5   r   r.   N)r   )r   )r   r   )r  )r  )r   r  )r    r!   r"   r	   Eitherr   r8   r#   r0   r   r   r   r   r_   titleZlegend_filelabelsrN   r   r  r  Zx_units	plot_sizeZx_precisionr$   Zsci_notationr   r%   r%   r%   r&   r     sX   r   c               @   s   e Zd ZedddZdS )PlotTimeSeriesOutputSpecTzimage to write)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 fddZ	dd Z
dd Z  ZS )	PlotTimeSeriesak  Use fsl_tsplot to create images of time course plots.

    Examples
    --------

    >>> import nipype.interfaces.fsl as fsl
    >>> plotter = fsl.PlotTimeSeries()
    >>> plotter.inputs.in_file = 'functional.par'
    >>> plotter.inputs.title = 'Functional timeseries'
    >>> plotter.inputs.labels = ['run1', 'run2']
    >>> plotter.run() #doctest: +SKIP


    
fsl_tsplotc                s   |dkr.t |tr$dj|}d| S d| S nn|dkr\t |trRdj|}d| S d| S n@|dkrld| S |dkr|d	| S |d
krd| S |dkrd| S tt| j|||S )Nr#   r   z-i %sr  z-a %sr  z-t '%s'r   z--start=%d --finish=%dr  z--ymin=%d --ymax=%dr  z-h %d -w %d)
isinstancer   r   rX   r  rY   )rE   rH   rx   r[   args)r\   r%   r&   rY   7  s&    





zPlotTimeSeries._format_argc             C   sb   | j  j }| jj}t|sNt| jjtr8| jjd }n| jj}| j|dd}t	j
j||d< |S )Nr   z.png)r>   r   )re   r?   r@   r   r   r
  r#   r   rA   rB   rC   rD   )rE   rF   r   infiler%   r%   r&   rG   N  s    zPlotTimeSeries._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI   Z  s    zPlotTimeSeries._gen_filename)r    r!   r"   r)   r*   r   r+   r  r,   rY   rG   rI   r]   r%   r%   )r\   r&   r  #  s   r  c               @   s   e Zd ZejeddejedddddddZejdddd	d
Z	ejdddddddZ
ejejejdddZedddddZdS )PlotMotionParamsInputSpecT)r   z%sr   zfile with motion parameters)r   r   r   r   spmfslz<which program generated the motion parameter file - fsl, spm)r   r   Z	rotationsr   displacementzAwhich motion type to plot - rotations, translations, displacement)r   r   r   zplot image height and width)r   r   z-o %szimage to writeF)r   r5   r   r.   N)r    r!   r"   r	   r  r   r8   r#   rq   	in_source	plot_typer   r0   r  r   r%   r%   r%   r&   r  `  s.   r  c               @   s   e Zd ZedddZdS )PlotMotionParamsOutputSpecTzimage to write)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 fddZ	dd Z
dd Z  ZS )	PlotMotionParamsad  Use fsl_tsplot to plot the estimated motion parameters from a
    realignment program.


    Examples
    --------

    >>> import nipype.interfaces.fsl as fsl
    >>> plotter = fsl.PlotMotionParams()
    >>> plotter.inputs.in_file = 'functional.par'
    >>> plotter.inputs.in_source = 'fsl'
    >>> plotter.inputs.plot_type = 'rotations'
    >>> res = plotter.run() #doctest: +SKIP


    Notes
    -----

    The 'in_source' attribute determines the order of columns that are expected
    in the source file.  FSL prints motion parameters in the order rotations,
    translations, while SPM prints them in the opposite order.  This interface
    should be able to plot timecourses of motion parameters generated from
    other sources as long as they fall under one of these two patterns.  For
    more flexibilty, see the :class:`fsl.PlotTimeSeries` interface.

    r	  c                s   |dkr| j j}| j jdkr0d}d}d||f S tddddd
}d|d||d d f   }tddd}	tddd}
d|	| ||
|d d  f }d||f S |dkrd| S |dkrt|trdj|}d| S d| S tt| j	|||S )Nr  r  z--t 'MCFLIRT estimated mean displacement (mm)'z
-a abs,relz%s %sr   r   rz   r|   )Zfsl_rotZfsl_traZspm_rotZspm_traz--start=%d --finish=%dz%s_%sZMCFLIRTZRealign)r  r  radiansmm)rottraz'%s estimated %s (%s)'z-t %s %s -a x,y,zr  z-h %d -w %dr#   r   z-i %s)r   r   )rz   r|   )rz   r|   )r   r   )
r@   r  r  r   r
  r   r   rX   r  rY   )rE   rH   rx   r[   sourcer  r  ZsfdictZsfstrZ	titledictZunitdictr  )r\   r%   r&   rY     s0    

zPlotMotionParams._format_argc             C   s   | j  j }| jj}t|spt| jjtr8| jjd }n| jj}tdddd| jj	d d  }t
|d| dd	}tjj||d
< |S )Nr   r  ZtransZdisp)r  r  disr   z_%s.pngF)r=   rd   r   )re   r?   r@   r   r   r
  r#   r   r   r  r   rB   rC   rD   )rE   rF   r   r  Zplttyper%   r%   r&   rG     s    zPlotMotionParams._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI     s    zPlotMotionParams._gen_filename)r    r!   r"   r)   r*   r  r+   r  r,   rY   rG   rI   r]   r%   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d	d
dgZejddeddZ	ejddedgddZ
ejddedgddZeddddddZdS ) ConvertXFMInputSpecTz%sr   zinput transformation matrix)r   r   r   r   r   r   z?second input matrix (for use with fix_scale_skew or concat_xfm))r   r   r   r   
invert_xfm
concat_xfmfix_scale_skewz-inverser   zinvert input transformation)r   r   rL   r   z-concatr   z0write joint transformation of two input matrices)r   r   rL   r   r   z-fixscaleskewz*use secondary matrix to fix scale and skewz-omat %szfinal transformation matrixF)r5   r   r   r   r.   Nrp   r   r  r  )r    r!   r"   r   r#   r   _optionsr	   r$   r  r  r  r   r%   r%   r%   r&   r    s@   
r  c               @   s   e Zd ZedddZdS )ConvertXFMOutputSpecTzoutput transformation matrix)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d Z	dd Z
dS )
ConvertXFMa  Use the FSL utility convert_xfm to modify FLIRT transformation matrices.

    Examples
    --------

    >>> import nipype.interfaces.fsl as fsl
    >>> invt = fsl.ConvertXFM()
    >>> invt.inputs.in_file = "flirt.mat"
    >>> invt.inputs.invert_xfm = True
    >>> invt.inputs.out_file = 'flirt_inv.mat'
    >>> invt.cmdline
    'convert_xfm -omat flirt_inv.mat -inverse flirt.mat'


    Zconvert_xfmc             C   s   | j  j }| jj}t|st| jj\}}}| jjrLt|dt	j
 dd}nL| jjrt| jj\}}}td||f dt	j
 dd}nt|dt	j
 dd}t	jj||d< |S )Nz_inv.matF)r=   newpathrd   z%s_%sz.matz_fix.matr   )re   r?   r@   r   r   r   r#   r  r   rB   r   r  r   rC   rD   )rE   rF   r   _Zinfile1Zinfile2r%   r%   r&   rG   %  s$    

zConvertXFM._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI   >  s    zConvertXFM._gen_filenameN)r    r!   r"   r)   r*   r  r+   r!  r,   rG   rI   r%   r%   r%   r&   r"    s   r"  c               @   sr   e Zd ZeddddddZdddd	d
dddddddgZejejeejeejeddddZ	edddddZ
dS )SwapDimensionsInputSpecTz%sr   zinput image)r   r   r   r   r   rk   z-xrl   z-yrm   z-zZRLZLRZAPZPAZISZSIz%s %s %sz3-tuple of new dimension order)r   r   r   zimage to writeF)r5   r   r   r.   N)r    r!   r"   r   r#   Z_dimsr	   r   rq   Znew_dimsr   r%   r%   r%   r&   r%  D  s   r%  c               @   s   e Zd ZedddZdS )SwapDimensionsOutputSpecTzimage with new dimensions)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   r&  U  s   r&  c               @   s,   e Zd ZdZdZeZeZdd Z	dd Z
dS )SwapDimensionsa  Use fslswapdim to alter the orientation of an image.

    This interface accepts a three-tuple corresponding to the new
    orientation.  You may either provide dimension ids in the form of
    (-)x, (-)y, or (-z), or nifti-syle dimension codes
    (RL, LR, AP, PA, IS, SI).

    Z
fslswapdimc             C   sR   | j  j }| jj|d< t| jjs:| j| jjdd|d< tjj	|d |d< |S )Nr   Z_newdims)r=   )
re   r?   r@   r   r   rA   r#   rB   rC   rD   )rE   rF   r%   r%   r&   rG   h  s    zSwapDimensions._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI   r  s    zSwapDimensions._gen_filenameN)r    r!   r"   r)   r*   r%  r+   r&  r,   rG   rI   r%   r%   r%   r&   r'  Z  s   
r'  c               @   s0   e Zd ZeddddddZedddddd	Zd
S )PowerSpectrumInputSpecTz,input 4D file to estimate the power spectrumz%sr   )r   r   r   r   r   z)name of output 4D file for power spectrumr   F)r   r   r   r5   r.   N)r    r!   r"   r   r#   r   r%   r%   r%   r&   r(  x  s   r(  c               @   s   e Zd ZedddZdS )PowerSpectrumOutputSpecTz.path/name of the output 4D power spectrum file)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   r)    s   r)  c               @   s4   e Zd ZdZdZeZeZdd Z	dd Z
dd Zd	S )
PowerSpectruma  Use FSL PowerSpectrum command for power spectrum estimation.

    Examples
    --------

    >>> from nipype.interfaces import fsl
    >>> pspec = fsl.PowerSpectrum()
    >>> pspec.inputs.in_file = 'functional.nii'
    >>> res = pspec.run() # doctest: +SKIP


    Zfslpspecc             C   s4   | j j}t| r0t| j jr0| j| j jdd}|S )NZ_ps)r=   )r@   r   r   r#   rA   )rE   r   r%   r%   r&   _gen_outfilename  s    zPowerSpectrum._gen_outfilenamec             C   s$   | j  j }tjj| j |d< |S )Nr   )r,   r?   rB   rC   rD   r+  )rE   rF   r%   r%   r&   rG     s    zPowerSpectrum._list_outputsc             C   s   |dkr| j  S d S )Nr   )r+  )rE   rH   r%   r%   r&   rI     s    zPowerSpectrum._gen_filenameN)r    r!   r"   r)   r*   r(  r+   r)  r,   r+  rG   rI   r%   r%   r%   r&   r*    s   r*  c               @   sZ   e Zd ZedddddZeddddZeddd	d
ZejdddZ	ej
ddddddZdS )SigLossInputSpecTz-i %szb0 fieldmap file)r   r   r   r   z-s %sz output signal loss estimate file)r   r   r5   z-m %szbrain mask file)r   r   r   z--te=%fzecho time in seconds)r   r   rk   rl   rm   z-d %szslicing directionN)r    r!   r"   r   r#   r   r   r	   rN   Z	echo_timerq   Zslice_directionr%   r%   r%   r&   r,    s   r,  c               @   s   e Zd ZedddZdS )SigLossOuputSpecTzsignal loss estimate file)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   r-    s   r-  c               @   s,   e Zd ZdZeZeZdZdd Z	dd Z
dS )SigLosszEstimates signal loss from a field map (in rad/s)

    Examples
    --------

    >>> sigloss = SigLoss()
    >>> sigloss.inputs.in_file = "phase.nii"
    >>> sigloss.inputs.echo_time = 0.03
    >>> res = sigloss.run() # doctest: +SKIP


    Zsiglossc             C   sL   | j  j }| jj|d< t|d  rHt| jjrH| j| jjdd|d< |S )Nr   Z_sigloss)r=   )r,   r?   r@   r   r   r#   rA   )rE   rF   r%   r%   r&   rG     s    zSigLoss._list_outputsc             C   s   |dkr| j  d S d S )Nr   )rG   )rE   rH   r%   r%   r&   rI     s    zSigLoss._gen_filenameN)r    r!   r"   r)   r,  r+   r-  r,   r*   rG   rI   r%   r%   r%   r&   r.    s   	r.  c               @   s(   e Zd ZeddddZeddddZdS )Reorient2StdInputSpecTz%s)r   r   r   F)r5   r.   r   N)r    r!   r"   r   r#   r   r%   r%   r%   r&   r/    s   r/  c               @   s   e Zd ZeddZdS )Reorient2StdOutputSpecT)r   N)r    r!   r"   r   r   r%   r%   r%   r&   r0    s   r0  c               @   s,   e Zd ZdZdZeZeZdd Z	dd Z
dS )Reorient2Stda-  fslreorient2std is a tool for reorienting the image to match the
    approximate orientation of the standard template images (MNI152).


    Examples
    --------

    >>> reorient = Reorient2Std()
    >>> reorient.inputs.in_file = "functional.nii"
    >>> res = reorient.run() # doctest: +SKIP


    Zfslreorient2stdc             C   s   |dkr| j | jjddS d S )Nr   Z_reoriented)r=   )rA   r@   r#   )rE   rH   r%   r%   r&   rI      s    zReorient2Std._gen_filenamec             C   s@   | j  j }t| jjs(| jd|d< ntjj| jj|d< |S )Nr   )	r,   r?   r   r@   r   rI   rB   rC   rD   )rE   rF   r%   r%   r&   rG     s
    zReorient2Std._list_outputsN)r    r!   r"   r)   r*   r/  r+   r0  r,   rI   rG   r%   r%   r%   r&   r1    s   r1  c               @   s   e Zd ZedddddZedddddZeddg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dddZejdddZejdddZdS ) InvWarpInputSpecTz	--warp=%szName of file containing warp-coefficients/fields. This would typically be the output from the --cout switch of fnirt (but can also use fields, like the output from --fout).)r   r   r   r   z--ref=%szName of a file in target space. Note that the target space is now different from the target space that was used to create the --warp file. It would typically be the file that was specified with the --in argument when running fnirt.z--out=%swarpFz
%s_inversezName of output file, containing warps that are the "reverse" of those in --warp. This will be a field-file (rather than a file of spline coefficients), and it will have any affine component included as part of the displacements.)r   r   r.   r   r   z--absrelativezIf set it indicates that the warps in --warp should be interpreted as absolute, provided that it is not created by fnirt (which always uses relative warps). If set it also indicates that the output --out should be absolute.)r   rL   r   z--relabsolutezIf set it indicates that the warps in --warp should be interpreted as relative. I.e. the values in --warp are displacements from the coordinates in the --ref space. If set it also indicates that the output --out should be relative.z
--niter=%dzQDetermines how many iterations of the gradient-descent search that should be run.)r   r   z--regularise=%fz&Regularization strength (deafult=1.0).z--noconstraintz Do not apply Jacobian constraintz	--jmin=%fz?Minimum acceptable Jacobian value for constraint (default 0.01)z	--jmax=%fz@Maximum acceptable Jacobian value for constraint (default 100.0)N)r    r!   r"   r   r3  	referenceinverse_warpr	   r$   r5  r4  r0   ZniterrN   Z
regulariseZnoconstraintjacobian_minjacobian_maxr%   r%   r%   r&   r2    sJ   

r2  c               @   s   e Zd ZedddZdS )InvWarpOutputSpecTzPName of output file, containing warps that are the "reverse" of those in --warp.)r   r   N)r    r!   r"   r   r7  r%   r%   r%   r&   r:  c  s   r:  c               @   s   e Zd ZdZeZeZdZdS )InvWarpa  
    Use FSL Invwarp to invert a FNIRT warp


    Examples
    --------

    >>> from nipype.interfaces.fsl import InvWarp
    >>> invwarp = InvWarp()
    >>> invwarp.inputs.warp = "struct2mni.nii"
    >>> invwarp.inputs.reference = "anatomical.nii"
    >>> invwarp.inputs.output_type = "NIFTI_GZ"
    >>> invwarp.cmdline
    'invwarp --out=struct2mni_inverse.nii.gz --ref=anatomical.nii --warp=struct2mni.nii'
    >>> res = invwarp.run() # doctest: +SKIP


    ZinvwarpN)	r    r!   r"   r)   r2  r+   r:  r,   r*   r%   r%   r%   r&   r;  m  s   r;  c               @   s  e Zd ZeddddZeddddZeddddZeddddZeddddZeddddZ	dddd	d
gZ
ddddddgZeddd e
edd  dZeddd!e
dd e
dd  edd  dZeddd"e
dd e
dd  edd  dZeddd#e
dd edd  edd  dZeddd$e
dd edd  edd  dZejd%ddZejd&ddZejdeddZejdeddZejdeddZejdeddZejdeddZejdeddg ddZdS )'ComplexInputSpecTz%sr   )r   r   r   r   complex_out_filemagnitude_out_filephase_out_filereal_out_fileimaginary_out_file
real_polarreal_cartesiancomplex_cartesiancomplex_polarcomplex_splitcomplex_mergeN)r5   r   r   rL   rz   r   z%d)r   r   z
-realpolar)r   rL   r   z-realcartesianz-complexz-complexpolarz-complexsplitz-complexmerge	start_volend_volr  r  rJ  r  r   rp   )r    r!   r"   r   complex_in_fileZcomplex_in_file2real_in_fileZimaginary_in_filemagnitude_in_fileZphase_in_file_ofsZ_conversionr=  r>  r?  r@  rA  r	   r0   rH  rI  r$   rB  rC  rD  rE  rF  rG  r%   r%   r%   r&   r<    s`   ((((r<  c               @   s*   e Zd Ze Ze Ze Ze Ze ZdS )ComplexOuputSpecN)	r    r!   r"   r   r>  r?  r@  rA  r=  r%   r%   r%   r&   rO    s
   rO  c                   sF   e Zd ZdZdZeZeZd fdd	Z	dd Z
dd	 Zd
d Z  ZS )Complexzfslcomplex is a tool for converting complex data

    Examples
    --------

    >>> cplx = Complex()
    >>> cplx.inputs.complex_in_file = "complex.nii"
    >>> cplx.real_polar = True
    >>> res = cplx.run() # doctest: +SKIP


    Z
fslcomplexNc                s|   |d krg }| j jr*|| j jd d 7 }nB| j jrX|| j jd d | j jdd   7 }n|| j jdd  7 }tt| j|S )Nr   r   )r@   rC  rN  rB  rX   rP  r   )rE   r   )r\   r%   r&   r     s    &zComplex._parse_inputsc             C   s   |dkrX| j jr| j j}n0| j jr,| j j}n| j js<| j jrF| j j}nd S | j|ddS |dkrr| j| j jddS |dkr| j| j jddS |dkr| j| j jd	dS |d
kr| j| j jddS d S )Nr=  Z_cplx)r=   r>  Z_magr?  Z_phaser@  Z_realrA  Z_imag)	r@   rD  rL  rE  rM  rF  rG  rK  rA   )rE   rH   r#   r%   r%   r&   rI     s$    


zComplex._gen_filenamec             C   s*   t | j|}t|s| j|}tjj|S )N)getattrr@   r   rI   rB   rC   rD   )rE   rH   outputr%   r%   r&   _get_output  s    
zComplex._get_outputc             C   s   | j  j }| jjs,| jjs,| jjs,| jjr<| jd|d< nJ| jjrb| jd|d< | jd|d< n$| jj	r| jd|d< | jd|d< |S )Nr=  r@  rA  r>  r?  )
r,   r?   r@   rD  rE  rF  rG  rS  rC  rB  )rE   rF   r%   r%   r&   rG     s    zComplex._list_outputs)N)r    r!   r"   r)   r*   r<  r+   rO  r,   r   rI   rS  rG   r]   r%   r%   )r\   r&   rP    s   rP  c               @   s   e Zd ZedddddZedddddZejddd	d
dZej	ej
ej
ej
dddZej	ejejejdddZedddgdddZejdddddZedddZejddddZdS )WarpUtilsInputSpecTz--in=%szName of file containing warp-coefficients/fields. This would typically be the output from the --cout switch of fnirt (but can also use fields, like the output from --fout).)r   r   r   r   z--ref=%szName of a file in target space. Note that the target space is now different from the target space that was used to create the --warp file. It would typically be the file that was specified with the --in argument when running fnirt.splinefieldz--outformat=%szSpecifies the output format. If set to field (default) the output will be a (4D) field-file. If set to spline the format will be a (4D) file of spline coefficients.)r   r   z--warpres=%0.4f,%0.4f,%0.4fa  Specifies the resolution/knot-spacing of the splines pertaining to the coefficients in the --out file. This parameter is only relevant if --outformat is set to spline. It should be noted that if the --in file has a higher resolution, the resulting coefficients will pertain to the closest (in a least-squares sense) file in the space of fields with the --warpres resolution. It should also be noted that the resolution will always be an integer multiple of the voxel size.z--knotspace=%d,%d,%dzVAlternative (to --warpres) specification of the resolution of the output spline-field.z--out=%sr   r#   r   zName of output file. The format of the output depends on what other parameters are set. The default format is a (4D) field-file. If the --outformat is set to spline the format will be a (4D) file of spline coefficients.)r   r   r   r   r   Fz:Switch on --jac flag with automatically generated filename)r   r6   r   z--jac=%szuSpecifies that a (3D) file of Jacobian determinants corresponding to --in should be produced and written to filename.z	--withaffaE  Specifies that the affine transform (i.e. that which was specified for the --aff parameter in fnirt) should be included as displacements in the --out file. That can be useful for interfacing with software that cannot decode FSL/fnirt coefficient-files (where the affine transform is stored separately from the displacements).Nrp   )r    r!   r"   r   r#   r6  r	   rq   
out_formatr   rN   Zwarp_resolutionr0   Z
knot_spacer   r$   write_jacobianout_jacobianZwith_affiner%   r%   r%   r&   rT  $  sZ   rT  c               @   s    e Zd ZeddZeddZdS )WarpUtilsOutputSpeczBName of output file, containing the warp as field or coefficients.)r   zJName of output file, containing the map of the determinant of the JacobianN)r    r!   r"   r   r   rY  r%   r%   r%   r&   rZ    s   rZ  c                   s.   e Zd ZdZeZeZdZd fdd	Z	  Z
S )	WarpUtilsa  Use FSL `fnirtfileutils <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/fnirt/warp_utils.html>`_
    to convert field->coefficients, coefficients->field, coefficients->other_coefficients etc


    Examples
    --------

    >>> from nipype.interfaces.fsl import WarpUtils
    >>> warputils = WarpUtils()
    >>> warputils.inputs.in_file = "warpfield.nii"
    >>> warputils.inputs.reference = "T1.nii"
    >>> warputils.inputs.out_format = 'spline'
    >>> warputils.inputs.warp_resolution = (10,10,10)
    >>> warputils.inputs.output_type = "NIFTI_GZ"
    >>> warputils.cmdline # doctest: +ELLIPSIS
    'fnirtfileutils --in=warpfield.nii --outformat=spline --ref=T1.nii --warpres=10.0000,10.0000,10.0000 --out=warpfield_coeffs.nii.gz'
    >>> res = invwarp.run() # doctest: +SKIP


    ZfnirtfileutilsNc                s   |d krg }d}t | jjr,| jjdkr,d}| jjd}d| |_| jjrxt | jjs| jjd}dg|_d|_d|_n
|dg7 }|d	g7 }t	t
| j|d
S )NrV  rU  Zcoeffsr   z%s_rY  r#   z%s_jacrX  )r   )r   r@   rW  Ztraitr   rX  rY  r   r   rX   r[  r   )rE   r   r=   rZ   Zjac_spec)r\   r%   r&   r     s     


zWarpUtils._parse_inputs)N)r    r!   r"   r)   rT  r+   rZ  r,   r*   r   r]   r%   r%   )r\   r&   r[    s
   r[  c               @   s  e Zd ZeddddddZedd9dgdd	d
dZeddddZeddddZeddddZeddddZ	eddddZ
eddddZejdddddddd g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,gd-d.Zejd/d0gd1d.Zejd2d3gd4d.Zejd5d6gd7d.Zd8S ):ConvertWarpInputSpecTz--ref=%sr   z5Name of a file in target space of the full transform.)r   r   r   r   r   z--out=%sr6  z%s_concatwarpr   zName of output file, containing warps that are the combination of all those given as arguments. The format of this will be a field-file (rather than spline coefficients) with any affine components included.)r   r   r   r   r   r   z--premat=%sz*filename for pre-transform (affine matrix))r   r   r   z
--warp1=%szName of file containing initial warp-fields/coefficients (follows premat). This could e.g. be a fnirt-transform from a subjects structural scan to an average of a group of subjects.z--midmat=%sz1Name of file containing mid-warp-affine transformz
--warp2=%szName of file containing secondary warp-fields/coefficients (after warp1/midmat but before postmat). This could e.g. be a fnirt-transform from the average of a group of subjects to some standard space (e.g. MNI152).z--postmat=%szName of file containing an affine transform (applied last). It could e.g. be an affine transform that maps the MNI152-space into a better approximation to the Talairach-space (if indeed there is one).z--shiftmap=%saN  Name of file containing a "shiftmap", a non-linear transform with displacements only in one direction (applied first, before premat). This would typically be a fieldmap that has been pre-processed using fugue that maps a subjects functional (EPI) data onto an undistorted space (i.e. a space that corresponds to his/her true anatomy).zy-rl   rk   zx-rm   zz-z--shiftdir=%sshift_in_filezIndicates the direction that the distortions from --shiftmap goes. It depends on the direction and polarity of the phase-encoding in the EPI sequence.)r   r   r   Fz--constrainjzOConstrain the Jacobian of the warpfield to lie within specified min/max limits.)r   r   z	--jmin=%fz?Minimum acceptable Jacobian value for constraint (default 0.01)z	--jmax=%fz@Maximum acceptable Jacobian value for constraint (default 100.0)z--absrelwarpa   If set it indicates that the warps in --warp1 and --warp2 should be interpreted as absolute. I.e. the values in --warp1/2 are the coordinates in the next space, rather than displacements. This flag is ignored if --warp1/2 was created by fnirt, which always creates relative displacements.)r   rL   r   z--relabswarpzIf set it indicates that the warps in --warp1/2 should be interpreted as relative. I.e. the values in --warp1/2 are displacements from the coordinates in the next space.z--absoutout_relwarpzIf set it indicates that the warps in --out should be absolute, i.e. the values in --out are displacements from the coordinates in --ref.z--reloutout_abswarpzIf set it indicates that the warps in --out should be relative, i.e. the values in --out are displacements from the coordinates in --ref.Nrp   )r    r!   r"   r   r6  r   ZprematZwarp1ZmidmatZwarp2Zpostmatr]  r	   rq   Zshift_directionr$   Zcons_jacobianrN   r8  r9  r_  r^  ra  r`  r%   r%   r%   r&   r\    s   r\  c               @   s   e Zd ZedddZdS )ConvertWarpOutputSpecTzBName of output file, containing the warp as field or coefficients.)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   rb  Y	  s   rb  c               @   s   e Zd ZdZeZeZdZdS )ConvertWarpao  Use FSL `convertwarp <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/fnirt/warp_utils.html>`_
    for combining multiple transforms into one.


    Examples
    --------

    >>> from nipype.interfaces.fsl import ConvertWarp
    >>> warputils = ConvertWarp()
    >>> warputils.inputs.warp1 = "warpfield.nii"
    >>> warputils.inputs.reference = "T1.nii"
    >>> warputils.inputs.relwarp = True
    >>> warputils.inputs.output_type = "NIFTI_GZ"
    >>> warputils.cmdline # doctest: +ELLIPSIS
    'convertwarp --ref=T1.nii --rel --warp1=warpfield.nii --out=T1_concatwarp.nii.gz'
    >>> res = warputils.run() # doctest: +SKIP


    ZconvertwarpN)	r    r!   r"   r)   r\  r+   rb  r,   r*   r%   r%   r%   r&   rc  `	  s   rc  c               @   sz   e Zd ZeddddddZedddgdd	Zedd
dgdd	ZejdddgddZ	ejdddgddZ
edddddZdS )WarpPointsBaseInputSpecTr   z%sz'filename of file containing coordinates)r   r   r   r   r   z-xfm %s	warp_filez3filename of affine transform (e.g. source2dest.mat))r   r   rL   r   z-warp %sxfm_filez:filename of warpfield (e.g. intermediate2dest_warp.nii.gz)z-voxcoord_mmz#all coordinates in voxels - default)r   rL   r   Fz-mm	coord_voxzall coordinates in mm	in_coordsz	%s_warpedr   zoutput file name)r   r   r   r   Nrp   )r    r!   r"   r   ri  rf  re  r	   r$   rh  rg  r   r%   r%   r%   r&   rd  z	  s8   rd  c               @   s,   e Zd ZedddddZedddddZdS )WarpPointsInputSpecTz-src %szfilename of source image)r   r   r   r   z-dest %szfilename of destination imageN)r    r!   r"   r   Zsrc_filer   r%   r%   r%   r&   rj  	  s   rj  c               @   s   e Zd ZedddZdS )WarpPointsOutputSpecTzBName of output file, containing the warp as field or coefficients.)r   r   N)r    r!   r"   r   r   r%   r%   r%   r&   rk  	  s   rk  c                   s   e Zd ZdZeZeZdZdZ	d fdd	Z
 fddZd fd	d
	ZdddZdd ZdddZdd Zdd Z fddZ  ZS )
WarpPointsa  Use FSL `img2imgcoord <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/flirt/overview.html>`_
    to transform point sets. Accepts plain text files and vtk files.

    .. Note:: transformation of TrackVis trk files is not yet implemented


    Examples
    --------

    >>> from nipype.interfaces.fsl import WarpPoints
    >>> warppoints = WarpPoints()
    >>> warppoints.inputs.in_coords = 'surf.txt'
    >>> warppoints.inputs.src_file = 'epi.nii'
    >>> warppoints.inputs.dest_file = 'T1.nii'
    >>> warppoints.inputs.warp_file = 'warpfield.nii'
    >>> warppoints.inputs.coord_mm = True
    >>> warppoints.cmdline # doctest: +ELLIPSIS
    'img2imgcoord -mm -dest T1.nii -src epi.nii -warp warpfield.nii surf.txt'
    >>> res = warppoints.run() # doctest: +SKIP


    Zimg2imgcoordstreamNc                s0   d | _ d | _d | _tt| jf d|i| d S )Ncommand)_tmpfile_in_file
_outformatrX   rl  __init__)rE   rn  r@   )r\   r%   r&   rr  	  s    zWarpPoints.__init__c                s    |dkrdS t t| j|||S )Nr   r   )rX   rl  rY   )rE   rH   rZ   r[   )r\   r%   r&   rY   	  s    zWarpPoints._format_argc                s   t j| jj\}}t| d| t| d|dd   tt| jddgd}|d }|dkr| jd krzt	j
dtj d
dj| _| j}||g S )Nrp  rq  r   ri  r   )r   z.txt.vtk.trkF)r=   dirdelete)rs  rt  )opsplitextr@   ri  r   rX   rl  r   ro  tempfileNamedTemporaryFilerB   r   rH   )rE   r   fnamer>   Z
first_argsZsecond_args)r\   r%   r&   r   	  s    

zWarpPoints._parse_inputsc       	      C   sz   ddl m} ddlm } |j r(td|j|d d}|j  |j|}|j}|d krjt	j
|d \}}tj|| |S )	Nr   )tvtkr   )vtkbasez/TVTK is required and tvtk package was not foundz.vtk)	file_namez.txt)r}  r|  
interfacesno_tvtkImportErrorPolyDataReaderupdate
vtk_outputpointsrw  rx  rU   savetxt)	rE   r#   r   r|  VTKInforeadermeshr  r$  r%   r%   r&   _vtk_to_coords	  s    
zWarpPoints._vtk_to_coordsc             C   st   ddl m} ddlm } |j r(td|j| jjd}|j  |j	|}||_
|j|d}|j|| |j  d S )Nr   )r|  r   )r}  z/TVTK is required and tvtk package was not found)r~  )r}  r|  r  r  r  r  r@   r#   r  r  r  ZPolyDataWriterZconfigure_input_datawrite)rE   r  r   r|  r  r  r  writerr%   r%   r&   _coords_to_vtk
  s    
zWarpPoints._coords_to_vtkc             C   sJ   ddl m} |j|}|j}|d kr2tj|\}}tj||d  |d S )Nr   )TrackvisFilez.txt)Znibabel.trackvisr  	from_filestreamlinesrw  rx  rU   r  )rE   r#   r   r  Ztrkfiler  r$  r%   r%   r&   _trk_to_coords
  s    
zWarpPoints._trk_to_coordsc             C   s   t dd S )Nztrk files are not yet supported)NotImplementedError)rE   r  r   r%   r%   r&   _coords_to_trk
  s    zWarpPoints._coords_to_trkc             C   s   |dkrd|t | df S d S )Nr   z%s.%srq  )rQ  )rE   r[   rH   r%   r%   r&   _overload_extension!
  s    zWarpPoints._overload_extensionc                s   t | d}t | d}d }|dkr6| j}| j||d n|dkrR| j}| j||d tt| j|}tjdj	|j
jddd  dd	}|d k	rytj|j W n   Y nX | jd
}|dkr| j|| n*|dkr| j|| ntj||jdd |S )Nrp  rq  Zvtk)r   Ztrkr   r   r   )sepr   r   rp   )rQ  ro  r  r  rX   rl  r   rU   
fromstringr   r   r   rB   removerH   Z_filename_from_sourcer  r  r  Zreshape)rE   r   r{  Z	outformatZtmpfileZ	newpointsr   )r\   r%   r&   r   %
  s.    

$
zWarpPoints._run_interface)N)N)N)N)r    r!   r"   r)   rj  r+   rk  r,   r*   _terminal_outputrr  rY   r   r  r  r  r  r  r   r]   r%   r%   )r\   r&   rl  	  s   

rl  c               @   s:   e Zd ZedddddZedddddZedddd	Zd
S )WarpPointsToStdInputSpecTz-img %szfilename of input image)r   r   r   r   z-std %szfilename of destination imagez
-premat %szEfilename of pre-warp affine transform (e.g. example_func2highres.mat))r   r   r   N)r    r!   r"   r   img_filestd_fileZpremat_filer%   r%   r%   r&   r  F
  s   r  c               @   s    e Zd ZdZeZeZdZdZ	dS )WarpPointsToStda,  
    Use FSL `img2stdcoord <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/flirt/overview.html>`_
    to transform point sets to standard space coordinates. Accepts plain text
    files and vtk files.

    .. Note:: transformation of TrackVis trk files is not yet implemented


    Examples
    --------

    >>> from nipype.interfaces.fsl import WarpPointsToStd
    >>> warppoints = WarpPointsToStd()
    >>> warppoints.inputs.in_coords = 'surf.txt'
    >>> warppoints.inputs.img_file = 'T1.nii'
    >>> warppoints.inputs.std_file = 'mni.nii'
    >>> warppoints.inputs.warp_file = 'warpfield.nii'
    >>> warppoints.inputs.coord_mm = True
    >>> warppoints.cmdline # doctest: +ELLIPSIS
    'img2stdcoord -mm -img T1.nii -std mni.nii -warp warpfield.nii surf.txt'
    >>> res = warppoints.run() # doctest: +SKIP


    Zimg2stdcoordZ
file_splitN)
r    r!   r"   r)   r  r+   rk  r,   r*   r  r%   r%   r%   r&   r  Y
  s
   r  c               @   s   e Zd ZedddddZedddddZeddddd	d
ZedddgddZedddgddZe	j
dddgddZe	j
dddgddZdS )WarpPointsFromStdInputSpecTz-img %szfilename of a destination image)r   r   r   r   z-std %sz'filename of the image in standard spacer   z%sz'filename of file containing coordinates)r   r   r   r   r   z-xfm %sre  z3filename of affine transform (e.g. source2dest.mat))r   r   rL   r   z-warp %srf  z:filename of warpfield (e.g. intermediate2dest_warp.nii.gz)z-voxrg  z#all coordinates in voxels - default)r   rL   r   Fz-mmrh  zall coordinates in mmNr   )r    r!   r"   r   r  r  ri  rf  re  r	   r$   rh  rg  r%   r%   r%   r&   r  y
  sB   r  c               @   s$   e Zd ZdZeZeZdZdd Z	dS )WarpPointsFromStda  
    Use FSL `std2imgcoord <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/flirt/overview.html>`_
    to transform point sets to standard space coordinates. Accepts plain text coordinates
    files.


    Examples
    --------

    >>> from nipype.interfaces.fsl import WarpPointsFromStd
    >>> warppoints = WarpPointsFromStd()
    >>> warppoints.inputs.in_coords = 'surf.txt'
    >>> warppoints.inputs.img_file = 'T1.nii'
    >>> warppoints.inputs.std_file = 'mni.nii'
    >>> warppoints.inputs.warp_file = 'warpfield.nii'
    >>> warppoints.inputs.coord_mm = True
    >>> warppoints.cmdline # doctest: +ELLIPSIS
    'std2imgcoord -mm -img T1.nii -std mni.nii -warp warpfield.nii surf.txt'
    >>> res = warppoints.run() # doctest: +SKIP


    Zstd2imgcoordc             C   s   | j  j }tjd|d< |S )Nzstdout.nipyper   )r,   r?   rw  rD   )rE   rF   r%   r%   r&   rG   
  s    zWarpPointsFromStd._list_outputsN)
r    r!   r"   r)   r  r+   rk  r,   r*   rG   r%   r%   r%   r&   r  
  s
   r  c               @   s   e Zd Ze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dddg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ddd	d
Zeddd d	dd!d"Zd#S )$MotionOutliersInputSpecTzunfiltered 4D imagez-i %s)r   r   r   r   z-o %sr#   z%s_outliers.txtzoutput outlier file nameF)r   r   r   keep_extensionr   r.   z-m %sz!mask image for calculating metric)r   r   r   ZrefrmsZdvarsZrefmsefdZfdrmsz--%sa	  metrics: refrms - RMS intensity difference to reference volume as metric [default metric], refmse - Mean Square Error version of refrms (used in original version of fsl_motion_outliers), dvars - DVARS, fd - frame displacement, fdrms - FD with RMS matrix calculation)r   r   z--thresh=%gzPspecify absolute threshold value (otherwise use box-plot cutoff = P75 + 1.5*IQR)z--nomocoz3do not run motion correction (assumed already done)z
--dummy=%dzJnumber of dummy scans to delete (before running anything and creating EVs)z-s %sz%s_metrics.txtz+output metric values (DVARS etc.) file namez-p %sz%s_metrics.pngz0output metric values plot (DVARS etc.) file name)r   r   r   r.   r  r   N)r    r!   r"   r   r#   r   r7   r	   rq   ZmetricrN   	thresholdr$   Zno_motion_correctionr0   dummyout_metric_valuesout_metric_plotr%   r%   r%   r&   r  
  sJ   
r  c               @   s*   e Zd ZeddZeddZeddZdS )MotionOutliersOutputSpecT)r   N)r    r!   r"   r   r   r  r  r%   r%   r%   r&   r  
  s   

r  c               @   s   e Zd ZdZeZeZdZdS )MotionOutliersa  
    Use FSL fsl_motion_outliers`http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FSLMotionOutliers`_ to find outliers in timeseries (4d) data.
    Examples
    --------
    >>> from nipype.interfaces.fsl import MotionOutliers
    >>> mo = MotionOutliers()
    >>> mo.inputs.in_file = "epi.nii"
    >>> mo.cmdline # doctest: +ELLIPSIS
    'fsl_motion_outliers -i epi.nii -o epi_outliers.txt -p epi_metrics.png -s epi_metrics.txt'
    >>> res = mo.run() # doctest: +SKIP
    Zfsl_motion_outliersN)	r    r!   r"   r)   r  r+   r  r,   r*   r%   r%   r%   r&   r    s   r  )pr)   rB   os.pathrC   rw  r   r   ry  numpyrU   Zutils.filemanipr   r   r   r   baser	   r
   r   r   r   r   r   r   r   r   r   r'   r(   r-   r2   r3   r4   r:   r;   rJ   rP   rQ   r^   ra   rc   ri   ru   rv   ry   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*  r,  r-  r.  r/  r0  r1  r2  r:  r;  r<  rO  rP  rT  rZ  r[  r\  rb  rc  rd  rj  rk  rl  r  r  r  r  r  r  r  r%   r%   r%   r&   <module>   s   
$	-14!+"B"+0&#;H^C_19= ^)4#!!U
KJl3 %  +"9