3
d                @   s  d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZ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
ZeddddddddddddddddZdddddddddddddddd dd!gZdgZejd"Zdd#d$Z d%d& 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/d0 d0e
Z&G d1d2 d2eZ'G d3d4 d4eZ(G d5d6 d6e
Z)G d7d8 d8eZ*G d9d: d:eZ+G d;d< d<e
Z,G d=d> d>eZ-G d?d@ d@eZ.G dAdB dBe
Z/G dCdD dDeZ0G dEdF dFeZ1G dGdH dHe
Z2G dIdJ dJeZ3G dKdL dLeZ4G dMdN dNe
Z5G dOdP dPeZ6G dQdR dReZ7G dSdT dTe
Z8G dUdV dVeZ9G dWdX dXeZ:G dYdZ dZe
Z;G d[d\ d\eZ<G d]d^ d^eZ=G d_d` d`e
Z>G dadb dbeZ?G dcdd ddeZ@G dedf dfe
ZAG dgdh dheZBG didj djeZCG dkdl dle
ZDG dmdn dneZEG dodp dpeZFG dqdr dre
ZGG dsdt dteZHG dudv dveZIG dwdx dxe
ZJG dydz dzeZKG d{d| d|eZLG d}d~ d~e
ZMG dd deZNG dd deZOG dd de
ZPG dd deZQG dd deZRG dd de
ZSG dd de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 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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ZG dd deZG dd de
ZG dd deZG dd deZG dd de
ZG dd deZG dd deZG dd de
ZG dd deZG dd deZG dd de
ZG dd deZG dd deZG dd  d e
ZG dd deZG dd deZG dd de
ZG dd deZG d	d
 d
eZG dd de
ZG dd deZG dd deZG dd de
ZG dd deZdS (  z4Interfaces to assorted Freesurfer utility programs.
    N   )logging)fname_presuffixsplit_filename   )TraitedSpec	DirectoryFiletraitsOutputMultiPath	isdefinedCommandLineCommandLineInputSpec   )	FSCommandFSTraitedSpecFSSurfaceCommandFSScriptCommandFSScriptOutputSpecFSTraitedSpecOpenMPFSCommandOpenMPZrestructuredtextcormghmgzZmncbrikbshortimgbfloatniiznii.gzgii)r   r   r   mincafnir   r   spmanalyze	analyze4dr   nifti1r   niigzr   r    r#   r$   r"   r!   ZsdtoutlineZotlZgdfr%   r&   znipype.interfacec             C   s   t |s|S t | jjr"| jj}ntj }|sHt | jjrD| jj}nd}|dkr\tjj|}|dk	rvtjj|||}ntjj||}tjj	|stj
| tjj||}tjj|stj|| |S )z1Method to copy an input to the subjects directory
subject_idN)r   inputssubjects_dirosgetcwdr(   pathbasenamejoinisdirmakedirsisfileshutilcopy)clsin_filefolderr.   r(   r*   out_dirout_file r:   D/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/freesurfer/utils.pycopy2subjdirM   s(    


r<   c             C   s<   x6t | j D ]&}tjj|}tjj|stj| qW dS )zNcreate all output directories. If not created, some freesurfer interfaces failN)listvaluesr+   r-   dirnamer0   r1   )outputsoutputr?   r:   r:   r;   createoutputdirsn   s    rB   c            
   @   s  e Zd Ze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Z
dddgZedddeddZejddgdeddZejdde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jd!dgd"d#Zejd$d%d&dd'd(gd)d*gd+d,Zejejejejejejd-d.Zejd/d0d1d.Zej	dd2gd3d4Zejd5d6dZejd7d8dZejd9d:d;d<dZejd=d>gd?d@ZeddAdBgdCdDZejdEdFdGdHdZejdIdJdZ ej	dKd.Z!ej	dLdMdZ"ejejej# dNdOgdPd#Z$ej%dQdOgdRd#Z&ejdSdTgdUd@Z'ejdVdWgdXd@Z(ej%dYdZdZ)ejd[d\dZ*ej%d]d^dZ+ed_dd`daZ,eje-e. dbdcdZ/ejejeddddedfdZ0eje-dgdhdZ1ejejedidjdZ2dkS )lSampleToSurfaceInputSpecTz--mov %szvolume to sample values from)exists	mandatoryargstrdescz--ref %sz&reference volume (default is orig.mgz))rD   rF   rG   lhrhz	--hemi %sztarget hemisphere)rE   rF   rG   z	--surf %sz!target surface (default is white))rF   rG   reg_file
reg_header	mni152regz--reg %sz%source-to-reference registration file)rD   rF   rE   xorrG   z--regheader %sr(   z!register based on header geometry)rF   requiresrE   rM   rG   z--mni152regz source volume is in MNI152 space)rF   rE   rM   rG   z--rot %.3f %.3f %.3fz3rotation angles (in degrees) to apply to reg matrixz--trans %.3f %.3f %.3fz*translation (in mm) to apply to reg matrixz--srcsubject %sz+override the subject in the reg file header)rF   rN   rG   pointmaxaveragez%sprojection_stemsampling_rangesampling_unitszAhow to sample -- at a point or at the max or average over a range)rE   rF   rM   rN   rG   z7sampling range - a point or a tuple of (min, max, step))rG   mmfracz,sampling range type -- either 'mm' or 'frac'sampling_methodz:stem for precomputed linear estimates and volume fractions)rE   rM   rG   z--fwhm %.3fzsmooth input volume (mm fwhm)z--surf-fwhm %.3fzsmooth output surface (mm fwhm)ZnearestZ	trilinearz--interp %szinterpolation methodz--cortex
mask_labelz.mask the target surface with hemi.cortex.label)rF   rM   rG   z	--mask %scortex_maskzlabel file to mask output with)rD   rF   rM   rG   roundZ
tkregisterz--float2int %sz6method to convert reg matrix values (default is round)z
--fixtkregz make reg matrix round-compatiblez
subject idz--trgsubject %sz2sample to surface of different subject than sourcez--surfreg %starget_subjectz*use surface registration to target subjectz--icoorder %dz.icosahedron order when target_subject is 'ico'z	--reshape
no_reshapez/reshape surface vector to fit in non-mgh formatz--noreshapereshapez'do not reshape surface vector (default)z--rf %dz number of 'slices' for reshapingz--scale %.3fz(multiple all intensities by scale factorz
--frame %dzsave only one frame (0-based)z--o %szsurface file to write)rF   genfilerG   z--out_type %szoutput file type)rD   z--srchit %sz,save image with number of hits at each voxelz--srchit_typezhits file typez	--nvox %sz<text file with the number of voxels intersecting the surfaceN)3__name__
__module____qualname__r	   source_fileZreference_filer
   EnumhemiStringsurfacereg_xorsrJ   BoolrK   rL   TupleFloatZ	apply_rotZapply_transoverride_reg_subjrW   EitherrS   rT   rR   Z
smooth_volZsmooth_surfZinterp_methodrY   rX   Zfloat2int_methodZ
fix_tk_regr(   r[   Strsurf_regIntZ	ico_orderr]   r\   Zreshape_slicesZscale_inputframer9   	filetypesimplicit_filetypesout_type	hits_fileZ	hits_typevox_filer:   r:   r:   r;   rC   v   s   






rC   c               @   s0   e Zd ZedddZedddZedddZdS )SampleToSurfaceOutputSpecTzsurface file)rD   rG   z'image with number of hits at each voxelz<text file with the number of voxels intersecting the surfaceN)r_   r`   ra   r	   r9   rt   ru   r:   r:   r:   r;   rv   #  s   rv   c                   sF   e Zd ZdZdZeZeZ fddZ	dddZ
dd	 Zd
d Z  ZS )SampleToSurfacea  Sample a volume to the cortical surface using Freesurfer's mri_vol2surf.

    You must supply a sampling method, range, and units.  You can project
    either a given distance (in mm) or a given fraction of the cortical
    thickness at that vertex along the surface normal from the target surface,
    and then set the value of that vertex to be either the value at that point
    or the average or maximum value found along the projection vector.

    By default, the surface will be saved as a vector with a length equal to the
    number of vertices on the target surface.  This is not a problem for Freesurfer
    programs, but if you intend to use the file with interfaces to another package,
    you must set the ``reshape`` input to True, which will factor the surface vector
    into a matrix with dimensions compatible with proper Nifti files.

    Examples
    --------

    >>> import nipype.interfaces.freesurfer as fs
    >>> sampler = fs.SampleToSurface(hemi="lh")
    >>> sampler.inputs.source_file = "cope1.nii.gz"
    >>> sampler.inputs.reg_file = "register.dat"
    >>> sampler.inputs.sampling_method = "average"
    >>> sampler.inputs.sampling_range = 1
    >>> sampler.inputs.sampling_units = "frac"
    >>> sampler.cmdline  # doctest: +ELLIPSIS
    'mri_vol2surf --hemi lh --o ...lh.cope1.mgz --reg register.dat --projfrac-avg 1.000 --mov cope1.nii.gz'
    >>> res = sampler.run() # doctest: +SKIP

    Zmri_vol2surfc       
         sL  |dkr`| j j}| j j}|dkr$d}t|tr8d| }nd| }tdddd	| }d
|||f S |dkrv|j| j j S |dkr|j| j j S |dkr|j| j| S |dkrt	| j j
rt| j \}}}	|	t| kr|	tj krtdj||	ntjd||	||	 |tkrdS |dkr8|dkr8|jd S tt| j|||S )NrW   rU   distz%.3f %.3f %.3fz%.3f z-maxz-avg)rO   rP   rQ   z--proj%s%s %srK   rk   rt   ru   rs   z'Cannot create {} file with extension {}z(Creating %s file with extension %s: %s%srn   Tz
sphere.reg)rt   ru   )r)   rS   rT   
isinstancetupledictrF   r(   _get_outfilenamer   r9   r   filemapr>   
ValueErrorformatloggerwarningrr   superrw   _format_arg)
selfnamespecvaluerangeZunitsmethod_baseext)	__class__r:   r;   r   O  sH    






zSampleToSurface._format_argr9   c             C   s   t | j|}t| s t|trt| jjrX|dkrFdt| jj  }qjdt| jj  }n|dkrfd}nd}t| jjt	j
 | jjd |dd}|S )Nrt   z_hits..z	_hits.mgzz.mgzF)newpathprefixsuffixuse_ext)getattrr)   r   rz   boolrs   r~   r   rb   r+   r,   rd   )r   optoutfiler   r:   r:   r;   r}   |  s     
z SampleToSurface._get_outfilenamec             C   s   | j  j }tjj| j |d< | jj}t|rL||d< t	|t
rL| jd}| jj}t|rt	|t
rt| jjtj | jjd ddd}||d< |S )Nr9   rt   r   z_vox.txtF)r   r   r   r   ru   )_outputsgetr+   r-   abspathr}   r)   rt   r   rz   r   ru   r   rb   r,   rd   )r   r@   ZhitsfileZvoxfiler:   r:   r;   _list_outputs  s$    



zSampleToSurface._list_outputsc             C   s   |dkr| j  | S d S )Nr9   )r   )r   r   r:   r:   r;   _gen_filename  s    zSampleToSurface._gen_filename)r9   )r_   r`   ra   __doc___cmdrC   
input_specrv   output_specr   r}   r   r   __classcell__r:   r:   )r   r;   rw   ,  s   -
rw   c               @   s   e Zd ZeddddZejddddZej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ddZejdddZeddddZdS )SurfaceSmoothInputSpecTz	--sval %szsource surface file)rE   rF   rG   z--s %szsubject id of surface filerH   rI   z	--hemi %szhemisphere to operate on)rF   rE   rG   z--fwhm %.4fsmooth_itersz'effective FWHM of the smoothing process)rF   rM   rG   z--smooth %dfwhmz#iterations of the smoothing processz--cortexz)only smooth within ``$hemi.cortex.label``)rF   
usedefaultrG   z	--reshapez/reshape surface vector to fit in non-mgh format)rF   rG   z	--tval %szsurface file to write)rF   r^   rG   N)r_   r`   ra   r	   r6   r
   re   r(   rc   rd   rj   r   ro   r   rh   cortexr]   r9   r:   r:   r:   r;   r     s&   
r   c               @   s   e Zd ZedddZdS )SurfaceSmoothOutputSpecTzsmoothed surface file)rD   rG   N)r_   r`   ra   r	   r9   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 )SurfaceSmootha  Smooth a surface image with mri_surf2surf.

    The surface is smoothed by an interative process of averaging the
    value at each vertex with those of its adjacent neighbors. You may supply
    either the number of iterations to run or a desired effective FWHM of the
    smoothing process.  If the latter, the underlying program will calculate
    the correct number of iterations internally.

    See Also
    --------
    `nipype.interfaces.freesurfer.utils.SmoothTessellation`_ interface for
    smoothing a tessellated surface (e.g. in gifti or .stl)

    Examples
    --------
    >>> import nipype.interfaces.freesurfer as fs
    >>> smoother = fs.SurfaceSmooth()
    >>> smoother.inputs.in_file = "lh.cope1.mgz"
    >>> smoother.inputs.subject_id = "subj_1"
    >>> smoother.inputs.hemi = "lh"
    >>> smoother.inputs.fwhm = 5
    >>> smoother.cmdline # doctest: +ELLIPSIS
    'mri_surf2surf --cortex --fwhm 5.0000 --hemi lh --sval lh.cope1.mgz --tval ...lh.cope1_smooth5.mgz --s subj_1'
    >>> smoother.run() # doctest: +SKIP

    mri_surf2surfc             C   sh   | j  j }| jj|d< t|d sd| jj}t| jjrB| jj}n| jj}t|d| t	j
 d|d< |S )Nr9   z	_smooth%d)r   r   )r   r   r)   r9   r   r6   r   r   r   r+   r,   )r   r@   r6   kernelr:   r:   r;   r     s    
zSurfaceSmooth._list_outputsc             C   s   |dkr| j  | S d S )Nr9   )r   )r   r   r:   r:   r;   r     s    zSurfaceSmooth._gen_filenameN)r_   r`   ra   r   r   r   r   r   r   r   r   r:   r:   r:   r;   r     s   r   c               @   s   e Zd ZeddddgddZeddddgddZejdd	d
dZej	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d	Zej	eddgddZej	ee d d!dZejd"d#dZejd$d%dZed&dd'd(Zd)S )*SurfaceTransformInputSpecTz	--sval %ssource_annot_filezsurface file with source values)rD   rE   rF   rM   rG   z--sval-annot %srb   zsurface annotation filez--srcsubject %szsubject id for source surface)rE   rF   rG   rH   rI   z	--hemi %szhemisphere to transform)rF   rE   rG   z--trgsubject %szsubject id of target surfacer   r   r               z--trgicoorder %dz3order of the icosahedron if target_subject is 'ico')rF   rG   z	--sfmt %szsource file format)rF   rN   rG   z	--tfmt %szoutput formatz	--reshapez,reshape output surface to conform with Niftiz--reshape-factorz"number of slices in reshaped imagez	--tval %szsurface file to write)rF   r^   rG   N)r_   r`   ra   r	   rb   r   r
   re   Zsource_subjectrc   rd   r[   Ztarget_ico_orderrq   Zsource_typerr   target_typerh   r]   ro   Zreshape_factorr9   r:   r:   r:   r;   r     sP   

