3
do                @   s  d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZ ejded 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/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
Z0G dAdB dBeZ1G dCdD dDeZ2G dEdF dFeZ3G dGdH dHeZ4G dIdJ dJe	Z5G dKdL dLeZ6G dMdN dNeZ7G dOdP dPe	Z8G dQdR dReZ9G dSdT dTeZ:G dUdV dVeZ;G 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ZAG dcdd ddeZBG dedf dfeZCG dgdh dhe	ZDG didj djeZEG dkdl dleZFG dmdn dne	ZGG dodp dpeZHG dqdr dreZIG dsdt dte	ZJG dudv dveZKG dwdx dxeZLG dydz dze	ZMG d{d| d|eZNG d}d~ d~eZOG dd 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	ZhdS )a  The minc module provides classes for interfacing with the `MINC
<http://www.bic.mni.mcgill.ca/ServicesSoftware/MINC>`_ command line tools.  This
module was written to work with MINC version 2.2.00.

Author: `Carlo Hamalainen <http://carlo-hamalainen.net>`__
    N   )TraitedSpecCommandLineInputSpecCommandLineStdOutCommandLineInputSpecStdOutCommandLineFile	DirectoryInputMultiPathOutputMultiPathtraits	isdefined   )aggregate_filenamealways)categoryc            
   @   s,  e Zd ZedddddcdZeddddgd	d
d	dZdeZejddedZ	ejddedZ
ejddedZejddedZejddedZejd d!edZejd"d#edZdfZejd$d%edZejd&d'edZejejejd(d)d*ZdgZejd-d.edZejd/d0edZejejejd1d2d3Zejd4d5d3Zejd6d7d3Zeejd8d9d:d;Zeejd<d9d=d;ZdhZ ejdAdBe dZ!ejdCdDe dZ"ejdEdFe dZ#diZ$ejdJdKe$dZ%ejdLdMe$dZ&ejdNdOe$dZ'djZ(ejdSdTe(dZ)ejdUdVe(dZ*ejdWdXe(dZ+dkZ,ejd\d]e,dZ-ejd^d_e,dZ.ejd`dae,dZ/dbS )lExtractInputSpecz
input fileTz%sr   )descexists	mandatoryargstrpositionzoutput filer   
input_fileFz%s.raw)r   r   name_source
hash_filesname_templatekeep_extensionwrite_ascii
write_bytewrite_short	write_int
write_longwrite_floatwrite_doublewrite_signedwrite_unsignedz*Write out data as ascii strings (default).z-ascii)r   r   xorzWrite out data as bytes.z-bytez!Write out data as short integers.z-shortz"Write out data as 32-bit integers.z-intzSuperseded by write_int.z-longz9Write out data as single precision floating-point values.z-floatz9Write out data as double precision floating-point values.z-doublezWrite out signed data.z-signedzWrite out unsigned data.z	-unsignedz-range %s %szLSpecify the range of output values
Default value: 1.79769e+308 1.79769e+308.)r   r   	normalizenonormalizez3Normalize integer pixel values to file max and min.z
-normalizezTurn off pixel normalization.z-nonormalizez9Specify the range of real image values for normalization.z-image_range %s %s)r   r   zSSpecify the minimum real image value for normalization.Default value: 1.79769e+308.z-image_minimum %szSSpecify the maximum real image value for normalization.Default value: 1.79769e+308.z-image_maximum %sz:Specifies corner of hyperslab (C conventions for indices).,z	-start %s)r   sepr   z,Specifies edge lengths of hyperslab to read.z	-count %sflip_positive_directionflip_negative_directionflip_any_directionz.Flip images to always have positive direction.z-positive_directionz.Flip images to always have negative direction.z-negative_directionzDo not flip images (Default).z-any_directionflip_x_positiveflip_x_negative
flip_x_anyz?Flip images to give positive xspace:step value (left-to-right).z+xdirectionz?Flip images to give negative xspace:step value (right-to-left).z-xdirectionz)Don't flip images along x-axis (default).z-xanydirectionflip_y_positiveflip_y_negative
flip_y_anyz=Flip images to give positive yspace:step value (post-to-ant).z+ydirectionz=Flip images to give negative yspace:step value (ant-to-post).z-ydirectionz)Don't flip images along y-axis (default).z-yanydirectionflip_z_positiveflip_z_negative
flip_z_anyz<Flip images to give positive zspace:step value (inf-to-sup).z+zdirectionz<Flip images to give negative zspace:step value (sup-to-inf).z-zdirectionz)Don't flip images along z-axis (default).z-zanydirectionN)
r   r   r   r   r    r!   r"   r#   r$   r%   )r$   r%   )r'   r(   )r+   r,   r-   )r.   r/   r0   )r1   r2   r3   )r4   r5   r6   )0__name__
__module____qualname__r   r   output_file
_xor_writer   Boolr   r   r   r    r!   r"   r#   _xor_signedr$   r%   TupleFloatwrite_range_xor_normalizer'   r(   image_rangeZimage_minimumZimage_maximumr
   IntstartcountZ	_xor_flipr+   r,   r-   Z_xor_x_flipr.   r/   r0   Z_xor_y_flipr1   r2   r3   Z_xor_z_flipr4   r5   r6    rH   rH   =/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/minc/minc.pyr   "   s             r   c               @   s   e Zd ZedddZdS )ExtractOutputSpeczoutput file in raw/text formatT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rJ      s   rJ   c               @   s   e Zd ZdZeZeZdZdS )Extracta  Dump a hyperslab of MINC file data.

    Examples
    --------

    >>> from nipype.interfaces.minc import Extract
    >>> from nipype.interfaces.minc.testdata import minc2Dfile

    >>> extract = Extract(input_file=minc2Dfile)
    >>> extract.run() # doctest: +SKIP

    >>> extract = Extract(input_file=minc2Dfile, start=[3, 10, 5], count=[4, 4, 4]) # extract a 4x4x4 slab at offset [3, 10, 5]
    >>> extract.run() # doctest: +SKIP
    ZmincextractN)	r9   r:   r;   __doc__r   
input_specrJ   output_spec_cmdrH   rH   rH   rI   rK      s   rK   c               @   s   e Zd Zeddddd/dZedd0dgd	d
d	dZd1ZejddedZ	ejddedZ
ejddedZejddedZejddedZejddedZd2Zejd!d"edZejd#d$edZejejejd%d&d'Zd3Zejd*d+edZejd,d-edZd.S )4ToRawInputSpecz
input fileTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s.raw)r   r   r   r   r   r   r   r   r    r!   r"   r#   zWrite out data as bytes.z-byte)r   r   r&   z!Write out data as short integers.z-shortz"Write out data as 32-bit integers.z-intzSuperseded by write_int.z-longz9Write out data as single precision floating-point values.z-floatz9Write out data as double precision floating-point values.z-doubler$   r%   zWrite out signed data.z-signedzWrite out unsigned data.z	-unsignedz-range %s %szLSpecify the range of output values.Default value: 1.79769e+308 1.79769e+308.)r   r   r'   r(   z3Normalize integer pixel values to file max and min.z
-normalizezTurn off pixel normalization.z-nonormalizeNr7   r8   )r   r   r    r!   r"   r#   )r$   r%   )r'   r(   )r9   r:   r;   r   r   r<   r=   r   r>   r   r   r    r!   r"   r#   r?   r$   r%   r@   rA   rB   rC   r'   r(   rH   rH   rH   rI   rP     s`        rP   c               @   s   e Zd ZedddZdS )ToRawOutputSpeczoutput file in raw formatT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rQ   [  s   rQ   c               @   s   e Zd ZdZeZeZdZdS )ToRawa  Dump a chunk of MINC file data. This program is largely
    superceded by mincextract (see Extract).

    Examples
    --------

    >>> from nipype.interfaces.minc import ToRaw
    >>> from nipype.interfaces.minc.testdata import minc2Dfile

    >>> toraw = ToRaw(input_file=minc2Dfile)
    >>> toraw.run() # doctest: +SKIP

    >>> toraw = ToRaw(input_file=minc2Dfile, write_range=(0, 100))
    >>> toraw.run() # doctest: +SKIP
    Z	minctorawN)	r9   r:   r;   rL   rP   rM   rQ   rN   rO   rH   rH   rH   rI   rR   _  s   rR   c               @   s   e Zd Zeddddd#dZedddd$dg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ddddddddddZejddd d!Zd"S )%ConvertInputSpeczinput file for convertingTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_convert_output.mnc)r   genfiler   r   r   r   r   zOverwrite existing file.z-clobber)r   r   
usedefaultdefault_valuezCreate a MINC 2 output file.z-2)r   r   z}Create a template file. The dimensions, variables, andattributes of the input file are preserved but all data it set to zero.z	-templater                     	   z-compress %sz<Set the compression level, from 0 (disabled) to 9 (maximum).)r   r   zBSet the target block size for chunking (0 default, >1 block size).z	-chunk %d)lowr   r   Nr7   r8   )r9   r:   r;   r   r   r<   r   r>   clobbertwotemplateEnumcompressionRangechunkrH   rH   rH   rI   rS   u  sP   rS   c               @   s   e Zd ZedddZdS )ConvertOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rf     s   rf   c               @   s   e Zd ZdZeZeZdZdS )ConvertaH  convert between MINC 1 to MINC 2 format.

    Examples
    --------

    >>> from nipype.interfaces.minc import Convert
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> c = Convert(input_file=minc2Dfile, output_file='/tmp/out.mnc', two=True) # Convert to MINC2 format.
    >>> c.run() # doctest: +SKIP
    ZmincconvertN)	r9   r:   r;   rL   rS   rM   rf   rN   rO   rH   rH   rH   rI   rg     s   
rg   c            	   @   sZ   e Zd ZeddddddZedddddgd	d
dZdZejddedZ	ejddedZ
dS )CopyInputSpeczinput file to copyTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_copy.mnc)r   rT   r   r   r   r   r   pixel_valuesreal_valueszCopy pixel values as is.z-pixel_values)r   r   r&   z&Copy real pixel intensities (default).z-real_valuesNr7   r8   )ri   rj   )r9   r:   r;   r   r   r<   Z
_xor_pixelr   r>   ri   rj   rH   rH   rH   rI   rh     s"   rh   c               @   s   e Zd ZedddZdS )CopyOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rk     s   rk   c               @   s   e Zd ZdZeZeZdZdS )Copya  
    Copy image values from one MINC file to another. Both the input
    and output files must exist, and the images in both files must
    have an equal number dimensions and equal dimension lengths.

    NOTE: This program is intended primarily for use with scripts
    such as mincedit. It does not follow the typical design rules of
    most MINC command-line tools and therefore should be used only
    with caution.
    ZminccopyN)	r9   r:   r;   rL   rh   rM   rk   rN   rO   rH   rH   rH   rI   rl     s   
