3
dǊ                 @   s  d dl jZddlmZ ddlmZmZmZm	Z	m
Z
mZmZ ddlmZmZ G dd	 d	eZG d
d de	ZG dd deZG dd deZG dd de	ZG dd deZG dd deZG dd de	ZG dd deZG dd deZG dd de	ZG dd deZG d d! d!eZG d"d# d#e	ZG d$d% d%eZG d&d' d'eZG d(d) d)e	ZG d*d+ d+eZ G d,d- d-eZ!G d.d/ d/e	Z"G d0d1 d1eZ#G d2d3 d3eZ$G d4d5 d5e	Z%G d6d7 d7eZ&G d8d9 d9eZ'G d:d; d;e	Z(G d<d= d=eZ)G d>d? d?eZ*G d@dA dAe	Z+G dBdC dCeZ,G dDdE dEeZ-G dFdG dGe	Z.G dHdI dIeZ/G dJdK dKeZ0G dLdM dMe	Z1G dNdO dOeZ2G dPdQ dQeZ3G dRdS dSe	Z4G dTdU dUeZ5G dVdW dWeZ6G dXdY dYe	Z7G dZd[ d[eZ8G d\d] d]eZ9G d^d_ d_e	Z:G d`da daeZ;dS )b    N   )split_filename   )CommandLineInputSpecCommandLinetraitsTraitedSpecFileInputMultiPath	isdefined   )MRTrix3BaseInputSpecMRTrix3Basec               @   s2   e Zd ZeddddddZeddddddd	Zd
S )BrainMaskInputSpecTz%sr   zinput diffusion weighted images)existsargstr	mandatorypositiondesczbrainmask.mifr   zoutput brain mask)r   r   r   
usedefaultr   N)__name__
__module____qualname__r	   in_fileout_file r   r   A/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/mrtrix3/utils.pyr      s   r   c               @   s   e Zd ZedddZdS )BrainMaskOutputSpecTzthe output response file)r   r   N)r   r   r   r	   r   r   r   r   r   r   &   s   r   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )	BrainMaska  
    Convert a mesh surface to a partial volume estimation image


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> bmsk = mrt.BrainMask()
    >>> bmsk.inputs.in_file = 'dwi.mif'
    >>> bmsk.cmdline                               # doctest: +ELLIPSIS
    'dwi2mask dwi.mif brainmask.mif'
    >>> bmsk.run()                                 # doctest: +SKIP
    Zdwi2maskc             C   s"   | j  j }tj| jj|d< |S )Nr   )output_specgetopabspathinputsr   )selfoutputsr   r   r   _list_outputs>   s    zBrainMask._list_outputsN)
r   r   r   __doc___cmdr   
input_specr   r!   r(   r   r   r   r   r    *   s
   r    c            %   @   s   e Zd Zejedddd2dddZedddd3dd	d
ZejdddZ	ej
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d#Zd1S )4MRCatInputSpecT)r   z%sr   zfiles to concatenate)r   r   r   r   zconcatenated.mifr   zoutput concatenated image)r   r   r   r   r   z-axis %sa  specify axis along which concatenation should be performed. By default,
     the program will use the last non-singleton, non-spatial axis of any of
     the input images - in other words axis 3 or whichever axis (greater than
     3) of the input images has size greater than one)r   r   Zfloat32Z	float32leZ	float32beZfloat64Z	float64leZ	float64beZint64Zuint64Zint64leZuint64leZint64beZuint64beZint32Zuint32Zint32leZuint32leZint32beZuint32beZint16Zuint16Zint16leZuint16leZint16beZuint16beZcfloat32Z
cfloat32leZ
cfloat32beZcfloat64Z
cfloat64leZ
cfloat64beZint8Zuint8bitz-datatype %szspecify output image data typeNr   r   )r   r   r   r   Listr	   in_filesr   IntaxisEnumdatatyper   r   r   r   r,   D   sh   r,   c               @   s   e Zd ZedddZdS )MRCatOutputSpecTzthe output concatenated image)r   r   N)r   r   r   r	   r   r   r   r   r   r4      s   r4   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )MRCata  
    Concatenate several images into one


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> mrcat = mrt.MRCat()
    >>> mrcat.inputs.in_files = ['dwi.mif','mask.mif']
    >>> mrcat.cmdline                               # doctest: +ELLIPSIS
    'mrcat dwi.mif mask.mif concatenated.mif'
    >>> mrcat.run()                                 # doctest: +SKIP
    Zmrcatc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(      s    zMRCat._list_outputsN)