r   c               @   s   e Zd ZedddZdS )SurfaceTransformOutputSpecTztransformed surface file)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   r   7  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 )	SurfaceTransforma{  Transform a surface file from one subject to another via a spherical registration.

    Both the source and target subject must reside in your Subjects Directory,
    and they must have been processed with recon-all, unless you are transforming
    to one of the icosahedron meshes.

    Examples
    --------

    >>> from nipype.interfaces.freesurfer import SurfaceTransform
    >>> sxfm = SurfaceTransform()
    >>> sxfm.inputs.source_file = "lh.cope1.nii.gz"
    >>> sxfm.inputs.source_subject = "my_subject"
    >>> sxfm.inputs.target_subject = "fsaverage"
    >>> sxfm.inputs.hemi = "lh"
    >>> sxfm.run() # doctest: +SKIP

    r   c                s   |dkrrt | jjrft| j d \}}}|t| krf|tj krTtdj||nt	j
d|||| |tkrrdS tt| j|||S )Nr   r9   z'Cannot create {} file with extension {}z(Creating %s file with extension %s: %s%sry   )r   r)   r9   r   r   r~   r>   r   r   r   r   rr   r   r   r   )r   r   r   r   r   r   r   )r   r:   r;   r   S  s"    zSurfaceTransform._format_argc             C   s   | j  j }| jj|d< t|d st| jjr:| jj}n| jj}dd dD }d}t|d |krp|d }d}d}t| jjrdt	| jj  }d}t
|d| jj|f tj |d|d< ntjj| jj|d< |S )Nr9   c             S   s   g | ]}d | qS )z.%sr:   ).0er:   r:   r;   
<listcomp>u  s   z2SurfaceTransform._list_outputs.<locals>.<listcomp>areamidpialavg_curvcurvinflatedjacobian_whiteorignofixsmoothwmcrvspheresulc	thicknessvolumewhiteTr   z.stripmeFry   r   z.%s%s)r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r)   r9   r   rb   r   r   r   r~   r   r[   r+   r,   r-   r   )r   r@   sourceZbad_extensionsr   r   r:   r:   r;   r   i  sL    
               zSurfaceTransform._list_outputsc             C   s   |dkr| j  | S d S )Nr9   )r   )r   r   r:   r:   r;   r     s    zSurfaceTransform._gen_filename)r_   r`   ra   r   r   r   r   r   r   r   r   r   r   r:   r:   )r   r;   r   ;  s   2r   c               @   s   e Zd ZedddddgddZejdddd	Zed
dddgddZedddddgdZ	eddddZ
ejdddgdZedd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%gd&Zd'S )(Surface2VolTransformInputSpecTz--surfval %sFmkmaskz(This is the source of the surface values)rD   rF   copyfilerE   rM   rG   z	--hemi %szhemisphere of data)rF   rE   rG   z%s_asVol.niizOutput volumez--outvol %srb   )name_templaterG   rF   name_source
hash_filesz--volreg %sz,tkRAS-to-tkRAS matrix   (tkregister2 format)r(   )rD   rF   rE   rG   rM   z--template %szOutput template volume)rD   rF   rG   z-make a mask instead of loading surface valuesz--mkmask)rG   rF   rM   z%s_asVol_vertex.niizPath name of the vertex output volume, which is the same as output volume except that the value of each voxel is the vertex-id that is mapped to that voxel.z--vtxvol %sz	--surf %szsurfname (default is white))rF   rG   z--projfrac %szthickness fractionz--sd %sz7freesurfer subjects directory defaults to $SUBJECTS_DIRz--identity %sz
subject idrJ   )rF   rG   rM   N)r_   r`   ra   r	   rb   r
   rm   rd   transformed_filerJ   Ztemplate_filerh   r   vertexvol_fileZ	surf_namerj   Zprojfracr*   r(   r:   r:   r:   r;   r     sL   

r   c               @   s"   e Zd ZedddZeddZdS )Surface2VolTransformOutputSpecTz$Path to output file if used normally)rD   rG   z#vertex map volume path id. Optional)rG   N)r_   r`   ra   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 )Surface2VolTransforma  Use FreeSurfer mri_surf2vol to apply a transform.

    Examples
    --------

    >>> from nipype.interfaces.freesurfer import Surface2VolTransform
    >>> xfm2vol = Surface2VolTransform()
    >>> xfm2vol.inputs.source_file = 'lh.cope1.mgz'
    >>> xfm2vol.inputs.reg_file = 'register.mat'
    >>> xfm2vol.inputs.hemi = 'lh'
    >>> xfm2vol.inputs.template_file = 'cope1.nii.gz'
    >>> xfm2vol.inputs.subjects_dir = '.'
    >>> xfm2vol.cmdline
    'mri_surf2vol --hemi lh --volreg register.mat --surfval lh.cope1.mgz --sd . --template cope1.nii.gz --outvol lh.cope1_asVol.nii --vtxvol lh.cope1_asVol_vertex.nii'
    >>> res = xfm2vol.run()# doctest: +SKIP

    Zmri_surf2volN)	r_   r`   ra   r   r   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dd!dddZedgd	ddd"dddZeddddZej	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Zej	dddZejdddZdS )#ApplyMaskInputSpecTr   z%szinput image (will be masked))rD   rE   positionrF   rG   r   zimage defining mask spacer6   z	%s_maskedr   zfinal image to write)r   r   r   keep_extensionr   rF   rG   z	-xform %sz9LTA-format transformation matrix to align mask with input)rD   rF   rG   z-invertzinvert transformation)rF   rG   z-lta_src %sz%image defining transform source spacez-lta_dst %sz%image defining transform target spacez-absz+take absolute value of mask before applyingz-T %.4fzthreshold mask before applyingz-keep_mask_deletion_editsz=transfer voxel-deletion edits (voxels=1) from mask to out volz-transfer %dz,transfer only voxel value # from mask to outN)r_   r`   ra   r	   r6   Z	mask_filer9   Zxfm_filer
   rh   Z
invert_xfmZ
xfm_sourceZ
xfm_targetZuse_absrj   Zmask_threshZkeep_mask_deletion_editsro   Ztransferr:   r:   r:   r;   r     sJ   
r   c               @   s   e Zd ZedddZdS )ApplyMaskOutputSpecTzmasked image)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   r   %  s   r   c               @   s   e Zd ZdZdZeZeZdS )	ApplyMaskzUse Freesurfer's mri_mask to apply a mask to an image.

    The mask file need not be binarized; it can be thresholded above a given
    value before application. It can also optionally be transformed into input
    space with an LTA matrix.

    Zmri_maskN)	r_   r`   ra   r   r   r   r   r   r   r:   r:   r:   r;   r   *  s   r   c               @   s"  e Zd ZejdddddZejdddddd	dZejd
ddddZej	dddgdZ
ej	dddgdZeddddgdZdddgZeddeddZej	deddZej	d ed!dZejejejejej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ej	d+d,d&Zej	d-d.d&Zedd/d0gd1dZejd/d2gd3dZedd4d5gd6dZejd4d7gd8dZedd9d:d;Zej	d<d=d&Z ej	d>d?d&Z!edd@dAd;Z"ejdBdCd&Z#ejdDdEd&Z$ej	dFdGd&Z%ej	dHdId&Z&ej	dJdKZ'ejdLdKZ(ej)ejdMgdNdOZ*eddddPdQZ+dRS )SSurfaceSnapshotsInputSpecr   z%sTzsubject to visualize)r   rF   rE   rG   rH   rI   r   zhemisphere to visualizer   zsurface to visualizez-curvzshow curvatureshow_gray_curv)rF   rG   rM   z-grayzshow curvature in gray	show_curvz-overlay %szload an overlay volume/surfaceoverlay_range)rD   rF   rG   rN   overlay_regidentity_reg
mni152_regz-overlay-reg %sz7registration matrix file to register overlay to surface)rD   rF   rM   rG   z-overlay-reg-identityz>use the identity matrix to register the overlay to the surface)rF   rM   rG   z
-mni152regz>use to display a volume in MNI152 space on the average subjectz8overlay range--either min, (min, max) or (min, mid, max))rG   rF   z-foffset %.3fz3overlay range will be symettric around offset value)rF   rG   z-truncphaseflag 1ztruncate the overlay displayz-revphaseflag 1zreverse the overlay displayz-invphaseflag 1zinvert the overlay displayz-zmzremove mean from overlayz-annotation %s
annot_namez"path to annotation file to display
annot_filezBname of annotation to display (must be in $subject/label directoryz	-label %s
label_namezpath to label file to display
label_filez=name of label to display (must be in $subject/label directoryz-colortable %szload colortable file)rD   rF   rG   z-labels-underz#draw label/annotation under overlayz-label-outlinez draw label/annotation as outlinez	-patch %szload a patchz-orig %sz"set the orig surface suffix stringz
-sphere %sz set the sphere.reg suffix stringz-colscalebarflag 1zdisplay the color scale barz-colscaletext 1z#display text in the color scale barz*also take anterior and posterior snapshots)rG   z%stem to use for screenshot file namesscreenshot_stemzCinput names to use as arguments for a string-formated stem template)rN   rG   z"override default screenshot script)rD   rF   r^   rG   N),r_   r`   ra   r
   re   r(   rc   rd   rf   rh   r   r   r	   Zoverlayrg   r   r   r   rl   rj   ri   r   Zoverlay_range_offsetZtruncate_overlayZreverse_overlayZinvert_overlayZdemean_overlayr   r   r   r   Z
colortableZlabel_underZlabel_outlineZ
patch_fileZorig_suffixZsphere_suffixZshow_color_scaleZshow_color_text
six_imagesr   Liststem_template_args
tcl_scriptr:   r:   r:   r;   r   8  s   










r   c               @   s   e Zd ZeeddddZdS )SurfaceSnapshotsOutputSpecT)rD   z6tiff images of the surface from different perspectives)rG   N)r_   r`   ra   r   r	   	snapshotsr:   r:   r:   r;   r     s   r   c                   sP   e Zd ZdZdZeZeZ fddZ	 fddZ
dd Zd	d
 Zdd Z  ZS )SurfaceSnapshotsa  Use Tksurfer to save pictures of the cortical surface.

    By default, this takes snapshots of the lateral, medial, ventral,
    and dorsal surfaces.  See the ``six_images`` option to add the
    anterior and posterior surfaces.

    You may also supply your own tcl script (see the Freesurfer wiki for
    information on scripting tksurfer). The screenshot stem is set as the
    environment variable "_SNAPSHOT_STEM", which you can use in your
    own scripts.

    Node that this interface will not run if you do not have graphics
    enabled on your system.

    Examples
    --------

    >>> import nipype.interfaces.freesurfer as fs
    >>> shots = fs.SurfaceSnapshots(subject_id="fsaverage", hemi="lh", surface="pial")
    >>> shots.inputs.overlay = "zstat1.nii.gz"
    >>> shots.inputs.overlay_range = (2.3, 6)
    >>> shots.inputs.overlay_reg = "register.dat"
    >>> res = shots.run() # doctest: +SKIP

    Ztksurferc                s   |dkrt |sdS d| S n|dkrht|tr8d| S t|dkrLd| S d|d	 |d |d
 f S nV|dkrt |r|jdr|d d }tjd| jj |d d r|dd  }d| S t	t
| j|||S )Nr   z-tcl snapshots.tclz-tcl %sr   z-fthresh %.3fr   z-fminmax %.3f %.3fz-fminmax %.3f %.3f -fmid %.3fr   r   r   z.annotr   z	%s[\.\-_]r   z-annotation %si)r   rz   floatlenendswithrematchr)   rd   r   r   r   )r   r   r   r   )r   r:   r;   r     s(    


zSurfaceSnapshots._format_argc                s   t  jjs(d jj jj jjf }n6 jj} jj}t |r^t fdd|D }|| }dtj	krpt
d||j	d<  j  tt j|}ddg}x |D ]}||jkr j| qW d	|_|S )
Nz%s_%s_%sc                s   g | ]}t  j|qS r:   )r   r)   )r   arg)r   r:   r;   r     s    z3SurfaceSnapshots._run_interface.<locals>.<listcomp>ZDISPLAYz/Graphics are not enabled -- cannot run tksurferZ_SNAPSHOT_STEMz)surfer: failed, no suitable display foundz3Fatal Error in tksurfer.bin: could not open displayr   )r   r)   r   r(   rd   rf   r   r{   r+   environRuntimeError_write_tcl_scriptr   r   _run_interfacestderrraise_exception
returncode)r   runtimestem	stem_argsargserrorserr)r   )r   r;   r      s,    



zSurfaceSnapshots._run_interfacec             C   s|   t dd}ddddddddd	dd
ddg}t| jjrV| jjrV|jddddddddg |jd |jdj| |j  d S )Nzsnapshots.tclwz&save_tiff $env(_SNAPSHOT_STEM)-lat.tifZmake_lateral_viewzrotate_brain_y 180Zredrawz&save_tiff $env(_SNAPSHOT_STEM)-med.tifzrotate_brain_x 90z&save_tiff $env(_SNAPSHOT_STEM)-ven.tifzrotate_brain_x -90z&save_tiff $env(_SNAPSHOT_STEM)-dor.tifzrotate_brain_y 90z&save_tiff $env(_SNAPSHOT_STEM)-pos.tifzrotate_brain_y -90z&save_tiff $env(_SNAPSHOT_STEM)-ant.tifexit
)	openr   r)   r   extendappendwriter/   close)r   Zfidscriptr:   r:   r;   r   "  s6    

z"SurfaceSnapshots._write_tcl_scriptc                s    j  j }t jjs4d jj jj jjf n6 jj jj}t|rjt	 fdd|D }| ddddg} jj
r|jdd	g  fd
d|D }||d< |S )Nz%s_%s_%sc                s   g | ]}t  j|qS r:   )r   r)   )r   r   )r   r:   r;   r   Q  s    z2SurfaceSnapshots._list_outputs.<locals>.<listcomp>z
%s-lat.tifz
%s-med.tifz
%s-dor.tifz
%s-ven.tifz
%s-pos.tifz
%s-ant.tifc                s   g | ]} j | d dqS )ry   )r   )
_gen_fname)r   f)r   r   r:   r;   r   V  s    r   )r   r   r   r)   r   r(   rd   rf   r   r{   r   r  )r   r@   r   r   r   r:   )r   r   r;   r   E  s"    zSurfaceSnapshots._list_outputsc             C   s   |dkrdS d S )Nr   zsnapshots.tclr:   )r   r   r:   r:   r;   r   Z  s    zSurfaceSnapshots._gen_filename)r_   r`   ra   r   r   r   r   r   r   r   r   r   r   r   r   r:   r:   )r   r;   r     s   "#r   c               @   s   e Zd ZedddddZdS )ImageInfoInputSpecTr   z%szimage to query)rD   r   rF   rG   N)r_   r`   ra   r	   r6   r:   r:   r:   r;   r  `  s   r  c               @   s   e Zd ZejddZedddZejddZ	ejddZ
ejddZejd	dZejd
dZejddZejddZejddZejddZdS )ImageInfoOutputSpeczoutput of mri_info)rG   Tz text file with image information)rD   rG   zimage data typezfile formatzecho time (msec)zrepetition time(msec)zinversion time (msec)zimage dimensions (voxels)zvoxel sizes (mm)zimage orientationzphase encode directionN)r_   r`   ra   r
   ZAnyinfor	   r9   re   	data_typefile_formatTETRTIri   
dimensions	vox_sizesorientation
ph_enc_dirr:   r:   r:   r;   r  e  s   r  c               @   s,   e Zd ZdZeZeZdddZd	ddZ	dS )
	ImageInfoZmri_infor  c             C   s*   t jd||f |}|r"|jdS d S d S )Nz%s\s*:\s+(.+?)%sr   )r   searchgroup)r   r  fielddelimmr:   r:   r;   info_regexpz  s    
zImageInfo.info_regexpNc             C   s   | j  }|j}||_x<dD ]4}| j||d}|jdrB|d d }t||| qW | j|d}t|jd}||_| j|d}td	d
 |jdD }||_	| j|d|_
| j|d|_tjdd |\}	}
|	|_|
|_|S )Nr  r  r  z, z msecr   zvoxel sizesr  c             S   s   g | ]}t |qS r:   )int)r   dr:   r:   r;   r     s    z/ImageInfo.aggregate_outputs.<locals>.<listcomp>z x ZOrientationZPhEncDirz%s\s*:\s+(.+?)\ntype)r  r  r  )r   stdoutr  r  r   setattrr{   splitr  r  r  r  r   findallr  r  )r   r   Zneeded_outputsr@   r  r  ZfieldvalZvoxZdimZftypeZdtyper:   r:   r;   aggregate_outputs  s(    

zImageInfo.aggregate_outputs)r  )NN)
r_   r`   ra   r   r  r   r  r   r  r&  r:   r:   r:   r;   r  t  s
   