rl   c            
   @   s   e Zd ZeddddddZedd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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 ) ToEcatInputSpeczinput file to convertTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_to_ecat.v)r   rT   r   r   r   r   r   r   z3Ignore informations from the minc patient variable.z-ignore_patient_variable)r   r   z1Ignore informations from the minc study variable.z-ignore_study_variablez7Ignore informations from the minc acquisition variable.z-ignore_acquisition_variablez<Ignore informations from the minc ecat_acquisition variable.z!-ignore_ecat_acquisition_variablez5Ignore informations from the minc ecat-main variable.z-ignore_ecat_mainz7Ignore informations from the minc ecat-subhdr variable.z-ignore_ecat_subheader_variablez+Do not compute the decay correction factorsz-no_decay_corr_fctrzSVoxel values are treated as integers, scale andcalibration factors are set to unityz-labelNr7   r8   )r9   r:   r;   r   r   r<   r   r>   Zignore_patient_variableZignore_study_variableZignore_acquisition_variableZ ignore_ecat_acquisition_variableZignore_ecat_mainZignore_ecat_subheader_variableZno_decay_corr_fctrZvoxels_as_integersrH   rH   rH   rI   rm     sL   
rm   c               @   s   e Zd ZedddZdS )ToEcatOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rn   3  s   rn   c               @   s   e Zd ZdZeZeZdZdS )ToEcata  Convert a 2D image, a 3D volumes or a 4D dynamic volumes
    written in MINC file format to a 2D, 3D or 4D Ecat7 file.

    Examples
    --------

    >>> from nipype.interfaces.minc import ToEcat
    >>> from nipype.interfaces.minc.testdata import minc2Dfile

    >>> c = ToEcat(input_file=minc2Dfile)
    >>> c.run() # doctest: +SKIP

    >>> c = ToEcat(input_file=minc2Dfile, voxels_as_integers=True)
    >>> c.run() # doctest: +SKIP

    Z
minctoecatN)	r9   r:   r;   rL   rm   rM   rn   rN   rO   rH   rH   rH   rI   ro   7  s   ro   c               @   s   e Zd Zeddddd)dZedd*dgd	d
d	dZd+ZejddedZ	ejddedZ
d,ZejddddedZejddddedZeejddddZejd d!d"d#Zejd$d%d&Zejej ejejejd'dd&Zd(S )-DumpInputSpecz
input fileTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_dump.txt)r   r   r   r   r   r   coordinate_dataheader_dataz0Coordinate variable data and header information.z-c)r   r   r&   z!Header information only, no data.z-hannotations_briefannotations_fullcfz-b %sz3Brief annotations for C or Fortran indices in data.)r   r   r&   z-f %sz2Full annotations for C or Fortran indices in data.z)Output data for specified variables only.r)   z-v %s)r   r*   r   r   z1Line length maximum in data section (default 80).z-l %d)r^   r   r   z1Name for netCDF (default derived from file name).z-n %s)r   r   z1Display floating-point values with less precisionNr7   r8   )rq   rr   )rs   rt   )r9   r:   r;   r   r   r<   Z_xor_coords_or_headerr   r>   rq   rr   Z_xor_annotationsrb   rs   rt   r
   Str	variablesrd   Zline_lengthZnetcdf_nameEitherrE   r@   	precisionrH   rH   rH   rI   rp   N  sV   
rp   c               @   s   e Zd ZedddZdS )DumpOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r{     s   r{   c                   s,   e Zd ZdZeZeZdZ fddZ	  Z
S )Dumpa  Dump a MINC file. Typically used in conjunction with mincgen (see Gen).

    Examples
    --------

    >>> from nipype.interfaces.minc import Dump
    >>> from nipype.interfaces.minc.testdata import minc2Dfile

    >>> dump = Dump(input_file=minc2Dfile)
    >>> dump.run() # doctest: +SKIP

    >>> dump = Dump(input_file=minc2Dfile, output_file='/tmp/out.txt', precision=(3, 4))
    >>> dump.run() # doctest: +SKIP

    Zmincdumpc                sx   |dkrdt |trd| S t |trTt |d trTt |d trTd|d |d f S tdt| tt| j|||S )Nrz   z-p %dr   r   z-p %d,%dzInvalid precision argument: )
isinstanceinttuple
ValueErrorstrsuperr|   _format_arg)selfnamespecvalue)	__class__rH   rI   r     s    

zDump._format_arg)r9   r:   r;   rL   rp   rM   r{   rN   rO   r   __classcell__rH   rH   )r   rI   r|     s
   r|   c            	   @   s@  e Zd ZdiZeedddddddjed	Zed
