3
d,                 @   s   d dl Z ddlmZ ddlmZmZmZmZmZ G dd deZ	G dd	 d	eZ
G d
d deZG dd deZG dd deZG dd deZdS )    N   )split_filename   )traitsTraitedSpecFileStdOutCommandLineStdOutCommandLineInputSpecc               @   s   e Zd ZejddddZedddddZed	d
ddddZejddddZ	ej
ejddddddZejddddZej
ejddddddZejddddZej
ejd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ejd!dd"dZd#S )$SFPICOCalibDataInputSpecz-snr %fNAzgSpecifies  the  signal-to-noise ratio of the non-diffusion-weighted measurements to use in simulations.)argstrunitsdescTz-schemefile %sz4Specifies the scheme file for the diffusion MRI data)existsr   	mandatoryr   z8The name to be given to the information output filename.z-infooutputfile %sF)r   r   r   ZgenfileZ
hash_filesz	-trace %fz;Trace of the diffusion tensor(s) used in the test function.z-onedtfarange %sr   z<Minimum and maximum FA for the single tensor synthetic data.)r   Zminlenmaxlenr   r   z-onedtfastep %fz^FA step size controlling how many steps there are between the minimum and maximum FA settings.z-twodtfarange %szMinimum and maximum FA for the two tensor synthetic data. FA is varied for both tensors to give all the different permutations.z-twodtfastep %fzwFA step size controlling how many steps there are between the minimum and maximum FA settings for the two tensor cases.z-twodtanglerange %sz;Minimum and maximum crossing angles between the two fibres.z-twodtanglestep %fz~Angle step size controlling how many steps there are between the minimum and maximum crossing angles for the two tensor cases.z-twodtmixmax %fzMixing parameter controlling the proportion of one fibre population to the other. The minimum mixing parameter is (1 - twodtmixmax).z-twodtmixstep %fziMixing parameter step size for the two tensor cases. Specify how many mixing parameter increments to use.z-seed %fzKSpecifies the random seed to use for noise generation in simulation trials.N)__name__
__module____qualname__r   ZFloatZsnrr   scheme_file	info_filetraceListZonedtfarangeZonedtfastepZtwodtfarangeZtwodtfastepZtwodtanglerangeZtwodtanglestepZtwodtmixmaxZtwodtmixstepseed r   r   @/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/camino/calib.pyr
      s   r
   c               @   s$   e Zd ZedddZedddZdS )SFPICOCalibDataOutputSpecTzCalibration dataset)r   r   N)r   r   r   r   	PICOCalib
calib_infor   r   r   r   r   w   s   r   c               @   s,   e Zd ZdZdZeZeZdd Z	dd Z
dS )SFPICOCalibDataaL  
    Generates Spherical Function PICo Calibration Data.

    SFPICOCalibData creates synthetic data for use with SFLUTGen. The
    synthetic data is generated using a mixture of gaussians, in the
    same way datasynth generates data.  Each voxel of data models a
    slightly different fibre configuration (varying FA and fibre-
    crossings) and undergoes a random rotation to help account for any
    directional bias in the chosen acquisition scheme.  A second file,
    which stores information about the datafile, is generated along with
    the datafile.

    Examples
    --------
    To create a calibration dataset using the default settings

    >>> import nipype.interfaces.camino as cam
    >>> calib = cam.SFPICOCalibData()
    >>> calib.inputs.scheme_file = 'A.scheme'
    >>> calib.inputs.snr = 20
    >>> calib.inputs.info_file = 'PICO_calib.info'
    >>> calib.run()           # doctest: +SKIP

    The default settings create a large dataset (249,231 voxels), of
    which 3401 voxels contain a single fibre population per voxel and
    the rest of the voxels contain two fibre-populations. The amount of
    data produced can be varied by specifying the ranges and steps of
    the parameters for both the one and two fibre datasets used.

    To create a custom calibration dataset

    >>> import nipype.interfaces.camino as cam
    >>> calib = cam.SFPICOCalibData()
    >>> calib.inputs.scheme_file = 'A.scheme'
    >>> calib.inputs.snr = 20
    >>> calib.inputs.info_file = 'PICO_calib.info'
    >>> calib.inputs.twodtfarange = [0.3, 0.9]
    >>> calib.inputs.twodtfastep = 0.02
    >>> calib.inputs.twodtanglerange = [0, 0.785]
    >>> calib.inputs.twodtanglestep = 0.03925
    >>> calib.inputs.twodtmixmax = 0.8
    >>> calib.inputs.twodtmixstep = 0.1
    >>> calib.run()              # doctest: +SKIP

    This would provide 76,313 voxels of synthetic data, where 3401 voxels
    simulate the one fibre cases and 72,912 voxels simulate the various
    two fibre cases. However, care should be taken to ensure that enough
    data is generated for calculating the LUT.      # doctest: +SKIP

    Zsfpicocalibdatac             C   s8   | j  j }tjj| j |d< tjj| jj|d< |S )Nr   r   )output_specgetospathabspath_gen_outfilenameinputsr   )selfoutputsr   r   r   _list_outputs   s    zSFPICOCalibData._list_outputsc             C   s   t | jj\}}}|d S )Nz_PICOCalib.Bfloat)r   r&   r   )r'   _namer   r   r   r%      s    z SFPICOCalibData._gen_outfilenameN)r   r   r   __doc___cmdr
   