r  c               @   sH  e Zd 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
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ddd<d%d&d'Zed%d=dd)gdd*d+Zejd,d-d.d/d0d1d2d3d4gdd5d6Zejd7d8dZejd9d:dZd;S )>MRIsConvertInputSpeczT
    Uses Freesurfer's mris_convert to convert surface files to various formats
    Tz
--annot %sz'input is annotation or gifti label data)rD   rF   rG   z--parcstats %sz6infile is name of text file containing label/val pairsz
--label %sz2infile is .label file, label is name of this labelz-c %sz>input is scalar curv overlay file (must still specify surface)z-f %szPinput is functional time-series or other multi-frame data (must specify surface)Fz--labelstats %szBoutfile is name of gifti file to which label stats will be writtenz-pz$input is a patch, not a full surface)rF   rG   z-rz9rescale vertex xyz so total area is same as group averagez-nz)output is an ascii file where vertex dataz-az$Print only surface xyz to ascii filez-vz,Writes out neighbors of a vertex in each rowz-s %.3fzscale vertex xyz by scalez--da_num %dz:if input is gifti, 'num' specifies which data array to usez-t %sz,apply talairach xfm of subject to vertex xyzz-o %szread orig positionsr   z%szFile to read/convert)rD   rE   r   rF   rG   r   out_datatypez'output filename or True to generate one)rF   r   r^   rM   rE   rG   ZascZicoZtristlZvtkr   r   r   r9   zThese file formats are supported:  ASCII:       .ascICO: .ico, .tri GEO: .geo STL: .stl VTK: .vtk GIFTI: .gii MGH surface-encoded 'volume': .mgh, .mgz)rM   rE   rG   z--to-scannerzAconvert coordinates from native FS (tkr) coords to scanner coordsz--to-tkrzAconvert coordinates from scanner coords to native FS (tkr) coordsNr   r   )r_   r`   ra   r   r	   r   parcstats_filer   scalarcurv_filefunctional_fileZlabelstats_outfiler
   rh   patchZrescaleZnormalZ	xyz_asciiZvertexrj   Zscalero   Zdataarray_numre   Ztalairachxfm_subjidZorignamer6   r9   rc   r(  Z
to_scannerZto_tkrr:   r:   r:   r;   r'    s   


r'  c               @   s   e Zd ZdZedddZdS )MRIsConvertOutputSpeczT
    Uses Freesurfer's mris_convert to convert surface files to various formats
    Tzconverted output surface)rD   rG   N)r_   r`   ra   r   r	   	convertedr:   r:   r:   r;   r.    s   r.  c                   sD   e Zd ZdZdZeZeZ fddZ	dd Z
dd Zd	d
 Z  ZS )MRIsConverta5  
    Uses Freesurfer's mris_convert to convert surface files to various formats

    Example
    -------

    >>> import nipype.interfaces.freesurfer as fs
    >>> mris = fs.MRIsConvert()
    >>> mris.inputs.in_file = 'lh.pial'
    >>> mris.inputs.out_datatype = 'gii'
    >>> mris.run() # doctest: +SKIP
    mris_convertc                s6   |dkr"t jj| r"t jj|}tt| j|||S )Nr9   )r+   r-   isabsr   r   r0  r   )r   r   r   r   )r   r:   r;   r     s    zMRIsConvert._format_argc             C   s$   | j  j }tjj| j |d< |S )Nr/  )r   r   r+   r-   r   _gen_outfilename)r   r@   r:   r:   r;   r   #  s    zMRIsConvert._list_outputsc             C   s    |dkrt jj| j S d S d S )Nr9   )r+   r-   r   r3  )r   r   r:   r:   r;   r   (  s    zMRIsConvert._gen_filenamec             C   s   t | jjr| jjS t | jjr4t| jj\}}}nt | jjrTt| jj\}}}n~t | jjrtt| jj\}}}n^t | jjrt| jj\}}}n>t | jjrt| jj\}}}nt | jj	rt| jj	\}}}|| d | jj
 S )Nz_converted.)r   r)   r9   r   r   r*  r   r+  r,  r6   r(  )r   r   r   r   r:   r:   r;   r3  .  s    zMRIsConvert._gen_outfilename)r_   r`   ra   r   r   r'  r   r.  r   r   r   r   r3  r   r:   r:   )r   r;   r0    s   r0  c            	   @   s@   e Zd ZdZejedddddddddZed	dddd
dZdS )MRIsCombineInputSpeczO
    Uses Freesurfer's mris_convert to combine two surface files into one.
    T)ZExistsr   r   z--combinesurfs %szTwo surfaces to be combined.)maxlenZminlenrE   r   rF   rG   z%sz1Output filename. Combined surfaces from in_files.)rF   r   r^   rE   rG   Nr   )	r_   r`   ra   r   r
   r   r	   Zin_filesr9   r:   r:   r:   r;   r4  A  s   r4  c               @   s   e Zd ZdZedddZdS )MRIsCombineOutputSpeczO
    Uses Freesurfer's mris_convert to combine two surface files into one.
    Tz1Output filename. Combined surfaces from in_files.)rD   rG   N)r_   r`   ra   r   r	   r9   r:   r:   r:   r;   r6  X  s   r6  c               @   s,   e Zd ZdZdZeZeZdd Z	dd Z
dS )MRIsCombineaI  
    Uses Freesurfer's ``mris_convert`` to combine two surface files into one.

    For complete details, see the `mris_convert Documentation.
    <https://surfer.nmr.mgh.harvard.edu/fswiki/mris_convert>`_

    If given an ``out_file`` that does not begin with ``'lh.'`` or ``'rh.'``,
    ``mris_convert`` will prepend ``'lh.'`` to the file name.
    To avoid this behavior, consider setting ``out_file = './<filename>'``, or
    leaving out_file blank.

    In a Node/Workflow, ``out_file`` is interpreted literally.

    Example
    -------

    >>> import nipype.interfaces.freesurfer as fs
    >>> mris = fs.MRIsCombine()
    >>> mris.inputs.in_files = ['lh.pial', 'rh.pial']
    >>> mris.inputs.out_file = 'bh.pial'
    >>> mris.cmdline
    'mris_convert --combinesurfs lh.pial rh.pial bh.pial'
    >>> mris.run()  # doctest: +SKIP
    r1  c             C   s^   | j  j }tjj| jj\}}|dkr@|d d dkr@d| }tjjtjj|||d< |S )Nry   r   lh.rh.r9   )r8  r9  )	r   r   r+   r-   r$  r)   r9   r   r/   )r   r@   r-   r   r:   r:   r;   r     s    zMRIsCombine._list_outputsc             C   s$   t | jjr tjj| jj| j_dS )z
        Filename normalization routine to perform only when run in Node
        context.
        Interpret out_file as a literal path to reduce surprise.
        N)r   r)   r9   r+   r-   r   )r   r:   r:   r;   normalize_filenames  s    zMRIsCombine.normalize_filenamesN)r_   r`   ra   r   r   r4  r   r6  r   r   r:  r:   r:   r:   r;   r7  b  s   r7  c               @   s`   e Zd ZdZeddddddZej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dS )MRITessellateInputSpeczb
    Uses Freesurfer's mri_tessellate to create surfaces by tessellating a given input volume
    Tr   z%sz&Input volume to tesselate voxels from.)rD   rE   r   rF   rG   r   z%dzvLabel value which to tesselate from the input volume. (integer, if input is "filled.mgz" volume, 127 is rh, 255 is lh))r   rF   rE   rG   r   z'output filename or True to generate one)rF   r   r^   rG   z-az:Tessellate the surface of all voxels with different labels)rF   rG   z-nz<Saves surface with real RAS coordinates where c_(r,a,s) != 0Nr   r   r   )r_   r`   ra   r   r	   r6   r
   ro   label_valuer9   rh   Ztesselate_all_voxelsZuse_real_RAS_coordinatesr:   r:   r:   r;   r;    s*   
r;  c               @   s   e Zd ZdZedddZdS )MRITessellateOutputSpeczb
    Uses Freesurfer's mri_tessellate to create surfaces by tessellating a given input volume
    Tz#binary surface of the tessellation )rD   rG   N)r_   r`   ra   r   r	   rf   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 )
MRITessellatear  
    Uses Freesurfer's mri_tessellate to create surfaces by tessellating a given input volume

    Example
    -------

    >>> import nipype.interfaces.freesurfer as fs
    >>> tess = fs.MRITessellate()
    >>> tess.inputs.in_file = 'aseg.mgz'
    >>> tess.inputs.label_value = 17
    >>> tess.inputs.out_file = 'lh.hippocampus'
    >>> tess.run() # doctest: +SKIP
    Zmri_tessellatec             C   s$   | j  j }tjj| j |d< |S )Nrf   )r   r   r+   r-   r   r3  )r   r@   r:   r:   r;   r     s    zMRITessellate._list_outputsc             C   s   |dkr| j  S d S d S )Nr9   )r3  )r   r   r:   r:   r;   r     s    zMRITessellate._gen_filenamec             C   sB   t | jjr| jjS t| jj\}}}|| d t| jj S d S )Nr   )r   r)   r9   r   r6   strr<  )r   r   r   r   r:   r:   r;   r3    s    zMRITessellate._gen_outfilenameN)r_   r`   ra   r   r   r;  r   r=  r   r   r   r3  r:   r:   r:   r;   r>    s   r>  c            
   @   s   e Zd ZeddddddZejejdejddddddd	d
Z	eddddddZ
edddg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dS )MRIPretessInputSpecTr   z%szfilled volume, usually wm.mgz)rD   rE   r   rF   rG   wmr   r   znlabel to be picked up, can be a Freesurfer's string like 'wm' or a label value (e.g. 127 for rh or 255 for lh))rF   defaultrE   r   r   rG   r   z;the normalized, brain-extracted T1w image. Usually norm.mgz	in_filledz%s_pretesswmz"the output file after mri_pretess.)r   rF   r   r   r   rG   Fz
-nocornersz=do not remove corner configurations in addition to edge ones.)rF   rG   z-keepzkeep WM editsz-testzadds a voxel that should be removed by mri_pretess. The value of the voxel is set to that of an ON-edited WM, so it should be kept with -keep. The output will NOT be saved.Nr   r   r   )r_   r`   ra   r	   rC  r
   rl   rm   ro   labelZin_normr9   rh   Z	nocornersZkeeptestr:   r:   r:   r;   r@    sJ   r@  c               @   s   e Zd ZedddZdS )MRIPretessOutputSpecTzoutput file after mri_pretess)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   rG    s   rG  c               @   s   e Zd ZdZdZeZeZdS )
MRIPretessaV  
    Uses Freesurfer's mri_pretess to prepare volumes to be tessellated.

    Changes white matter (WM) segmentation so that the neighbors of all
    voxels labeled as WM have a face in common - no edges or corners
    allowed.

    Example
    -------
    >>> import nipype.interfaces.freesurfer as fs
    >>> pretess = fs.MRIPretess()
    >>> pretess.inputs.in_filled = 'wm.mgz'
    >>> pretess.inputs.in_norm = 'norm.mgz'
    >>> pretess.inputs.nocorners = True
    >>> pretess.cmdline
    'mri_pretess -nocorners wm.mgz wm norm.mgz wm_pretesswm.mgz'
    >>> pretess.run() # doctest: +SKIP

    Zmri_pretessN)	r_   r`   ra   r   r   r@  r   rG  r   r:   r:   r:   r;   rH    s   rH  c               @   sX   e Zd ZdZeddddddZejdddd	d
ZejddddddZ	edddddZ
dS )MRIMarchingCubesInputSpeczZ
    Uses Freesurfer's mri_mc to create surfaces by tessellating a given input volume
    Tr   z%sz&Input volume to tesselate voxels from.)rD   rE   r   rF   rG   r   z%dzvLabel value which to tesselate from the input volume. (integer, if input is "filled.mgz" volume, 127 is rh, 255 is lh))r   rF   rE   rG   zEAlter the marching cubes connectivity: 1=6+,2=18,3=6,4=26 (default=1))r   rF   r   rG   z./%sz'output filename or True to generate one)rF   r   r^   rG   Nr   r   )r_   r`   ra   r   r	   r6   r
   ro   r<  Zconnectivity_valuer9   r:   r:   r:   r;   rI  9  s.   rI  c               @   s   e Zd ZdZedddZdS )MRIMarchingCubesOutputSpeczZ
    Uses Freesurfer's mri_mc to create surfaces by tessellating a given input volume
    Tz#binary surface of the tessellation )rD   rG   N)r_   r`   ra   r   r	   rf   r:   r:   r:   r;   rJ  Z  s   rJ  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 )