dddedZeddddkdgdddZe	j
dddZe	j
dddddZdlZe	j
ddedZe	j
ddedZe	j
dd dZdmZe	j
d#d$edZe	j
d%d&edZdnZe	j
d0d1edZe	j
d2d3edZe	j
d4d5edZe	j
d6d7edZe	j
d8d9edZe	j
d:d;edZe	j
d<d=edZe	j
d>d?edZe	j
d@dAedZe	jdBdCdDddEdFZdoZ e	j
dIdJe dZ!e	j
dKdLe dZ"e	j#e	j$e	j$dMdNdOZ%edPdQdZ&dpZ'e	j
dTdUe'dZ(e	j
dVdWe'dZ)e	j*dXdYdZ+e	j
dZd[dZ,e	j#e	j-e	j-d\d]dOZ.e	j-d^d_dZ/ee	j*d`dadbdcZ0e	j
dddedqdgZ1dhS )rAverageInputSpecinput_filesfilelistT)r   zinput file(s) z%sr   )r   r   r*   r   r   r&   z7Specify the name of a file containing input file names.z-filelist %s)r   r   r   r   r&   zoutput filer   Fz%s_averaged.mnc)r   rT   r   r   r   r   r   zCreate a MINC 2 output file.z-2)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   verbosequietz!Print out log messages (default).z-verbose)r   r   r&   zDo not print out log messages.z-quietzPrint out debugging messages.z-debugcheck_dimensionsno_check_dimensionsz9Check that dimension info matches across files (default).z-check_dimensionszDo not check dimension info.z-nocheck_dimensionsformat_filetypeformat_byteformat_short
format_intformat_longformat_floatformat_doubleformat_signedformat_unsignedz&Use data type of first file (default).z	-filetypezWrite out byte data.z-bytezWrite out short integer data.z-shortzWrite out 32-bit integer data.z-intzSuperseded by -int.z-longz/Write out single-precision floating-point data.z-floatz/Write out double-precision floating-point data.z-doublezWrite signed integer data.z-signedz&Write unsigned integer data (default).z	-unsignedr   z=Specify the maximum size of the internal buffers (in kbytes).i   z-max_buffer_size_in_kb %d)r^   r   r   rU   r   r'   r(   z'Normalize data sets for mean intensity.z
-normalizez%Do not normalize data sets (default).z-nonormalizez-range %d %dzValid range for output data.)r   r   z)Specify an output sd file (default=none).z
-sdfile %scopy_headerno_copy_headerzBCopy all of the header from the first file (default for one file).z-copy_headerzLDo not copy all of the header from the first file (default for many files)).z-nocopy_headerz3Specify a dimension along which we wish to average.z
-avgdim %sz;Binarize the volume by looking for values in a given range.z	-binarizez-binrange %s %szLSpecify a range for binarization. Default value: 1.79769e+308 -1.79769e+308.zNSpecify a target value (+/- 0.5) forbinarization. Default value: -1.79769e+308z-binvalue %sz0Specify weights for averaging ("<w1>,<w2>,...").r)   z-weights %s)r   r*   r   z0Weight by dimension widths when -avgdim is used.z-width_weightedavgdim)r   r   requiresN)r   r   r7   r8   )r   r   )r   r   )	r   r   r   r   r   r   r   r   r   )r'   r(   )r   r   )r   )2r9   r:   r;   _xor_input_filesr
   r   r   r   r<   r   r>   r`   r_   _xor_verboser   r   debug_xor_check_dimensionsr   r   _xor_formatr   r   r   r   r   r   r   r   r   rd   max_buffer_size_in_kbrC   r'   r(   r@   rE   voxel_rangeZsdfile_xor_copy_headerr   r   rw   r   ZbinarizerA   ZbinrangeZbinvalueweightsZwidth_weightedrH   rH   rH   rI   r     s          
r   c               @   s   e Zd ZedddZdS )AverageOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r   z  s   r   c               @   s   e Zd ZdZeZeZdZdS )Averageaf  Average a number of MINC files.

    Examples
    --------

    >>> from nipype.interfaces.minc import Average
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> files = [nonempty_minc_data(i) for i in range(3)]
    >>> average = Average(input_files=files, output_file='/tmp/tmp.mnc')
    >>> average.run() # doctest: +SKIP

    ZmincaverageN)	r9   r:   r;   rL   r   rM   r   rN   rO   rH   rH   rH   rI   r   ~  s   r   c            	   @   sn   e Zd ZeddddddZedddddgd	d
dZejdddZejdddZ	ejdddZ
ejdddZdS )BlobInputSpeczinput file to blobTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_blob.mnc)r   rT   r   r   r   r   r   z<compute the trace (approximate growth and shrinkage) -- FASTz-trace)r   r   z<compute the determinant (exact growth and shrinkage) -- SLOWz-determinantz,compute translation (structure displacement)z-translationz0compute the magnitude of the displacement vectorz
-magnitudeNr7   r8   )r9   r:   r;   r   r   r<   r   r>   traceZdeterminanttranslationZ	magnituderH   rH   rH   rI   r     s(   
r   c               @   s   e Zd ZedddZdS )BlobOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r     s   r   c               @   s   e Zd ZdZeZeZdZdS )Bloba4  Calculate blobs from minc deformation grids.

    Examples
    --------

    >>> from nipype.interfaces.minc import Blob
    >>> from nipype.interfaces.minc.testdata import minc2Dfile

    >>> blob = Blob(input_file=minc2Dfile, output_file='/tmp/tmp.mnc', trace=True)
    >>> blob.run() # doctest: +SKIP
    ZmincblobN)	r9   r:   r;   rL   r   rM   r   rN   rO   rH   rH   rH   rI   r     s   r   c            	   @   sD  e Zd ZdhZeedddddddid	Zed
dddjdgdddZej	dddZ
ej	dddddZdkZej	ddedZej	ddedZej	dddZeddded ZdlZej	d#d$edZej	d%d&edZdmZej	d0d1edZej	d2d3edZej	d4d5edZej	d6d7edZej	d8d9edZej	d:d;edZej	d<d=edZej	d>d?edZej	d@dAedZejejejdBdCdDZ ej!dEdFdGdHZ"dnZ#ej	dKdLe#dZ$ej	dMdNe#dZ%ej	dOdPdZ&ej	dQdRdZ'doZ(ej	dVdWe(dZ)ej	dXdYe(dZ*ej	dZd[e(dZ+dpZ,ej-d^d_e,dd`Z.edadbe,dd`Z/ej0ejej-edcdddDZ1ejdedfdZ2dgS )qCalcInputSpecr   r   T)r   zinput file(s) for calculationr   z%sr   )r   r   r*   r   r   zoutput filer   Fz%s_calc.mnc)r   rT   r   r   r   r   r   zCreate a MINC 2 output file.z-2)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   r   r   z!Print out log messages (default).z-verbose)r   r   r&   zDo not print out log messages.z-quietzPrint out debugging messages.z-debugz7Specify the name of a file containing input file names.z-filelist %s)r   r   r   r&   r   r   z+Copy all of the header from the first file.z-copy_headerz2Do not copy all of the header from the first file.z-nocopy_headerr   r   r   r   r   r   r   r   r   z&Use data type of first file (default).z	-filetypezWrite out byte data.z-bytezWrite out short integer data.z-shortzWrite out 32-bit integer data.z-intzSuperseded by -int.z-longz/Write out single-precision floating-point data.z-floatz/Write out double-precision floating-point data.z-doublezWrite signed integer data.z-signedz&Write unsigned integer data (default).z	-unsignedz-range %d %dzValid range for output data.)r   r   r   z=Specify the maximum size of the internal buffers (in kbytes).z-max_buffer_size_in_kb %d)r^   r   r   r   r   z4Check that files have matching dimensions (default).z-check_dimensionsz1Do not check that files have matching dimensions.z-nocheck_dimensionsz,Ignore invalid data (NaN) for accumulations.z-ignore_nanz=Invalid data in any file at a voxel produces a NaN (default).z-propagate_nan
output_nanoutput_zerooutput_illegal_valuez7Output NaN when an illegal operation is done (default).z-nanz.Output zero when an illegal operation is done.z-zerozQValue to write out when an illegal operation is done. Default value: 1.79769e+308z-illegal_value
expressionexpfilez"Expression to use in calculations.z-expression '%s')r   r   r&   r   z#Name of file containing expression.z-expfile %sz-outfile %s %saP  List of (symbol, file) tuples indicating that output should be writtento the specified file, taking values from the symbol which should becreated in the expression (see the EXAMPLES section). If this optionis given, then all non-option arguments are taken as input files.This option can be used multiple times for multiple output files.z,Number of voxels to evaluate simultaneously.z-eval_width %sN)r   r   r7   r8   )r   r   )r   r   )	r   r   r   r   r   r   r   r   r   )r   r   )r   r   r   )r   r   )3r9   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@   rE   r   rd   r   r   r   r   
ignore_nanpropagate_nan_xor_nan_zero_illegalr   r   output_illegalZ_xor_expressionrw   r   r   ListoutfilesZ
eval_widthrH   rH   rH   rI   r     s          

	r   c               @   s   e Zd ZedddZdS )CalcOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r     s   r   c               @   s   e Zd ZdZeZeZdZdS )Calca  Compute an expression using MINC files as input.

    Examples
    --------

    >>> from nipype.interfaces.minc import Calc
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> file0 = nonempty_minc_data(0)
    >>> file1 = nonempty_minc_data(1)
    >>> calc = Calc(input_files=[file0, file1], output_file='/tmp/calc.mnc', expression='A[0] + A[1]') # add files together
    >>> calc.run() # doctest: +SKIP
    ZminccalcN)	r9   r:   r;   rL   r   rM   r   rN   rO   rH   rH   rH   rI   r     s   r   c               @   s   e Z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d Z	ej
dde	dZej
dde	dZej
dddZej
dddZej
dddZdS )!BBoxInputSpecz
input fileTz%sr   )r   r   r   r   r   z+output file containing bounding box cornersr   r   Fz%s_bbox.txt)r   r   r   r   r   r   r   z<VIO_Real value threshold for bounding box. Default value: 0.z
-threshold)r   r   one_line	two_linesz5Output on one line (default): start_x y z width_x y zz	-one_line)r   r   r&   z-Write output with two rows (start and width).z
-two_lineszJOutput format for mincresample: (-step x y z -start x y z -nelements x y zz-mincresamplez<Output format for mincreshape: (-start x,y,z -count dx,dy,dzz-mincreshapez@Output format for minccrop: (-xlim x1 x2 -ylim y1 y2 -zlim z1 z2z	-minccropNr7   r8   )r   r   )r9   r:   r;   r   r   r<   r   rE   	thresholdZ_xor_one_twor>   r   r   Zformat_mincresampleZformat_mincreshapeZformat_minccroprH   rH   rH   rI   r     s>   r   c               @   s   e Zd ZedddZdS )BBoxOutputSpecz+output file containing bounding box cornersT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r     s   r   c               @   s   e Zd ZdZeZeZdZdS )BBoxa+  Determine a bounding box of image.

    Examples
    --------
    >>> from nipype.interfaces.minc import BBox
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> file0 = nonempty_minc_data(0)
    >>> bbox = BBox(input_file=file0)
    >>> bbox.run() # doctest: +SKIP

    ZmincbboxN)	r9   r:   r;   rL   r   rM   r   rN   rO   rH   rH   rH   rI   r     s   r   c               @   sV  e Zd Z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ddZedddZejdddddZejdddddZejdddddZejdddd dZejd!dd"d#dZejd!dd$d%dZejd&dd'd(dZejd)dd*d+dZejd,d-dZed.d9d0dd1Zed2d:d0dd1Zed3d;d0d4gd5d6d7Zd8S )<BeastInputSpeca  

    TODO:

    Command-specific options:
     -verbose:          Enable verbose output.
     -positive:         Specify mask of positive segmentation (inside mask) instead of the default mask.
     -output_selection: Specify file to output selected files.
     -count:            Specify file to output the patch count.
     -mask:             Specify a segmentation mask instead of the the default mask.
     -no_mask:          Do not apply a segmentation mask. Perform the segmentation over the entire image.
     -no_positive:      Do not apply a positive mask.
    Generic options for all commands:
     -help:             Print summary of command-line options and abort
     -version:          Print version number of program and exit
    Copyright (C) 2011  Simon Fristed Eskildsen, Vladimir Fonov,
                Pierrick Coupe, Jose V. Manjon

    This program comes with ABSOLUTELY NO WARRANTY; for details type 'cat COPYING'.
    This is free software, and you are welcome to redistribute it under certain
    conditions; type 'cat COPYING' for details.

    Usage: mincbeast [options] <library dir> <input> <output>
           mincbeast -help

    Get this example to work?

    https://github.com/BIC-MNI/BEaST/blob/master/README.library


        2.3 Source the minc-toolkit (if installed):
        $ source /opt/minc/minc-toolkit-config.sh

        2.4 Generate library by running:
        $ beast_prepareADNIlib -flip <ADNI download directory> <BEaST library directory>
        Example:
        $ sudo beast_prepareADNIlib -flip Downloads/ADNI /opt/minc/share/beast-library-1.1

        3. Test the setup
        3.1 Normalize your data
        $ beast_normalize -modeldir /opt/minc/share/icbm152_model_09c input.mnc normal.mnc normal.xfm
        3.2 Run BEaST
        $ mincbeast /opt/minc/share/beast-library-1.1 normal.mnc brainmask.mnc -conf /opt/minc/share/beast-library-1.1/default.2mm.conf -same_res
    z1Output the probability map instead of crisp mask.z-probability)r   r   zBFlip images around the mid-sagittal plane to increase patch count.z-flipz^Do not calculate moments instead use precalculatedlibrary moments. (for optimization purposes)z-load_momentsz Fill holes in the binary output.z-fillz-Apply a median filter on the probability map.z-medianz:Apply an NLM filter on the probability map (experimental).z-nlm_filterzOverwrite existing file.z-clobberT)r   r   rU   rV   zSpecify configuration file.z-configuration %srX   zSpecify voxel size for calculations (4, 2, or 1).Default value: 4. Assumes no multiscale. Use configurationfile for multiscale.z-voxel_size %s)rU   r   r   zMFile paths in the library are absolute (default is relative to library root).z-abspathr   z?Specify patch size for single scale approach. Default value: 1.z-patch_size %sr   zHSpecify size of search area for single scale approach. Default value: 2.z-search_area %sg      ?z2Specify confidence level Alpha. Default value: 0.5z	-alpha %sz3Specify smoothness factor Beta. Default value: 0.25z-beta %sgffffff?z:Specify threshold for patch selection. Default value: 0.95z-threshold %s   z4Specify number of selected images. Default value: 20z-selection_num %sz9Output final mask with the same resolution as input file.z-same_resolutionzlibrary directoryrW   z%s)r   r   r   r   z
input filezoutput filer   Fz%s_beast_mask.mnc)r   r   r   r   r   r   Nr7   r8   )r9   r:   r;   rL   r   r>   Zprobability_mapZflip_imagesZload_momentsZ
fill_holesZmedian_filterZ
nlm_filterr_   r   Zconfiguration_filerE   Z
voxel_sizeabspathZ
patch_sizeZsearch_arearA   Zconfidence_level_alphaZsmoothness_factor_betaZthreshold_patch_selectionZnumber_selected_imagesZsame_resolutionr	   Zlibrary_dirr   r<   rH   rH   rH   rI   r     s   ,


r   c               @   s   e Zd ZedddZdS )BeastOutputSpeczoutput mask fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r     s   r   c               @   s   e Zd ZdZeZeZdZdS )Beastal  Extract brain image using BEaST (Brain Extraction using
    non-local Segmentation Technique).

    Examples
    --------

    >>> from nipype.interfaces.minc import Beast
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> file0 = nonempty_minc_data(0)
    >>> beast = Beast(input_file=file0)
    >>> beast .run() # doctest: +SKIP
    Z	mincbeastN)	r9   r:   r;   rL   r   rM   r   rN   rO   rH   rH   rH   rI   r     s   r   c            
   @   s  e Zd ZedddddTdZdUZejded	Zejd
ed	Z	eddddVdgddddZ
ejdddddZejdddddZejdddZejdddddZdWZejejd d!ejd"d!dd#Zejd$d%d&gd'Zejd(d)dZejejejd*d+dZdXZejejejd.d/ed0Zejd1d2ed0Zejd3d4dZdYZejd8d9ed0Zejd:d;ed0Z ejd<d=ed0Z!ejd>d?dZ"ejd@dAdZ#dZZ$ejdDdEdZ%ej&dFdGdHdIdJZ'd[Z(ejdMdNe(d0Z)ejdOdPe(d0Z*ejdQdRdZ+dSS )\PikInputSpecz
input fileTz%sr   )r   r   r   r   r   jpgpngzOutput a jpg file.)r   r&   zOutput a png file (default).zoutput filer   r   Fz%s.png)r   r   rT   r   r   r   r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   zcScaling factor for resulting image. By default images areoutput at twice their original resolution.z
--scale %s)rU   r   r   zFAutoscale the resulting image to have a fixed image width (in pixels).z
--width %s)r   r   r\      z9Bitdepth for resulting image 8 or 16 (MSB machines only!)z
--depth %stitle_stringtitle_with_filenamez/Use input filename as title in resulting image.)r   z#Add a title to the resulting image.)r   zFont point size for the title.z--title_size %stitle)r   r   r   zKcreate an annotated bar to match the image (use height of the output image)z
--anot_barz$Valid range of values for MINC file.z--range %s %srD   
auto_rangez1Range of image values to use for pixel intensity.z--image_range %s %s)r   r   r&   zFAutomatically determine image range using a 5 and 95% PcT. (histogram)z--auto_rangez:Slice number to get. (note this is in voxel co-ordinates).z
--slice %sslice_zslice_yslice_xz"Get an axial/transverse (z) slice.z-zzGet a coronal (y) slice.z-yzGet a sagittal (x) slice.z-xz*Create a triplanar view of the input file.z--triplanarz)Pixel size for each image in a triplanar.z--tilesize %ssagittal_offsetsagittal_offset_percz*Offset the sagittal slice from the centre.z--sagittal_offset %sr   d   z:Offset the sagittal slice by a percentage from the centre.z--sagittal_offset_perc %d)r^   highr   r   vertical_triplanar_viewhorizontal_triplanar_viewz+Create a vertical triplanar view (Default).z
--verticalz#Create a horizontal triplanar view.z--horizontalzArguments to pass to minclookupz--lookup %sNr7   )r   r   r8   )r   r   )rD   r   )r   r   r   )r   r   )r   r   ),r9   r:   r;   r   r   Z_xor_image_typer   r>   r   r   r<   r_   rE   scalewidthrb   depthZ
_xor_titlery   rw   r   Z
title_sizeZannotated_barr@   rA   Z
minc_rangeZ_xor_image_rangerD   r   rF   Z
_xor_slicer   r   r   Z	triplanarZ	tile_sizeZ_xor_sagittal_offsetr   rd   r   Z_xor_vertical_horizontalr   r   lookuprH   rH   rH   rI   r     s   





r   c               @   s   e Zd ZedddZdS )PikOutputSpeczoutput imageT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r   E  s   r   c                   s,   e Zd ZdZeZeZdZ fddZ	  Z
S )Pikaz  Generate images from minc files.

    Mincpik uses Imagemagick to generate images
    from Minc files.

    Examples
    --------

    >>> from nipype.interfaces.minc import Pik
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> file0 = nonempty_minc_data(0)
    >>> pik = Pik(input_file=file0, title='foo')
    >>> pik .run() # doctest: +SKIP

    Zmincpikc                sR   |dkr>t |tr|rdS t |tr.d|f S tdt| tt| j|||S )Nr   z--titlez--title --title_text %sz$Unknown value for "title" argument: )r}   boolr   r   r   r   r   )r   r   r   r   )r   rH   rI   r   _  s    

zPik._format_arg)r9   r:   r;   rL   r   rM   r   rN   rO   r   r   rH   rH   )r   rI   r   I  s
   r   c            	   @   s   e Zd Zeddddd*dZeddd+dZejd	d
dddZd,Z	ejdde	dZ
ejdde	dZejdddZejdddZejdddZd-Zejdddedd Zejdd!d"edd Zejejejejd#d$edd%Zejd&ddd'd(dZd)S ).BlurInputSpecz
input fileTz%sr   )r   r   r   r   r   zoutput file baser   )r   r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   gaussianrectz*Use a gaussian smoothing kernel (default).z	-gaussian)r   r   r&   z"Use a rect (box) smoothing kernel.z-rectz-Create the gradient magnitude volume as well.z	-gradient)r   r   zECreate the partial derivative and gradient magnitude volumes as well.z-partialz(Do not apodize the data before blurring.z-no_apodizefwhmfwhm3dstandard_devr   z=Full-width-half-maximum of gaussian kernel. Default value: 0.z-fwhm %s)r   r   r&   r   z8Standard deviation of gaussian kernel. Default value: 0.z-standarddev %sz-3dfwhm %s %s %szdFull-width-half-maximum of gaussian kernel.Default value: -1.79769e+308 -1.79769e+308 -1.79769e+308.)r   r   r&   r   rW   zANumber of dimensions to blur (either 1,2 or 3). Default value: 3.z-dimensions %sNr7   r8   )r   r   )r   r   r   )r9   r:   r;   r   r   output_file_baser   r>   r_   Z_xor_kernelr   r   gradientpartialZ
no_apodizeZ_xor_main_optionsrA   r   r   r@   r   rb   Z
dimensionsrH   rH   rH   rI   r   j  sb   

r   c               @   sJ   e Zd Zed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 )BlurOutputSpeczBlurred output file.T)r   r   zGradient dxyz.)r   zPartial gradient dx.zPartial gradient dy.zPartial gradient dz.zPartial gradient dxyz.N)
r9   r:   r;   r   r<   gradient_dxyz
partial_dx
partial_dy
partial_dzpartial_dxyzrH   rH   rH   rI   r     s   



r   c                   s@   e Zd ZdZeZeZdZdd Z	dd Z
e fddZ  ZS )	Blura  
    Convolve an input volume with a Gaussian blurring kernel of
    user-defined width.  Optionally, the first partial derivatives
    and the gradient magnitude volume can be calculated.

    Examples
    --------

    >>> from nipype.interfaces.minc import Blur
    >>> from nipype.interfaces.minc.testdata import minc3Dfile

    (1) Blur  an  input  volume with a 6mm fwhm isotropic Gaussian
    blurring kernel:

    >>> blur = Blur(input_file=minc3Dfile, fwhm=6, output_file_base='/tmp/out_6')
    >>> blur.run() # doctest: +SKIP

    mincblur will create /tmp/out_6_blur.mnc.

    (2) Calculate the blurred and gradient magnitude data:

    >>> blur = Blur(input_file=minc3Dfile, fwhm=6, gradient=True, output_file_base='/tmp/out_6')
    >>> blur.run() # doctest: +SKIP

    will create /tmp/out_6_blur.mnc and /tmp/out_6_dxyz.mnc.

    (3) Calculate the blurred data, the partial derivative volumes
    and  the gradient magnitude for the same data:

    >>> blur = Blur(input_file=minc3Dfile, fwhm=6, partial=True, output_file_base='/tmp/out_6')
    >>> blur.run() # doctest: +SKIP

    will create /tmp/out_6_blur.mnc, /tmp/out_6_dx.mnc,
    /tmp/out_6_dy.mnc, /tmp/out_6_dz.mnc and /tmp/out_6_dxyz.mnc.
    Zmincblurc             C   sV   | j j}t|r|S tjj| j jd }tjj|d }tjjtj	 |d }|S d S )Nr   r   Z_bluroutput)
inputsr   r   ospathsplitr   splitextjoingetcwd)r   r   Zbase_file_nameZbase_file_name_no_extZoutput_baserH   rH   rI   _gen_output_base  s    zBlur._gen_output_basec             C   sx   | j  j }| j }|d |d< t| jjr8|d |d< t| jjrt|d |d< |d |d< |d	 |d
< |d |d< |S )Nz	_blur.mncr<   z	_dxyz.mncr   z_dx.mncr   z_dy.mncr   z_dz.mncr   r   )rN   getr   r   r   r   r   )r   outputsr   rH   rH   rI   _list_outputs  s    zBlur._list_outputsc                s4   | j j}tt| j}t|r |S d|| j f S d S )Nz%s %s)r   r   r   r   cmdliner   r   )r   r   Zorig_cmdline)r   rH   rI   r     s
    zBlur.cmdline)r9   r:   r;   rL   r   rM   r   rN   rO   r   r   propertyr   r   rH   rH   )r   rI   r     s   #r   c               @   sh  e Zd ZdZeeddddddded	Zed
ddddgdddZeddddedZe	j
dddddZe	j
dddZdZe	j
ddedZe	j
ddedZdZe	j
d(d)edZe	j
d*d+edZe	j
d,d-edZe	j
d.d/edZe	j
d0d1edZe	j
d2d3edZe	j
d4d5edZe	j
d6d7edZe	j
d8d9edZe	je	je	jd:d;d<Ze	jd=d>d?dd@dAZdZe	j
dDdEedZ e	j
dFdGedZ!e	j"dHdIdZ#e	j
dJdKdZ$e	j
dLdMdZ%dZ&e	j
dQdRe&dZ'e	j
dSdTe&dZ(e	j
dUdVe&dZ)dWdXdYdZd[d\d]d^d_d`g
Z*e	j+e	j
 e	j, dadbdZ-e	j+e	j
 e	j, dcdddZ.e	j+e	j
 e	j, dedfdZ/e	j+e	j
 e	j, dgdhdZ0e	j+e	j
 e	j, didjdZ1e	j+e	j
 e	j, dkdldZ2e	j+e	j
 e	j, dmdndZ3e	j+e	j
 e	j, dodpdZ4e	j+e	j
 e	j, dqdrdZ5e	j+e	j
 e	j, dsdtdZ6dudvdwdxdydzd{d|d}d~dddgZ7e	j+e	j, dddZ8e	j
