U
    f»{j  ã                   @   s:   d Z ddlZddlmZmZ dd„ Zdd„ Zej ¡  dS )aD  Create 3-layer BEM model from Flash MRI images.

Examples
--------
.. code-block:: console

    $ mne flash_bem --subject=sample
    $ mne flash_bem -s sample -n --registered -5 sample/mri/mef05.mgz -3 sample/mri/mef30.mgz
    $ mne flash_bem -s sample -n --registered -5 sample/mri/flash/mef05_*.mgz -3 sample/mri/flash/mef30_*.mgz

Notes
-----
This program assumes that FreeSurfer and MNE are installed and
sourced properly.

This function extracts the BEM surfaces (outer skull, inner skull, and
outer skin) from multiecho FLASH MRI data with spin angles of 5 and 30
degrees. The multiecho FLASH data can be input as .mgz or .nii files.
This function assumes that the Freesurfer segmentation of the subject
has been completed. In particular, the T1.mgz and brain.mgz MRI volumes
should be, as usual, in the subject's mri directory.

é    N)Úconvert_flash_mrisÚmake_flash_bemc                 C   sŠ   |d kst ‚g }|jD ]N}|d d… dkr:t|ƒdkr: qf|d d… dkrZt|ƒdkrZ qf| |¡ q|jd t|ƒ…= t|j| j|ƒ d S )Né   z--é   ú-)ÚAssertionErrorÚrargsÚlenÚappendÚsetattrÚvaluesÚdest)ÚoptionÚopt_strÚvalueÚparserÚarg© r   úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/commands/mne_flash_bem.pyÚ_vararg_callback    s    
r   c                  C   sÞ  ddl m}  | tƒ}|jdddddd� |jd	d
dddd� |jdddddtdd� |jddddtdd� |jddddddd� |jdd d!ddd"d� |jd#d$d%ddd&d� |jd'd(d)ddd*d� |jd+d,d-dd.dd/� |jd0d1d2dd3� |jd4d5d6dd7d8� | ¡ \}}|j}|j}|j}|dk�s4t	|ƒdk�r8d9}|j
}|dk�rNd9}nt	|ƒdk�r`d}|j }|j }	|j}
|j}|j}|j}|j}|jdk�rª| ¡  td:ƒ‚t||||||
d9d;�}t|||||||	|d9d<�	 dS )=zRun command.r   )Úget_optparserz-sz	--subjectÚsubjectzSubject nameN)r   ÚhelpÚdefaultz-dz--subjects-dirÚsubjects_dirzSubjects directoryz-3z	--flash30z--noflash30Úflash30ÚcallbackzmThe 30-degree flip angle data. If no argument do not use flash30. If arguments are given, them as file names.)r   Úactionr   r   z-5z--flash5Úflash5zFPath to the multiecho flash 5 images. Can be one file or one per echo.z-rz--registeredÚ
registeredÚ
store_trueFzNSet if the Flash MRI images have already been registered with the T1.mgz file.)r   r   r   r   z-nz--noconvertÚ	noconvertzV[DEPRECATED] Assume that the Flash MRI images have already been converted to mgz filesz-uz--unwarpÚunwarpzMRun grad_unwarp with -unwarp <type> option on each of the converted data setsz-oz--overwriteÚ	overwritez-Write over existing .surf files in bem folderz-vz--viewÚshowz*Show BEM model in 3D for visual inspection)r   r   r   r   z--copyÚcopyz+Use copies instead of symlinks for surfaces)r   r   r   z-pz--flash-pathÚ
flash_pathzs[DEPRECATED] The directory containing flash5.mgz files (defaults to $SUBJECTS_DIR/$SUBJECT/mri/flash/parameter_maps)r   r   r   Tz The subject argument must be set)r   r   r   r   Úconvertr"   Úverbose)	r   r   r#   r$   r&   r%   ÚregisterÚ
flash5_imgr(   )Zmne.commands.utilsr   Ú__file__Ú
add_optionr   Ú
parse_argsr   r   r   r	   r   r!   r   r"   r#   r$   r&   r%   Ú
print_helpÚRuntimeErrorr   r   )r   r   ÚoptionsÚ_r   r   r   r   r'   r)   r"   r#   r$   r&   r%   r*   r   r   r   Úrun0   s¶    
 ÿ
 ÿ þ
 þ
 þ
 þ
 þ
 þþþ
þ
     þ    ýr2   )	Ú__doc__ZmneZmne.bemr   r   r   r2   ÚutilsZrun_command_if_mainr   r   r   r   Ú<module>   s
   P