U
    f»{j³e  ã                   @   s¦  d Z ddlmZ ddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZmZ dd
lmZmZmZmZmZmZm Z  dd„ Z!dd„ Z"d?dd„Z#d@dd„Z$dd„ Z%dd„ Z&dd„ Z'dd„ Z(dAdd„Z)edBd d!„ƒZ*edCd"d#„ƒZ+edDd$d%„ƒZ,edEd&d'„ƒZ-edFd(d)„ƒZ.d*d+„ Z/edGd,d-„ƒZ0edHd.d/„ƒZ1d0d1„ Z2dId3d4„Z3dJd5d6„Z4dKd7d8„Z5edLd9d:„ƒZ6edMd;d<„ƒZ7d=d>„ Z8dS )NzFreesurfer handling functions.é    N)ÚGzipFileé   )Ú_bem_find_surfaceÚread_bem_surfaces)ÚFIFF)Úread_fiducials)Úapply_transÚinvert_transformÚcombine_transformsÚ_ensure_transÚread_ras_mni_tÚ	Transform)Úread_surfaceÚ_read_mri_surface)ÚverboseÚ_validate_typeÚ_check_fnameÚ_check_optionÚget_subjects_dirÚ_require_versionÚloggerc              
   C   sT   t |dd�}dD ]6}t t || d|› d�¡¡stdt || ¡› �ƒ‚qt || ¡S )z;Check that the Freesurfer subject directory is as expected.T©Zraise_error)ZT1ÚbrainÚasegÚmriú.mgzzNFreesurfer recon-all subject folder is incorrect or improperly formatted, got )r   ÚopÚisfileÚjoinÚ
ValueError)ÚsubjectÚsubjects_dirZimg_name© r"   úN/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/_freesurfer.pyÚ_check_subject_dir   s    ÿr$   c                 C   st   t dddƒ ddl}t|dd�}|  d¡s8td	| › �ƒ‚tt ||d
| d ¡ddd�} | | ¡} t	 
| j¡}| |fS )z?Check that the anatomical segmentation file exists and load it.Únibabelz	load asegz2.1.0r   NTr   r   z+`aseg` file path must end with "aseg", got r   r   Úread)Ú	overwriteÚ
must_exist)r   r%   r   ÚendswithÚRuntimeErrorr   r   r   ÚloadÚnpÚarrayÚdataobj)r   r    r!   ÚnibZ	aseg_datar"   r"   r#   Ú	_get_aseg"   s    
ÿ ÿ
r0   úuse MRI filesc              
   C   sP   zdd l }W n. tk
r: } zd| |f }W 5 d }~X Y nX d}|rLt|ƒ‚|S )Nr   z"nibabel is required to %s, got:
%sÚ )r%   ÚImportError)Úwhyr/   ÚexpÚmsgr"   r"   r#   Ú_import_nibabel1   s    r7   ÚRASc                 C   s˜   ddl }t | j¡ tj¡}|j |j | j	¡¡ t
¡}|j |¡}|j ||¡}|j ||¡}| || j	¡}|j || j¡}	t |j ¡ |	¡}
||
fS )aï  Reorient an image to a given orientation.

    Parameters
    ----------
    img : instance of SpatialImage
        The MRI image.
    axcodes : tuple | str
        The axis codes specifying the orientation, e.g. "RAS".
        See :func:`nibabel.orientations.aff2axcodes`.

    Returns
    -------
    img_data : ndarray
        The reoriented image data.
    vox_ras_t : ndarray
        The new transform from the new voxels to surface RAS.

    Notes
    -----
    .. versionadded:: 0.24
    r   N)r%   r,   r-   r.   ÚastypeÚfloat32ZorientationsZaxcodes2orntZaff2axcodesÚaffineÚintZornt_transformZapply_orientationÚMGHImageZinv_ornt_affÚshapeÚdotÚheaderÚget_vox2ras_tkr)ZimgZaxcodesr/   Z	orig_dataZorntZras_orntZ