dddZ9e	j
dddZ:e	j
dddZ;e	j
dddZ<e	je	j,e	j,ddd<Z=e	je	j,e	j,ddd<Z>e	je	j,e	j,ddd<Z?e	je	j,e	j,ddd<Z@e	je	j,e	j,ddd<ZAe	je	j,e	j,ddd<ZBe	j
dddZCe	j
dddZDdgZEe	j,dddZFdddd]dgZGe	j
dddZHe	j
dddZIe	j
dddZJe	j
dddZKe	j
dddZLdS )MathInputSpecr   r   T)r   zinput file(s) for calculationr   z%sr   )r   r   r*   r   r   r&   zoutput filer   Fz%s_mincmath.mnc)r   r   rT   r   r   r   r   z7Specify the name of a file containing input file names.z-filelist %s)r   r   r   r   r&   zOverwrite existing file.z-clobber)r   r   rU   rV   zCreate a MINC 2 output file.z-2)r   r   r   r   zBCopy all of the header from the first file (default for one file).z-copy_header)r   r   r&   zLDo not copy all of the header from the first file (default for many files)).z-nocopy_headerr   r   r   r   r   r   r   r   r   z&Use data type of first file (default).z	-filetypezWrite out byte data.z-bytezWrite out short integer data.z-shortzWrite out 32-bit integer data.z-intzSuperseded by -int.z-longz/Write out single-precision floating-point data.z-floatz/Write out double-precision floating-point data.z-doublezWrite signed integer data.z-signedz&Write unsigned integer data (default).z	-unsignedz-range %d %dzValid range for output data.)r   r   r   z=Specify the maximum size of the internal buffers (in kbytes).i   z-max_buffer_size_in_kb %d)r^   r   r   rU   r   r   r   z9Check that dimension info matches across files (default).z-check_dimensionszDo not check dimension info.z-nocheck_dimensionszASpecify a dimension along which we wish to perform a calculation.z-dimension %sz,Ignore invalid data (NaN) for accumulations.z-ignore_nanz=Invalid data in any file at a voxel produces a NaN (default).z-propagate_nanr   r   r   z7Output NaN when an illegal operation is done (default).z-nanz.Output zero when an illegal operation is done.z-zerozPValue to write out when an illegal operationis done. Default value: 1.79769e+308z-illegal_valuetest_gttest_lttest_eqtest_netest_getest_lecalc_addcalc_subcalc_mulcalc_divz(Test for vol1 > vol2 or vol1 > constant.z-gtz(Test for vol1 < vol2 or vol1 < constant.z-ltz2Test for integer vol1 == vol2 or vol1 == constant.z-eqz/Test for integer vol1 != vol2 or vol1 != const.z-nez'Test for vol1 >= vol2 or vol1 >= const.z-gez'Test for vol1 <= vol2 or vol1 <= const.z-lez#Add N volumes or volume + constant.z-addz(Subtract 2 volumes or volume - constant.z-subz(Multiply N volumes or volume * constant.z-multz&Divide 2 volumes or volume / constant.z-divinvertcalc_notsqrtsquareabsexplogr   clampsegmentnsegmentisnanzCalculate 1/c.z-invert -const %szCalculate !vol1.z-notzTake square root of a volume.z-sqrtzTake square of a volume.z-squarez Take absolute value of a volume.z-absz-exp -const2 %s %sz9Calculate c2*exp(c1*x). Both constants must be specified.z-log -const2 %s %sz=Calculate log(x/c2)/c1. The constants c1 and c2 default to 1.z-scale -const2 %s %sz!Scale a volume: volume * c1 + c2.z-clamp -const2 %s %sz)Clamp a volume to lie between two values.z-segment -const2 %s %szMSegment a volume using range of -const2: within range = 1, outside range = 0.z-nsegment -const2 %s %sz:Opposite of -segment: within range = 0, outside range = 1.zTest for NaN values in vol1.z-isnanzNegation of -isnan.z-nisnanpercentdiffzBPercent difference between 2 volumes, thresholded (const def=0.0).z-percentdiffcount_validmaximumminimumcalc_orz.Count the number of valid values in N volumes.z-count_validzFind maximum of N volumes.z-maximumzFind minimum of N volumes.z-minimumz Calculate vol1 && vol2 (&& ...).z-andz Calculate vol1 || vol2 (|| ...).z-orN)r   r   r7   r8   )r   r   )	r   r   r   r   r   r   r   r   r   )r   r   )r   r   r   )Mr9   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@   rE   r   rd   r   r   r   r   rw   Z	dimensionr   r   r   r   r   r   bool_or_const_traitsry   rA   r   r   r  r  r  r  r  r  r  r  single_volume_traitsr	  r
  r  r  r  r  r  r   r  r  r  r  Znisnantwo_volume_traitsr  n_volume_traitsr  r  r  Zcalc_andr  rH   rH   rH   rI   r     s          

r   c               @   s   e Zd ZedddZdS )MathOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r  y  s   r  c                   s8   e Zd ZdZeZeZdZ fddZ	 fddZ
  ZS )Matha  
    Various mathematical operations supplied by mincmath.

    Examples
    --------

    >>> from nipype.interfaces.minc import Math
    >>> from nipype.interfaces.minc.testdata import minc2Dfile

    Scale: volume*3.0 + 2:

    >>> scale = Math(input_files=[minc2Dfile], scale=(3.0, 2))
    >>> scale.run() # doctest: +SKIP

    Test if >= 1.5:

    >>> gt = Math(input_files=[minc2Dfile], test_gt=1.5)
    >>> gt.run() # doctest: +SKIP
    Zmincmathc                s   |d k	st || jjkrtt|tr,|r,|jS t|trL| rLtd|f n(t|trdd|j|f S td||f tt	| j
|||S )Nz'Does not make sense to specify %s=Falsez%s -const %szInvalid %s argument: %s)AssertionErrorrM   r  r}   r   r   r   floatr   r  r   )r   r   r   r   )r   rH   rI   r     s    
zMath._format_argc                sT  t | jj}xx| jjD ]l}| jj|}t|rt|trR|dkrt	d||f qt|t
rv|dkrt	d||f qt	d| qW x<| jjD ]0}| jj|}t|r|dkrt	d||f qW x<| jjD ]0}| jj|}t|r|dkrt	d||f qW xB| jjD ]6}| jj|}t|r|dkst	d||f qW tt| j S )zGA number of the command line options expect precisely one or two files.r   zHDue to the %s option we expected 2 files but input_files is of length %dr   zGDue to the %s option we expected 1 file but input_files is of length %dz/Argument should be a bool or const, but got: %szRDue to the %s option we expected at least one file but input_files is of length %d)lenr   r   rM   r  __getattribute__r   r}   r   r   r   r  r  r  r   r  _parse_inputs)r   Znr_input_filesnt)r   rH   rI   r#    sL    