r   r   r   r)   r*   r,   r+   r4   r!   r(   r   r   r   r   r5      s
   r5   c               @   sR   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dddZdS )Mesh2PVEInputSpecTz%sr   z
input mesh)r   r   r   r   r   r   zinput reference imagez	-first %sz5indicates that the mesh file is provided by FSL FIRST)r   r   r   zmesh2volume.nii.gzr   z&output file containing SH coefficients)r   r   r   r   r   Nr   r   )r   r   r   r	   r   	referenceZin_firstr   r   r   r   r   r6      s&   r6   c               @   s   e Zd ZedddZdS )Mesh2PVEOutputSpecTzthe output response file)r   r   N)r   r   r   r	   r   r   r   r   r   r9      s   r9   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )Mesh2PVEa  
    Convert a mesh surface to a partial volume estimation image


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> m2p = mrt.Mesh2PVE()
    >>> m2p.inputs.in_file = 'surf1.vtk'
    >>> m2p.inputs.reference = 'dwi.mif'
    >>> m2p.inputs.in_first = 'T1.nii.gz'
    >>> m2p.cmdline                               # doctest: +ELLIPSIS
    'mesh2pve -first T1.nii.gz surf1.vtk dwi.mif mesh2volume.nii.gz'
    >>> m2p.run()                                 # doctest: +SKIP
    Zmesh2pvec             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(      s    zMesh2PVE._list_outputsN)
r   r   r   r)   r*   r6   r+   r9   r!   r(   r   r   r   r   r:      s
   r:   c            	   @   sF   e Zd ZejddddddddZeddddd
dZedddddZdS )Generate5ttInputSpecZfslZgifZ
freesurferz%sr   Tztissue segmentation algorithm)r   r   r   r   r   zinput image)r   r   r   r   r   r   zoutput image)r   r   r   r   Nr7   r   r   )	r   r   r   r   r2   	algorithmr	   r   r   r   r   r   r   r;      s   r;   c               @   s   e Zd ZedddZdS )Generate5ttOutputSpecTzoutput image)r   r   N)r   r   r   r	   r   r   r   r   r   r=      s   r=   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )Generate5tta  
    Generate a 5TT image suitable for ACT using the selected algorithm


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> gen5tt = mrt.Generate5tt()
    >>> gen5tt.inputs.in_file = 'T1.nii.gz'
    >>> gen5tt.inputs.algorithm = 'fsl'
    >>> gen5tt.inputs.out_file = '5tt.mif'
    >>> gen5tt.cmdline                             # doctest: +ELLIPSIS
    '5ttgen fsl T1.nii.gz 5tt.mif'
    >>> gen5tt.run()                               # doctest: +SKIP
    Z5ttgenc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(     s    zGenerate5tt._list_outputsN)
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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
edddZedddZedddZejdgdddddZeddddZejd d!d"d#d$dZd%S )'TensorMetricsInputSpecTz%sr   zinput DTI image)r   r   r   r   r   z-fa %szoutput FA file)r   r   z-adc %szoutput ADC filez-ad %szoutput AD filez-rd %szoutput RD filez-cl %szoutput CL filez-cp %szoutput CP filez-cs %szoutput CS filez
-vector %sz#output selected eigenvector(s) filez	-value %sz"output selected eigenvalue(s) filez-num %s,zrspecify the desired eigenvalue/eigenvector(s). Note that several eigenvalues can be specified as a number sequence)r   r   sepr   z-mask %szEonly perform computation within the specified binary brain mask image)r   r   r   ZFAnoneevalz-modulate %sz1how to modulate the magnitude of the eigenvectorsNr   )r   r   r   r	   r   out_faout_adcout_adout_rdout_clout_cpout_csout_evecout_evalr   r.   	componentZin_maskr2   Zmodulater   r   r   r   r?     s>   r?   c               @   sf   e Zd ZeddZeddZeddZeddZeddZeddZ	eddZ
ed	dZed
dZdS )TensorMetricsOutputSpeczoutput FA file)r   zoutput ADC filezoutput AD filezoutput RD filezoutput CL filezoutput CP filezoutput CS filez#output selected eigenvector(s) filez"output selected eigenvalue(s) fileN)r   r   r   r	   rD   rE   rF   rG   rH   rI   rJ   rK   rL   r   r   r   r   rN   :  s   







