3
d(H                 @   s   d Z ddlmZmZmZmZmZ ddlmZ ddl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dS )zJ
The dwi module of niftyfit, which wraps the fitting methods in NiftyFit.
   )FileTraitedSpectraits	isdefinedCommandLineInputSpec   )NiftyFitCommand)get_custom_pathc            
   @   s  e Zd ZdZeddddddZdZeddd	dedZd
ZeddddedZeddddgdZ	eddddgdZ
eddddZdZeddedZdZejeddZedgddddZedgd d!d"dZedgd#d$d%dZedgd&d'd(dZedgd)d*d+d,gd-Zedgd.d/d0dZedgd1d2d3dZedgd4d5d6dZedgd7d8d9d:gd-Zd;Zejd<d=edd>Zedgd?d@dAd:gd-ZedgdBdCdDd:gd-ZdEZejedFdGdHd:dIdJdKd,gdLZejdMdNdGdOd:dIdJdKd,gdLZdPZejedQdGdOdHdIdJdKd,gdLZ ejdRdSdGdOdHd:dJdKd,gdLZ!dTZejedUdGdOdHd:dIdKd,gdLZ"ejdVdWdGdOdHd:dIdJd,gdLZ#ejdXdYdGdOdHd:dIdJdKgdLZ$dZZejed[d\gd]Z%d^Zej&ej'ej'd_d\ged`Z(daZejedbdcgddZ)deZejedfdZ*eddgdhdZ+ejedid\gddZ,djZej'edkdZ-ejdldmdZ.ej&ejejejdndodZ/ej'dpdqdZ0ej'drdsdZ1ej'dtdudZ2ej'dvdwdZ3dxZej'edydZ4edgdzd{d|dZ5ejd}d~dZ6ejdddZ7ej'dddZ8dS )FitDwiInputSpeczInput Spec for FitDwi.r   Tz
-source %sz)The source image containing the dwi data.)positionexistsargstr	mandatorydescz2The file containing the bvalues of the source DWI.r   z-bval %sz3The file containing the bvectors of the source DWI.   z-bvec %sz-TE %szFilename of TEs (ms).te_file)r   r   r   xorzValue of TEs (ms).zThe image maskz-mask %s)r   r   r   z0Filename of parameter priors for -ball and -nod.z	-prior %s)r   r   r   z{Rotate the output tensors according to the q/s form of the image (resulting tensors will be in mm coordinates, default: 0).z-rotsform %d)r   r   source_filez%s_error.nii.gzz!Filename of parameter error maps.z	-error %s)name_sourcename_templater   r   z%s_resmap.nii.gzzFilename of model residual map.z-res %sz%s_syn.nii.gzzFilename of synthetic image.z-syn %sz%s_no_diff.nii.gzz'Filename of average no diffusion image.z
-nodiff %sz%s_mcmap.nii.gzzDFilename of multi-compartment model parameter map (-ivim,-ball,-nod)z	-mcmap %s	nodv_flag)r   r   r   r   requiresz%s_mdmap.nii.gzzFilename of MD map/ADCz	-mdmap %sz%s_famap.nii.gzzFilename of FA mapz	-famap %sz%s_v1map.nii.gzzFilename of PDD map [x,y,z]z	-v1map %sz%s_rgbmap.nii.gzzFilename of colour-coded FA mapz
-rgbmap %sdti_flagzFUse lower triangular (tenmap2) or diagonal, off-diagonal tensor formatz	lower-trizdiag-off-diag)r   Z
usedefaultz%s_tenmap.nii.gzz&Filename of tensor map [diag,offdiag].z
-tenmap %sz%s_tenmap2.nii.gzz"Filename of tensor map [lower tri]z-tenmap2 %szJFit single exponential to non-directional data [default with no b-vectors]z-mono   	ivim_flag	ball_flag
ballv_flagnod_flag)r   r   r   r   z'Fit IVIM model to non-directional data.z-ivim	mono_flagz.Fit the tensor model [default with b-vectors].z-dtizFit the ball and stick model.z-ballz0Fit the ball and stick model with optimised PDD.z-ballvzFit the NODDI modelz-nodz&Fit the NODDI model with optimised PDDz-nodvz<Maximum number of non-linear LSQR iterations [100x2 passes])z	-maxit %dgn_flag)r   r   r   z7LM parameters (initial value, decrease rate) [100,1.2].z	-lm %f %f)r   r   r   z1Use Gauss-Newton algorithm [Levenberg-Marquardt].z-gnwls_flag)r   r   r   zRUse Variational Bayes fitting with known prior (currently identity covariance...).z-vbz,Filename of ithe nc*nc covariance matrix [I]z-cov %sz-wlszBUse location-weighted least squares for DTI fitting [3x3 Gaussian]z-swls %fzFit to single slice number.z	-slice %dzFit to single voxel only.z-voxel %d %d %dz%Isotropic diffusivity for -nod [3e-3]z-diso %fz'Parallel diffusivity for -nod [1.7e-3].z-dpr %fzWhite matter T2 value [80ms].z-wmT2 %fzCSF T2 value [400ms].z	-csfT2 %fz0Threshold for perfusion/diffsuion effects [100].z-perfthreshold %fz%s_mcout.txtz(Filename of mc samples (ascii text file)z	-mcout %sz Number of samples to keep [100].z-mcsamples %dz%Number of iterations to run [10,000].z-mcmaxit %dz(Fraction of iterations to accept [0.23].z-accpetance %fN)9__name__
__module____qualname____doc__r   r   r   	bval_file	bvec_filer   Zte_value	mask_fileZ
prior_filer   ZIntZrot_sform_flag
error_fileres_filesyn_filenodiff_file
mcmap_file
mdmap_file
famap_file
v1map_filergbmap_fileEnumten_typetenmap_filetenmap2_fileBoolr   r   r   r   r   r   r   Z	maxit_valTupleFloatZlm_valsr   Zvb_flagZcov_filer    Zswls_valZslice_noZvoxeldiso_valdpr_valZ	wm_t2_valZ
csf_t2_valZperf_thrmcoutZ	mcsamplesZmcmaxitZ
acceptance r;   r;   @/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/niftyfit/dwi.pyr
      s  














r
   c               @   s   e Zd 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eddZeddZeddZdS )FitDwiOutputSpeczOutput Spec for FitDwi.z Filename of parameter error maps)r   zFilename of model residual mapzFilename of synthetic imagez'Filename of average no diffusion image.zFilename of MD map/ADCzFilename of FA mapzFilename of PDD map [x,y,z]zFilename of colour FA mapzFilename of tensor mapz"Filename of tensor map [lower tri]zEFilename of multi-compartment model parameter map (-ivim,-ball,-nod).z(Filename of mc samples (ascii text file)N)r!   r"   r#   r$   r   r(   r)   r*   r+   r-   r.   r/   r0   r3   r4   r,   r:   r;   r;   r;   r<   r=     s   