zMath._parse_inputs)r9   r:   r;   rL   r   rM   r  rN   rO   r   r#  r   rH   rH   )r   rI   r  }  s   r  c               @   s   e Zd ZdZeddddddZeddddd	gd
ddZeeddZe	j
dddZe	j
dddddZdZe	j
ddedZe	j
ddedZe	j
ddedZe	j
d d!edZe	jd"ddd#d$d%d&d'd(d)d*d+dgd,ZdZe	j
d/d0edgd1Ze	j
d2d3edgd1Zed4dd5d6Ze	j
d7d8dZdZe	j
d;d<edZe	j
d=d>edZed?d@ddAZdZe	j
dJdKedZe	j
dLdMedZe	j
dNdOedZ e	j
dPdQedZ!e	j
dRdSedZ"e	j
dTdUedZ#e	j
dVdWedZ$e	j
dXdYedZ%e	j&e	j'e	j'dZd[d\Z(dZ)e	j
d`dae)dZ*e	j
dbdce)dZ+e	j
dddee)dZ,dZ-e	j
dhdie-dZ.e	j
djdke-dZ/e	j'dldmdggd,Z0dZ1e	j
dpdqe1dZ2e	j
drdse1dZ3dZ4e	j5dvdwdZ6e	j
dxdydZ7e	j&e	j'e	j'e	j'dzd{dZ8e	j
d|d}dZ9e	j5d~ddZ:dZ;e	j&e	j<e	j<e	j<dde;dZ=e	j<ddde;dZ>e	j<ddde;dZ?e	j<ddde;dZ@dZAe	j&e	j<e	j<e	j<dde;dZBe	j<dddeAdZCe	j<dddeAdZDe	j<dddeAdZEdZFe	j&e	j'e	j'e	j'dde;dZGe	j'dddeFdZHe	j'dddeFdZIe	j'dddeFdZJdZKe	j&e	j'e	j'e	j'dde;dZLe	j'dddeKdZMe	j'dddeKdZNe	j'dddeKdZOdS )ResampleInputSpecz
    not implemented:
     -size:                    synonym for -nelements)
     -xsize:                   synonym for -xnelements
     -ysize:                   synonym for -ynelements
     -zsize:                   synonym for -ynelements

    zinput file for resamplingTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_resample.mnc)r   rT   r   r   r   r   r   zinput grid file(s))r   zCreate a MINC 2 output file.z-2)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   trilinear_interpolationtricubic_interpolationnearest_neighbour_interpolationsinc_interpolationzDo trilinear interpolation.z
-trilinear)r   r   r&   zDo tricubic interpolation.z	-tricubicz#Do nearest neighbour interpolation.z-nearest_neighbourzDo windowed sinc interpolation.z-sincrY   rW   rX   rZ   r[   r\   r]   
   z7Set half-width of sinc window (1-10). Default value: 5.z	-width %s)r   r   r   sinc_window_hanningsinc_window_hammingz Set sinc window type to Hanning.z-hanning)r   r   r&   r   z Set sinc window type to Hamming.z-hammingz7File giving world transformation. (Default = identity).z-transformation %s)r   r   r   z*Invert the transformation before using it.z-invert_transformationvio_transformno_input_samplingz>VIO_Transform the input sampling with the transform (default).z-tfm_input_samplingz<Use the input sampling without transforming (old behaviour).z-use_input_samplingz*Specifies a model file for the resampling.z-like %s)r   r   r   r   r   r   r   r   r   r   r   zWrite out byte data.z-bytezWrite out short integer data.z-shortzWrite out 32-bit integer data.z-intzSuperseded by -int.z-longz/Write out single-precision floating-point data.z-floatz/Write out double-precision floating-point data.z-doublezWrite signed integer data.z-signedz&Write unsigned integer data (default).z	-unsignedz-range %s %szHValid range for output data. Default value: -1.79769e+308 -1.79769e+308.)r   r   
transversesagittalcoronalzWrite out transverse slices.z-transversezWrite out sagittal slicesz	-sagittalzWrite out coronal slicesz-coronalnofillfillz2Use value zero for points outside of input volume.z-nofillz4Use a fill value for points outside of input volume.z-fillzTSpecify a fill value for points outside of input volume.Default value: 1.79769e+308.z-fillvalue %skeep_real_rangenokeep_real_rangez(Keep the real scale of the input volume.z-keep_real_rangez1Do not keep the real scale of the data (default).z-nokeep_real_range	spacetype	talairachz2Set the spacetype attribute to a specified string.z-spacetype %szOutput is in Talairach space.z
-talairachzXOrigin of first pixel in 3D space.Default value: 1.79769e+308 1.79769e+308 1.79769e+308.z-origin %s %s %sz=Set the sampling to standard values (step, start and dircos).z-standard_samplingz)Specify the units of the output sampling.z	-units %s	nelementsnelements_x_y_or_zz2Number of elements along each dimension (X, Y, Z).z-nelements %s %s %sz)Number of elements along the X dimension.z-xnelements %s
ynelements
znelements)r   r   r   r&   z)Number of elements along the Y dimension.z-ynelements %s
xnelementsz)Number of elements along the Z dimension.z-znelements %sstepstep_x_y_or_zzCStep size along each dimension (X, Y, Z). Default value: (0, 0, 0).z-step %s %s %sz2Step size along the X dimension. Default value: 0.z	-xstep %systepzstepz2Step size along the Y dimension. Default value: 0.z	-ystep %sxstepz2Step size along the Z dimension. Default value: 0.z	-zstep %srF   start_x_y_or_zzaStart point along each dimension (X, Y, Z).Default value: 1.79769e+308 1.79769e+308 1.79769e+308.z-start %s %s %sz?Start point along the X dimension. Default value: 1.79769e+308.z
-xstart %systartzstartz?Start point along the Y dimension. Default value: 1.79769e+308.z
-ystart %sxstartz?Start point along the Z dimension. Default value: 1.79769e+308.z
-zstart %sdircosdircos_x_y_or_zzDirection cosines along each dimension (X, Y, Z). Default value:1.79769e+308 1.79769e+308 1.79769e+308 1.79769e+308 ...  1.79769e+308 1.79769e+308 1.79769e+308 1.79769e+308 1.79769e+308.z-dircos %s %s %sz^Direction cosines along the X dimension.Default value: 1.79769e+308 1.79769e+308 1.79769e+308.z-xdircos %sydircoszdircosz^Direction cosines along the Y dimension.Default value: 1.79769e+308 1.79769e+308 1.79769e+308.z-ydircos %sxdircosz^Direction cosines along the Z dimension.Default value: 1.79769e+308 1.79769e+308 1.79769e+308.z-zdircos %sNr7   r8   )r'  r(  r)  r*  )r,  r-  )r.  r/  )r   r   r   r   r   r   r   r   )r0  r1  r2  )r3  r4  )r5  r6  )r7  r8  )r9  r:  )r;  r<  )r=  r<  )r=  r;  )r>  r?  )r@  rA  )rB  rA  )rB  r@  )rF   rC  )rD  rE  )rF  rE  )rF  rD  )rG  rH  )rI  rJ  )rK  rJ  )rK  rI  )Pr9   r:   r;   rL   r   r   r<   r
   input_grid_filesr   r>   r`   r_   Z_xor_interpolationr'  r(  r)  r*  rb   Zhalf_width_sinc_windowZ_xor_sinc_window_typer,  r-  ZtransformationZinvert_transformationZ_xor_input_samplingr.  r/  liker   r   r   r   r   r   r   r   r   r@   rA   Zoutput_rangeZ_xor_slicesZtransverse_slicesZsagittal_slicesZcoronal_slicesZ	_xor_fillZno_fillr4  Z
fill_valueZ
_xor_scaler5  r6  Z_xor_spacetyperw   r7  r8  originZstandard_samplingZunitsZ_xor_nelementsrE   r9  r=  r;  r<  Z	_xor_stepr>  rB  r@  rA  Z
_xor_startrF   rF  rD  rE  Z_xor_dircosrG  rK  rI  rJ  rH   rH   rH   rI   r&    s     


       

r&  c               @   s   e Zd ZedddZdS )ResampleOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rO  }
  s   rO  c               @   s   e Zd ZdZeZeZdZdS )Resamplea.  
    Resample a minc file.'

    Examples
    --------

    >>> from nipype.interfaces.minc import Resample
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> r = Resample(input_file=minc2Dfile, output_file='/tmp/out.mnc') # Resample the file.
    >>> r.run() # doctest: +SKIP

    ZmincresampleN)	r9   r:   r;   rL   r&  rM   rO  rN   rO   rH   rH   rH   rI   rP  
  s   rP  c            	   @   s  e Zd ZdZeddddd0dZedddd1d	gd