ornt_transZimg_dataZorig_mghZ	aff_transÚ	vox_ras_tr"   r"   r#   Ú_reorient_image=   s    ÿÿrC   c                 C   sJ   t d| dƒ tdddd�|  }ttdddgƒ t|gƒ¡ƒ\}}|||fS )aÑ  Get MRI orientation information from an image.

    Parameters
    ----------
    orientation : str
        Orientation that you want. Can be "axial", "sagittal", or "coronal".

    Returns
    -------
    axis : int
        The dimension of the axis to take slices over when plotting.
    x : int
        The dimension of the x axis.
    y : int
        The dimension of the y axis.

    Notes
    -----
    .. versionadded:: 0.21
    .. versionchanged:: 0.24
    Úorientation)ZcoronalZaxialZsagittalr   é   r   )r   ÚdictÚsortedÚsetÚ
difference)rD   ZaxisÚxÚyr"   r"   r#   Ú_mri_orientationa   s    "rL   c                 C   s„   |rt dƒ tƒ }t| dd�\}|d< |d< }}}|j|d |d |d | d� |r€|d k	s`t‚t|d ƒ|d	< t |j¡|d
< |S )Nzload MRI atlas dataT)Ú
return_imgÚ	vox_mri_tÚ	mri_ras_tr   r   )Z	mri_widthZ
mri_heightZ	mri_depthZmri_volume_nameÚ	mri_vox_tÚdata)	r7   rF   Ú_read_mri_infoÚupdateÚAssertionErrorr	   r,   Úasarrayr.   )r   rQ   ÚoutÚ_ÚdimsZmgzr"   r"   r#   Ú_get_mri_info_data}   s$     ÿ  þrY   c              	   C   s¢  t | dddd�} |  d¡s"tdƒ‚ddd	d
ddddg}t |¡}t| dƒ�}| |j¡}W 5 Q R X tjd||d�}|d  	t
¡}t|ƒdkr˜|dd… n|}|d }t |t¡}t || ¡d }	tj|d  dd|	d gdd|d |	d  gd|d  d|	d gddddggtjd�}
t |¡}|d }|d j}|d t |t ||¡¡ }t dd¡}t ||¡|dd…dd…f< |j|dd…df< t||
||d d�}|S )z4Adapted from nibabel to quickly extract header info.r&   Tz	MRI image©r'   r(   Únamer   zFilename must end with .mgz)Úversionú>i4)rX   r]   )é   )Útyper]   )Zdofr]   )ZgoodRASFlagz>i2)Údeltaú>f4©é   )ÚMdcra   )rc   rc   )ÚPxyz_cra   rb   Úrbr"   )r>   ÚdtypeÚbufferrX   r^   Nrc   r`   g       @r   rE   r   ©rg   rd   re   )rX   Úvox2ras_tkrÚvox2rasÚzooms)r   r)   ÚIOErrorr,   rg   r   r&   ÚitemsizeÚndarrayr9   r<   Úlenr-   Úfloatr:   ZdiagÚTr?   ÚeyerF   )ÚfnameZ
header_dtdZheader_dtypeÚfidZhdr_strr@   rX   r`   ZdsÚnsZv2rtkrÚdZpcrs_crd   Zpxyz_0ÚMr"   r"   r#   Ú_get_mgz_headerŽ   sT    ÿ
   ý
ÿ
ýý

ÿry   c                 C   sz   t | d |ƒ}|dk|t | d jt¡d k @  d¡}t || j¡ tj	¡}t 
|jd tj¡}| d t|ƒ ||< |S )NrP   g      à¿rQ   ç      à?éÿÿÿÿr   )r   r,   r-   r>   r<   ÚallÚroundrr   r9   Zint64ÚfullÚnanÚtuple)Zvol_infoÚrrZrr_voxZgoodÚidxÚvaluesr"   r"   r#   Ú_get_atlas_valuesµ   s    ÿÿr„   Fc           	         sÄ   ddl }t | ¡std|  ƒ‚| | ¡}t |j¡}t |¡}ˆ dkrRt	ƒ \‰ ‰n|r^t
dƒ‚t tˆ  ¡ ƒ|¡‰t‡fdd„tˆ  ¡ ƒD ƒ‡ fdd„d	�}|r¼‡fd
d„|D ƒ‰|ˆf}n|}|S )a°  Return a list of names and colors of segmented volumes.

    Parameters
    ----------
    mgz_fname : str
        Filename to read. Typically aseg.mgz or some variant in the freesurfer
        pipeline.
    return_colors : bool
        If True returns also the labels colors.
    atlas_ids : dict | None
        A lookup table providing a mapping from region names (str) to ID values
        (int). Can be None to use the standard Freesurfer LUT.

        .. versionadded:: 0.21.0

    Returns
    -------
    label_names : list of str
        The names of segmented volumes included in this mgz file.
    label_colors : list of str
        The RGB colors of the labels included in this mgz file.

    See Also
    --------
    read_freesurfer_lut

    Notes
    -----
    .. versionchanged:: 0.21.0
       The label names are now sorted in the same order as their corresponding
       values in the MRI file.

    .. versionadded:: 0.9.0
    r   Nzaseg file "%s" not foundz5return_colors must be False if atlas_ids are providedc                 3   s   | ]\}}ˆ | r|V  qd S ©Nr"   )Ú.0ZkiÚkey)Úkeepr"   r#   Ú	<genexpr>ñ   s      z.get_volume_labels_from_aseg.<locals>.<genexpr>c                    s   ˆ |  S r…   r"   )rJ   )Ú	atlas_idsr"   r#   Ú<lambda>ò   ó    z-get_volume_labels_from_aseg.<locals>.<lambda>)r‡   c                    s   g | ]}ˆ | ‘qS r"   r"   )r†   Úk)Úcolorsr"   r#   Ú
<listcomp>ô   s     z/get_volume_labels_from_aseg.<locals>.<listcomp>)r%   r   r   rm   r+   r,   rU   r.   ÚuniqueÚread_freesurfer_lutr   Zin1dÚlistrƒ   rG   Ú	enumerateÚkeys)	Z	mgz_fnameZreturn_colorsrŠ   r/   ZatlasrQ   Zwantr”   rV   r"   )rŠ   rŽ   rˆ   r#   Úget_volume_labels_from_asegÀ   s&    $



ÿ
r•   c           
      C   sV   t |dd�}t ||dd¡}t|ddƒ}t|ƒ\}}}}}t||ddƒ}	dt|	| ƒ S )a:  Convert pos from head coordinate system to MRI ones.

    This function converts to MRI RAS coordinates and not to surface
    RAS.

    Parameters
    ----------
    pos : array, shape (n_pos, 3)
        The  coordinates (in m) in head coordinate system.
    %(subject)s
    mri_head_t : instance of Transform
        MRI<->Head coordinate transformation.
    %(subjects_dir)s
    %(verbose)s

    Returns
    -------
    coordinates : array, shape (n_pos, 3)
        The MRI RAS coordinates (in mm) of pos.

    Notes
    -----
    This function requires nibabel.
    Tr   r   úT1.mgzÚheadÚrasç     @�@)r   r   r   r   rR   r
   r   )
Úposr    Ú
mri_head_tr!   r   Zt1_fnameZ
head_mri_trW   rO   Z
head_ras_tr"   r"   r#   Úhead_to_mriÿ   s    rœ   c           	         sì   d}t | tƒs$t | tjƒs$d}| g} t |tƒsHt |tjƒsH|gt| ƒ }t|ƒt| ƒks`tdƒ‚tˆdd�‰‡‡fdd„dD ƒ}dd„ |D ƒ‰ tˆˆƒ}|d	 d
d…df  d9  < t ‡ fdd„t	|| ƒD ƒ¡}|rÞ|d }t
|d	 |ƒS )aû  Convert the array of vertices for a hemisphere to MNI coordinates.

    Parameters
    ----------
    vertices : int, or list of int
        Vertex number(s) to convert.
    hemis : int, or list of int
        Hemisphere(s) the vertices belong to.
    %(subject)s
    subjects_dir : str, or None
        Path to SUBJECTS_DIR if it is not set in the environment.
    %(verbose)s

    Returns
    -------
    coordinates : array, shape (n_vertices, 3)
        The MNI coordinates (in mm) of the vertices.
    FTz&hemi and vertices must match in lengthr   c              	      s    g | ]}t  ˆˆ d d| ¡‘qS )Úsurfz%s.white)r   r   )r†   Úh)r    r!   r"   r#   r�   F  s   ÿz!vertex_to_mni.<locals>.<listcomp>)ZlhZrhc                 S   s   g | ]}t |ƒd  ‘qS ©r   )r   )r†   Úsr"   r"   r#   r�   J  s     ÚtransNrc   r™   c                    s$   g | ]\}}ˆ | |d d …f ‘qS r…   r"   )r†   rž   Úv)r�   r"   r#   r�   O  s     r   )Ú