MRIMarchingCubesac  
    Uses Freesurfer's mri_mc to create surfaces by tessellating a given input volume

    Example
    -------

    >>> import nipype.interfaces.freesurfer as fs
    >>> mc = fs.MRIMarchingCubes()
    >>> mc.inputs.in_file = 'aseg.mgz'
    >>> mc.inputs.label_value = 17
    >>> mc.inputs.out_file = 'lh.hippocampus'
    >>> mc.run() # doctest: +SKIP
    Zmri_mcc             C   s   | j  j }| j |d< |S )Nrf   )r   r   r3  )r   r@   r:   r:   r;   r   u  s    zMRIMarchingCubes._list_outputsc             C   s   |dkr| j  S d S d S )Nr9   )r3  )r   r   r:   r:   r;   r   z  s    zMRIMarchingCubes._gen_filenamec             C   sR   t | jjrtjj| jjS t| jj\}}}tjj|| d t| jj	 S d S )Nr   )
r   r)   r9   r+   r-   r   r   r6   r?  r<  )r   r   r   r   r:   r:   r;   r3    s    z!MRIMarchingCubes._gen_outfilenameN)r_   r`   ra   r   r   rI  r   rJ  r   r   r   r3  r:   r:   r:   r;   rK  b  s   rK  c               @   s   e Z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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dd"dddZedddZedddZejdddZd S )#SmoothTessellationInputSpecTz%sr   z&Input volume to tesselate voxels from.)rD   rE   rF   r   r   rG   z-a %dz5Number of curvature averaging iterations (default=10))rF   rG   z-n %dz+Number of smoothing iterations (default=10)z-w %dz#Write snapshot every *n* iterationsz-gz Use Gaussian curvature smoothingz%dz %dz-nwz4Disables the writing of curvature and area estimatesz-areaz#Normalizes the area after smoothingz-mzUses momentumr   z'output filename or True to generate one)rF   r   r^   rG   z-c %sz3Write curvature to ``?h.curvname`` (default "curv")z-b %sz.Write area to ``?h.areaname`` (default "area")z-seed %dz(Seed for setting random number generatorNr   r   )r_   r`   ra   r	   r6   r
   ro   Zcurvature_averaging_iterationsZsmoothing_iterationsZsnapshot_writing_iterationsrh   Z use_gaussian_curvature_smoothingZgaussian_curvature_norm_stepsZ"gaussian_curvature_smoothing_stepsZdisable_estimatesZnormalize_areaZuse_momentumr9   Zout_curvature_fileZout_area_fileseedr:   r:   r:   r;   rL    sF   









rL  c               @   s   e Zd ZdZedddZdS )SmoothTessellationOutputSpeczP
    This program smooths the tessellation of a surface using 'mris_smooth'
    TzSmoothed surface file.)rD   rG   N)r_   r`   ra   r   r	   rf   r:   r:   r:   r;   rN    s   rN  c                   sD   e Zd ZdZdZeZeZdd Z	dd Z
dd Z fd	d
Z  ZS )SmoothTessellationa  
    Smooth a tessellated surface.

    See Also
    --------
    `nipype.interfaces.freesurfer.utils.SurfaceSmooth`_ interface for smoothing a scalar field
    along a surface manifold

    Example
    -------
    >>> import nipype.interfaces.freesurfer as fs
    >>> smooth = fs.SmoothTessellation()
    >>> smooth.inputs.in_file = 'lh.hippocampus.stl'
    >>> smooth.run() # doctest: +SKIP

    Zmris_smoothc             C   s   | j  j }| j |d< |S )Nrf   )r   r   r3  )r   r@   r:   r:   r;   r     s    z SmoothTessellation._list_outputsc             C   s   |dkr| j  S d S d S )Nr9   )r3  )r   r   r:   r:   r;   r     s    z SmoothTessellation._gen_filenamec             C   sF   t | jjrtjj| jjS t| jj\}}}tjj|d | S d S )N	_smoothed)r   r)   r9   r+   r-   r   r   r6   )r   r   r   r   r:   r:   r;   r3    s    z#SmoothTessellation._gen_outfilenamec                s(   t t| j|}d|jkr$| j| |S )Nfailed)r   rO  r   r   r   )r   r   )r   r:   r;   r     s    

z!SmoothTessellation._run_interface)r_   r`   ra   r   r   rL  r   rN  r   r   r   r3  r   r   r:   r:   )r   r;   rO    s   rO  c               @   s4   e Zd Zejej dddddZeddddd	Zd
S )MakeAverageSubjectInputSpecz--subjects %sz"freesurfer subjects ids to averageT )rF   rG   rE   seprQ   z--out %szname for the average subject)rF   rG   r   N)	r_   r`   ra   r
   r   rm   Zsubjects_idsr	   out_namer:   r:   r:   r;   rR    s   rR  c               @   s   e Zd ZejddZdS )MakeAverageSubjectOutputSpeczOutput registration file)rG   N)r_   r`   ra   r
   rm   average_subject_namer:   r:   r:   r;   rV    s   rV  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )MakeAverageSubjecta  Make an average freesurfer subject

    Examples
    --------

    >>> from nipype.interfaces.freesurfer import MakeAverageSubject
    >>> avg = MakeAverageSubject(subjects_ids=['s1', 's2'])
    >>> avg.cmdline
    'make_average_subject --out average --subjects s1 s2'

    Zmake_average_subjectc             C   s   | j  j }| jj|d< |S )NrW  )r   r   r)   rU  )r   r@   r:   r:   r;   r     s    z MakeAverageSubject._list_outputsN)
r_   r`   ra   r   r   rR  r   rV  r   r   r:   r:   r:   r;   rX    s
   rX  c               @   s0   e Zd ZeddddddZeddddd	d
ZdS )ExtractMainComponentInputSpecTz%sr   zinput surface file)rD   rE   rF   r   rG   z
%s.maincmpr6   r   z!surface containing main component)r   r   rF   r   rG   N)r_   r`   ra   r	   r6   r9   r:   r:   r:   r;   rY  #  s   rY  c               @   s   e Zd ZedddZdS )ExtractMainComponentOutputSpecTz!surface containing main component)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   rZ  0  s   rZ  c               @   s   e Zd ZdZdZeZeZdS )ExtractMainComponenta  Extract the main component of a tesselated surface

    Examples
    --------

    >>> from nipype.interfaces.freesurfer import ExtractMainComponent
    >>> mcmp = ExtractMainComponent(in_file='lh.pial')
    >>> mcmp.cmdline
    'mris_extract_main_component lh.pial lh.maincmp'

    Zmris_extract_main_componentN)	r_   r`   ra   r   r   rY  r   rZ  r   r:   r:   r:   r;   r[  4  s   r[  c               @   s  e Zd ZedddgddZejdddgd	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ZejdgddZejdedddZejdedddZejddgddZejdddZejdd dd!d"Zed#ddd$d%d&Zejdd'd(dZejdd)dd*d+gd,d
Zejd-d.dZd/S )0Tkregister2InputSpecTz	--targ %sfstargztarget volume)rD   rF   rM   rG   Fz--fstargtarget_imagezuse subject's T1 as reference)rF   rM   rG   z--mov %szmoving volume)rD   rE   rF   rG   z--fsl %sz#fsl-style registration input matrix)rD   rF   rG   z--xfm %sz7use a matrix in MNI coordinates as initial registrationz--lta %slta_inz Invert input LTA before applying)rN   rG   z--fslregout %sz-compute an FSL-compatible resgitration matrix)rF   rG   z--ltaout %sz%output registration file (LTA format)z--ltaout-inv)rF   rN   rG   z--s %szfreesurfer subject IDz--noeditzdo not open edit window (exit))rF   r   rG   zregister.datz--reg %sz"freesurfer-style registration file)r   rE   rF   rG   z--regheaderz compute regstration from headersz--fstalmoving_imagerJ   z'set mov to be tal and reg to be tal xfmz--movscale %fz'adjust registration matrix to scale movN)r_   r`   ra   r	   r^  r
   rh   r]  r`  Zfsl_in_matrixZxfmr_  invert_lta_inrl   fsl_outlta_outZinvert_lta_outre   r(   ZnoeditrJ   rK   Zfstalrj   Zmovscaler:   r:   r:   r;   r\  F  sd   r\  c               @   s,   e Zd ZedddZeddZeddZdS )Tkregister2OutputSpecTz"freesurfer-style registration file)rD   rG   zFSL-style registration file)rG   zLTA-style registration fileN)r_   r`   ra   r	   rJ   fsl_filelta_filer:   r:   r:   r;   rd    s   
rd  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 )	Tkregister2a  

    Examples
    --------
    Get transform matrix between orig (*tkRAS*) and native (*scannerRAS*)
    coordinates in Freesurfer. Implements the first step of mapping surfaces
    to native space in `this guide
    <http://surfer.nmr.mgh.harvard.edu/fswiki/FsAnat-to-NativeAnat>`__.

    >>> from nipype.interfaces.freesurfer import Tkregister2
    >>> tk2 = Tkregister2(reg_file='T1_to_native.dat')
    >>> tk2.inputs.moving_image = 'T1.mgz'
    >>> tk2.inputs.target_image = 'structural.nii'
    >>> tk2.inputs.reg_header = True
    >>> tk2.cmdline
    'tkregister2 --mov T1.mgz --noedit --reg T1_to_native.dat --regheader --targ structural.nii'
    >>> tk2.run() # doctest: +SKIP

    The example below uses tkregister2 without the manual editing
    stage to convert FSL-style registration matrix (.mat) to
    FreeSurfer-style registration matrix (.dat)

    >>> from nipype.interfaces.freesurfer import Tkregister2
    >>> tk2 = Tkregister2()
    >>> tk2.inputs.moving_image = 'epi.nii'
    >>> tk2.inputs.fsl_in_matrix = 'flirt.mat'
    >>> tk2.cmdline
    'tkregister2 --fsl flirt.mat --mov epi.nii --noedit --reg register.dat'
    >>> tk2.run() # doctest: +SKIP
    Ztkregister2c                sD   |dkr| j jrd}|dkr0|dkr0| j | }tt| j|||S )Nr_  z--lta-inv %srb  rc  T)rb  rc  )r)   ra  r   r   rg  r   )r   r   r   r   )r   r:   r;   r     s
    zTkregister2._format_argc             C   s   | j  j }tjj| jj}||d< tj }| jj}t	|rn|dkrZt
|d|dd|d< ntjj| jj|d< | jj}t	|r|dkrt
|d|dd|d< ntjj| jj|d< |S )	NrJ   Tz.matF)r   r   r   re  z.ltarf  )r   r   r+   r-   r   r)   rJ   r,   rb  r   r   rc  )r   r@   rJ   cwdrb  rc  r:   r:   r;   r     s"    zTkregister2._list_outputsc             C   sF   t | jjrtjj| jjS t| jj\}}}tjj|d | S d S )NrP  )r   r)   r9   r+   r-   r   r   r6   )r   r   r   r   r:   r:   r;   r3    s    zTkregister2._gen_outfilename)r_   r`   ra   r   r   r\  r   rd  r   r   r   r3  r   r:   r:   )r   r;   rg    s   rg  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dddZ	ejdddZ
dS )AddXFormToHeaderInputSpecTr   z%szinput volume)rD   rE   r   rF   rG   Fr   zxfm filez
output.mgzr   zoutput volume)r   rF   r   rG   z-cz.do not try to load the xfmfile, just copy name)rF   rG   z-vz
be verboseNr   r   r   )r_   r`   ra   r	   r6   	transformr9   r
   rh   Z	copy_nameverboser:   r:   r:   r;   ri    s   
ri  c               @   s   e Zd ZedddZdS )AddXFormToHeaderOutputSpecTzoutput volume)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   rl    s   rl  c                   s4   e Zd ZdZdZeZeZ fddZ	dd Z
  ZS )AddXFormToHeadera"  
    Just adds specified xform to the volume header.

    .. danger ::

        Input transform **MUST** be an absolute path to a DataSink'ed transform or
        the output will reference a transform in the workflow cache directory!

    Examples
    --------
    >>> from nipype.interfaces.freesurfer import AddXFormToHeader
    >>> adder = AddXFormToHeader()
    >>> adder.inputs.in_file = 'norm.mgz'
    >>> adder.inputs.transform = 'trans.mat'
    >>> adder.cmdline
    'mri_add_xform_to_header trans.mat norm.mgz output.mgz'

    >>> adder.inputs.copy_name = True
    >>> adder.cmdline
    'mri_add_xform_to_header -c trans.mat norm.mgz output.mgz'
    >>> adder.run()   # doctest: +SKIP

    References
    ----------
    [https://surfer.nmr.mgh.harvard.edu/fswiki/mri_add_xform_to_header]

    Zmri_add_xform_to_headerc                s    |dkr|S t t| j|||S )Nrj  )r   rm  r   )r   r   r   r   )r   r:   r;   r     s    zAddXFormToHeader._format_argc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r   "  s    zAddXFormToHeader._list_outputs)r_   r`   ra   r   r   ri  r   rl  r   r   r   r   r:   r:   )r   r;   rm    s   rm  c               @   sJ   e Zd ZeddgdddddZejddgddd	d