rN   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )TensorMetricsa  
    Compute metrics from tensors


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> comp = mrt.TensorMetrics()
    >>> comp.inputs.in_file = 'dti.mif'
    >>> comp.inputs.out_fa = 'fa.mif'
    >>> comp.cmdline                               # doctest: +ELLIPSIS
    'tensor2metric -num 1 -fa fa.mif dti.mif'
    >>> comp.run()                                 # doctest: +SKIP
    Ztensor2metricc             C   sL   | j  j }x:t|j D ]*}tt| j|rtjt| j|||< qW |S )N)	r!   r"   listkeysr   getattrr%   r#   r$   )r&   r'   kr   r   r   r(   [  s
    zTensorMetrics._list_outputsN)
r   r   r   r)   r*   r?   r+   rN   r!   r(   r   r   r   r   rO   F  s
   rO   c               @   sT  e Zd ZeddddFddZeddddGdd	Zedd
ddZejej	ddddZ
ejdddddZejdddZedddZej	dddZejddddd d!d"d#d$d	Zedd%d&dZejd'd(d)d*d+d,dZejd)d'd(d*d-d.d/d0d1d2d3d4d5dZejd6d7dZejd8d9dZej	d:d;dZejd<d=dZejd>d?dZedd@dAdZej	dBdCddDZdES )HComputeTDIInputSpecTz%sr   zinput tractography)r   r   r   r   r   ztdi.mifr   zoutput TDI file)r   r   r   r   z-template %sz'a referenceimage to be used as template)r   r   r   z-vox %sr@   zvoxel dimensions)r   rA   r   floatzunsigned intz-datatype %szspecify output image data type)r   r   z-deczperform mapping in DEC spacez	-dixel %sz\map streamlines todixels within each voxel. Directions are stored asazimuth elevation pairs.z-tod %dz>generate a Track Orientation Distribution (TOD) in each voxel.ZtdilengthZ	invlengthZ
scalar_mapZscalar_map_conutZfod_ampZ	curvaturez-constrast %sz8define the desired form of contrast for the output imagez	-image %szkprovide thescalar image map for generating images with 'scalar_map' contrasts, or the SHs image for fod_ampsumminmeanmaxz-stat_vox %szPdefine the statistic for choosing the finalvoxel intesities for a given contrastmedianZmean_nonzeroZgaussianZends_minZ	ends_meanZends_maxZ	ends_prodz-stat_tck %szdefine the statistic for choosing the contribution to be made by each streamline as a function of the samples taken along their lengths.z-fwhm_tck %fzdefine the statistic for choosing the contribution to be made by each streamline as a function of the samples taken along their lengthsz	-map_zeroa  if a streamline has zero contribution based on the contrast & statistic, typically it is not mapped; use this option to still contribute to the map even if this is the case (these non-contributing voxels can then influence the mean value in each voxel of the map)z-upsample %dzMupsample the tracks by some ratio using Hermite interpolation before mapppingz-precisezuse a more precise streamline mapping strategy, that accurately quantifies the length through each voxel (these lengths are then taken into account during TWI calculation)z
-ends_onlyz.only map the streamline endpoints to the imagez-tck_weights_in %sz<specify a text scalar file containing the streamline weightsz-nthreads %dzEnumber of threads. if zero, the number of available cpus will be used)r   r   nohashNr   r   )r   r   r   r	   r   r   r8   r   r.   r0   Zvox_sizer2   Z	data_typeBoolZuse_decZdixelZmax_todZcontrastZin_mapZstat_voxZstat_tckFloatZfwhm_tckZmap_zeroZupsampleZpreciseZ	ends_onlyZtck_weightsnthreadsr   r   r   r   rT   e  s   
rT   c               @   s   e Zd ZeddZdS )ComputeTDIOutputSpeczoutput TDI file)r   N)r   r   r   r	   r   r   r   r   r   r`     s   r`   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )
ComputeTDIa  
    Use track data as a form of contrast for producing a high-resolution
    image.

    .. admonition:: References

      * For TDI or DEC TDI: Calamante, F.; Tournier, J.-D.; Jackson, G. D. &
        Connelly, A. Track-density imaging (TDI): Super-resolution white
        matter imaging using whole-brain track-density mapping. NeuroImage,
        2010, 53, 1233-1243

      * If using -contrast length and -stat_vox mean: Pannek, K.; Mathias,
        J. L.; Bigler, E. D.; Brown, G.; Taylor, J. D. & Rose, S. E. The
        average pathlength map: A diffusion MRI tractography-derived index
        for studying brain pathology. NeuroImage, 2011, 55, 133-141

      * If using -dixel option with TDI contrast only: Smith, R.E., Tournier,
        J-D., Calamante, F., Connelly, A. A novel paradigm for automated
        segmentation of very large whole-brain probabilistic tractography
        data sets. In proc. ISMRM, 2011, 19, 673

      * If using -dixel option with any other contrast: Pannek, K., Raffelt,
        D., Salvado, O., Rose, S. Incorporating directional information in
        diffusion tractography derived maps: angular track imaging (ATI).
        In Proc. ISMRM, 2012, 20, 1912

      * If using -tod option: Dhollander, T., Emsell, L., Van Hecke, W., Maes,
        F., Sunaert, S., Suetens, P. Track Orientation Density Imaging (TODI)
        and Track Orientation Distribution (TOD) based tractography.
        NeuroImage, 2014, 94, 312-336

      * If using other contrasts / statistics: Calamante, F.; Tournier, J.-D.;
        Smith, R. E. & Connelly, A. A generalised framework for
        super-resolution track-weighted imaging. NeuroImage, 2012, 59,
        2494-2503

      * If using -precise mapping option: Smith, R. E.; Tournier, J.-D.;
        Calamante, F. & Connelly, A. SIFT: Spherical-deconvolution informed
        filtering of tractograms. NeuroImage, 2013, 67, 298-312 (Appendix 3)



    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> tdi = mrt.ComputeTDI()
    >>> tdi.inputs.in_file = 'dti.mif'
    >>> tdi.cmdline                               # doctest: +ELLIPSIS
    'tckmap dti.mif tdi.mif'
    >>> tdi.run()                                 # doctest: +SKIP
    Ztckmapc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(     s    zComputeTDI._list_outputsN)