isinstancer’   r,   ro   rp   r   r   Úread_talxfmr-   Úzipr   )	ZverticesZhemisr    r!   r   Z	singletonZsurfsÚxfmrQ   r"   )r�   r    r!   r#   Úvertex_to_mni%  s&    ÿ
r§   c                 C   s6   t |dd�}tt|ddƒt||ƒddƒ}t|| ƒd S )aî  Convert pos from head coordinate system to MNI ones.

    Parameters
    ----------
    pos : array, shape (n_pos, 3)
        The  coordinates (in m) in head coordinate system.
    %(subject)s
    mri_head_t : instance of Transform
        MRI<->Head coordinate transformation.
    %(subjects_dir)s
    %(verbose)s

    Returns
    -------
    coordinates : array, shape (n_pos, 3)
        The MNI coordinates (in mm) of pos.

    Notes
    -----
    This function requires either nibabel.
    Tr   r—   r   Úmni_talr™   )r   r
   r   r¤   r   )rš   r    r›   r!   r   Z
head_mni_tr"   r"   r#   Úhead_to_mniX  s    
  þr©   c                 C   sj   t  t  t¡ddd¡}t|ƒ\}}|tjks0t‚| dkr<|S tt	| |ƒƒ}|D ]}t
||d ƒ|d< qN|S )uÀ  Estimate fiducials for a subject.

    Parameters
    ----------
    %(subject)s
    %(subjects_dir)s
    %(verbose)s

    Returns
    -------
    fids_mri : list
        List of estimated fiducials (each point in a dict), in the order
        LPA, nasion, RPA.

    Notes
    -----
    This takes the ``fsaverage-fiducials.fif`` file included with MNEâ€”which
    contain the LPA, nasion, and RPA for the ``fsaverage`` subjectâ€”and
    transforms them to the given FreeSurfer subject's MRI space.
    The MRI of ``fsaverage`` is already in MNI Talairach space, so applying
    the inverse of the given subject's MNI Talairach affine transformation
    (``$SUBJECTS_DIR/$SUBJECT/mri/transforms/talairach.xfm``) is used
    to estimate the subject's fiducial locations.

    For more details about the coordinate systems and transformations involved,
    see https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems and
    :ref:`tut-source-alignment`.
    rQ   Z	fsaveragezfsaverage-fiducials.fifÚr)r   r   ÚdirnameÚ__file__r   r   ZFIFFV_COORD_MRIrT   r	   r¤   r   )r    r!   r   Zfname_fids_fsZfidsÚcoord_frameZ	mni_mri_tÚfr"   r"   r#   Úget_mni_fiducialsy  s    " ÿr¯   c           	      C   sT   ddl m}m} t|dd�}t| |ƒ\}}}||d |d |d dd�}t||ƒƒS )a�  Estimate the head->mri transform from fsaverage fiducials.

    A subject's fiducials can be estimated given a Freesurfer ``recon-all``
    by transforming ``fsaverage`` fiducials using the inverse Talairach
    transform, see :func:`mne.coreg.get_mni_fiducials`.

    Parameters
    ----------
    %(subject)s
    %(subjects_dir)s
    %(verbose)s

    Returns
    -------
    %(trans_not_none)s
    r   )Úmake_dig_montageÚcompute_native_head_tTr   rª   r   )ÚlpaÚnasionÚrpar­   )Zchannels.montager°   r±   r   r¯   r	   )	r    r!   r   r°   r±   r²   r³   r´   Zmontager"   r"   r#   Úestimate_head_mri_t©  s    ÿrµ   c                 C   sn   ddl }t| |jjƒs | | ¡} | | j tj	¡| j