ddZeddd	gd
ddZej	dddddZ
eddddZej	d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ejddd)d*dZej	d+d,d Zejd-d.d Zd/S )2NormInputSpecaf  

    Not implemented:

       -version         print version and exit
       -verbose         be verbose
       -noverbose       opposite of -verbose [default]
       -quiet           be quiet
       -noquiet         opposite of -quiet [default]
       -fake            do a dry run, (echo cmds only)
       -nofake          opposite of -fake [default]
    zinput file to normaliseTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_norm.mnc)r   rT   r   r   r   r   r   z*File in which to store the threshold mask.z-threshold_mask %sz%s_norm_threshold_mask.mnc)r   r   r   r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   z0Calculate the image normalisation within a mask.z-mask %s)r   r   r   z/Force the ouput range between limits [default].z-clampg        g      Y@zTCutoff value to use to calculate thresholds by a histogram PcT in %. [default: 0.01]z
-cutoff %s)r^   r   r   r   zLower real value to use.z	-lower %s)r   r   zUpper real value to use.z	-upper %sz!Output files maximum [default: 0]z-out_floor %sz#Output files minimum [default: 100]z-out_ceil %szDThreshold the image (set values below threshold_perc to -out_floor).z
-thresholdzJThreshold percentage (0.1 == lower 10% of intensity range) [default: 0.1].z-threshold_perc %sz2Use the resulting image BiModalT as the threshold.z-threshold_bmtz=Blur FWHM for intensity edges then thresholding [default: 2].z-threshold_blur %sNr7   r8   )r9   r:   r;   rL   r   r   r<   output_threshold_maskr   r>   r_   maskr  rd   cutoffrA   lowerupperZ	out_floorZout_ceilr   Zthreshold_percZthreshold_bmtZthreshold_blurrH   rH   rH   rI   rQ  
  sx   

rQ  c               @   s"   e Zd ZedddZeddZdS )NormOutputSpeczoutput fileT)r   r   zthreshold mask file)r   N)r9   r:   r;   r   r<   rR  rH   rH   rH   rI   rW  
  s   rW  c               @   s   e Zd ZdZeZeZdZdS )Normab  Normalise a file between a max and minimum (possibly)
       using two histogram pct's.

    Examples
    --------

    >>> from nipype.interfaces.minc import Norm
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> n = Norm(input_file=minc2Dfile, output_file='/tmp/out.mnc') # Normalise the file.
    >>> n.run() # doctest: +SKIP
    ZmincnormN)	r9   r:   r;   rL   rQ  rM   rW  rN   rO   rH   rH   rH   rI   rX  
  s   rX  c            	   @   s   e Zd ZdZeddddddZeddddd	gd
ddZejdddZ	ejdddddZ
ejdddZejejejejdddZejdddZdS )VolcentreInputSpecz{
    Not implemented:

    -fake         do a dry run, (echo cmds only)
    -nofake       opposite of -fake [default]

    zinput file to centreTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_volcentre.mnc)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   zLUse the CoM of the volume for the new centre (via mincstats). Default: Falsez-comz-centre %s %s %sz'Centre to use (x,y,z) [default: 0 0 0].)r   r   z0Set the direction cosines to identity [default].z-zero_dircosNr7   r8   )r9   r:   r;   rL   r   r   r<   r   r>   r   r_   comr@   rA   ZcentreZzero_dircosrH   rH   rH   rI   rY  ,  sB   
rY  c               @   s   e Zd ZedddZdS )VolcentreOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r[  c  s   r[  c               @   s   e Zd ZdZeZeZdZdS )	Volcentrea$  Centre a MINC image's sampling about a point, typically (0,0,0).

    Example
    --------

    >>> from nipype.interfaces.minc import Volcentre
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> vc = Volcentre(input_file=minc2Dfile)
    >>> vc.run() # doctest: +SKIP
    Z	volcentreN)	r9   r:   r;   rL   rY  rM   r[  rN   rO   rH   rH   rH   rI   r\  g  s   
r\  c            	   @   s   e Zd ZdZeddddddZeddddd	gd
ddZejdddZ	ejdddddZ
ejdddZejdddZejdddZejdddZejdddZdS ) VolpadInputSpeca  
    Not implemented:

    -fake         do a dry run, (echo cmds only)
    -nofake       opposite of -fake [default]

     | volpad pads a MINC volume
     |
     | Problems or comments should be sent to: a.janke@gmail.com

    Summary of options:

    -- General Options -------------------------------------------------------------
       -verbose          be verbose
       -noverbose        opposite of -verbose [default]
       -clobber          clobber existing files
       -noclobber        opposite of -clobber [default]
       -fake             do a dry run, (echo cmds only)
       -nofake           opposite of -fake [default]


    zinput file to centreTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_volpad.mnc)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   zRAutomatically determine padding distances (uses -distance as max). Default: False.z-autozFFrequency of voxels over bimodalt threshold to stop at [default: 500].z-auto_freq %sz*Padding distance (in voxels) [default: 4].z-distance %sz3Smooth (blur) edges before padding. Default: False.z-smoothz,Smoothing distance (in voxels) [default: 4].z-smooth_distance %sNr7   r8   )r9   r:   r;   rL   r   r   r<   r   r>   r   r_   autorA   Z	auto_freqrE   ZdistanceZsmoothZsmooth_distancerH   rH   rH   rI   r]  x  sF   