r=   c                   s8   e Zd ZdZedddZeZeZ	dZ
 fddZ  ZS )FitDwia  Interface for executable fit_dwi from Niftyfit platform.

    Use NiftyFit to perform diffusion model fitting.

    Diffusion-weighted MR Fitting.
    Fits DWI parameter maps to multi-shell, multi-directional data.

    `Source code <https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyFit-Release>`_

    Examples
    --------

    >>> from nipype.interfaces import niftyfit
    >>> fit_dwi = niftyfit.FitDwi(dti_flag=True)
    >>> fit_dwi.inputs.source_file = 'dwi.nii.gz'
    >>> fit_dwi.inputs.bvec_file = 'bvecs'
    >>> fit_dwi.inputs.bval_file = 'bvals'
    >>> fit_dwi.inputs.rgbmap_file = 'rgb.nii.gz'
    >>> fit_dwi.cmdline
    'fit_dwi -source dwi.nii.gz -bval bvals -bvec bvecs -dti -error dwi_error.nii.gz -famap dwi_famap.nii.gz -mcout dwi_mcout.txt -mdmap dwi_mdmap.nii.gz -nodiff dwi_no_diff.nii.gz -res dwi_resmap.nii.gz -rgbmap rgb.nii.gz -syn dwi_syn.nii.gz -tenmap2 dwi_tenmap2.nii.gz -v1map dwi_v1map.nii.gz'

    Zfit_dwiNIFTYFITDIR)env_dirZ_fit_dwic                sD   |dkr| j jdkrdS |dkr0| j jdkr0dS tt| j|||S )Nr3   zdiag-off-diag r4   z	lower-tri)inputsr2   superr>   _format_arg)selfname
trait_specvalue)	__class__r;   r<   rD   P  s
    zFitDwi._format_arg)r!   r"   r#   r$   r	   _cmdr
   