¡} | t ||dd¡¡}tj| j
|j
dd�sjtdƒ‚| S )z6Check if the image is in Freesurfer surface RAS space.r   Nr   z	brain.mgzg�íµ ÷Æ°>)Zatolz¦The `image` is not aligned to Freesurfer surface RAS space. This space is required as it is the space where the anatomical segmentation and reconstructed surfaces are)r%   r£   ZspatialimagesZSpatialImager+   r=   r.   r9   r,   r:   r;   r   r   Zallcloser*   )Úimager    r!   r/   Zfs_imgr"   r"   r#   Ú_ensure_image_in_surface_RASÃ  s    
r·   c              	   C   sJ   t | ddƒ t| ddd� t| dƒ�}t | ¡ dd… ¡}W 5 Q R X |S )	a  Read a Freesurfer linear transform array file.

    Parameters
    ----------
    fname : str | None
        The transform filename.
    %(verbose)s

    Returns
    -------
    affine : ndarray
        The affine transformation described by the lta file.
    ©ú	path-likeNrt   r&   T©r(   rª   é   é	   )r   r   Úopenr,   ZloadtxtÚ	readlines)rt   r   ru   r;   r"   r"   r#   Úread_ltaÒ  s
     r¿   c                 C   s’   t |ƒ}t| |ƒ}|d dd…df  d  < t || dd¡}t |¡sXt || dd¡}t |¡sntd| ƒ‚t|ƒ\}}}}}t||dd	ƒ}|S )