r   r   r   r)   r*   rT   r+   r`   r!   r(   r   r   r   r   ra     s
   4ra   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Zedd
ddZej	ddddZ
dS )TCK2VTKInputSpecTz%sr   zinput tractography)r   r   r   r   r   z
tracks.vtkr   zoutput VTK file)r   r   r   r   z	-image %szif specified, the properties of this image will be used to convert track point positions from real (scanner) coordinates into image coordinates (in mm).)r   r   r   zif specified, the properties of this image will be used to convert track point positions from real (scanner) coordinates into image coordinates.z-nthreads %dzEnumber of threads. if zero, the number of available cpus will be used)r   r   r\   Nr   r   )r   r   r   r	   r   r   r8   Zvoxelr   r0   r_   r   r   r   r   rb   %  s    rb   c               @   s   e Zd ZeddZdS )TCK2VTKOutputSpeczoutput VTK file)r   N)r   r   r   r	   r   r   r   r   r   rc   B  s   rc   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )TCK2VTKa  
    Convert a track file to a vtk format, cave: coordinates are in XYZ
    coordinates not reference

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> vtk = mrt.TCK2VTK()
    >>> vtk.inputs.in_file = 'tracks.tck'
    >>> vtk.inputs.reference = 'b0.nii'
    >>> vtk.cmdline                               # doctest: +ELLIPSIS
    'tck2vtk -image b0.nii tracks.tck tracks.vtk'
    >>> vtk.run()                                 # doctest: +SKIP
    Ztck2vtkc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(   [  s    zTCK2VTK._list_outputsN)
r   r   r   r)   r*   rb   r+   rc   r!   r(   r   r   r   r   rd   F  s
   rd   c               @   sl   e Zd ZeddddddZedddddZejd	d
dZejdddZ	ejdddZ
ejejddddZdS )DWIExtractInputSpecTz%sr   zinput image)r   r   r   r   r   r   zoutput image)r   r   r   r   z-bzerozextract b=0 volumes)r   r   z	-no_bzerozextract non b=0 volumesz-singleshellz%extract volumes with a specific shellr@   z	-shell %sz#specify one or more gradient shells)rA   r   r   Nr   r   )r   r   r   r	   r   r   r   r]   ZbzeroZnobzeroZsingleshellr.   r^   shellr   r   r   r   re   a  s   
re   c               @   s   e Zd ZedddZdS )DWIExtractOutputSpecTzoutput image)r   r   N)r   r   r   r	   r   r   r   r   r   rg   s  s   rg   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )
DWIExtractaf  
    Extract diffusion-weighted volumes, b=0 volumes, or certain shells from a
    DWI dataset

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> dwiextract = mrt.DWIExtract()
    >>> dwiextract.inputs.in_file = 'dwi.mif'
    >>> dwiextract.inputs.bzero = True
    >>> dwiextract.inputs.out_file = 'b0vols.mif'
    >>> dwiextract.inputs.grad_fsl = ('bvecs', 'bvals')
    >>> dwiextract.cmdline                             # doctest: +ELLIPSIS
    'dwiextract -bzero -fslgrad bvecs bvals dwi.mif b0vols.mif'
    >>> dwiextract.run()                               # doctest: +SKIP
    Z
dwiextractc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(     s    zDWIExtract._list_outputsN)
r   r   r   r)   r*   re   r+   rg   r!   r(   r   r   r   r   rh   w  s
   rh   c               @   s   e Zd ZeddddddZeddddddd	Zejejd
dddZ	ejej
ddddZejejddddZejej
ddddZedddddZedddddZdS )MRConvertInputSpecTz%sr   zinput image)r   r   r   r   r   zdwi.mifr   zoutput image)r   r   r   r   r    z	-coord %sz)extract data at the specified coordinates)rA   r   r   r@   z-vox %szchange the voxel dimensionsz-axes %sz"specify the axes that will be usedz-scaling %sz"specify the data scaling parameterz-json_import %sFz8import data from a JSON file into header key-value pairs)r   r   r   r   z-json_export %szAexport data from an image header key-value pairs into a JSON fileNr   r   )r   r   r   r	   r   r   r   r.   r0   Zcoordr^   ZvoxZaxesZscalingZjson_importjson_exportr   r   r   r   ri     sH   ri   c               @   s<   e Zd ZedddZedddZedddZedddZdS )MRConvertOutputSpecTzoutput image)r   r   zAexported data from an image header key-value pairs in a JSON filezexport bvec file in FSL formatN)r   r   r   r	   r   rk   out_bvecout_bvalr   r   r   r   rl     s   rl   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )	MRConverta  
    Perform conversion between different file types and optionally extract a
    subset of the input image

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> mrconvert = mrt.MRConvert()
    >>> mrconvert.inputs.in_file = 'dwi.nii.gz'
    >>> mrconvert.inputs.grad_fsl = ('bvecs', 'bvals')
    >>> mrconvert.cmdline                             # doctest: +ELLIPSIS
    'mrconvert -fslgrad bvecs bvals dwi.nii.gz dwi.mif'
    >>> mrconvert.run()                               # doctest: +SKIP
    Z	mrconvertc             C   sp   | j  j }tj| jj|d< | jjr8tj| jj|d< | jjrRtj| jj|d< | jjrltj| jj|d< |S )Nr   rk   rm   rn   )	r!   r"   r#   r$   r%   r   rk   rm   rn   )r&   r'   r   r   r   r(     s    zMRConvert._list_outputsN)
r   r   r   r)   r*   ri   r+   rl   r!   r(   r   r   r   r   ro     s
   ro   c               @   sl   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d
ddddddZej	dddddddZ
dS )TransformFSLConvertInputSpecTz%sr   zFLIRT input image)r   r   r   r   r   r   zFLIRT reference imager   z"FLIRT output transformation matrixztransform_mrtrix.txtz-output transformed affine in mrtrix3's format)r   r   r   r   r   flirt_importz"import transform from FSL's FLIRT.)r   r   r   r   r   Nr   r   )r   r   r   r	   r   r8   Zin_transformout_transformr   r]   rq   r   r   r   r   rp     s@   rp   c               @   s   e Zd ZedddZdS )TransformFSLConvertOutputSpecTz-output transformed affine in mrtrix3's format)r   r   N)r   r   r   r	   rr   r   r   r   r   rs     s   rs   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )TransformFSLConvertzU
    Perform conversion between FSL's transformation matrix format to mrtrix3's.
    Ztransformconvertc             C   s"   | j  j }tj| jj|d< |S )Nrr   )r!   r"   r#   r$   r%   rr   )r&   r'   r   r   r   r(   %  s    z!TransformFSLConvert._list_outputsN)
r   r   r   r)   r*   rp   r+   rs   r!   r(   r   r   r   r   rt     s
   rt   c               @   s   e Zd ZeedddddddZeddd dd	Zejd
dddZ	edddddZ
ejddddZedddddZedddddZedddddZejddddZejddddZejddddZdS )!MRTransformInputSpecT)r   z%sr   zInput images to be transformed)r   r   r   r   r   zOutput image)Zgenfiler   r   r   z-inversez.Invert the specified transform before using it)r   r   r   z
-linear %sa  Specify a linear transform to apply, in the form of a 3x4 or 4x4 ascii file. Note the standard reverse convention is used, where the transform maps points in the template image to the moving image. Note that the reverse convention is still assumed even if no -template image is supplied.)r   r   r   r   z-replacezareplace the current transform by that specified, rather than applying it to the current transformz-transform %sz8The transform to apply, in the form of a 4x4 ascii file.z-template %sz>Reslice the input image to match the specified template image.z-reference %szin case the transform supplied maps from the input image onto a reference image, use this option to specify the reference. Note that this implicitly sets the -replace option.z-flipxa+  assume the transform is supplied assuming a coordinate system with the x-axis reversed relative to the MRtrix convention (i.e. x increases from right to left). This is required to handle transform matrices produced by FSL's FLIRT command. This is only used in conjunction with the -reference option.z-quietz7Do not display information messages or progress status.z-debugzDisplay debugging messages.Nr   r   )r   r   r   r
   r	   r/   r   r   r]   invertZlinear_transformZreplace_transformZtransformation_fileZtemplate_imageZreference_imageZflip_xquietdebugr   r   r   r   ru   +  s`   ru   c               @   s   e Zd ZedddZdS )MRTransformOutputSpecTz&the output image of the transformation)r   r   N)r   r   r   r	   r   r   r   r   r   ry   m  s   ry   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 )