ZejdddddZ	dS ) CheckTalairachAlignmentInputSpecz-xfm %ssubjectTr   z'specify the talairach.xfm file to check)rF   rM   rD   rE   r   rG   z-subj %sr6   zspecify subject's name)rF   rM   rE   r   rG   g{Gz?z-T %.3fz5Talairach transforms for subjects with p-values <= T z-are considered as very unlikely default=0.010)default_valuer   rF   rG   Nr   r   zbTalairach transforms for subjects with p-values <= T are considered as very unlikely default=0.010)
r_   r`   ra   r	   r6   r
   re   ro  rj   	thresholdr:   r:   r:   r;   rn  (  s&    rn  c               @   s   e Zd ZedddZdS )!CheckTalairachAlignmentOutputSpecTz*The input file for CheckTalairachAlignment)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   rr  B  s   rr  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )CheckTalairachAlignmenta  
    This program detects Talairach alignment failures

    Examples
    ========

    >>> from nipype.interfaces.freesurfer import CheckTalairachAlignment
    >>> checker = CheckTalairachAlignment()

    >>> checker.inputs.in_file = 'trans.mat'
    >>> checker.inputs.threshold = 0.005
    >>> checker.cmdline
    'talairach_afd -T 0.005 -xfm trans.mat'

    >>> checker.run() # doctest: +SKIP
    Ztalairach_afdc             C   s   | j  j }| jj|d< |S )Nr9   )r   r   r)   r6   )r   r@   r:   r:   r;   r   \  s    z%CheckTalairachAlignment._list_outputsN)
r_   r`   ra   r   r   rn  r   rr  r   r   r:   r:   r:   r;   rs  F  s
   rs  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ZdS )TalairachAVIInputSpecz--i %sTzinput volume)rF   rD   rE   rG   z--xfm %sFzoutput xfm file)rF   rE   rD   rG   z
--atlas %sz2alternate target atlas (in freesurfer/average dir))rF   rG   N)	r_   r`   ra   r	   r6   r9   r
   re   atlasr:   r:   r:   r;   rt  b  s
   rt  c               @   s0   e Zd ZedddZedddZedddZdS )TalairachAVIOutputSpecFz%The output transform for TalairachAVI)rD   rG   z$The output log file for TalairachAVIz%The output text file for TaliarachAVIN)r_   r`   ra   r	   r9   out_logout_txtr:   r:   r:   r;   rv  m  s   rv  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )TalairachAVIa{  
    Front-end for Avi Snyders image registration tool. Computes the
    talairach transform that maps the input volume to the MNI average_305.
    This does not add the xfm to the header of the input file. When called
    by recon-all, the xfm is added to the header after the transform is
    computed.

    Examples
    ========

    >>> from nipype.interfaces.freesurfer import TalairachAVI
    >>> example = TalairachAVI()
    >>> example.inputs.in_file = 'norm.mgz'
    >>> example.inputs.out_file = 'trans.mat'
    >>> example.cmdline
    'talairach_avi --i norm.mgz --xfm trans.mat'

    >>> example.run() # doctest: +SKIP
    Ztalairach_avic             C   sb   | j  j }tjj| jj|d< tjjd|d< tjjtjj| jjdt	| jj
 d |d< |S )Nr9   ztalairach_avi.logrw  Ztalsrcimg_to_zt4_vox2vox.txtrx  )r   r   r+   r-   r   r)   r9   r/   r?   r?  ru  )r   r@   r:   r:   r;   r     s    zTalairachAVI._list_outputsN)
r_   r`   ra   r   r   rt  r   rv  r   r   r:   r:   r:   r;   ry  s  s
   ry  c               @   s   e Zd ZeddddddZdS )TalairachQCInputSpecz%sTr   zThe log file for TalairachQC)rF   rE   rD   r   rG   N)r_   r`   ra   r	   log_filer:   r:   r:   r;   rz    s   rz  c               @   s   e Zd ZdZdZeZeZdS )TalairachQCz
    Examples
    ========

    >>> from nipype.interfaces.freesurfer import TalairachQC
    >>> qc = TalairachQC()
    >>> qc.inputs.log_file = 'dirs.txt'
    >>> qc.cmdline
    'tal_QC_AZS dirs.txt'
    Z
tal_QC_AZSN)	r_   r`   ra   r   r   rz  r   r   r   r:   r:   r:   r;   r|    s   
r|  c            
   @   sj   e Zd ZeddddddZedddg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	dddZ
dS )RemoveNeckInputSpecz%sTr   zInput file for RemoveNeck)rF   rD   rE   r   rG   Fr6   z	%s_noneckr   zOutput file for RemoveNeck)rF   rD   r   r   r   r   r   rG   r   z#Input transform file for RemoveNeckr   z"Input template file for RemoveNeckz
-radius %dZRadius)rF   rG   NrD  r   r   r   )r_   r`   ra   r	   r6   r9   rj  templater
   ro   Zradiusr:   r:   r:   r;   r}    s8   r}  c               @   s   e Zd ZedddZdS )RemoveNeckOutputSpecFzOutput file with neck removed)rD   rG   N)r_   r`   ra   r	   r9   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 )
RemoveNecka  
    Crops the neck out of the mri image

    Examples
    ========

    >>> from nipype.interfaces.freesurfer import TalairachQC
    >>> remove_neck = RemoveNeck()
    >>> remove_neck.inputs.in_file = 'norm.mgz'
    >>> remove_neck.inputs.transform = 'trans.mat'
    >>> remove_neck.inputs.template = 'trans.mat'
    >>> remove_neck.cmdline
    'mri_remove_neck norm.mgz trans.mat trans.mat norm_noneck.mgz'
    Zmri_remove_neckc             C   s   |dkrt jjdS d S )Nr9   znu_noneck.mgz)r+   r-   r   )r   r   r:   r:   r;   r	    s    zRemoveNeck._gen_fnamec             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r     s    zRemoveNeck._list_outputsN)r_   r`   ra   r   r   r}  r   r  r   r	  r   r:   r:   r:   r;   r    s   r  c               @   sX   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ZeddddZedddZdS )MRIFillInputSpecz%sTr   zInput white matter file)rF   rE   rD   r   rG   Fr   z*Output filled volume file name for MRIFillz-segmentation %sz#Input segmentation file for MRIFill)rF   rD   rG   z	-xform %sz Input transform file for MRIFillz-a %szOutput log file for MRIFill)rF   rG   Nr   r   )	r_   r`   ra   r	   r6   r9   Zsegmentationrj  r{  r:   r:   r:   r;   r    s&   r  c               @   s"   e Zd ZedddZeddZdS )MRIFillOutputSpecFzOutput file from MRIFill)rD   rG   zOutput log file from MRIFill)rG   N)r_   r`   ra   r	   r9   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 )MRIFilla  
    This program creates hemispheric cutting planes and fills white matter
    with specific values for subsequent surface tesselation.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import MRIFill
    >>> fill = MRIFill()
    >>> fill.inputs.in_file = 'wm.mgz' # doctest: +SKIP
    >>> fill.inputs.out_file = 'filled.mgz' # doctest: +SKIP
    >>> fill.cmdline # doctest: +SKIP
    'mri_fill wm.mgz filled.mgz'
    Zmri_fillc             C   sD   | j  j }tjj| jj|d< t| jjr@tjj| jj|d< |S )Nr9   r{  )	r   r   r+   r-   r   r)   r9   r   r{  )r   r@   r:   r:   r;   r   ,	  s
    zMRIFill._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   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gd	ddd
dZeddgddZejddgddZ	dS )MRIsInflateInputSpecz%sr   TzInput file for MRIsInflate)rF   r   rE   rD   r   rG   r   Fr6   z%s.inflatedzOutput file for MRIsInflate)rF   r   rD   r   r   r   r   rG   no_save_sulczOutput sulc file)rD   rM   rG   z-no-save-sulcout_sulczDo not save sulc file as output)rF   rM   rG   Nr   r   )
r_   r`   ra   r	   r6   r9   r  r
   rh   r  r:   r:   r:   r;   r  4	  s&   r  c               @   s$   e Zd ZedddZedddZdS )MRIsInflateOutputSpecFzOutput file for MRIsInflate)rD   rG   zOutput sulc fileN)r_   r`   ra   r	   r9   r  r:   r:   r:   r;   r  N	  s   r  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )MRIsInflateac  
    This program will inflate a cortical surface.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import MRIsInflate
    >>> inflate = MRIsInflate()
    >>> inflate.inputs.in_file = 'lh.pial'
    >>> inflate.inputs.no_save_sulc = True
    >>> inflate.cmdline # doctest: +SKIP
    'mris_inflate -no-save-sulc lh.pial lh.inflated'
    Zmris_inflatec             C   s@   | j  j }tjj| jj|d< | jjs<tjj| jj|d< |S )Nr9   r  )	r   r   r+   r-   r   r)   r9   r  r  )r   r@   r:   r:   r;   r   e	  s
    zMRIsInflate._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   r   r:   r:   r:   r;   r  S	  s
   r  c            	   @   sb   e Zd ZedddddddZeddddgdd	d
dZejdddZej	dddZ
eddddZdS )SphereInputSpecz%sr   TzInput file for Sphere)rF   r   r   rE   rD   rG   r   Fr6   z	%s.spherezOutput file for Sphere)rF   r   rD   r   r   r   rG   z-seed %dz(Seed for setting random number generator)rF   rG   z-qzGNo documentation. Direct questions to analysis-bugs@nmr.mgh.harvard.eduz3Input surface required when -q flag is not selected)rD   r   rG   Nr   r   )r_   r`   ra   r	   r6   r9   r
   ro   rM  rh   magicZin_smoothwmr:   r:   r:   r;   r  n	  s0   
r  c               @   s   e Zd ZedddZdS )SphereOutputSpecFzOutput file for Sphere)rD   rG   N)r_   r`   ra   r	   r9   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 )Spherea  
    This program will add a template into an average surface

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import Sphere
    >>> sphere = Sphere()
    >>> sphere.inputs.in_file = 'lh.pial'
    >>> sphere.cmdline
    'mris_sphere lh.pial lh.sphere'
    Zmris_spherec             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r   	  s    zSphere._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   r   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eddddZe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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dS ) FixTopologyInputSpecTz)Undocumented input file <hemisphere>.orig)rD   rE   rG   z-Undocumented input file <hemisphere>.inflatedzImplicit input brain.mgzzImplicit input wm.mgzr   z%szHemisphere being processed)r   rF   rE   rG   r(   r   zSubject being processed)r   rF   rE   r   rG   z'If running as a node, set this to True z,otherwise, the topology fixing will be done z	in place.)rE   rG   z-seed %dz(Seed for setting random number generator)rF   rG   z-gazGNo documentation. Direct questions to analysis-bugs@nmr.mgh.harvard.eduz-mgzz
-sphere %szSphere input fileNr   r   zSIf running as a node, set this to True otherwise, the topology fixing will be done z\If running as a node, set this to True otherwise, the topology fixing will be done in place.)r_   r`   ra   r	   in_origin_inflatedin_brainin_wmr
   re   
hemispherer(   rh   copy_inputsro   rM  gar   r   r:   r:   r:   r;   r  	  s:   
r  c               @   s   e Zd ZedddZdS )FixTopologyOutputSpecFzOutput file for FixTopology)rD   rG   N)r_   r`   ra   r	   r9   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	 fddZ
dd Z  ZS )	FixTopologya  
    This program computes a mapping from the unit sphere onto the surface
    of the cortex from a previously generated approximation of the
    cortical surface, thus guaranteeing a topologically correct surface.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import FixTopology
    >>> ft = FixTopology()
    >>> ft.inputs.in_orig = 'lh.orig' # doctest: +SKIP
    >>> ft.inputs.in_inflated = 'lh.inflated' # doctest: +SKIP
    >>> ft.inputs.sphere = 'lh.qsphere.nofix' # doctest: +SKIP
    >>> ft.inputs.hemisphere = 'lh'
    >>> ft.inputs.subject_id = '10335'
    >>> ft.inputs.mgz = True
    >>> ft.inputs.ga = True
    >>> ft.cmdline # doctest: +SKIP
    'mris_fix_topology -ga -mgz -sphere qsphere.nofix 10335 lh'
    Zmris_fix_topologyc                s   | j jrtj | j _d|kr(| j j|d< | j j}t| | j jdd t| | j jddj	|d| j _t| | j j
ddj	|d t| | j jddd t| | j jdd	d tt| jf |S )
Nr*   surf)r7   z{0}.orig)r7   r.   z{0}.inflatedmriz	brain.mgzzwm.mgz)r)   r  r+   r,   r*   r  r<   r   r  r   r  r  r  r   r  run)r   r)   rd   )r   r:   r;   r  	  s&    zFixTopology.runc                s>   |dkr*t jj|jddd }|j| S tt| j|||S )Nr   r   r   )r+   r-   r.   r$  rF   r   r  r   )r   r   r   r   r   )r   r:   r;   r   
  s    