a!  Compute MRI-to-MNI transform from FreeSurfer talairach.xfm file.

    Parameters
    ----------
    %(subject)s
    %(subjects_dir)s
    %(verbose)s

    Returns
    -------
    mri_mni_t : instance of Transform
        The affine transformation from MRI to MNI space for the subject.
    r¡   Nrc   r™   r   zorig.mgzr–   zmri not found: %sr¨   )r   r   r   r   r   rm   rR   r
   )r    r!   r   Z	ras_mni_tÚpathrW   rO   Z	mri_mni_tr"   r"   r#   r¤   è  s    


r¤   c                 C   s¦   t | ddƒ t | ¡r(t | ¡| kr(| S t | ¡s€|dkrJtd| ›d�ƒ‚t|dd�}t ||d| ¡} t | ¡s€td| ›d�ƒ‚t | ¡| kr¢d	| ›d
�}t|ƒ‚| S )z@Check whether an mri exists in the Freesurfer subject directory.r¹   r   Nz	MRI file z" not found and no subject providedTr   z
 not foundzAmbiguous filename - found zQ in current folder.
If this is correct prefix name with relative or absolute path)r   r   r   ÚbasenameÚFileNotFoundErrorr   r   rm   )r   r    r!   Úerrr"   r"   r#   Ú
_check_mri  s     