MRTransformz
    Apply spatial transformations or reslice images

    Example
    -------

    >>> MRxform = MRTransform()
    >>> MRxform.inputs.in_files = 'anat_coreg.mif'
    >>> MRxform.run()                                   # doctest: +SKIP
    Zmrtransformc             C   sN   | j  j }| jj|d< t|d s8tj| j |d< ntj|d |d< |S )Nr   )r!   r"   r%   r   r   r#   r$   _gen_outfilename)r&   r'   r   r   r   r(     s    zMRTransform._list_outputsc             C   s   |dkr| j  S d S d S )Nr   )r{   )r&   namer   r   r   _gen_filename  s    zMRTransform._gen_filenamec             C   s   t | jjd \}}}|d S )Nr   z_MRTransform.mif)r   r%   r/   )r&   _r|   r   r   r   r{     s    zMRTransform._gen_outfilenameN)r   r   r   r)   r*   ru   r+   ry   r!   r(   r}   r{   r   r   r   r   rz   q  s   
	rz   c               @   sh   e Zd ZeddddddZedddddZejd	d
dddddddddddddddZej	ddddZ
dS ) MRMathInputSpecTz%sr   zinput image)r   r   r   r   r   r   zoutput image)r   r   r   r   rY   r[   rW   productZrmsZnormvarZstdrX   rZ   ZabsmaxZmagmaxr   z,operation to computer along a specified axis)r   r   r   r   r   z-axis %dz,specfied axis to perform the operation along)r   r   Nr7   r   r   )r   r   r   r	   r   r   r   r2   Z	operationr0   r1   r   r   r   r   r     s,   r   c               @   s   e Zd ZedddZdS )MRMathOutputSpecTzoutput image)r   r   N)r   r   r   r	   r   r   r   r   r   r     s   r   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )MRMathas  
    Compute summary statistic on image intensities
    along a specified axis of a single image

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> mrmath = mrt.MRMath()
    >>> mrmath.inputs.in_file = 'dwi.mif'
    >>> mrmath.inputs.operation = 'mean'
    >>> mrmath.inputs.axis = 3
    >>> mrmath.inputs.out_file = 'dwi_mean.mif'
    >>> mrmath.inputs.grad_fsl = ('bvecs', 'bvals')
    >>> mrmath.cmdline                             # doctest: +ELLIPSIS
    'mrmath -axis 3 -fslgrad bvecs bvals dwi.mif mean dwi_mean.mif'
    >>> mrmath.run()                               # doctest: +SKIP
    Zmrmathc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(     s    zMRMath._list_outputsN)
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ejejejejfddddd	gd
Zejej	ej	ej	fddddd	gd
Z
ejej	ej	ej	fdddddgd
ZejddddddddZedddgddddZdS )MRResizeInputSpecTz%sr   zinput DWI image)r   r   r   r   r   z-size %d,%d,%dz2Number of voxels in each dimension of output image
voxel_sizescale_factor)r   r   r   xorz-voxel %g,%g,%gz-Desired voxel size in mm for the output image
image_sizez-scale %g,%g,%gz7Scale factors to rescale the image by in each dimensionZcubicZnearestZlinearZsincz
-interp %szjset the interpolation method to use when resizing (choices: nearest, linear, cubic, sinc. Default: cubic).)r   r   r   z
%s_resizedr   r   zthe output resized DWI image)r   name_templatename_sourceZkeep_extensionr   r   Nr   r   )r   r   r   r	   r   r   Tupler0   r   r^   r   r   r2   interpolationr   r   r   r   r   r     sF   r   c               @   s   e Zd ZedddZdS )MRResizeOutputSpeczthe output resized DWI imageT)r   r   N)r   r   r   r	   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdZeZeZdS )MRResizea  
    Resize an image by defining the new image resolution, voxel size or a
    scale factor. If the image is 4D, then only the first 3 dimensions can be
    resized. Also, if the image is down-sampled, the appropriate smoothing is
    automatically applied using Gaussian smoothing.
    For more information, see
    <https://mrtrix.readthedocs.io/en/latest/reference/commands/mrresize.html>

    Example
    -------
    >>> import nipype.interfaces.mrtrix3 as mrt

    Defining the new image resolution:
    >>> image_resize = mrt.MRResize()
    >>> image_resize.inputs.in_file = 'dwi.mif'
    >>> image_resize.inputs.image_size = (256, 256, 144)
    >>> image_resize.cmdline                               # doctest: +ELLIPSIS
    'mrresize -size 256,256,144 -interp cubic dwi.mif dwi_resized.mif'
    >>> image_resize.run()                                 # doctest: +SKIP

    Defining the new image's voxel size:
    >>> voxel_resize = mrt.MRResize()
    >>> voxel_resize.inputs.in_file = 'dwi.mif'
    >>> voxel_resize.inputs.voxel_size = (1, 1, 1)
    >>> voxel_resize.cmdline                               # doctest: +ELLIPSIS
    'mrresize -interp cubic -voxel 1,1,1 dwi.mif dwi_resized.mif'
    >>> voxel_resize.run()                                 # doctest: +SKIP

    Defining the scale factor of each image dimension:
    >>> scale_resize = mrt.MRResize()
    >>> scale_resize.inputs.in_file = 'dwi.mif'
    >>> scale_resize.inputs.scale_factor = (0.5,0.5,0.5)
    >>> scale_resize.cmdline                               # doctest: +ELLIPSIS
    'mrresize -interp cubic -scale 0.5,0.5,0.5 dwi.mif dwi_resized.mif'
    >>> scale_resize.run()                                 # doctest: +SKIP
    ZmrresizeN)	r   r   r   r)   r*   r   r+   r   r!   r   r   r   r   r     s   $r   c               @   sF   e Zd ZeddddddZeddddddZed	d