input_specr   r    r)   r%   r   r   r   r   r   |   s   2r   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Zej	d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ZejddddZdS )SFLUTGenInputSpecTz-inputfile %sz2Voxel-order data of the spherical functions peaks.)r   r   r   r   z-infofile %szVThe Info file that corresponds to the calibration datafile used in the reconstruction.)r   r   r   ZLUTz-outputstem %szDefine the name of the generated luts.  The form of the filenames will be [outputstem]_oneFibreSurfaceCoeffs.Bdouble and [outputstem]_twoFibreSurfaceCoeffs.Bdouble)r   r   Z
usedefaultZbinghamZwatsonz-pdf %sak  Sets the distribution to use for the calibration. The default is the Bingham
distribution, which allows elliptical probability density contours.
Currently supported options are:

  * bingham -- The Bingham distribution, which allows elliptical probability
    density contours.
  * watson -- The Watson distribution. This distribution is rotationally symmetric.

z-binincsize %dr   zwSets the size of the bins.  In the case of 2D histograms such as the Bingham, the bins are always square. Default is 1.)r   r   r   z-minvectsperbin %da!  Specifies the minimum number of fibre-orientation estimates a bin must contain before it is used in the lut line/surface generation. Default is 50. If you get the error "no fibre-orientation estimates in histogram!", the calibration data set is too small to get enough samples in any of the  histogram  bins. You can decrease the minimum number  per  bin to get things running in quick tests, but the sta- tistics will not be reliable and for serious applications, you need  to increase the size of the calibration data set until the error goes.z
-directmapzqUse direct mapping between the eigenvalues and the distribution parameters instead of the log of the eigenvalues.)r   r   z	-order %dzcThe order of the polynomial fitting the surface. Order 1 is linear. Order 2 (default) is quadratic.N)r   r   r   r   in_filer   r   Str
outputstemEnumZpdfZIntZ
binincsizeZminvectsperbinZBoolZ	directmaporderr   r   r   r   r/      sF   

r/   c               @   s$   e Zd ZedddZedddZdS )SFLUTGenOutputSpecTzPICo lut for one-fibre model)r   r   zPICo lut for two-fibre modelN)r   r   r   r   lut_one_fibrelut_two_fibresr   r   r   r   r5     s   r5   c               @   s,   e Zd ZdZdZeZeZdd Z	dd Z
dS )SFLUTGenau  
    Generates PICo lookup tables (LUT) for multi-fibre methods such as
    PASMRI and Q-Ball.

    SFLUTGen creates the lookup tables for the generalized multi-fibre
    implementation of the PICo tractography algorithm.  The outputs of
    this utility are either surface or line coefficients up to a given
    order. The calibration can be performed for different distributions,
    such as the Bingham and Watson distributions.

    This utility uses calibration data generated from SFPICOCalibData
    and peak information created by SFPeaks.

    The utility outputs two lut's, ``*_oneFibreSurfaceCoeffs.Bdouble`` and
    ``*_twoFibreSurfaceCoeffs.Bdouble``. Each of these files contains big-endian doubles
    as standard. The format of the output is::

          dimensions    (1 for Watson, 2 for Bingham)
          order         (the order of the polynomial)
          coefficient_1
          coefficient_2
          ...
          coefficient_N

    In  the case of the Watson, there is a single set of coefficients,
    which are ordered::

          constant, x, x^2, ..., x^order.

    In the case of the Bingham, there are two sets of coefficients (one
    for each surface), ordered so that::

          for j = 1 to order
            for k = 1 to order
              coeff_i = x^j * y^k
          where j+k < order

    Example
    -------
    To create a calibration dataset using the default settings

    >>> import nipype.interfaces.camino as cam
    >>> lutgen = cam.SFLUTGen()
    >>> lutgen.inputs.in_file = 'QSH_peaks.Bdouble'
    >>> lutgen.inputs.info_file = 'PICO_calib.info'
    >>> lutgen.run()        # doctest: +SKIP

    Zsflutgenc             C   s0   | j  j }| jjd |d< | jjd |d< |S )Nz_oneFibreSurfaceCoeffs.Bdoubler6   z_twoFibreSurfaceCoeffs.Bdoubler7   )r    r!   r&   r2   )r'   r(   r   r   r   r)   J  s    zSFLUTGen._list_outputsc             C   s   dS )Nz	/dev/nullr   )r'   r   r   r   r%   T  s    zSFLUTGen._gen_outfilenameN)r   r   r   r,   r-   r/   r.   r5   r    r)   r%   r   r   r   r   r8     s   0
r8   )r"   Zutils.filemanipr   baser   r   r   r   r	   r
   r   r   r/   r5   r8   r   r   r   r   <module>   s   	hCP