zFixTopology._format_argc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r  )r   r@   r:   r:   r;   r   
  s    zFixTopology._list_outputs)r_   r`   ra   r   r   r  r   r  r   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dS )EulerNumberInputSpecz%sr   TzInput file for EulerNumber)rF   r   rE   rD   rG   Nr   )r_   r`   ra   r	   r6   r:   r:   r:   r;   r  
  s   r  c               @   s$   e Zd ZejddZejddZdS )EulerNumberOutputSpeczjEuler number of cortical surface. A value of 2 signals a topologically correct surface model with no holes)rG   zNumber of defectsN)r_   r`   ra   r
   ro   eulerdefectsr:   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 )	EulerNumbera  
    This program computes EulerNumber for a cortical surface

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import EulerNumber
    >>> ft = EulerNumber()
    >>> ft.inputs.in_file = 'lh.pial'
    >>> ft.cmdline
    'mris_euler_number lh.pial'
    Zmris_euler_numberc                s    t  j|}| j|j|j |S )N)r   r   _parse_outputr"  r   )r   r   )r   r:   r;   r   ;
  s    zEulerNumber._run_interfacec             C   s2   t jd|p|}|dkr tdt|j | _dS )z)Parse stdout / stderr and extract defectsz(?<=total defect index = )\d+NzCould not fetch defect index)r   r  r   r  r  _defects)r   r"  r   r  r:   r:   r;   r  @
  s    zEulerNumber._parse_outputc             C   s,   | j  j }| j|d< dd| j  |d< |S )Nr  r   r  )r   r   r  )r   r@   r:   r:   r;   r   G
  s    
zEulerNumber._list_outputs)r_   r`   ra   r   r   r  r   r  r   r   r  r   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gdddd	d
ZdS )RemoveIntersectionInputSpecz%sr   Tz!Input file for RemoveIntersection)rF   r   rE   rD   r   rG   r   Fr6   z"Output file for RemoveIntersection)rF   r   rD   r   r   r   r   rG   Nr   r   )r_   r`   ra   r	   r6   r9   r:   r:   r:   r;   r  N
  s    r  c               @   s   e Zd ZedddZdS )RemoveIntersectionOutputSpecFz"Output file for RemoveIntersection)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   r  c
  s   r  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )RemoveIntersectiona)  
    This program removes the intersection of the given MRI

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import RemoveIntersection
    >>> ri = RemoveIntersection()
    >>> ri.inputs.in_file = 'lh.pial'
    >>> ri.cmdline
    'mris_remove_intersection lh.pial lh.pial'
    Zmris_remove_intersectionc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r   x
  s    z RemoveIntersection._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   r   r:   r:   r:   r;   r  g
  s
   r  c               @   s<  e Zd Zejddd6ddddZejddd7ddd
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ZeddgddZeddddZed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d$dd%dZed&dd'dZejd(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/d0d Zejd9d4Zd5S ):MakeSurfacesInputSpecrH   rI   r   z%sTzHemisphere being processed)r   rF   rE   rG   r(   r   zSubject being processed)r   r   rF   rE   rG   z-orig %sz%Implicit input file <hemisphere>.orig)rD   rE   rF   rG   zImplicit input file wm.mgz)rD   rE   rG   zImplicit input file filled.mgzz%Implicit input that is sometimes used)rD   rG   noaparcz-Implicit input label/<hemisphere>.aparc.annot)rD   rM   rG   z-orig_white %sz%Specify a white surface to start with)rF   rD   rG   z-orig_pial %sin_labelz$Specify a pial surface to start with)rF   rD   rN   rG   z-fix_mtlzUndocumented flag)rF   rG   z-nowhitez
-whiteonlyzUndocumented flagez-aseg %szInput segmentation filez-T1 %szInput brain or T1 filez-mgzzGNo documentation. Direct questions to analysis-bugs@nmr.mgh.harvard.eduz-noaparc)rF   rM   rG   z	-max %.1fz3No documentation (used for longitudinal processing)z-longz	-white %szWhite surface namez'If running as a node, set this to True.z+This will copy the input files to the node z
directory.)rG   Nr   r   zRIf running as a node, set this to True.This will copy the input files to the node z\If running as a node, set this to True.This will copy the input files to the node directory.)r_   r`   ra   r
   rc   r  re   r(   r	   r  r  rC  in_whiter  
orig_white	orig_pialrh   Zfix_mtlno_whiteZ
white_onlyin_asegin_T1r   r  rj   maximumZlongitudinalr   r  r:   r:   r:   r;   r  ~
  sl   

r  c               @   sT   e Zd ZedddZedddZedddZedddZedddZedddZ	d	S )
MakeSurfacesOutputSpecFz&Output white matter hemisphere surface)rD   rG   z!Output curv file for MakeSurfacesz!Output area file for MakeSurfacesz#Output cortex file for MakeSurfacesz$Output pial surface for MakeSurfacesz&Output thickness file for MakeSurfacesN)
r_   r`   ra   r	   	out_whiteout_curvout_area
out_cortexout_pialout_thicknessr:   r:   r:   r;   r  
  s   r  c                   s@   e Zd ZdZdZeZeZ fddZ	 fddZ
dd Z  ZS )	MakeSurfacesa  
    This program positions the tessellation of the cortical surface at the
    white matter surface, then the gray matter surface and generate
    surface files for these surfaces as well as a 'curvature' file for the
    cortical thickness, and a surface file which approximates layer IV of
    the cortical sheet.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import MakeSurfaces
    >>> makesurfaces = MakeSurfaces()
    >>> makesurfaces.inputs.hemisphere = 'lh'
    >>> makesurfaces.inputs.subject_id = '10335'
    >>> makesurfaces.inputs.in_orig = 'lh.pial'
    >>> makesurfaces.inputs.in_wm = 'wm.mgz'
    >>> makesurfaces.inputs.in_filled = 'norm.mgz'
    >>> makesurfaces.inputs.in_label = 'aparc+aseg.nii'
    >>> makesurfaces.inputs.in_T1 = 'T1.mgz'
    >>> makesurfaces.inputs.orig_pial = 'lh.pial'
    >>> makesurfaces.cmdline
    'mris_make_surfaces -T1 T1.mgz -orig pial -orig_pial pial 10335 lh'
    Zmris_make_surfacesc                s  | j jrtj | j _d|kr*| j j|d< t| | j jddd t| | j jddd t| | j jddj	| j j
 x&| j j| j jgD ]}t| |dd qW x,| j j| j j| j jgD ]}t| |dd qW t| j jrt| | j jd	d
j	| j j
 ntjtjj| j j| j jd	 tt| jf |S )Nr*   r  zwm.mgz)r7   r.   z
filled.mgzr  z	{0}.white)r7   rE  z{0}.aparc.annot)r)   r  r+   r,   r*   r<   r  rC  r  r   r  r  r  r  r  r  r   r  r1   r-   r/   r(   r   r  r  )r   r)   Zoriginalfile)r   r:   r;   r  
  s:    
zMakeSurfaces.runc                s   |dkrHt jj|}| jjr.t jj|d }n|}|dkr>d S |j| S |dkrtt jj|}|jdd }|j| S |d	kr|jd
s|jdrd S t jj|}|jdd }|j| S t	t
| j|||S )Nr  r  r   asegr  r  r   r   r  zlh.origzrh.orig)r  r  )r  r  )r+   r-   r.   r)   r   splitextrF   r$  r   r   r  r   )r   r   r   r   r.   r   r   )r   r:   r;   r     s&    


zMakeSurfaces._format_argc             C   s8  | j  j }tjj| jj| jjd}tjj| jj| jjd}| jjsbtjj|t	| jj
d |d< tjj|t	| jj
d |d< tjj|t	| jj
d |d< t| jjs| jjd	kr|d d
 |d< |d d
 |d< tjj|t	| jj
d
 |d< tjj|t	| jj
d |d< ntjj|t	| jj
d |d< |S )Nr  rE  z.whiter  z.curvr  z.arear  ZNOWRITEz.pialr  z
.thicknessr  z.cortex.labelr  )r   r   r+   r-   r/   r)   r*   r(   r  r?  r  r   r  r   )r   r@   dest_dirZ	label_dirr:   r:   r;   r   /  s,    zMakeSurfaces._list_outputs)r_   r`   ra   r   r   r  r   r  r   r  r   r   r   r:   r:   )r   r;   r  
  s   &r  c               @   sz   e Z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ZejdddZejej
ej
dddZejddZdS )CurvatureInputSpecz%sr   TzInput file for Curvature)rF   r   rE   rD   r   rG   z-thresh %.3fzUndocumented input threshold)rF   rG   z-nzUndocumented boolean flagz-a %dzIPerform this number iterative averages of curvature measure before savingz-wzKSave curvature files (will only generate screen output without this option)z-distances %d %dz$Undocumented input integer distancesz$Copy input file to current directory)rG   Nr   )r_   r`   ra   r	   r6   r
   rj   rq  rh   nro   Zaveragessaveri   Z	distances
copy_inputr:   r:   r:   r;   r  Y  s*   r  c               @   s$   e Zd ZedddZedddZdS )CurvatureOutputSpecFzMean curvature output file)rD   rG   zGaussian curvature output fileN)r_   r`   ra   r	   out_mean	out_gaussr:   r:   r:   r;   r  v  s   r  c                   s4   e Zd ZdZdZeZeZ fddZ	dd Z
  ZS )	Curvaturea  
    This program will compute the second fundamental form of a cortical
    surface. It will create two new files <hemi>.<surface>.H and
    <hemi>.<surface>.K with the mean and Gaussian curvature respectively.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import Curvature
    >>> curv = Curvature()
    >>> curv.inputs.in_file = 'lh.pial'
    >>> curv.inputs.save = True
    >>> curv.cmdline
    'mris_curvature -w lh.pial'
    Zmris_curvaturec                s:   | j jr&|dkr&tjj|}|j| S tt| j|||S )Nr6   )	r)   r  r+   r-   r.   rF   r   r  r   )r   r   r   r   r.   )r   r:   r;   r     s
    
zCurvature._format_argc             C   sZ   | j  j }| jjr&tjj| jj}n| jj}tjj|d |d< tjj|d |d< |S )Nz.Hr  z.Kr  )	r   r   r)   r  r+   r-   r.   r6   r   )r   r@   r6   r:   r:   r;   r     s    zCurvature._list_outputs)r_   r`   ra   r   r   r  r   r  r   r   r   r   r:   r:   )r   r;   r  {  s   r  c               @   s   e Zd ZeddddZedd%ddddZedd&ddddZejd
dd'ddddZ	ej
ddd(ddddZedddg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#Zd$S )+CurvatureStatsInputSpecz-F %sTz'Specify surface file for CurvatureStats)rF   rD   rG   z%sr   zInput file for CurvatureStats)rF   r   rE   rD   rG   r   rH   rI   r   zHemisphere being processed)r   rF   rE   rG   r(   r   zSubject being processed)r   r   rF   rE   rG   z-o %sFr  z%s.curv.statszOutput curvature stats file)rF   rD   r   r   r   rG   z-mz9Output min / max information for the processed curvature.)rF   rG   z-Gz-Triggers a series of derived curvature valuesz--writeCurvatureFileszWrite curvature filesz'If running as a node, set this to True.z+This will copy the input files to the node z
directory.)rG   Nr   r   r   rD  zRIf running as a node, set this to True.This will copy the input files to the node z\If running as a node, set this to True.This will copy the input files to the node directory.)r_   r`   ra   r	   rf   	curvfile1	curvfile2r
   rc   r  re   r(   r9   rh   Zmin_maxr>   r  r  r:   r:   r:   r;   r    sT   

r  c               @   s   e Zd ZedddZdS )CurvatureStatsOutputSpecFzOutput curvature stats file)rD   rG   N)r_   r`   ra   r	   r9   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
 fddZ  ZS )	CurvatureStatsa  
    In its simplest usage, 'mris_curvature_stats' will compute a set
    of statistics on its input <curvFile>. These statistics are the
    mean and standard deviation of the particular curvature on the
    surface, as well as the results from several surface-based
    integrals.

    Additionally, 'mris_curvature_stats' can report the max/min
    curvature values, and compute a simple histogram based on
    all curvature values.

    Curvatures can also be normalised and constrained to a given
    range before computation.

    Principal curvature (K, H, k1 and k2) calculations on a surface
    structure can also be performed, as well as several functions
    derived from k1 and k2.

    Finally, all output to the console, as well as any new
    curvatures that result from the above calculations can be
    saved to a series of text and binary-curvature files.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import CurvatureStats
    >>> curvstats = CurvatureStats()
    >>> curvstats.inputs.hemisphere = 'lh'
    >>> curvstats.inputs.curvfile1 = 'lh.pial'
    >>> curvstats.inputs.curvfile2 = 'lh.pial'
    >>> curvstats.inputs.surface = 'lh.pial'
    >>> curvstats.inputs.out_file = 'lh.curv.stats'
    >>> curvstats.inputs.values = True
    >>> curvstats.inputs.min_max = True
    >>> curvstats.inputs.write = True
    >>> curvstats.cmdline
    'mris_curvature_stats -m -o lh.curv.stats -F pial -G --writeCurvatureFiles subject_id lh pial pial'
    Zmris_curvature_statsc                s<   |dkr(t jj|jdd }|j| S tt| j|||S )Nrf   r  r  r   r   )rf   r  r  )r+   r-   r.   r$  rF   r   r  r   )r   r   r   r   r   )r   r:   r;   r   	  s    
zCurvatureStats._format_argc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r     s    zCurvatureStats._list_outputsc                sj   | j jrXtj | j _d|kr(| j j|d< t| | j jd t| | j jd t| | j jd t	t
| jf |S )Nr*   r  )r)   r  r+   r,   r*   r<   rf   r  r  r   r  r  )r   r)   )r   r:   r;   r    s    zCurvatureStats.run)r_   r`   ra   r   r   r  r   r  r   r   r   r  r   r:   r:   )r   r;   r    s   %r  c            
   @   sJ   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
gdddddZdS )JacobianInputSpecz%sr   TzOriginal surface)rF   r   rE   rD   rG   r   zMapped surfaceFr   in_origsurfz%s.jacobianz&Output Jacobian of the surface mapping)rF   rD   r   r   r   r   r   rG   Nr   r   r   )r_   r`   ra   r	   r  Zin_mappedsurfr9   r:   r:   r:   r;   r    s   r  c               @   s   e Zd ZedddZdS )JacobianOutputSpecFz&Output Jacobian of the surface mapping)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   r  4  s   r  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )Jacobiana`  
    This program computes the Jacobian of a surface mapping.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import Jacobian
    >>> jacobian = Jacobian()
    >>> jacobian.inputs.in_origsurf = 'lh.pial'
    >>> jacobian.inputs.in_mappedsurf = 'lh.pial'
    >>> jacobian.cmdline
    'mris_jacobian lh.pial lh.pial lh.jacobian'
    Zmris_jacobianc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r   J  s    zJacobian._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   r   r:   r:   r:   r;   r  8  s
   r  c               @   s   e Z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gddZ	ej
ddddgddZejddddgddZdS )MRIsCalcInputSpecz%sr   TzInput file 1)rF   r   rE   rD   rG   r   z"Action to perform on input file(s))rF   r   rE   rG   z-o %szOutput file after calculation)rF   rE   rG   r   in_floatin_intzInput file 2)rF   rD   r   rM   rG   z%fin_file2zInput float)rF   r   rM   rG   z%dzInput integerNr   r   r   r   r   )r_   r`   ra   r	   Zin_file1r
   re   actionr9   r  rj   r  ro   r  r:   r:   r:   r;   r  P  s&   r  c               @   s   e Zd ZedddZdS )MRIsCalcOutputSpecFzOutput file after calculation)rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   r  o  s   r  c               @   s$   e Zd ZdZdZeZeZdd Z	dS )MRIsCalca  
    'mris_calc' is a simple calculator that operates on FreeSurfer
    curvatures and volumes. In most cases, the calculator functions with
    three arguments: two inputs and an <ACTION> linking them. Some
    actions, however, operate with only one input <file1>. In all cases,
    the first input <file1> is the name of a FreeSurfer curvature overlay
    (e.g. rh.curv) or volume file (e.g. orig.mgz). For two inputs, the
    calculator first assumes that the second input is a file. If, however,
    this second input file doesn't exist, the calculator assumes it refers
    to a float number, which is then processed according to <ACTION>.Note:
    <file1> and <file2> should typically be generated on the same subject.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import MRIsCalc
    >>> example = MRIsCalc()
    >>> example.inputs.in_file1 = 'lh.area' # doctest: +SKIP
    >>> example.inputs.in_file2 = 'lh.area.pial' # doctest: +SKIP
    >>> example.inputs.action = 'add'
    >>> example.inputs.out_file = 'area.mid'
    >>> example.cmdline # doctest: +SKIP
    'mris_calc -o lh.area.mid lh.area add lh.area.pial'
    Z	mris_calcc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r     s    zMRIsCalc._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   r   r:   r:   r:   r;   r  s  s
   r  c               @   s   e Z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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gd&dZejddd'ddddZe	dddgddZejdd(d Zejd*d$Zd%S )+VolumeMaskInputSpecz--label_left_white %dTzLeft white matter label)rF   rE   rG   z--label_left_ribbon %dzLeft cortical ribbon labelz--label_right_white %dzRight white matter labelz--label_right_ribbon %dzRight cortical ribbon labelz Implicit input left pial surface)rE   rD   rG   z!Implicit input right pial surfacez(Implicit input left white matter surfacez)Implicit input right white matter surfacer  z Implicit aseg.mgz segmentation. z6Specify a different aseg by using the 'in_aseg' input.)rD   rM   rG   r(   r   z%szSubject being processed)r   r   rF   rE   rG   z--aseg_name %sr  zInput aseg file for VolumeMask)rF   rD   rM   rG   z--save_ribbonz'option to save just the ribbon for the z'hemispheres in the format ?h.ribbon.mgz)rF   rG   z'If running as a node, set this to True.z/This will copy the implicit input files to the znode directory.)rG   NzVImplicit aseg.mgz segmentation. Specify a different aseg by using the 'in_aseg' input.r   zNoption to save just the ribbon for the hemispheres in the format ?h.ribbon.mgzzVIf running as a node, set this to True.This will copy the implicit input files to the zeIf running as a node, set this to True.This will copy the implicit input files to the node directory.)r_   r`   ra   r
   ro   Zleft_whitelabelZleft_ribbonlabelZright_whitelabelZright_ribbonlabelr	   lh_pialrh_piallh_whiterh_whiter  re   r(   r  rh   save_ribbonr  r:   r:   r:   r;   r    sT     r  c               @   s0   e Zd ZedddZedddZedddZdS )VolumeMaskOutputSpecFzOutput cortical ribbon mask)rD   rG   z Output left cortical ribbon maskz!Output right cortical ribbon maskN)r_   r`   ra   r	   