r]  c               @   s   e Zd ZedddZdS )VolpadOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r_    s   r_  c               @   s   e Zd ZdZeZeZdZdS )Volpada?  Centre a MINC image's sampling about a point, typically (0,0,0).

    Examples
    --------

    >>> from nipype.interfaces.minc import Volpad
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> vp = Volpad(input_file=minc2Dfile, smooth=True, smooth_distance=4)
    >>> vp.run() # doctest: +SKIP
    ZvolpadN)	r9   r:   r;   rL   r]  rM   r_  rN   rO   rH   rH   rH   rI   r`    s   
r`  c            	   @   s   e Zd ZeddddddZedddddgd	d
dZejdddZejdddddZ	ej
dddZej
dddZejdddZdS )VolisoInputSpecz+input file to convert to isotropic samplingTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_voliso.mnc)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z	--verbose)r   r   zOverwrite existing file.z	--clobber)r   r   rU   rV   z5The target maximum step desired in the output volume.z--maxstep %sz5The target minimum step desired in the output volume.z--minstep %szFCalculate the maximum step from the average steps of the input volume.z	--avgstepNr7   r8   )r9   r:   r;   r   r   r<   r   r>   r   r_   rA   ZmaxstepZminstepZavgsteprH   rH   rH   rI   ra    s<   
ra  c               @   s   e Zd ZedddZdS )VolisoOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   rb    s   rb  c               @   s   e Zd ZdZeZeZdZdS )VolisoaV  Changes the steps and starts in order that the output volume
    has isotropic sampling.

    Examples
    --------

    >>> from nipype.interfaces.minc import Voliso
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> viso = Voliso(input_file=minc2Dfile, minstep=0.1, avgstep=True)
    >>> viso.run() # doctest: +SKIP
    ZvolisoN)	r9   r:   r;   rL   ra  rM   rb  rN   rO   rH   rH   rH   rI   rc    s   rc  c            	   @   sn   e Zd ZedddddgdddZejd	d
dZejdddddZejdddZ	ej
dddZeddddZdS )GennlxfmInputSpeczoutput fileTz%sr   rM  Fz%s_gennlxfm.xfm)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   z)Generate an identity xfm. Default: False.z-identz#Output ident xfm step [default: 1].z-step %sz Generate a nlxfm like this file.z-like %s)r   r   r   Nr8   )r9   r:   r;   r   r<   r   r>   r   r_   identrE   r>  rM  rH   rH   rH   rI   rd    s&   

rd  c               @   s$   e Zd ZedddZedddZdS )GennlxfmOutputSpeczoutput fileT)r   r   zoutput gridN)r9   r:   r;   r   r<   output_gridrH   rH   rH   rI   rf  :  s   rf  c                   s,   e Zd ZdZeZeZdZ fddZ	  Z
S )Gennlxfma  Generate nonlinear xfms. Currently only identity xfms
    are supported!

    This tool is part of minc-widgets:

    https://github.com/BIC-MNI/minc-widgets/blob/master/gennlxfm/gennlxfm

    Examples
    --------

    >>> from nipype.interfaces.minc import Gennlxfm
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> gennlxfm = Gennlxfm(step=1, like=minc2Dfile)
    >>> gennlxfm.run() # doctest: +SKIP

    Zgennlxfmc                s(   t t| j }tjdd|d |d< |S )Nz.(nlxfm|xfm)$z_grid_0.mncr<   rg  )r   rh  r   resub)r   r   )r   rH   rI   r   U  s    zGennlxfm._list_outputs)r9   r:   r;   rL   rd  rM   rf  rN   rO   r   r   rH   rH   )r   rI   rh  ?  s
   rh  c            	   @   sj   e Zd ZeeddddddddZeedd	Zed
ddddgdddZej	dddZ
ej	dddddZdS )XfmConcatInputSpecT)r   zinput file(s)r   z%sr   )r   r   r*   r   r   zinput grid file(s))r   zoutput filer   r   Fz%s_xfmconcat.xfm)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   Nr7   r8   )r9   r:   r;   r
   r   r   rL  r<   r   r>   r   r_   rH   rH   rH   rI   rk  ]  s.   
rk  c               @   s*   e Zd ZedddZeeddddZdS )XfmConcatOutputSpeczoutput fileT)r   r   )r   zoutput grids)r   N)r9   r:   r;   r   r<   r   output_gridsrH   rH   rH   rI   rl    s   rl  c                   s,   e Zd ZdZeZeZdZ fddZ	  Z
S )	XfmConcata  Concatenate transforms together. The output transformation
    is equivalent to applying input1.xfm, then input2.xfm, ..., in
    that order.

    Examples
    --------

    >>> from nipype.interfaces.minc import XfmConcat
    >>> from nipype.interfaces.minc.testdata import minc2Dfile
    >>> conc = XfmConcat(input_files=['input1.xfm', 'input1.xfm'])
    >>> conc.run() # doctest: +SKIP
    Z	xfmconcatc                sT   t t| j }tjj|d rPdt|d dj krPtjt	j
dd|d |d< |S )Nr<   gridrz.(nlxfm|xfm)$z_grid_*.mncrm  )r   rn  r   r   r   r   openreadglobri  rj  )r   r   )r   rH   rI   r     s    zXfmConcat._list_outputs)r9   r:   r;   rL   rk  rM   rl  rN   rO   r   r   rH   rH   )r   rI   rn    s
   rn  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
gddddZeddddd
gddddZej	dddZ
ej	dddddZdS )BestLinRegInputSpeczsource Minc fileTz%srX   )r   r   r   r   r   ztarget Minc filerW   zoutput xfm filer   sourceFz%s_bestlinreg.xfm)r   rT   r   r   r   r   r   r   zoutput mnc filer   z%s_bestlinreg.mncz'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   Nr   r7   r8   )r9   r:   r;   r   ru  target
output_xfm
output_mncr   r>   r   r_   rH   rH   rH   rI   rt    s<   
rt  c               @   s$   e Zd ZedddZedddZdS )BestLinRegOutputSpeczoutput xfm fileT)r   r   zoutput mnc fileN)r9   r:   r;   r   rx  ry  rH   rH   rH   rI   rz    s   rz  c               @   s   e Zd ZdZeZeZdZdS )
BestLinRega  Hierachial linear fitting between two files.

    The bestlinreg script is part of the EZminc package:

    https://github.com/BIC-MNI/EZminc/blob/master/scripts/bestlinreg.pl

    Examples
    --------

    >>> from nipype.interfaces.minc import BestLinReg
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> input_file = nonempty_minc_data(0)
    >>> target_file = nonempty_minc_data(1)
    >>> linreg = BestLinReg(source=input_file, target=target_file)
    >>> linreg.run() # doctest: +SKIP
    Z
bestlinregN)	r9   r:   r;   rL   rt  rM   rz  rN   rO   rH   rH   rH   rI   r{    s   r{  c               @   s   e Zd ZeddddddZeddddddZeddddd
Zee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ZejdddddZdS )NlpFitInputSpeczsource Minc fileTz%srW   )r   r   r   r   r   ztarget Minc filer   zoutput xfm filer   )r   rT   r   r   zinput grid file(s))r   z.File containing the fitting configuration use.z-config_file %s)r   r   r   r   z*Initial transformation (default identity).z-init_xfm %sz"Source mask to use during fitting.z-source_mask %sz'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   Nr   r7   r8   )r9   r:   r;   r   ru  rw  rx  r
   rL  config_fileZinit_xfmZsource_maskr   r>   r   r_   rH   rH   rH   rI   r|    s8   
r|  c               @   s$   e Zd ZedddZedddZdS )NlpFitOutputSpeczoutput xfm fileT)r   r   zoutput grid fileN)r9   r:   r;   r   rx  rg  rH   rH   rH   rI   r~  !  s   r~  c               @   s,   e Zd ZdZeZeZdZdd Z	dd Z
dS )NlpFita  Hierarchial non-linear fitting with bluring.

    This tool is part of the minc-widgets package:

    https://github.com/BIC-MNI/minc-widgets/blob/master/nlpfit/nlpfit

    Examples
    --------

    >>> from nipype.interfaces.minc import NlpFit
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data, nlp_config
    >>> from nipype.testing import example_data

    >>> source = nonempty_minc_data(0)
    >>> target = nonempty_minc_data(1)
    >>> source_mask = nonempty_minc_data(2)
    >>> config = nlp_config
    >>> initial = example_data('minc_initial.xfm')
    >>> nlpfit = NlpFit(config_file=config, init_xfm=initial, source_mask=source_mask, source=source, target=target)
    >>> nlpfit.run() # doctest: +SKIP
    Znlpfitc             C   sH   |dkr@| j j}t|r$tjj|S t| j j| j jgdd S nt	d S )Nrx  Znlpfit_xfm_outputz.xfm)
r   rx  r   r   r   r   r   ru  rw  NotImplemented)r   r   rx  rH   rH   rI   _gen_filenameA  s    zNlpFit._gen_filenamec             C   sf   | j  j }tjj| jd|d< tjj|d s6tdt|d dj	 krbt
jdd|d |d< |S )Nrx  ro  rp  z.(nlxfm|xfm)$z_grid_0.mncrg  )rN   r   r   r   r   r  r   r  rq  rr  ri  rj  )r   r   rH   rH   rI   r   Q  s    zNlpFit._list_outputsN)r9   r:   r;   rL   r|  rM   r~  rN   rO   r  r   rH   rH   rH   rI   r  &  s   r  c               @   s   e Zd ZeeddddddddZeedd	Zed
ddddZej	dddZ
ej	dddddZej	dddZej	dddZej	dddZej	dddZdS )XfmAvgInputSpecT)r   zinput file(s)r   z%sr   )r   r   r*   r   r   zinput grid file(s))r   zoutput filer   )r   rT   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   z"average the linear part [default].z-avg_linearz&average the non-linear part [default].z-avg_nonlinearzopposite of -avg_linear.z-ignore_linearzopposite of -avg_nonlinear.z-ignore_nonlineNr7   r8   )r9   r:   r;   r
   r   r   rL  r<   r   r>   r   r_   Z
avg_linearZavg_nonlinearZignore_linearZignore_nonlinearrH   rH   rH   rI   r  ^  s0   