ÿ
rÄ   Úmc                 C   s,  |rBdd l }| | ¡j}| ¡ }| ¡ }| ¡ }| ¡ d d… }	n(t| ƒ}|d }|d }|d }|d }	tdd|ƒ}
tdd	|ƒ}t	t
|ƒ|
d	dƒ}|d
ks t‚|dkrþt ddddgg¡j}|
d  |9  < |d  |9  < |d d d …dd…f  |9  < |
||||	f}|�r(tƒ }|| | ¡f7 }|S )Nr   rc   rk   rj   rX   rl   Z	mri_voxelr˜   r   )rÅ   ÚmmrÅ   gü©ñÒMbP?r   r¡   r^   )r%   r+   r@   Zget_vox2rasrA   Zget_data_shapeZ	get_zoomsry   r   r
   r	   rT   r,   r-   rr   r7   )rÀ   ZunitsrM   Zuse_nibabelr%   ÚhdrZn_origZt_origrX   rl   rB   rN   rO   ÚconvrV   r"   r"   r#   rR   "  s>       ÿ rR   c                 C   sd   t | ƒ}|d |d  }}t |d |d |d |d gt¡j}tt||ƒƒ}tt||ƒƒ}||fS )a7  Read a Freesurfer-formatted LUT.

    Parameters
    ----------
    fname : str | None
        The filename. Can be None to read the standard Freesurfer LUT.

    Returns
    -------
    atlas_ids : dict
        Mapping from label names to IDs.
    colors : dict
        Mapping from label names to colors.
    r[   ÚidÚRÚGÚBÚA)Ú_get_lutr,   r-   rq   rr   rF   r¥   )rt   ÚlutÚnamesZidsrŽ   rŠ   r"   r"   r#   r‘   M  s    &r‘   c              	      s  t | ddƒ | dkr(t t t¡dd¡} t| ddd� d	d
ddddg}dd„ |D ƒ‰ t| dƒ�t}|D ]h}| ¡ }| d¡sd|s€qd| 	¡ }t
|ƒt
|ƒkr¦td| › �ƒ‚t||ƒD ]\}}ˆ |d   |¡ q°qdW 5 Q R X ‡ fdd„|D ƒ‰ t
ˆ d ƒdksþt‚ˆ S )zGet a FreeSurfer LUT.r¸   rt   NrQ   zFreeSurferColorLUT.txtr&   Trº   )rÉ   ú<i8)r[   ÚU)rÊ   rÑ   )rË   rÑ   )rÌ   rÑ   )rÍ   rÑ   c                 S   s   i | ]}|d  t ƒ “qS rŸ   )r’   ©r†   rw   r"   r"   r#   Ú
<dictcomp>m  s      z_get_lut.<locals>.<dictcomp>rª   ú#zLUT is improperly formatted: r   c                    s,   i | ]$}|d  t jˆ |d   |d d�“qS )r   r   ri   )r,   r-   rÓ   ©rÏ   r"   r#   rÔ   x  s      r[   )r   r   r   r«   r¬   r   r½   ÚstripÚ
startswithÚsplitrp   r*   r¥   ÚappendrT   )rt   rg   ru   Úlinerw   Úpartr"   rÖ   r#   rÎ   d  s4    ÿ   ÿ rÎ   c              	   C   sd  t d| dƒ | dkrH|dk	rHzt|dƒW S  tk
rF   t d¡ Y nX |dkrd| dkr\dS tdƒ‚t t|d	d
�|¡}| dkr¤t |d|› d�¡t |dd¡g}nBt |dd¡t |ddd¡t |d|› d�¡t |d|› d�¡g}|D ]Z}t 	|¡rêt dt 
|¡› d�¡ t |¡d dk�r8t|dd�d   S t|ƒ  S qêtd|› d�d |¡ ƒ‚dS )a   Get a head surface from the Freesurfer subject directory.

    Parameters
    ----------
    surf : str
        The name of the surface 'auto', 'head', 'outer_skin', 'head-dense'
        or 'seghead'.
    %(subject)s
    %(subjects_dir)s
    bem : mne.bem.ConductorModel | None
        The conductor model that stores information about the head surface.
    %(verbose)s

    Returns
    -------
    head_surf : dict | None
        A dictionary with keys 'rr', 'tris', 'ntri', 'use_tris', 'np'
        and 'coord_frame' that store information for mesh plotting and other
        useful information about the head surface.

    Notes
    -----
    .. versionadded: 0.24
    r�   )Úautor—   Ú