input_specr=   output_spec_suffixrD   __classcell__r;   r;   )rI   r<   r>   /  s   r>   c               @   s$  e Zd ZdZdZeddedddZdZedded	ddZd
ZeddeddZedddddZ	edddddZ
dZedgdeddZdZedgdedddgdZedgdd d!dZedgd"d#d$dZedgd%d&d'dZedgd(d)d*dZedgd+d,d-dZd.Zejed/d0d1d2d3d4d5d6d7gd8Zd9Zejed/d:d;d2d3d4d5d6d7gd8Zejd<d/d=d;d1d3d4d5d6d7gd8Zejd>d/d?d;d1d2d4d5d6d7gd8Zejd@d/dAd;d1d2d3d5d6d7gd8ZdBZejed/dCd;d1d2d3d4d6d7gd8ZejdDd/dEd;d1d2d3d4d5d7gd8ZejdFd/dGd;d1d2d3d4d5d6gd8ZejdHdIdJZejdKdLdJZdMS )NDwiToolInputSpeczInput Spec for DwiTool.z-The source image containing the fitted model.r   Tz
-source %s)r   r   r   r   r   z2The file containing the bvalues of the source DWI.r   z-bval %sz3The file containing the bvectors of the source DWI.r   z-bvec %s)r   r   r   r   r   z,The B0 image corresponding to the source DWIz-b0 %s   zThe image maskz-mask %szDFilename of multi-compartment model parameter map (-ivim,-ball,-nod)r   z%s_mcmap.nii.gzz	-mcmap %s)r   r   r   r   z9Filename of synthetic image. Requires: bvec_file/b0_file.z%s_syn.nii.gzz-syn %sr&   b0_file)r   r   r   r   r   z%s_mdmap.nii.gzzFilename of MD map/ADCz	-mdmap %sz%s_famap.nii.gzzFilename of FA mapz	-famap %sz%s_v1map.nii.gzzFilename of PDD map [x,y,z]z	-v1map %sz%s_rgbmap.nii.gzzFilename of colour FA map.z
-rgbmap %sz%s_logdti2.nii.gzzFilename of output logdti map.z-logdti2 %szQInput is a single exponential to non-directional data [default with no b-vectors]   z-monor   r   	dti_flag2r   r   r   r   )r   r   r   r   z0Inputs is an IVIM model to non-directional data.z-ivimr   z&Input is a tensor model diag/off-diag.z-dtiz(Input is a tensor model lower triangularz-dti2z Input is a ball and stick model.z-ballz3Input is a ball and stick model with optimised PDD.z-ballvzInput is a NODDI modelz-nodz)Input is a NODDI model with optimised PDDz-nodvz%Isotropic diffusivity for -nod [3e-3]z-diso %f)r   r   z'Parallel diffusivity for -nod [1.7e-3].z-dpr %fN)r!   r"   r#   r$   r   r   r   r%   r&   rQ   r'   r,   r*   r-   r.   r/   r0   logdti_filer   r5   r   r   r   rS   r   r   r   r   r7   r8   r9   r;   r;   r;   r<   rO   X  s(  








rO   c               @   sZ   e Zd ZdZdZee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 )DwiToolOutputSpeczOutput Spec for DwiTool.zDFilename of multi-compartment model parameter map (-ivim,-ball,-nod))r   zFilename of synthetic imagezFilename of MD map/ADCzFilename of FA mapzFilename of PDD map [x,y,z]zFilename of colour FA mapzFilename of output logdti mapN)r!   r"   r#   r$   r   r   r,   r*   r-   r.   r/   r0   rT   r;   r;   r;   r<   rU     s   





rU   c                   s8   e Zd ZdZedddZeZeZ	dZ
 fddZ  ZS )DwiToola  Interface for executable dwi_tool from Niftyfit platform.

    Use DwiTool.

    Diffusion-Weighted MR Prediction.
    Predicts DWI from previously fitted models and calculates model derived
    maps.

    `Source code <https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyFit-Release>`_

    Examples
    --------

    >>> from nipype.interfaces import niftyfit
    >>> dwi_tool = niftyfit.DwiTool(dti_flag=True)
    >>> dwi_tool.inputs.source_file = 'dwi.nii.gz'
    >>> dwi_tool.inputs.bvec_file = 'bvecs'
    >>> dwi_tool.inputs.bval_file = 'bvals'
    >>> dwi_tool.inputs.mask_file = 'mask.nii.gz'
    >>> dwi_tool.inputs.b0_file = 'b0.nii.gz'
    >>> dwi_tool.inputs.rgbmap_file = 'rgb_map.nii.gz'
    >>> dwi_tool.cmdline
    'dwi_tool -source dwi.nii.gz -bval bvals -bvec bvecs -b0 b0.nii.gz -mask mask.nii.gz -dti -famap dwi_famap.nii.gz -logdti2 dwi_logdti2.nii.gz -mcmap dwi_mcmap.nii.gz -mdmap dwi_mdmap.nii.gz -rgbmap rgb_map.nii.gz -syn dwi_syn.nii.gz -v1map dwi_v1map.nii.gz'

    Zdwi_toolr?   )r@   Z	_dwi_toolc                sd   |dkr(t | jj s$t | jj r(dS |dkrPt | jj rPt | jj rPdS tt| j|||S )Nr*   rA   rT   r0   )rT   r0   )	r   rB   r&   rQ   r   rS   rC   rV   rD   )rE   rF   rG   rH   )rI   r;   r<   rD   P  s    zDwiTool._format_arg)r!   r"   r#   r$   r	   rJ   rO   rK   rU   rL   rM   rD   rN   r;   r;   )rI   r<   rV   -  s   rV   N)r$   baser   r   r   r   r   r   Zniftyreg.baser	   r
   r=   r>   rO   rU   rV   r;   r;   r;   r<   <module>   s     ) G