out_ribbon	lh_ribbon	rh_ribbonr:   r:   r:   r;   r    s   r  c                   s@   e Zd ZdZdZeZeZ fddZ	 fddZ
dd Z  ZS )	
VolumeMaskaH  
    Computes a volume mask, at the same resolution as the
    <subject>/mri/brain.mgz.  The volume mask contains 4 values: LH_WM
    (default 10), LH_GM (default 100), RH_WM (default 20), RH_GM (default
    200).
    The algorithm uses the 4 surfaces situated in <subject>/surf/
    [lh|rh].[white|pial] and labels voxels based on the
    signed-distance function from the surface.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import VolumeMask
    >>> volmask = VolumeMask()
    >>> volmask.inputs.left_whitelabel = 2
    >>> volmask.inputs.left_ribbonlabel = 3
    >>> volmask.inputs.right_whitelabel = 41
    >>> volmask.inputs.right_ribbonlabel = 42
    >>> volmask.inputs.lh_pial = 'lh.pial'
    >>> volmask.inputs.rh_pial = 'lh.pial'
    >>> volmask.inputs.lh_white = 'lh.pial'
    >>> volmask.inputs.rh_white = 'lh.pial'
    >>> volmask.inputs.subject_id = '10335'
    >>> volmask.inputs.save_ribbon = True
    >>> volmask.cmdline
    'mris_volmask --label_left_ribbon 3 --label_left_white 2 --label_right_ribbon 42 --label_right_white 41 --save_ribbon 10335'
    Zmris_volmaskc                s   | j jrtj | j _d|kr(| j j|d< t| | j jdd t| | j jdd t| | j jdd t| | j j	dd t| | j j
d t| | j jdd tt| jf |S )	Nr*   r  zlh.pialzrh.pialzlh.whitezrh.whiter  zaseg.mgz)r)   r  r+   r,   r*   r<   r  r  r  r  r  r  r   r  r  )r   r)   )r   r:   r;   r    s    zVolumeMask.runc                s4   |dkr |j tjj|jd S tt| j|||S )Nr  z.mgz)rF   r+   r-   r.   rstripr   r  r   )r   r   r   r   )r   r:   r;   r     s    zVolumeMask._format_argc             C   sf   | j  j }tjj| jj| jjd}tjj|d|d< | jjrbtjj|d|d< tjj|d|d< |S )Nr  z
ribbon.mgzr  zrh.ribbon.mgzr  zlh.ribbon.mgzr  )	r   r   r+   r-   r/   r)   r*   r(   r  )r   r@   r8   r:   r:   r;   r     s    zVolumeMask._list_outputs)r_   r`   ra   r   r   r  r   r  r   r  r   r   r   r:   r:   )r   r;   r    s   r  c               @   sv  e Zd Zejddd=ddddZejddd>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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Zejd?dddZejdddZeddd d!Zed"dd#gd$d%Zed&dd'd(gd)d%Zejd*d+dZed,d-dd.gd/d0Zed1d-dd#gd2d3ZejdAd7Zejd8d9gd:d;Zd<S )BParcellationStatsInputSpecr(   Tr   z%szSubject being processed)r   r   rF   rE   rG   rH   rI   r   zHemisphere being processed)r   rF   rE   rG   z*Input file must be <subject_id>/mri/wm.mgz)rE   rD   rG   z-Input file must be <subject_id>/surf/lh.whitez-Input file must be <subject_id>/surf/rh.whitez,Input file must be <subject_id>/surf/lh.pialz,Input file must be <subject_id>/surf/rh.pialz<Input file must be <subject_id>/mri/transforms/talairach.xfmz1Input file must be <subject_id>/surf/?h.thicknessz1Input file must be <subject_id>/mri/brainmask.mgzz4Input file must be <subject_id>/mri/aseg.presurf.mgzz.Input file must be <subject_id>/mri/ribbon.mgzz'implicit input file {hemi}.cortex.label)rD   rG   r   zInput surface (e.g. 'white'))r   rF   rG   z-mgzzLook for mgz files)rF   rG   z
-cortex %szInput cortex label)rF   rD   rG   z-a %sr  zCcompute properties for each label in the annotation file separately)rF   rD   rM   rG   z-l %sZin_annotatoin	out_colorz%limit calculations to specified labelz-bzTabular outputz-f %sFtabular_outputzTable output to tablefile)rF   rD   r^   rN   rG   z-c %sz1Output annotation files's colortable to text file)rF   rD   r^   rM   rG   z'If running as a node, set this to True.z+This will copy the input files to the node z
directory.)rG   z-th3cortex_labelz8turns on new vertex-wise volume calc for mris_anat_stats)rF   rN   rG   Nr   r   r   zRIf running as a node, set this to True.This will copy the input files to the node z\If running as a node, set this to True.This will copy the input files to the node directory.)r_   r`   ra   r
   re   r(   rc   r  r	   rA  r  r  r  r  rj  r   	brainmaskr  ribbonr  rf   rh   r   Z	in_cortexin_annotationr  r  	out_tabler  r  Zth3r:   r:   r:   r;   r    s   r  c               @   s$   e Zd ZedddZedddZdS )ParcellationStatsOutputSpecFzTable output to tablefile)rD   rG   z1Output annotation files's colortable to text fileN)r_   r`   ra   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 )	ParcellationStatsa  
    This program computes a number of anatomical properties.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import ParcellationStats
    >>> import os
    >>> parcstats = ParcellationStats()
    >>> parcstats.inputs.subject_id = '10335'
    >>> parcstats.inputs.hemisphere = 'lh'
    >>> parcstats.inputs.wm = './../mri/wm.mgz' # doctest: +SKIP
    >>> parcstats.inputs.transform = './../mri/transforms/talairach.xfm' # doctest: +SKIP
    >>> parcstats.inputs.brainmask = './../mri/brainmask.mgz' # doctest: +SKIP
    >>> parcstats.inputs.aseg = './../mri/aseg.presurf.mgz' # doctest: +SKIP
    >>> parcstats.inputs.ribbon = './../mri/ribbon.mgz' # doctest: +SKIP
    >>> parcstats.inputs.lh_pial = 'lh.pial' # doctest: +SKIP
    >>> parcstats.inputs.rh_pial = 'lh.pial' # doctest: +SKIP
    >>> parcstats.inputs.lh_white = 'lh.white' # doctest: +SKIP
    >>> parcstats.inputs.rh_white = 'rh.white' # doctest: +SKIP
    >>> parcstats.inputs.thickness = 'lh.thickness' # doctest: +SKIP
    >>> parcstats.inputs.surface = 'white'
    >>> parcstats.inputs.out_table = 'lh.test.stats'
    >>> parcstats.inputs.out_color = 'test.ctab'
    >>> parcstats.cmdline # doctest: +SKIP
    'mris_anatomical_stats -c test.ctab -f lh.test.stats 10335 lh white'
    Zmris_anatomical_statsc                s:  | j jrtj | j _d|kr*| j j|d< t| | j jdd t| | j jdd t| | j jdd t| | j j	dd t| | j j
dd t| | j jtjjdd	d
 t| | j jdd t| | j jdd t| | j jdd t| | j jddj| j j t| j jrt| | j jddj| j j t| j  tt| jf |S )Nr*   r  zlh.whitezlh.pialzrh.whitezrh.pialr  zwm.mgzZ
transformsztalairach.xfmzbrainmask.mgzzaseg.presurf.mgzz
ribbon.mgzz{0}.thicknessrE  z{0}.cortex.label)r)   r  r+   r,   r*   r<   r  r  r  r  rA  rj  r-   r/   r  r  r  r   r   r  r   r  rB   r   r   r  r  )r   r)   )r   r:   r;   r    s<    
zParcellationStats.runc             C   s   |dkr| j  | S d S )Nr  r  )r  r  )r   )r   r   r:   r:   r;   r     s    zParcellationStats._gen_filenamec             C   s  | j  j }t| jjr.tjj| jj|d< ntjj| jj	| jj
d}t| jjr| jjdkrxtjj| jjjdd}qtjj| jjjdd}n\t| jjr| jjdkrtjj| jjjdd}qtjj| jjjdd}nt| jjd }tjj|||d< t| jjr$tjj| jj|d	< ntjj| jj	| jj
d
}t| jjrtjj| jj}xdD ]}|j|d}q`W |}d|krtjj||d |d	< ntjj|d| d |d	< ntjj|d|d	< |S )Nr  statsr   z.annotz.pial.statsz.statsz.labelz.aparc.annot.statsr  rE  lh.rh.aparc.annotry   ZBAZctabzaparc.annot.zaparc.annot.ctab)r  r  r  r  )r   r   r   r)   r  r+   r-   r   r/   r*   r(   r  rf   r.   replacer  r?  r  r  )r   r@   Z	stats_dirr.   r8   itemr  r:   r:   r;   r     sD    





zParcellationStats._list_outputs)r_   r`   ra   r   r   r  r   r  r   r  r   r   r   r:   r:   )r   r;   r    s   #r  c               @   s   e Zd ZejddddddZejdd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ZdS )ContrastInputSpecr(   z--s %sTzSubject being processed)rF   r   rE   rG   rH   rI   z	--%s-onlyzHemisphere being processed)rF   rE   rG   z1Input file must be <subject_id>/surf/?h.thickness)rE   rD   rG   z7Input file must be <subject_id>/surf/<hemisphere>.whitezIInput annotation file must be <subject_id>/label/<hemisphere>.aparc.annotzGInput cortex label must be <subject_id>/label/<hemisphere>.cortex.labelz Implicit input file mri/orig.mgz)rD   rE   rG   z"Implicit input file mri/rawavg.mgzz'If running as a node, set this to True.z+This will copy the input files to the node z
directory.)rG   NzRIf running as a node, set this to True.This will copy the input files to the node z\If running as a node, set this to True.This will copy the input files to the node directory.)r_   r`   ra   r
   re   r(   rc   r  r	   r   r   
annotationr   r   rawavgrh   r  r:   r:   r:   r;   r    sB   r  c               @   s0   e Zd ZedddZedddZedddZdS )ContrastOutputSpecFz"Output contrast file from Contrast)rD   rG   zOutput stats file from ContrastTzOutput log from ContrastN)r_   r`   ra   r	   out_contrast	out_statsrw  r:   r:   r:   r;   r  =  s   r  c                   s4   e Zd ZdZdZeZeZ fddZ	dd Z
  ZS )Contrasta  
    Compute surface-wise gray/white contrast

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import Contrast
    >>> contrast = Contrast()
    >>> contrast.inputs.subject_id = '10335'
    >>> contrast.inputs.hemisphere = 'lh'
    >>> contrast.inputs.white = 'lh.white' # doctest: +SKIP
    >>> contrast.inputs.thickness = 'lh.thickness' # doctest: +SKIP
    >>> contrast.inputs.annotation = '../label/lh.aparc.annot' # doctest: +SKIP
    >>> contrast.inputs.cortex = '../label/lh.cortex.label' # doctest: +SKIP
    >>> contrast.inputs.rawavg = '../mri/rawavg.mgz' # doctest: +SKIP
    >>> contrast.inputs.orig = '../mri/orig.mgz' # doctest: +SKIP
    >>> contrast.cmdline # doctest: +SKIP
    'pctsurfcon --lh-only --s 10335'
    Z
pctsurfconc                s   | j jrtj | j _d|kr(| j j|d< | j j}t| | j jddj| t| | j j	ddj| t| | j j
ddj| t| | j jddj| t| | j jdd	 t| | j jdd
 t| j  tt| jf |S )Nr*   rE  z{0}.aparc.annotz{0}.cortex.labelr  z	{0}.whitez{0}.thicknessr  zorig.mgzz