outer_skinú
head-denseÚseghead)rÝ   r—   rÞ   Nr—   z`Could not find the surface for head in the provided BEM model, looking in the subject directory.rÝ   zsTo plot the head surface, the BEM/sphere model must contain a head surface or "subject" must be provided (got None)Tr   )rß   rà   Úbemz-head-dense.fifz
lh.segheadzouter_skin.surfZflashz-head-sparse.fifz	-head.fifzUsing z for head surface.r{   z.fifÚwarn)Z
on_defectsr   z"No head surface found for subject z after trying:
Ú
)r   r   r*   r   Úinfor   r   r   r   ÚexistsrÁ   Úsplitextr   r   rm   )r�   r    r!   rá   r   Zsubject_dirZ
try_fnamesrt   r"   r"   r#   Ú_get_head_surface}  sJ      ÿ
 ÿÿü
ÿrç   c                 C   sr   |dk	r8zt || d ƒW S  tk
r6   t d¡ Y nX t|dd�}tt ||d| d ¡dd| › d	�d
�}t|ƒS )av  Get a skull surface from the Freesurfer subject directory.

    Parameters
    ----------
    surf : str
        The name of the surface 'outer' or 'inner'.
    %(subject)s
    %(subjects_dir)s
    bem : mne.bem.ConductorModel | None
        The conductor model that stores information about the skull surface.
    %(verbose)s

    Returns
    -------
    skull_surf : dict | None
        A dictionary with keys 'rr', 'tris', 'ntri', 'use_tris', 'np'
        and 'coord_frame' that store information for mesh plotting and other
        useful information about the head surface.

    Notes
    -----
    .. versionadded: 0.24
    NZ_skullzaCould not find the surface for skull in the provided BEM model, looking in the subject directory.Tr   rá   z_skull.surfr&   z skull surfacerZ   )	r   r*   r   rä   r   r   r   r   r   )r�   r    r!   rá   r   rt   r"   r"   r#   Ú_get_skull_surface¿  s    ÿ ýrè   c           	      C   s|   ddl m}m} t| |ƒ}t t d¡d d …d d…f t d¡d g¡}tt|ƒ|ƒ}|||ddd�}|d|d d	… ƒ}|S )
Nr   )Úfit_matched_pointsÚ_trans_from_paramsr^   rc   rz   Úparams)ÚscalerV   )TTFé   )	Zcoregré   rê   r¤   r,   Zconcatenaters   r   r	   )	r    r!   ré   rê   r¦   Zpts_talZpts_subjrë   Zrigidr"   r"   r#   Ú_estimate_talxfm_rigidç  s    
.rî   )r1   )r8   )FN)NN)NN)NN)NN)NN)N)NN)rÅ   FF)N)N)NN)NN)9Ú__doc__Úos.pathrÀ   r   Únumpyr,   Úgzipr   rá   r   r   Zio.constantsr   Zio.meas_infor   Z
transformsr   r	   r
   r   r   r   Zsurfacer   r   Úutilsr   r   r   r   r   r   r   r$   r0   r7   rC   rL   rY   ry   r„   r•   rœ   r§   r©   r¯   rµ   r·   r¿   r¤   rÄ   rR   r‘   rÎ   rç   rè   rî   r"   r"   r"   r#   Ú<module>   s`    $

$'  ÿ
?  ÿ%2  ÿ /%
+

A'