gdddddZdS )SHConvInputSpecTz%sr   zinput ODF image)r   r   r   r   r   r   zThe response function)r   r   r   r   r   z%s_shconv.mifr   r   zthe output spherical harmonics)r   r   r   r   r   r   Nr7   r   r   )r   r   r   r	   r   responser   r   r   r   r   r   /  s&   r   c               @   s   e Zd ZedddZdS )SHConvOutputSpecTz.the output convoluted spherical harmonics file)r   r   N)r   r   r   r	   r   r   r   r   r   r   I  s   r   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )SHConva  
    Convolve spherical harmonics with a tissue response function. Useful for
    checking residuals of ODF estimates.


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> sh = mrt.SHConv()
    >>> sh.inputs.in_file = 'csd.mif'
    >>> sh.inputs.response = 'response.txt'
    >>> sh.cmdline
    'shconv csd.mif response.txt csd_shconv.mif'
    >>> sh.run()                                 # doctest: +SKIP
    Zshconvc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(   c  s    zSHConv._list_outputsN)
r   r   r   r)   r*   r   r+   r   r!   r(   r   r   r   r   r   M  s
   r   c               @   sT   e Zd ZeddddddZeddddddZed	d
gdddddZejdddZ	dS )SH2AmpInputSpecTz%sr   zinput ODF image)r   r   r   r   r   r   zSThe gradient directions along which to sample the spherical harmonics MRtrix format)r   r   r   r   r   z
%s_amp.mifr   r   zthe output spherical harmonics)r   r   r   r   r   r   z-nonnegativez#cap all negative amplitudes to zero)r   r   Nr7   r   r   )
r   r   r   r	   r   Z
directionsr   r   r]   Znonnegativer   r   r   r   r   i  s*   r   c               @   s   e Zd ZedddZdS )SH2AmpOutputSpecTz.the output convoluted spherical harmonics file)r   r   N)r   r   r   r	   r   r   r   r   r   r     s   r   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )SH2Ampa  
    Sample spherical harmonics on a set of gradient orientations.  Useful for
    checking residuals of ODF estimates.


    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> sh = mrt.SH2Amp()
    >>> sh.inputs.in_file = 'sh.mif'
    >>> sh.inputs.directions = 'grads.txt'
    >>> sh.cmdline
    'sh2amp sh.mif grads.txt sh_amp.mif'
    >>> sh.run()                                 # doctest: +SKIP
    Zsh2ampc             C   s"   | j  j }tj| jj|d< |S )Nr   )r!   r"   r#   r$   r%   r   )r&   r'   r   r   r   r(     s    zSH2Amp._list_outputsN)
r   r   r   r)   r*   r   r+   r   r!   r(   r   r   r   r   r     s
   r   )<os.pathpathr#   Zutils.filemanipr   baser   r   r   r   r	   r
   r   r   r   r   r   r    r,   r4   r5   r6   r9   r:   r;   r=   r>   r?   rN   rO   rT   r`   ra   rb   rc   rd   re   rg   rh   ri   rl   ro   rp   rs   rt   ru   ry   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s`   
$	A,|@/
!(B$-+ 