r  c               @   s$   e Zd ZedddZedddZdS )XfmAvgOutputSpeczoutput fileT)r   r   zoutput grid fileN)r9   r:   r;   r   r<   rg  rH   rH   rH   rI   r    s   r  c               @   s4   e Zd ZdZeZeZdZdd Z	dd Z
dd Zd	S )
XfmAvga  Average a number of xfm transforms using matrix logs and exponents.
    The program xfmavg calls Octave for numerical work.

    This tool is part of the minc-widgets package:

    https://github.com/BIC-MNI/minc-widgets/tree/master/xfmavg

    Examples
    --------

    >>> from nipype.interfaces.minc import XfmAvg
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data, nlp_config
    >>> from nipype.testing import example_data

    >>> xfm1 = example_data('minc_initial.xfm')
    >>> xfm2 = example_data('minc_initial.xfm')  # cheating for doctest
    >>> xfmavg = XfmAvg(input_files=[xfm1, xfm2])
    >>> xfmavg.run() # doctest: +SKIP
    Zxfmavgc             C   s@   |dkr8| j j}t|r$tjj|S t| j jdd S ntd S )Nr<   Zxfmavg_outputz.xfm)	r   r<   r   r   r   r   r   r   r  )r   r   r<   rH   rH   rI   r    s    zXfmAvg._gen_filenamec             C   s
   | j dS )Nr<   )r  )r   rH   rH   rI   _gen_outfilename  s    zXfmAvg._gen_outfilenamec             C   sd   | j  j }tjj| j |d< tjj|d s4tdt|d dj	 kr`t
jdd|d |d< |S )Nr<   ro  rp  z.(nlxfm|xfm)$z_grid_0.mncrg  )rN   r   r   r   r   r  r   r  rq  rr  ri  rj  )r   r   rH   rH   rI   r     s    zXfmAvg._list_outputsN)r9   r:   r;   rL   r  rM   r  rN   rO   r  r  r   rH   rH   rH   rI   r    s   r  c               @   sN   e Zd ZeddddddZedddddZejd	d
dZejdddddZ	dS )XfmInvertInputSpecz
input fileTz%sr   )r   r   r   r   r   zoutput filer   )r   rT   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   Nr7   r8   )
r9   r:   r;   r   r   r<   r   r>   r   r_   rH   rH   rH   rI   r    s   
r  c               @   s$   e Zd ZedddZedddZdS )XfmInvertOutputSpeczoutput fileT)r   r   zoutput grid fileN)r9   r:   r;   r   r<   rg  rH   rH   rH   rI   r    s   r  c               @   s4   e Zd ZdZeZeZdZdd Z	dd Z
dd Zd	S )
	XfmInverta!  Invert an xfm transform file.

    Examples
    --------

    >>> from nipype.interfaces.minc import XfmAvg
    >>> from nipype.testing import example_data

    >>> xfm = example_data('minc_initial.xfm')
    >>> invert = XfmInvert(input_file=xfm)
    >>> invert.run() # doctest: +SKIP
    Z	xfminvertc             C   sB   |dkr:| j j}t|r$tjj|S t| j jgdd S ntd S )Nr<   Zxfminvert_outputz.xfm)	r   r<   r   r   r   r   r   r   r  )r   r   r<   rH   rH   rI   r    s    zXfmInvert._gen_filenamec             C   s
   | j dS )Nr<   )r  )r   rH   rH   rI   r    s    zXfmInvert._gen_outfilenamec             C   sd   | j  j }tjj| j |d< tjj|d s4tdt|d dj	 kr`t
jdd|d |d< |S )Nr<   ro  rp  z.(nlxfm|xfm)$z_grid_0.mncrg  )rN   r   r   r   r   r  r   r  rq  rr  ri  rj  )r   r   rH   rH   rI   r     s    zXfmInvert._list_outputsN)r9   r:   r;   rL   r  rM   r  rN   rO   r  r  r   rH   rH   rH   rI   r    s   r  c            	   @   s   e Zd ZeeddddddddZedddd d
gdddZejdddZ	ejdddddZ
ejdddZejdddZedddZeddd
gdddZdS )!BigAverageInputSpecT)r   zinput file(s)r   z%sr   )r   r   r*   r   r   zoutput filer   r   Fz%s_bigaverage.mnc)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z	--verbose)r   r   zOverwrite existing file.z	--clobber)r   r   rU   rV   z"Output files with float precision.z--floatzPerform robust averaging, features that are outside 1 standarddeviation from the mean are downweighted. Works well for noisydata with artifacts. see the --tmpdir option if you have alarge number of input files.z-robustztemporary files directoryz
-tmpdir %sz1Place standard deviation image in specified file.z--sdfile %sz%s_bigaverage_stdev.mnc)r   r   r   r   r   Nr7   r8   )r9   r:   r;   r
   r   r   r<   r   r>   r   r_   Zoutput_floatZrobustr	   Ztmpdirsd_filerH   rH   rH   rI   r    sD   

r  c               @   s$   e Zd ZedddZedddZdS )BigAverageOutputSpeczoutput fileT)r   r   zstandard deviation imageN)r9   r:   r;   r   r<   r  rH   rH   rH   rI   r  D  s   r  c               @   s   e Zd ZdZeZeZdZdS )
BigAveragea=  Average 1000's of MINC files in linear time.

    mincbigaverage is designed to discretise the problem of averaging either
    a large number of input files or averaging a smaller number of large
    files. (>1GB each). There is also some code included to perform "robust"
    averaging in which only the most common features are kept via down-weighting
    outliers beyond a standard deviation.

    One advantage of mincbigaverage is that it avoids issues around the number
    of possible open files in HDF/netCDF. In short if you have more than 100
    files open at once while averaging things will slow down significantly.

    mincbigaverage does this via a iterative approach to averaging files and
    is a direct drop in replacement for mincaverage. That said not all the
    arguments of mincaverage are supported in mincbigaverage but they should
    be.

    This tool is part of the minc-widgets package:

    https://github.com/BIC-MNI/minc-widgets/blob/master/mincbigaverage/mincbigaverage

    Examples
    --------

    >>> from nipype.interfaces.minc import BigAverage
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> files = [nonempty_minc_data(i) for i in range(3)]
    >>> average = BigAverage(input_files=files, output_float=True, robust=True)
    >>> average.run() # doctest: +SKIP
    ZmincbigaverageN)	r9   r:   r;   rL   r  rM   r  rN   rO   rH   rH   rH   rI   r  I  s   r  c            	   @   sd   e Zd ZeddddddZedddddgd	d
dZejdddZejdddddZ	ejdddZ
dS )ReshapeInputSpecz
input fileTz%sr   )r   r   r   r   r   zoutput filer   r   Fz%s_reshape.mnc)r   rT   r   r   r   r   r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   zConvert to short integer data.z-shortNr7   r8   )r9   r:   r;   r   r   r<   r   r>   r   r_   r   rH   rH   rH   rI   r  o  s$   
r  c               @   s   e Zd ZedddZdS )ReshapeOutputSpeczoutput fileT)r   r   N)r9   r:   r;   r   r<   rH   rH   rH   rI   r    s   r  c               @   s   e Zd ZdZeZeZdZdS )Reshapea  Cut a hyperslab out of a minc file, with dimension reordering.

    This is also useful for rewriting with a different format, for
    example converting to short (see example below).

    Examples
    --------

    >>> from nipype.interfaces.minc import Reshape
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> input_file = nonempty_minc_data(0)
    >>> reshape_to_short = Reshape(input_file=input_file, write_short=True)
    >>> reshape_to_short.run() # doctest: +SKIP

    ZmincreshapeN)	r9   r:   r;   rL   r  rM   r  rN   rO   rH   rH   rH   rI   r    s   r  c            
   @   s   e Zd Zeddddd(dZedddd)dgd	d
d	dZedddd*dgd	ddZeeddZe	j
dddZe	j
dddddZe	j
dddZe	j
dddZ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d'S )+VolSymmInputSpecz
input fileTz%srW   )r   r   r   r   r   zoutput xfm trans filer   r   Fz%s_vol_symm.xfm)r   rT   r   r   r   r   r   r   zoutput filer   z%s_vol_symm.mnc)r   rT   r   r   r   r   r   zinput grid file(s))r   z'Print out log messages. Default: False.z-verbose)r   r   zOverwrite existing file.z-clobber)r   r   rU   rV   zFit using a linear xfm.z-linearzFit using a non-linear xfm.z
-nonlinearz7Use the input transformation instead of generating one.z-nofitzBFile containing the fitting configuration (nlpfit -help for info).z-config_file %s)r   r   r   z!Flip volume in x-plane (default).z-xzFlip volume in y-plane.z-yzFlip volume in z-plane.z-zNr   r7   r8   )r9   r:   r;   r   r   
trans_filer<   r
   rL  r   r>   r   r_   Z
fit_linearZfit_nonlinearZnofitr}  xyzrH   rH   rH   rI   r    sL   

r  c               @   s0   e Zd ZedddZedddZedddZdS )VolSymmOutputSpeczoutput fileT)r   r   zxfm trans filezoutput grid fileN)r9   r:   r;   r   r<   r  rg  rH   rH   rH   rI   r    s   r  c                   s,   e Zd ZdZeZeZdZ fddZ	  Z
S )VolSymma1  Make a volume symmetric about an axis either linearly
    and/or nonlinearly. This is done by registering a volume
    to a flipped image of itself.

    This tool is part of the minc-widgets package:

    https://github.com/BIC-MNI/minc-widgets/blob/master/volsymm/volsymm

    Examples
    --------

    >>> from nipype.interfaces.minc import VolSymm
    >>> from nipype.interfaces.minc.testdata import nonempty_minc_data

    >>> input_file = nonempty_minc_data(0)
    >>> volsymm = VolSymm(input_file=input_file)
    >>> volsymm.run() # doctest: +SKIP

    Zvolsymmc                sN   t t| j }tjj|d rJdt|d dj krJtj	dd|d |d< |S )Nr  ro  rp  z.(nlxfm|xfm)$z_grid_0.mncrg  )
r   r  r   r   r   r   rq  rr  ri  rj  )r   r   )r   rH   rI   r     s    zVolSymm._list_outputs)r9   r:   r;   rL   r  rM   r  rN   rO   r   r   rH   rH   )r   rI   r    s
   r  )irL   rs  r   os.pathri  warningsbaser   r   r   r   r   r   r	   r
   r   r   r   r   filterwarningsUserWarningr   rJ   rK   rP   rQ   rR   rS   rf   rg   rh   rk   rl   rm   rn   ro   rp   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&  rO  rP  rQ  rW  rX  rY  r[  r\  r]  r_  r`  ra  rb  rc  rd  rf  rh  rk  rl  rn  rt  rz  r{  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rH   rH   rH   rI   <module>	   s   4 MT9?C$ B K6  !M
X  bf   e.7L."4.8*709&=