rawavg.mgz)r)   r  r+   r,   r*   r  r<   r  r   r   r   r   r   r  rB   r   r   r  r  )r   r)   rd   )r   r:   r;   r  [  s     zContrast.runc             C   sz   | j  j }tjj| jj| jj}tjj|dt| jj	d |d< tjj|dt| jj	d |d< tjj|dd|d	< |S )
Nr  z.w-g.pct.mghr  r  z.w-g.pct.statsr  scriptszpctsurfcon.logrw  )
r   r   r+   r-   r/   r)   r*   r(   r?  r  )r   r@   Zsubject_dirr:   r:   r;   r   q  s    zContrast._list_outputs)r_   r`   ra   r   r   r  r   r  r   r  r   r   r:   r:   )r   r;   r  C  s   r  c            
   @   sl   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ddddZeddddgdddddZ	dS )RelabelHypointensitiesInputSpecTz$Implicit input file must be lh.white)rE   rD   r   rG   z$Implicit input file must be rh.whitez%sr   zInput aseg file)rF   r   rE   rD   rG   r   r   z*Directory containing lh.white and rh.white)rF   r   rD   r   rG   r   Fr  z%s.hypos.mgzzOutput aseg file)rF   r   rD   r   r   r   r   rG   Nr   r   r   )
r_   r`   ra   r	   r  r  r  r   Zsurf_directoryr9   r:   r:   r:   r;   r  ~  s8   r  c               @   s   e Zd ZeddddZdS ) RelabelHypointensitiesOutputSpecz%sFzOutput aseg file)rF   rD   rG   N)r_   r`   ra   r	   r9   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 )RelabelHypointensitiesa  
    Relabel Hypointensities

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import RelabelHypointensities
    >>> relabelhypos = RelabelHypointensities()
    >>> relabelhypos.inputs.lh_white = 'lh.pial'
    >>> relabelhypos.inputs.rh_white = 'lh.pial'
    >>> relabelhypos.inputs.surf_directory = '.'
    >>> relabelhypos.inputs.aseg = 'aseg.mgz'
    >>> relabelhypos.cmdline
    'mri_relabel_hypointensities aseg.mgz . aseg.hypos.mgz'
    Zmri_relabel_hypointensitiesc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r     s    z$RelabelHypointensities._list_outputsN)
r_   r`   ra   r   r   r  r   r  r   r   r:   r:   r:   r;   r    s
   r  c               @   s(  e Zd Zejddddd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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dddZeddddZej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'Zd(S ))Aparc2AsegInputSpecr(   z--s %sTzSubject being processed)rF   r   rE   rG   z--o %sFz4Full path of file to save the output segmentation in)rF   rD   rE   rG   z-Input file must be <subject_id>/surf/lh.white)rE   rD   rG   z-Input file must be <subject_id>/surf/rh.whitez,Input file must be <subject_id>/surf/lh.pialz,Input file must be <subject_id>/surf/rh.pialz1Input file must be <subject_id>/mri/lh.ribbon.mgzz1Input file must be <subject_id>/mri/rh.ribbon.mgzz.Input file must be <subject_id>/mri/ribbon.mgzz4Input file must be <subject_id>/label/lh.aparc.annotz4Input file must be <subject_id>/label/rh.aparc.annotz7Implicit input filled file. Only required with FS v5.3.)rD   rG   z	--aseg %szInput aseg file)rF   rD   rG   z	--volmaskzVolume mask flag)rF   rG   z--ctxseg %sry   z	--labelwmzFor each voxel labeled as white matter in the aseg, re-assign
its label to be that of the closest cortical point if its
distance is less than dmaxctx.z--hypo-as-wmzLabel hypointensities as WMz--rip-unknownz0Do not label WM based on 'unknown' corical labelz--a2009szUsing the a2009s atlasz\If running as a node, set this to True.This will copy the input files to the node directory.)rG   N)r_   r`   ra   r
   re   r(   r	   r9   r  r  r  r  r  r  r  lh_annotationrh_annotationfilledr  rh   ZvolmaskZctxsegZlabel_wmZhypo_wmZrip_unknownZa2009sr  r:   r:   r:   r;   r    sr   

r  c               @   s   e Zd ZedddZdS )Aparc2AsegOutputSpecz%szOutput aseg file)rF   rG   N)r_   r`   ra   r	   r9   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	 fddZ
dd Z  ZS )	
Aparc2Asega  
    Maps the cortical labels from the automatic cortical parcellation
    (aparc) to the automatic segmentation volume (aseg). The result can be
    used as the aseg would. The algorithm is to find each aseg voxel
    labeled as cortex (3 and 42) and assign it the label of the closest
    cortical vertex. If the voxel is not in the ribbon (as defined by mri/
    lh.ribbon and rh.ribbon), then the voxel is marked as unknown (0).
    This can be turned off with ``--noribbon``. The cortical parcellation is
    obtained from subject/label/hemi.aparc.annot which should be based on
    the curvature.buckner40.filled.desikan_killiany.gcs atlas. The aseg is
    obtained from subject/mri/aseg.mgz and should be based on the
    RB40_talairach_2005-07-20.gca atlas. If these atlases are used, then the
    segmentations can be viewed with tkmedit and the
    FreeSurferColorLUT.txt color table found in ``$FREESURFER_HOME``. These
    are the default atlases used by ``recon-all``.

    Examples
    --------
    >>> from nipype.interfaces.freesurfer import Aparc2Aseg
    >>> aparc2aseg = Aparc2Aseg()
    >>> aparc2aseg.inputs.lh_white = 'lh.pial'
    >>> aparc2aseg.inputs.rh_white = 'lh.pial'
    >>> aparc2aseg.inputs.lh_pial = 'lh.pial'
    >>> aparc2aseg.inputs.rh_pial = 'lh.pial'
    >>> aparc2aseg.inputs.lh_ribbon = 'label.mgz'
    >>> aparc2aseg.inputs.rh_ribbon = 'label.mgz'
    >>> aparc2aseg.inputs.ribbon = 'label.mgz'
    >>> aparc2aseg.inputs.lh_annotation = 'lh.pial'
    >>> aparc2aseg.inputs.rh_annotation = 'lh.pial'
    >>> aparc2aseg.inputs.out_file = 'aparc+aseg.mgz'
    >>> aparc2aseg.inputs.label_wm = True
    >>> aparc2aseg.inputs.rip_unknown = True
    >>> aparc2aseg.cmdline # doctest: +SKIP
    'mri_aparc2aseg --labelwm  --o aparc+aseg.mgz --rip-unknown --s subject_id'

    Zmri_aparc2asegc                s   | j jrtj | j _d|kr(| j j|d< t| | j jdd t| | j jdd t| | j jdd t| | j j	dd t| | j j
dd t| | j jdd	 t| | j jdd
 t| | j jd t| | j jdd t| | j jd t| | j jd tt| jf |S )Nr*   r  zlh.whitezlh.pialzrh.whitezrh.pialr  zlh.ribbon.mgzzrh.ribbon.mgzz
ribbon.mgzz
filled.mgzrE  )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  B  s     zAparc2Aseg.runc                sT   |dkr&t jj|jdd}|j| S |dkr@|jt jj| S tt| j|||S )Nr  z.mgzry   r9   )	r+   r-   r.   r  rF   r   r   r  r   )r   r   r   r   r.   )r   r:   r;   r   U  s    
zAparc2Aseg._format_argc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r   _  s    zAparc2Aseg._list_outputs)r_   r`   ra   r   r   r  r   r  r   r  r   r   r   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dS )	Apas2AsegInputSpecz--i %sTzInput aparc+aseg.mgz)rF   rE   rD   rG   z--o %szOutput aseg file)rF   rE   rG   N)r_   r`   ra   r	   r6   r9   r:   r:   r:   r;   r  e  s   r  c               @   s   e Zd ZeddddZdS )Apas2AsegOutputSpecz%sFzOutput aseg file)rF   rD   rG   N)r_   r`   ra   r	   r9   r:   r:   r:   r;   r   m  s   r   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )	Apas2Asega3  
    Converts aparc+aseg.mgz into something like aseg.mgz by replacing the
    cortical segmentations 1000-1035 with 3 and 2000-2035 with 42. The
    advantage of this output is that the cortical label conforms to the
    actual surface (this is not the case with aseg.mgz).

    Examples
    --------
    >>> from nipype.interfaces.freesurfer import Apas2Aseg
    >>> apas2aseg = Apas2Aseg()
    >>> apas2aseg.inputs.in_file = 'aseg.mgz'
    >>> apas2aseg.inputs.out_file = 'output.mgz'
    >>> apas2aseg.cmdline
    'apas2aseg --i aseg.mgz --o output.mgz'

    Z	apas2asegc             C   s$   | j  j }tjj| jj|d< |S )Nr9   )r   r   r+   r-   r   r)   r9   )r   r@   r:   r:   r;   r     s    zApas2Aseg._list_outputsN)
r_   r`   ra   r   r   r  r   r   r   r   r:   r:   r:   r;   r  q  s
   r  c               @   s   e Zd Z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Z	ej
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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 )(MRIsExpandInputSpecTz%sr   FzSurface to expand)rD   rE   rF   r   r   rG   z%gr   z0Distance in mm or fraction of cortical thickness)rE   rF   r   rG   expandedr   z~Output surface file. If no path, uses directory of ``in_file``. If no path AND missing "lh." or "rh.", derive from ``in_file``)rF   r   r   rG   z
-thicknessz0Expand by fraction of cortical thickness, not mm)rF   rG   z-thickness_name %szName of thickness file (implicit: "thickness")
If no path, uses directory of ``in_file``
If no path AND missing "lh." or "rh.", derive from `in_file`)rF   r   rG   z-pial %szName of pial file (implicit: "pial")
If no path, uses directory of ``in_file``
If no path AND missing "lh." or "rh.", derive from ``in_file``r   z!WARNING: Do not change this trait)r   r   rG   z-S %gzSpring term (implicit: 0.05)z-T %gzdt (implicit: 0.25)z-W %dz/Write snapshots of expansion every N iterationsz-A %dz0Smooth surface with N iterations after expansionz-N %dz-Number of surfacces to write during expansionNr   r   r   )r_   r`   ra   r	   r6   r
   rj   Zdistancerm   rU  rh   r   thickness_namer   r   Zspringdtro   Zwrite_iterationsZsmooth_averagesZ	nsurfacesr:   r:   r:   r;   r    sR   


r  c               @   s   e Zd ZeddZdS )MRIsExpandOutputSpeczOutput surface file)rG   N)r_   r`   ra   r	   r9   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 )
MRIsExpanda  
    Expands a surface (typically ?h.white) outwards while maintaining
    smoothness and self-intersection constraints.

    Examples
    ========
    >>> from nipype.interfaces.freesurfer import MRIsExpand
    >>> mris_expand = MRIsExpand(thickness=True, distance=0.5)
    >>> mris_expand.inputs.in_file = 'lh.white'
    >>> mris_expand.cmdline
    'mris_expand -thickness lh.white 0.5 expanded'
    >>> mris_expand.inputs.out_name = 'graymid'
    >>> mris_expand.cmdline
    'mris_expand -thickness lh.white 0.5 graymid'
    Zmris_expandc             C   s(   | j  j }| j| jj| jj|d< |S )Nr9   )r   r   _associated_filer)   r6   rU  )r   r@   r:   r:   r;   r     s    zMRIsExpand._list_outputsc             C   s|   | j j}| j j}t|sd}| j||| j _t| j jrd| j jrd| j j}t|sTd}| j||| j _| j|| j j| j _dS )z
        Filename normalization routine to perform only when run in Node
        context.
        Find full paths for pial, thickness and sphere files for copying.
        r   r   N)r)   r6   r   r   r  r   r  r   )r   r6   r   r  r:   r:   r;   r:    s    zMRIsExpand.normalize_filenamesN)r_   r`   ra   r   r   r  r   r  r   r   r:  r:   r:   r:   r;   r    s   r  c               @   s*  e Zd Zd-Zejeddd	d
deddZedddeddZedddeddZ	edddeddZ
edddeddZedddeddZejejedddZejejedddZejejedddZejejedd dZejejed!d"dZejd#d$Zejd%d&gd'Zedd(d)Zedd*d)Zejd+d$Zd,S ).LTAConvertInputSpecin_ltain_fslin_mniin_regin_niftyregin_itkT)rD   zidentity.nofilez
--inlta %szinput transform of LTA type)rF   rE   rM   rG   z
--infsl %szinput transform of FSL type)rD   rF   rE   rM   rG   z
--inmni %szinput transform of MNI/XFM typez
--inreg %sz2input transform of TK REG type (deprecated format)z--inniftyreg %sz3input transform of Nifty Reg type (inverse RAS2RAS)z
--initk %szinput transform of ITK typez--outlta %sz/output linear transform (LTA Freesurfer format))rF   rG   z--outfsl %szoutput transform in FSL formatz--outmni %sz"output transform in MNI/XFM formatz--outreg %sz"output transform in reg dat formatz--outitk %szoutput transform in ITK formatz--invert)rF   z--ltavox2voxout_lta)rF   rN   z--src %s)rD   rF   z--trg %sz--trgconformN)r
  r  r  r  r  r  )r_   r`   ra   Z_in_xorr
   rl   r	   r
  r  r  r  r  r  rh   r  out_fslout_mniout_regout_itkinvertZ
ltavox2voxrb   Ztarget_fileZtarget_conformr:   r:   r:   r;   r	    s|   r	  c               @   sH   e Zd ZedddZedddZedddZedddZedddZdS )	LTAConvertOutputSpecTz/output linear transform (LTA Freesurfer format))rD   rG   zoutput transform in FSL formatz"output transform in MNI/XFM formatz"output transform in reg dat formatzoutput transform in ITK formatN)	r_   r`   ra   r	   r  r  r  r  r  r:   r:   r:   r;   r  a  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 )
LTAConverta:  Convert different transformation formats.
    Some formats may require you to pass an image if the geometry information
    is missing form the transform file format.

    For complete details, see the `lta_convert documentation.
    <https://ftp.nmr.mgh.harvard.edu/pub/docs/html/lta_convert.help.xml.html>`_
    Zlta_convertc                s2   |j dr|dkr| j | }tt| j|||S )NZout_T)
startswithr   r   r  r   )r   r   r   r   )r   r:   r;   r   v  s    zLTAConvert._format_argc             C   sR   | j  j }x@dD ]8\}}t| j|}|r|dkr6|n|}tjj|||< qW |S )Nr  out.ltar  out.matr  out.xfmr  out.datr  out.txtT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   rB  attrfnamer:   r:   r;   r   {  s        zLTAConvert._list_outputs)r_   r`   ra   r   r	  r   r  r   r   r   r   r   r:   r:   )r   r;   r  i  s   r  )NNN)r   r+   r   r3   ry   r   Zutils.filemanipr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Z__docformat__r|   r~   rq   rr   	getLoggerr   r<   rB   rC   rv   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r'  r.  r0  r4  r6  r7  r;  r=  r>  r@  rG  rH  rI  rJ  rK  rL  rN  rO  rR  rV  rX  rY  rZ  r[  r\  rd  rg  ri  rl  rm  rn  rr  rs  rt  rv  ry  rz  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  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r	  r  r  r:   r:   r:   r;   <module>   sV  (
$

! .	 45f52  ,d5
5 &6!&62HM.$
$!,>
$I	 
&9A#<=m 0;%SMO2O