U
    f»{jü ã                   @   sr  d Z ddl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	Z	ddlm
Z
mZ ddlZddlZddlmZ ddlmZ ddlZddlZddlmZ ddlZddlZddlZddl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&m'Z'm(Z(m)Z)m*Z*m+Z+ d	dl,m-Z- d	dl.m/Z/ d	dlm0Z0m1Z1m2Z2 d	dl3m4Z5 d	dl6m7Z7 d	dl8m9Z9 d	dl:m;Z;m<Z< d	dl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK d	dlLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZU d	dlVmWZWmXZX d	dlYmZZZm[Z[ d	dl\m]Z] d	dl^m_Z_m`Z` d	dlambZbmcZc d	dldmeZe d	dlmfZf d	dlgmhZhmiZi d	dljmkZk dZleme5 n¡ ƒZog ZpeoD ]`Zqep rd eq› �¡ eqd!k�r–ep rd"eq› �¡ ep rd#eq› �¡ ep rd$eq› �¡ ep rd%eq› �¡ �qhd&emepƒ Zs[pd'Zteeuƒjvd( Zweeuƒjvd) Zxewd* jyd+d,�Zzewd- jyd+d,�Z{d.Z|d/Z}d0d1„ Z~d2d3„ Zd4d5„ Z€d6d7„ Z�d8d9„ Z‚d:d;„ Zƒd<d=œd>d?„Z„d@dA„ Z…dBdC„ Z†dDdE„ Z‡dFdG„ ZˆdHdI„ Z‰eG dJdK„ dKƒƒZŠee‹ dLœdMdN„ZŒdOdP„ Z�dQdRdSœdTdU„ZŽdVdW„ Z�dXdY„ Z�dZd[„ Z‘d\d]„ Z’d^d_„ Z“d`da„ Z”dbdc„ Z•eeuƒj–dd de df Z—e	 ˜e— ™¡ ¡ šdg¡Z›dhdi„ Zœdjdk„ Z�eCG dldm„ dmƒƒZždndo„ ZŸdpdq„ Z drZ¡dsZ¢G dtdu„ due£ƒZ¤dS )vz6Generate self-contained HTML reports from MNE objects.é    N)Ú	dataclass)ÚTupleÚOptional)ÚSequence)ÚBytesIOÚStringIO)ÚPath)Úcopyfileé   ©Ú__version__)Ú_compare_version)Úread_evokedsÚread_eventsÚread_covÚread_source_estimateÚ
read_transÚsys_infoÚEvokedÚSourceEstimateÚ
CovarianceÚInfoÚ	Transform)Ú_get_ch_type)Ú_handle_default)Úread_rawÚ	read_infoÚBaseRaw)Ú	supported©Ú_DATA_CH_TYPES_SPLIT)Ú	read_proj)Ú_reorient_imageÚ_mri_orientation)ÚloggerÚverboseÚget_subjects_dirÚwarnÚ_ensure_intÚfill_docÚ_check_optionÚ_validate_typeÚ_safe_inputÚ
_path_likeÚuse_log_levelÚ_check_fnameÚ_check_ch_locsÚ_import_h5io_funcs)	Úplot_eventsÚplot_alignmentÚplot_covÚplot_projs_topomapÚplot_compare_evokedsÚset_3d_viewÚget_3d_backendÚFigure3DÚuse_browser_backend)Ú_plot_mri_contoursÚ_get_bem_plotting_surfaces)Ú_ndarray_to_figÚtight_layout)Ú_mne_qt_browser_screenshot)Úread_forward_solutionÚForward)Úread_epochsÚ
BaseEpochs)Úread_ica)Údig_mri_distances)Úread_inverse_operatorÚInverseOperator)Úparallel_func)ÚaxialÚsagittalÚcoronalÚraw)z.bdfz.edfz.setz.vhdrÚmegÚeegZieegÚnirs)zsss.fifz
sss.fif.gzzeve.fifz
eve.fif.gzzcov.fifz
cov.fif.gzzproj.fifzprof.fif.gzz	trans.fifztrans.fif.gzzfwd.fifz
fwd.fif.gzzepo.fifz
epo.fif.gzzinv.fifz
inv.fif.gzzave.fifz
ave.fif.gzúT1.mgz)rL   ÚeventsÚepochszssp-projectorsÚevokedÚ
covarianceÚcoregistrationÚbemúforward-solutionúinverse-operatorúsource-estimateZ
js_and_cssZ	templatesz	report.jsúutf-8©Úencodingzreport.sasséd   iR  c                    s   ‡ fdd„t D ƒS )Nc                    s   g | ]}|ˆ kr|‘qS © r^   )Ú.0Úch_type©Úinstr^   úP/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/report/report.pyÚ
<listcomp>n   s      z!_get_ch_types.<locals>.<listcomp>r   ra   r^   ra   rc   Ú_get_ch_typesm   s    re   c           
   	   C   s2   ddl m} | d¡}|j| ||||||d�}	|	S )Nr
   ©Úreport_templates_envzheader.html.jinja)ÚlangÚincludeÚjsÚcssÚtitleÚtagsÚmne_logo_img©Úhtml_templatesrg   Úget_templateÚrender)
rh   ri   rj   rk   rl   rm   rn   rg   ÚtÚ
t_renderedr^   r^   rc   Ú_html_header_elementt   s    
     þru   c                 C   s(   ddl m} | d¡}|j| |d�}|S )Nr
   rf   zfooter.html.jinja©Úmne_versionÚdatero   )rw   rx   rg   rs   rt   r^   r^   rc   Ú_html_footer_element~   s    
ry   c                 C   s*   ddl m} | d¡}|j| ||d�}|S )Nr
   rf   ztoc.html.jinja©ÚtitlesÚdom_idsrm   ro   )r{   r|   rm   rg   rs   rt   r^   r^   rc   Ú_html_toc_element…   s    
r}   c                 C   s.   ddl m} | d¡}|j| ||||d�}|S )Nr
   rf   zforward.html.jinja)ÚidÚreprÚsensitivity_mapsrm   rl   ro   )r~   r   r€   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_forward_sol_elementŒ   s    
   þr�   c                 C   s.   ddl m} | d¡}|j| ||||d�}|S )Nr
   rf   zinverse.html.jinja)r~   r   Úsource_spacerm   rl   ro   )r~   r   r‚   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_inverse_operator_element–   s    
    ÿrƒ   Ú )Úklassc              
   C   sZ   ddl m} g }	|D ]}
|
d kr$d}
|	 |
¡ q~| d¡}|j| ||	|||||d�}|S )Nr
   rf   r„   zslider.html.jinja)r~   ÚimagesÚcaptionsrm   rl   Ú	start_idxÚimage_formatr…   )rp   rg   Úappendrq   rr   )r~   r†   r‡   rˆ   r‰   rl   rm   r…   rg   Z	captions_Úcaptionrs   rt   r^   r^   rc   Ú_html_slider_elementŸ   s&    
      þrŒ   c        	         C   s6   ddl m}	 |	 d¡}
|
j| ||||||||d�	}|S )Nr
   rf   zimage.html.jinja)	r~   Úimgr‹   rm   rl   r‰   Ú	div_klassÚ	img_klassÚshowro   )r~   r�   r‰   r‹   r�   rŽ   r�   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_image_element±   s    
      ýr‘   c                 C   s.   ddl m} | d¡}|j| ||||d�}|S )Nr
   rf   zcode.html.jinja)r~   ÚcodeÚlanguagerl   rm   ro   )r~   r’   r“   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_code_element½   s    
    ÿr”   c                 C   s.   ddl m} | d¡}|j| ||||d�}|S )Nr
   rf   zsection.html.jinja)r~   rŽ   Úhtmlsrl   rm   ro   )r~   rŽ   r•   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_section_elementÆ   s    
    ÿr–   c           
   	   C   s2   ddl m} | d¡}|j| ||||||d�}	|	S )Nr
   rf   zbem.html.jinja)r~   rŽ   Úhtml_slider_axialÚhtml_slider_sagittalÚhtml_slider_coronalrl   rm   ro   )
r~   rŽ   r—   r˜   r™   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_bem_elementÏ   s    
   ürš   c                 C   s.   ddl m} | d¡}|j| ||||d�}|S )Nr
   rf   zhtml.html.jinja)r~   rŽ   Úhtmlrl   rm   ro   )r~   rŽ   r›   rl   rm   rg   rs   rt   r^   r^   rc   Ú_html_elementÞ   s    
    ÿrœ   c                   @   s>   e Zd ZU eed< ee ed< eed< ee ed< eed< dS )Ú_ContentElementÚnameÚsectionÚdom_idrm   r›   N)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r   r   r^   r^   r^   rc   r�   ç   s
   
r�   )Úreturnc                 C   sÌ   t | tƒr| f} n2t | ttjfƒr,t| ƒ} ntdt| ƒ› d| › �ƒ‚dd„ | D ƒ}|rttdd dd„ |D ƒ¡› �ƒ‚d}g }| D ]$}|D ]}||krˆ| 	|¡  q€qˆq€|rÈt
d	d d
d„ |D ƒ¡› �ƒ‚| S )Nzntags must be a string (without spaces or special characters) or an array-like object of such strings, but got z
 instead: c                 S   s   g | ]}t |tƒs|‘qS r^   )Ú
isinstancer¤   ©r_   Útagr^   r^   rc   rd   þ   s    
ÿz_check_tags.<locals>.<listcomp>z^All tags must be strings without spaces or special characters, but got the following instead: z, c                 S   s   g | ]}t |ƒ‘qS r^   )r¤   r¨   r^   r^   rc   rd     s     )ú ú"Ú
z1The following tags contained invalid characters: c                 s   s   | ]}t |ƒV  qd S ©N)r   r¨   r^   r^   rc   Ú	<genexpr>  s     z_check_tags.<locals>.<genexpr>)r§   r¤   r   ÚnpÚndarrayÚtupleÚ	TypeErrorÚtypeÚjoinrŠ   Ú
ValueError)rm   Zbad_tagsZinvalid_charsr©   Zinvalid_charr^   r^   rc   Ú_check_tagsð   s0    

ÿÿ
ÿr¶   c                C   s$   t |||  ¡ d  ƒ}|  |¡ dS )ac  Limit the resolution (DPI) of a figure.

    Parameters
    ----------
    fig : matplotlib.figure.Figure
        The figure whose DPI to adjust.
    max_width : int
        The max. allowed width, in pixels.
    max_res : int
        The max. allowed resolution, in DPI.

    Returns
    -------
    Nothing, alters the figure's properties in-place.
    r   N)ÚminÚget_size_inchesÚset_dpi)ÚfigÚ	max_widthÚmax_resÚdpir^   r^   rc   Ú_constrain_fig_resolution  s    r¾   ÚpngT©r‰   Ú
own_figurec          	   	   C   s¦  ddl m} ddlm} t| tjƒrDt| ƒ} |r>t| t	t
d� d}nÈt| |ƒrPn¼| jjdkr†t| dd�}t|j| ¡ | ¡ | ¡ ƒ nft| tƒrÚd	d
lm}m} |j| d� |s¾|j| d�}n
t d¡}|rì|j| d� ntdt| ƒ› �ƒ‚t|ƒ} |�rt| t	t
d� d}tƒ }t d|   ¡ › d|  !¡ › d�¡ t" #¡ �* t"j$ddt%d� | j&|||  !¡ d� W 5 Q R X |�rz| '| ¡ | (¡ }|dk�r–| )d¡S t* +|¡ )d¡S )z&Plot figure and create a binary image.r   N)ÚFigure©r»   r¼   T)ZMNEQtBrowserZPyQtGraphBrowserr°   )Úreturn_typer
   )ÚbackendÚMNE_3D_BACKEND_TESTING©Úfigure©r
   r
   é   zzfigure must be an instance of np.ndarray, matplotlib Figure, mne_qt_browser.figure.MNEQtBrowser, or mne.viz.Figure3D, got zSaving figure with dimension z inches with z dpiÚignorez2.*Axes that are not compatible with tight_layout.*©ÚactionÚmessageÚcategory)Úformatr½   ÚsvgrZ   Úascii),Úmatplotlib.pyplotÚpyplotZmatplotlib.figurerÂ   r§   r¯   r°   r=   r¾   ÚMAX_IMG_WIDTHÚMAX_IMG_RESÚ	__class__r¡   r?   ÚprintÚshapeÚmaxr·   Úmeanr9   Úviz.backends.rendererrÅ   rÆ   Ú_check_3d_figureÚ_take_3d_screenshotÚzerosÚ_close_3d_figurer²   r³   r   r$   Údebugr¸   Úget_dpiÚwarningsÚcatch_warningsÚfilterwarningsÚUserWarningÚsavefigÚcloseÚgetvalueÚdecodeÚbase64Ú	b64encode)	rº   r‰   rÁ   ÚpltrÂ   r�   rÅ   rÆ   Úoutputr^   r^   rc   Ú_fig_to_img0  sh      ÿ


ÿ  ÿÿ
ý
ÿrï   c                 C   s    t |ƒ}|  |  ¡ | ¡ |  |  ¡ | ¡ ddl}|dkrF|d }nd| d  }|  |jj¡D ].}| 	¡ }|| }|dkr†t
dƒ‚| |¡ qb| j ¡  dS )zÁMagic scaling helper.

    Keeps font size and artist sizes constant
    0.5 : current font - 4pt
    2.0 : current font + 4pt

    This is a heuristic but it seems to work for most cases.
    r   Né   r
   g      ð?z?could not rescale matplotlib fonts, consider increasing "scale")ÚfloatÚset_size_inchesr¸   r¹   râ   Ú
matplotlibZfindobjÚtextÚTextZget_fontsizerµ   Zset_fontsizeZcanvasZdraw)rº   ÚscaleZmplZsfactorrô   ÚfsÚnew_sizer^   r^   rc   Ú_scale_mpl_figureq  s    	
rù   c        	      	      s�   ddl m}	 tƒ }
t|	ddƒr&d|
d< tt|fdt| ƒi|
—Ž\}‰}|‡ ‡‡‡‡‡‡‡fdd	„t | |¡D ƒƒ}t	ƒ }|D ]}| 
|¡ q||S )
zªRender BEM surface contours on MRI slices.

    Returns
    -------
    list of array
        A list of NumPy arrays that represent the generated Matplotlib figures.
    r   r   ú<z3.2ÚthreadsZpreferÚmax_jobsc                 3   s(   | ] }ˆ|ˆ ˆˆˆˆˆˆd d�	V  qdS )F)	ZslicesÚ	mri_fnameÚsurfacesÚorientationÚsrcr�   Úshow_orientationÚwidthZslices_as_subplotsNr^   )r_   Ús©rý   rÿ   Úp_funr�   r  r   rþ   r  r^   rc   r®      s   ú     üz2_get_bem_contour_figs_as_arrays.<locals>.<genexpr>)ró   r   Údictr   rH   r;   Úlenr¯   Úarray_splitÚlistÚextend)ÚslÚn_jobsrý   rþ   rÿ   r   r�   r  r  ZMPL_VERSIONÚkwargsÚparallelÚoutsÚoutÚor^   r  rc   Ú_get_bem_contour_figs_as_arrays�  s&     ÿÿÿ
ù	r  c              	   K   s¦   ddl m} ddlm} |r dnd}||dd�}ddlm} zXz t| |fd	d
|ii|—ŽW W ¢8S  tk
r�   t| |fd	d|ii|—Ž Y W ¢S X W 5 | |¡ X dS )z6Auxiliary function to iterate over views in trans fig.r
   )Úcreate_3d_figure)rÆ   )éP   r  )é   r  )ç      à?r  r  )Úbgcolor)rÅ   rþ   z
head-denseÚheadN)Úvizr  rÜ   rÆ   rÅ   rà   Ú_itvÚIOError)ÚfunctionÚalphar  r  rÆ   Úsizerº   rÅ   r^   r^   rc   Ú_iterate_trans_views¯  s$     ÿÿÿ(r  c              
   K   sR  ddl m}m} ddlm} | f d|i|—Ž d}g }|D ]H}|snt|f|d | Ž | |¡ |j|d�}	n
t 	d¡}	| 
|	¡ q:tjtj|d d	… d
d�tj|d	d … d
d�gdd�}zHt|d |d |d |d dd�}
dt|
ƒ› ddt |
¡ d›d�}W n: tk
�r< } zd}t|› d|› �ƒ W 5 d }~X Y nX t|dd�}||fS )Nr
   )rÆ   rÅ   )Úviews_dictsrº   )ZfrontalZlateralZmedialrI   ZrostralrK   ZbothrÇ   rÉ   rÊ   rð   )Úaxisr   ÚinfoÚtransÚsubjectÚsubjects_dirrË   )r"  r#  r$  r%  Z
on_defectszAverage distance from z digitized points to head: g     @�@z.2fz mmz7Distances could not be calculated from digitized pointsú: r¿   )r‰   )rÜ   rÆ   rÅ   Zviz._brain.viewr   r7   rÝ   rÞ   r¯   rß   rŠ   ZconcatenaterE   r  rÛ   ÚBaseExceptionr'   rï   )r  rº   r  rÆ   rÅ   r   Úviewsr†   ÚviewZimÚdistsr‹   Úer�   r^   r^   rc   r  Â  s>    

ÿýü&$r  c                    sd   ddl m‰ |dkr"ttˆ jƒƒ}‡fdd„}t||t|ƒd�\}‰}|‡ ‡‡fdd„|D ƒƒ}|S )z¦Parallelize ICA component properties plotting, and return arrays.

    Returns
    -------
    outs : list of array
        The properties plots as NumPy arrays.
    r   Nc              	      s€   | j ||dd�}t|ƒdks t‚|d }t|ttd� t ¡ �.}|j|ddd� | 	d¡ ˆ j
|dd�}W 5 Q R X ˆ  |¡ |S )	NF)rb   Úpicksr�   rð   r   rÃ   r¿   ©rÐ   Z
pad_inches©rÐ   )Zplot_propertiesr  ÚAssertionErrorr¾   rÕ   rÖ   Úior   rç   ÚseekÚimreadrè   )Úicarb   ÚpickÚfigsrº   ÚbuffÚ	fig_array)rí   r^   rc   Ú_plot_one_ica_propertyø  s$      ÿ
ý

z>_plot_ica_properties_as_arrays.<locals>._plot_one_ica_property©Úfuncr  rü   c                 3   s   | ]}ˆˆ ˆ|d �V  qdS ))r3  rb   r4  Nr^   )r_   r4  )r3  rb   r  r^   rc   r®     s   þ  ÿz1_plot_ica_properties_as_arrays.<locals>.<genexpr>)rÓ   rÔ   r	  ÚrangeZn_components_rH   r  )r3  rb   r,  r  r8  r  r  r^   )r3  rb   r  rí   rc   Ú_plot_ica_properties_as_arraysë  s    ýýr<  c              
   C   sj   t |tƒr|g}|D ]P}tD ]F}|  d|› |› �d|› |› �d|› |› �d|› |› �f¡r  dS qqdS )zBAux function to test if file name includes the specified suffixes.ú-Ú_TF)r§   r¤   ÚSUPPORTED_READ_RAW_EXTENSIONSÚendswith)ÚfnameÚsuffixesÚsuffixÚextr^   r^   rc   Ú	_endswith  s    
 ÿrE  c                 K   s’   t | ddd�} t | ¡r~tƒ \}}|| dd�}| ¡ D ]4}||krNtd| ƒ‚|| || kr6td| ƒ‚q6tƒ }| |¡ n
tf |Ž}| |_|S )aJ  Read a saved report or, if it doesn't exist yet, create a new one.

    The returned report can be used as a context manager, in which case any
    changes to the report are saved when exiting the context block.

    Parameters
    ----------
    fname : str
        The file containing the report, stored in the HDF5 format. If the file
        does not exist yet, a new report is created that will be saved to the
        specified file.
    **params : kwargs
        When creating a new report, any named parameters other than ``fname``
        are passed to the ``__init__`` function of the `Report` object. When
        reading an existing report, the parameters are checked with the
        loaded report and an exception is raised when they don't match.

    Returns
    -------
    report : instance of Report
        The report.
    ÚreadF)rA  Ú	overwriteÚ
must_existÚ	mnepython)rl   z%The loaded report has no attribute %szCAttribute '%s' of loaded report does not match the given parameter.)	r/   ÚopÚexistsr1   Úkeysrµ   ÚReportÚ__setstate__rA  )rA  ÚparamsZ	read_hdf5r>  ÚstateÚparamÚreportr^   r^   rc   Úopen_report'  s$    

ÿÿ
rS  rð   Ziconszmne_icon-cropped.pngrÒ   c                 C   s"   t  | ¡r| dkrtd|  ƒ‚dS )z#Ensure valid scale value is passed.r   zscale must be positive, not %sN)r¯   Zisscalarrµ   )rö   r^   r^   rc   Ú_check_scale[  s    rT  c                 C   s*   | dks|dk	r t d|dd� n| j}|S )zEnsure fmt is valid.Nr‰   )r¿   rÑ   Úgif)Úallowed_values)r*   r‰   )Úrepr‰   r^   r^   rc   Ú_check_image_formata  s    ÿrX  c                   @   s  e Zd ZdZedÆddœdd„ƒZdd	„ Zd
d„ Zedd„ ƒZ	dÇdd„Z
dd„ ZdÈdd„Zdd„ Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zeddddd dd!œd"d#„ƒZeddddd$dddd%œd&d'„ƒZeddddd(ddd)œd*d+„ƒZedddd,ddd-œd.d/„ƒZeddd0dd1œd2d3„ƒZedddd4dd5œd6d7„ƒZedddd8dd9œd:d;„ƒZed<dd=œd>d?„ƒZedd@dAddBœdCdD„ƒZedddEddFœdGdH„ƒZdIdJ„ ZdKdL„ ZdMdN„ Z dOdP„ Z!dQdR„ Z"dSdT„ Z#edddddddUddVœdWdX„ƒZ$ddddYœdZd[„Z%edd\œd]d^„ƒZ&d_d`„ Z'edadbddcœddde„ƒZ(edfdd=œdgdh„ƒZ)didj„ Z*dkdl„ Z+edddmdddnœdodp„ƒZ,eddqdddrœdsdt„ƒZ-edudd=œdvdw„ƒZ.eddxdyddzdd{œd|d}„ƒZ/d~d„ Z0d€dd�œd‚dƒ„Z1edÉd„d…„ƒZ2d†d‡„ Z3edÊdˆddddddddd‰œ	dŠd‹„ƒZ4dŒd�„ Z5dŽd�„ Z6edËddœd�d‘„ƒZ7d’d“„ Z8d”d•„ Z9ed–d—„ ƒZ:dxddyd˜œd™dš„Z;d›dœ„ Z<e=d(œd�dž„Z>dŸd „ Z?d¡d¢„ Z@d£d¤„ ZAd¥d¦„ ZBd§d¨„ ZCd©dª„ ZDd«d¬„ ZEd­d®„ ZFd¯d°„ ZGd±d²„ ZHd³d´„ ZIdµd¶„ ZJd·d¸„ ZKd¹dº„ ZLd»d¼„ ZMd½d¾„ ZNd¿dÀ„ ZOdÁdÂ„ ZPdydÃœdÄdÅ„ZQdS )ÌrM  a¡	  Object for rendering HTML.

    Parameters
    ----------
    info_fname : None | str
        Name of the file containing the info dictionary.
    %(subjects_dir)s
    subject : str | None
        Subject name.
    title : str
        Title of the report.
    cov_fname : None | str
        Name of the file containing the noise covariance.
    %(baseline_report)s
        Defaults to ``None``, i.e. no baseline correction.
    image_format : 'png' | 'svg' | 'gif'
        Default image format to use (default is ``'png'``).
        ``'svg'`` uses vector graphics, so fidelity is higher but can increase
        file size and browser image rendering time as well.

        .. versionadded:: 0.15

    raw_psd : bool | dict
        If True, include PSD plots for raw files. Can be False (default) to
        omit, True to plot, or a dict to pass as ``kwargs`` to
        :meth:`mne.io.Raw.plot_psd`.

        .. versionadded:: 0.17
    projs : bool
        Whether to include topographic plots of SSP projectors, if present in
        the data. Defaults to ``False``.

        .. versionadded:: 0.21
    %(verbose)s

    Attributes
    ----------
    info_fname : None | str
        Name of the file containing the info dictionary.
    %(subjects_dir)s
    subject : str | None
        Subject name.
    title : str
        Title of the report.
    cov_fname : None | str
        Name of the file containing the noise covariance.
    %(baseline_report)s
        Defaults to ``None``, i.e. no baseline correction.
    image_format : str
        Default image format to use.

        .. versionadded:: 0.15

    raw_psd : bool | dict
        If True, include PSD plots for raw files. Can be False (default) to
        omit, True to plot, or a dict to pass as ``kwargs`` to
        :meth:`mne.io.Raw.plot_psd`.

        .. versionadded:: 0.17
    projs : bool
        Whether to include topographic plots of SSP projectors, if present in
        the data. Defaults to ``False``.

        .. versionadded:: 0.21
    %(verbose)s
    html : list of str
        Contains items of html-page.
    include : list of str
        Dictionary containing elements included in head.
    fnames : list of str
        List of file names rendered.
    sections : list of str
        List of sections.
    lang : str
        language setting for the HTML file.

    Notes
    -----
    See :ref:`tut-report` for an introduction to using ``mne.Report``.

    .. versionadded:: 0.8.0
    Nr¿   F©r%   c
                C   sÂ   |d k	rt |ƒnd | _|d k	r&t |ƒnd | _|| _|d k	rBt|ƒ}|| _|| _|| _td |ƒ| _	|	| _
d| _g | _g | _d| _t|tƒs¤t|tƒs¤tdt|ƒf ƒ‚|| _|  ¡  d | _d | _d S )Nr   zen-usz$raw_psd must be bool or dict, got %s)r¤   Ú
info_fnameÚ	cov_fnameÚbaseliner&   r%  r$  rl   rX  r‰   ÚprojsÚ_dom_idÚ_contentri   rh   r§   Úboolr  r²   r³   Úraw_psdÚ_init_renderrA  Ú	data_path)ÚselfrZ  r%  r$  rl   r[  r\  r‰   ra  r]  r%   r^   r^   rc   Ú__init__À  s,    ÿzReport.__init__c                 C   s¼   dt | jƒ› d�}| jdk	r,|d| j› �7 }dd„ | jD ƒ}t |ƒdkrŒd |dd	… ¡}d |d
d… ¡}|d|› �7 }|d7 }||7 }n$t |ƒdkr°d |¡}|d|› �7 }|d7 }|S )zPrint useful info about report.z
<Report | z itemsNz | c                 S   s   g | ]
}|j ‘qS r^   ©rž   ©r_   Úelementr^   r^   rc   rd   â  s     z#Report.__repr__.<locals>.<listcomp>é   r¬   r
   éþÿÿÿz
 ...
r   z
>)r  r_  rl   r´   )rd  r  Zcontent_element_namesZfirst_entriesZlast_entriesÚentriesr^   r^   rc   Ú__repr__Ý  s    


zReport.__repr__c                 C   s
   t | jƒS )zžReturn the number of files processed by the report.

        Returns
        -------
        n_files : int
            The number of files processed.
        )r  r_  ©rd  r^   r^   rc   Ú__len__ï  s    zReport.__len__c                   C   s   dS )N)r\  r[  ri   r_  r‰   rZ  r^  ra  r]  r%  r$  rl   rc  rh   rA  r^   r^   r^   r^   rc   Ú_get_state_paramsù  s    zReport._get_state_paramsTc                 C   s   |r|  j d7  _ d| j › �S )zéGet unique ID for content to append to the DOM.

        This method is just a counter.

        increment : bool
            Whether to increment the counter. If ``False``, simply returns the
            latest DOM ID used.
        rð   zglobal-)r^  )rd  Ú	incrementr^   r^   rc   Ú_get_dom_id  s    	zReport._get_dom_idc                 C   s&   t |td fdƒ |d krtƒ n|}|S )NÚtopomap_kwargs)r+   r  )rd  rr  r^   r^   rc   Ú_validate_topomap_kwargs  s    zReport._validate_topomap_kwargsc                 C   s¸   t |ttfƒs|g}t |ttfƒs(|g}t |ttfƒsD|dk	rD|g}|dk	rzt|ƒt|ƒkrztdt|ƒ› dt|ƒ› �ƒ‚n4|dk	r®t|ƒt|ƒkr®tdt|ƒ› dt|ƒ› �ƒ‚|||fS )zValidate input.NzUNumber of "comments" and report items must be equal, or comments should be None; got z and z9Number of "captions" and report items must be equal; got )r§   r	  r±   r  rµ   )rd  Úitemsr‡   r©   Úcommentsr^   r^   rc   Ú_validate_input  s    ÿÿzReport._validate_inputc                    sL  g }g }g }g }g }| j  ¡ }t|ƒD �]\}‰ ˆ j�rˆ j|krDq&‡ fdd„||d… D ƒ}dd„ |D ƒ}	tttdd„ |D ƒƒƒƒ}
|r”|d }n| jdd�}| d	¡\}}|› d	t	|ƒd
 › �}| 
|¡ t||	|
ˆ jdd�}| 
|¡ | 
|¡ | 
ˆ j¡ | 
|
¡ q&| 
ˆ j¡ | 
ˆ j¡ | 
ˆ j¡ | 
ˆ j¡ q&||||fS )aã  Generate HTML representations based on the added content & sections.

        Returns
        -------
        htmls : list of str
            The HTML representations of the content.
        dom_ids : list of str
            The DOM IDs corresponding to the HTML representations.
        titles : list of str
            The titles corresponding to the HTML representations.
        tags : list of tuple of str
            The tags corresponding to the HTML representations.
        c                    s   g | ]}|j ˆ j kr|‘qS r^   )rŸ   ©r_   Úel©Úcontent_elementr^   rc   rd   L  s   ÿz+Report._content_as_html.<locals>.<listcomp>Nc                 S   s   g | ]
}|j ‘qS r^   )r›   rw  r^   r^   rc   rd   P  s     c                 S   s   g | ]}|j D ]}|‘qqS r^   ©rm   )r_   rx  rs   r^   r^   rc   rd   R  s    þéÿÿÿÿF)rp  r=  rð   rŸ   )r~   r•   rm   rl   rŽ   )r_  ÚcopyÚ	enumeraterŸ   r±   ÚsortedÚsetrq  ÚsplitÚintrŠ   r–   r›   r    rž   rm   )rd  Zsection_dom_idsr•   r|   r{   rm   Zcontent_elementsÚidxZsection_elementsZsection_htmlsZsection_tagsZsection_dom_idÚlabelÚcounterZsection_htmlr^   ry  rc   Ú_content_as_html+  sR    



ÿ
ÿÿ

û

zReport._content_as_htmlc                 C   s   |   ¡ \}}}}|S )z8A list of HTML representations for all content elements.)r†  )rd  r•   r>  r^   r^   rc   r›   v  s    zReport.htmlc                 C   s0   g }| j D ]}| |j¡ q
ttt|ƒƒƒ}|S )z&All tags currently used in the report.)r_  r
  rm   r±   r  r€  )rd  rm   Úcr^   r^   rc   rm   |  s
    
zReport.tagsc                 C   s   d|› d�}|  j |7  _ dS )a7  Add custom CSS to the report.

        Parameters
        ----------
        css : str
            Style definitions to add to the report. The content of this string
            will be embedded between HTML ``<style>`` and ``</style>`` tags.

        Notes
        -----
        .. versionadded:: 0.23
        z
<style type="text/css">
ú	
</style>N©ri   )rd  rk   Ústyler^   r^   rc   Úadd_custom_css†  s    zReport.add_custom_cssc                 C   s   d|› d�}|  j |7  _ dS )a=  Add custom JavaScript to the report.

        Parameters
        ----------
        js : str
            JavaScript code to add to the report. The content of this string
            will be embedded between HTML ``<script>`` and ``</script>`` tags.

        Notes
        -----
        .. versionadded:: 0.23
        z!
<script type="text/javascript">
ú

</script>Nr‰  )rd  rj   Úscriptr^   r^   rc   Úadd_custom_js–  s    zReport.add_custom_js)ZIGNORED)rR   )Úpsdr]  rr  Údrop_log_ignorerm   Úreplacec          
      C   s<   t |ƒ}|dkr| jn|}	| j|||	||||| j|d�	 dS )at  Add `~mne.Epochs` to the report.

        Parameters
        ----------
        epochs : path-like | instance of Epochs
            The epochs to add to the report.
        title : str
            The title to add.
        psd : bool | float
            If a float, the duration of data to use for creation of PSD plots,
            in seconds. PSD will be calculated on as many epochs as required to
            cover at least this duration. Epochs will be picked across the
            entire time range in equally-spaced distance.

            .. note::
              In rare edge cases, we may not be able to create a grid of
              equally-spaced epochs that cover the entire requested time range.
              In these situations, a warning will be emitted, informing you
              about the duration that's actually being used.

            If ``True``, add PSD plots based on all ``epochs``. If ``False``,
            do not add PSD plots.
        %(projs_report)s
        %(topomap_kwargs)s
        drop_log_ignore : array-like of str
            The drop reasons to ignore when creating the drop log bar plot.
            All epochs for which a drop reason listed here appears in
            ``epochs.drop_log`` will be excluded from the drop log plot.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N)	rR   r�  Ú	add_projsrr  r�  rŸ   rm   r‰   r‘  )r¶   r]  Ú_add_epochsr‰   )
rd  rR   rl   r�  r]  rr  r�  rm   r‘  r’  r^   r^   rc   Ú
add_epochs¦  s    (÷zReport.add_epochs)rS   )r{   Ú	noise_covr]  Ún_time_pointsrm   r‘  rr  r  c                   s,  t |tƒr|g}n,t |tƒrn |}
t d|
› �¡ t|
dd�}ˆ jdk	rZ‡ fdd„|D ƒ}|dkrrdd„ |D ƒ}nt |tƒr‚|g}t|ƒt|ƒkr°t	dt|ƒ› d	t|ƒ› d
�ƒ‚|dkr¾ˆ j
}|dk	rÚt |tƒsÚt|d�}t|ƒ}|dkrðˆ jn|}t||ƒD ](\}}ˆ j||ˆ j||||||	|d�
 qþdS )uÛ  Add `~mne.Evoked` objects to the report.

        Parameters
        ----------
        evokeds : path-like | instance of Evoked | list of Evoked
            The evoked data to add to the report. Multiple `~mne.Evoked`
            objects â€“ as returned from `mne.read_evokeds` â€“ can be passed as
            a list.
        titles : str | list of str | None
            The titles corresponding to the evoked data. If ``None``, the
            content of ``evoked.comment`` from each evoked will be used as
            title.
        noise_cov : path-like | instance of Covariance | None
            A noise covariance matrix. If provided, will be used to whiten
            the ``evokeds``. If ``None``, will fall back to the ``cov_fname``
            provided upon report creation.
        %(projs_report)s
        n_time_points : int | None
            The number of equidistant time points to render. If ``None``,
            will render each `~mne.Evoked` at 21 time points, unless the data
            contains fewer time points, in which case all will be rendered.
        %(tags_report)s
        %(replace_report)s
        %(topomap_kwargs)s
        %(n_jobs)s

        Notes
        -----
        .. versionadded:: 0.24.0
        zEvoked: Reading FrY  Nc                    s   g | ]}|  ¡  ˆ j¡‘qS r^   )r}  Zapply_baseliner\  ©r_   r+  rm  r^   rc   rd   
  s   ÿz&Report.add_evokeds.<locals>.<listcomp>c                 S   s   g | ]
}|j ‘qS r^   )Úcommentr—  r^   r^   rc   rd     s     zNumber of evoked objects (z!) must match number of captions (ú)©rA  )
rS   r•  r‰   r’  r–  rm   rŸ   rr  r  r‘  )r§   r   r	  r$   rá   r   r\  r¤   r  rµ   r[  r   r   r¶   r]  ÚzipÚ_add_evokedr‰   )rd  Úevokedsr{   r•  r]  r–  rm   r‘  rr  r  Zevoked_fnamer’  rS   rl   r^   rm  rc   Úadd_evokedsÜ  sL    $



ÿ
ÿ
özReport.add_evokeds©rL   )r�  r]  Ú	butterflyÚscalingsrm   r‘  rr  c                C   sr   t |ƒ}|dkr(| jdkr tƒ n| j}
n|dkr8tƒ }
nd}
|dkrJ| jn|}| j||
|||| j||	||d�
 dS )au  Add `~mne.io.Raw` objects to the report.

        Parameters
        ----------
        raw : path-like | instance of Raw
            The data to add to the report.
        title : str
            The title corresponding to the ``raw`` object.
        psd : bool | None
            Whether to add PSD plots. Overrides the ``raw_psd`` parameter
            passed when initializing the `~mne.Report`. If ``None``, use
            ``raw_psd`` from `~mne.Report` creation.
        %(projs_report)s
        butterfly : bool | int
            Whether to add butterfly plots of the data. Can be useful to
            spot problematic channels. If ``True``, 10 equally-spaced 1-second
            segments will be plotted. If an integer, specifies the number of
            1-second segments to plot. Larger numbers may take a considerable
            amount of time if the data contains many sensors. You can disable
            butterfly plots altogether by passing ``False``.
        %(scalings)s
        %(tags_report)s
        %(replace_report)s
        %(topomap_kwargs)s

        Notes
        -----
        .. versionadded:: 0.24.0
        NTF)
rL   Úadd_psdr’  r   Úbutterfly_scalingsr‰   rm   rr  rŸ   r‘  )r¶   ra  r  r]  Ú_add_rawr‰   )rd  rL   rl   r�  r]  r   r¡  rm   r‘  rr  r¢  r’  r^   r^   rc   Úadd_raw.  s&    "özReport.add_raw)rY   )r$  r%  r–  rm   r‘  Ústc_plot_kwargsc          	      C   s,   t |ƒ}| j|||| j||||d|d�
 dS )a  Add a `~mne.SourceEstimate` (STC) to the report.

        Parameters
        ----------
        stc : path-like | instance of SourceEstimate
            The `~mne.SourceEstimate` to add to the report.
        title : str
            The title to add.
        subject : str | None
            The name of the FreeSurfer subject the STC belongs to. The name is
            not stored with the STC data and therefore needs to be specified.
            If ``None``, will use the value of ``subject`` passed on report
            creation.
        subjects_dir : path-like | None
            The FreeSurfer ``SUBJECTS_DIR``.
        n_time_points : int | None
            The number of equidistant time points to render. If ``None``,
            will render ``stc`` at 51 time points, unless the data
            contains fewer time points, in which case all will be rendered.
        %(tags_report)s
        %(replace_report)s
        %(stc_plot_kwargs_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N)
Ústcrl   rm   r‰   r$  r%  r–  r¦  rŸ   r‘  )r¶   Ú_add_stcr‰   )	rd  r§  rl   r$  r%  r–  rm   r‘  r¦  r^   r^   rc   Úadd_stch  s    !özReport.add_stc)rW   )r$  r%  rm   r‘  c             
   C   s(   t |ƒ}| j||||| jd||d� dS )a  Add a forward solution.

        Parameters
        ----------
        forward : instance of Forward | path-like
            The forward solution to add to the report.
        title : str
            The title corresponding to forward solution.
        subject : str | None
            The name of the FreeSurfer subject ``forward`` belongs to. If
            provided, the sensitivity maps of the forward solution will
            be visualized. If ``None``, will use the value of ``subject``
            passed on report creation. If supplied, also pass ``subjects_dir``.
        subjects_dir : path-like | None
            The FreeSurfer ``SUBJECTS_DIR``.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N)Úforwardr$  r%  rl   r‰   rŸ   rm   r‘  )r¶   Ú_add_forwardr‰   )rd  rª  rl   r$  r%  rm   r‘  r^   r^   rc   Úadd_forward—  s         ýzReport.add_forward)rX   )r$  r%  r#  rm   r‘  c                C   sR   t |ƒ}|dk	r|dks(|dk	r0|dkr0tdƒ‚| j|||||| jd||d�	 dS )aÄ  Add an inverse operator.

        Parameters
        ----------
        inverse_operator : instance of InverseOperator | path-like
            The inverse operator to add to the report.
        title : str
            The title corresponding to the inverse operator object.
        subject : str | None
            The name of the FreeSurfer subject ``inverse_op`` belongs to. If
            provided, the source space the inverse solution is based on will
            be visualized. If ``None``, will use the value of ``subject``
            passed on report creation. If supplied, also pass ``subjects_dir``
            and ``trans``.
        subjects_dir : path-like | None
            The FreeSurfer ``SUBJECTS_DIR``.
        trans : path-like | instance of Transform | None
            The ``head -> MRI`` transformation for ``subject``.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        Nz*Please pass subject AND trans, or neither.)	Úinverse_operatorr$  r%  r#  rl   r‰   rŸ   rm   r‘  )r¶   rµ   Ú_add_inverse_operatorr‰   )rd  r­  rl   r$  r%  r#  rm   r‘  r^   r^   rc   Úadd_inverse_operatorº  s$    ÿÿ     üzReport.add_inverse_operator)rU   )r$  r%  r  rm   r‘  c          	      C   s(   t |ƒ}| j||||||d||d�	 dS )aB  Add a coregistration visualization to the report.

        Parameters
        ----------
        trans : path-like | instance of Transform
            The ``head -> MRI`` transformation to render.
        info : path-like | instance of Info
            The `~mne.Info` corresponding to ``trans``.
        title : str
            The title to add.
        subject : str | None
            The name of the FreeSurfer subject the ``trans```` belong to. The
            name is not stored with the ``trans`` and therefore needs to be
            specified. If ``None``, will use the value of ``subject`` passed on
            report creation.
        subjects_dir : path-like | None
            The FreeSurfer ``SUBJECTS_DIR``.
        alpha : float | None
            The level of opacity to apply to the head surface. If a float, must
            be between 0 and 1 (inclusive), where 1 means fully opaque. If
            ``None``, will use the MNE-Python default value.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N)	r#  r"  r$  r%  r  rl   rŸ   rm   r‘  )r¶   Ú
_add_trans)	rd  r#  r"  rl   r$  r%  r  rm   r‘  r^   r^   rc   Ú	add_transæ  s    !÷zReport.add_trans)rT   )rm   r‘  c                C   s$   t |ƒ}| j||| j|||d� dS )aâ  Add covariance to the report.

        Parameters
        ----------
        cov : path-like | instance of Covariance
            The `~mne.Covariance` to add to the report.
        info : path-like | instance of Info
            The `~mne.Info` corresponding to ``cov``.
        title : str
            The title corresponding to the `~mne.Covariance` object.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        )Úcovr"  r‰   rŸ   rm   r‘  N)r¶   Ú_add_covr‰   )rd  r²  r"  rl   rm   r‘  r^   r^   rc   Úadd_covariance  s    úzReport.add_covariancer   )rQ   )Úevent_idÚ
first_samprm   r‘  c                C   s*   t |ƒ}| j|||||d| j||d�	 dS )aÅ  Add events to the report.

        Parameters
        ----------
        events : path-like | array, shape (n_events, 3)
            An MNE-Python events array.
        title : str
            The title corresponding to the events.
        event_id : dict
            A dictionary mapping event names (keys) to event codes (values).
        sfreq : float
            The sampling frequency used while recording.
        first_samp : int
            The first sample point in the recording. This corresponds to
            ``raw.first_samp`` on files created with Elekta/Neuromag systems.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N)	rQ   rµ  Úsfreqr¶  rl   rŸ   r‰   rm   r‘  )r¶   Ú_add_eventsr‰   )rd  rQ   rl   rµ  r·  r¶  rm   r‘  r^   r^   rc   Ú
add_events3  s    ÷zReport.add_events)Ússp)r]  rr  rm   r‘  c             
   C   s(   t |ƒ}| j|||| jd|||d� dS )aú  Render (SSP) projection vectors.

        Parameters
        ----------
        info : instance of Info | path-like
            An `~mne.Info` structure or the path of a file containing one. This
            is required to create the topographic plots.
        projs : iterable of mne.Projection | path-like | None
            The projection vectors to add to the report. Can be the path to a
            file that will be loaded via `mne.read_proj`. If ``None``, the
            projectors are taken from ``info['projs']``.
        title : str
            The title corresponding to the `~mne.Projection` object.
        %(topomap_kwargs)s
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N©r"  r]  rl   r‰   rŸ   rm   rr  r‘  )r¶   Ú
_add_projsr‰   )rd  r"  r]  rl   rr  rm   r‘  r^   r^   rc   r’  [  s         ýzReport.add_projsc          	   
   C   s^   t |tƒr|}n| ¡ }|j|dd�}~t|d� t|ttd� | j|dd ||||dd� d S )NF©rb   r�   ©rº   rÃ   zOriginal and cleaned signalT©rº   rl   r‹   r‰   rŸ   rm   r‘  rÁ   )	r§   r   ZaverageZplot_overlayr>   r¾   rÕ   rÖ   Ú_add_figure)	rd  r3  rb   r‰   rŸ   rm   r‘  Zinst_rº   r^   r^   rc   Ú_add_ica_overlayz  s*    

  ÿøzReport._add_ica_overlayc                C   sH  t |jd d�}	t|j|	d�s<tdƒ|	 }
td|
› d�ƒ d S t||||d�}|j|j ¡  }t 	|¡}g }t
tt|ƒƒ|d t|ƒ… |d t|ƒ… ƒD ]X\}}}d|› dtd	| ƒ› d
�}|dkrÌ|d7 }n|dtd	| ƒ› d�7 }| |¡ q–d}t|ƒdk�r&| j|d ||d ||||dd� n| j|d ||d||||dd�
 d S )N©rb   r`   ©r"  r`   r{   úNo z< channel locations found, cannot create ICA properties plots)r3  rb   r,  r  zICA component z. Variance explained: r]   ú%r   Ú.ú (z% cumulative).zICA component propertiesrð   T©rº   rl   r‹   r‰   rm   rŸ   r‘  rÁ   )
r5  Úimgsrl   r‡   rˆ   r‰   rŸ   rm   r‘  rÁ   )r   r"  r0   r   r'   r<  Zpca_explained_variance_Úsumr¯   Zcumsumr›  r;  r  ÚroundrŠ   rÀ  Ú_add_slider)rd  r3  r,  rb   r  r‰   rŸ   rm   r‘  r`   Úch_type_namer5  Zrel_explained_varZcum_explained_varr‡   rƒ  Zrel_varZcum_varr‹   rl   r^   r^   rc   Ú_add_ica_properties“  sf       ÿÿ

ýÿ
øözReport._add_ica_propertiesc          	   
   C   sV   t dƒ� |j|dd�}W 5 Q R X t|ttd� | j|d|› d�d ||||dd� d S )	Nró   Fr½  rÃ   zOriginal and cleaned z epochsTrÈ  )r:   Zplot_sourcesr¾   rÕ   rÖ   rÀ  )	rd  r3  rb   Úartifact_typer‰   rŸ   rm   r‘  rº   r^   r^   rc   Ú_add_ica_artifact_sourcesÏ  s"    
  ÿ
øz Report._add_ica_artifact_sourcesc          	   
   C   sD   |j |d dd�}t|ttd� | j|d|› d�d ||||dd� d S )NF)Úscoresrl   r�   rÃ   zScores for matching z	 patternsTrÈ  )Zplot_scoresr¾   rÕ   rÖ   rÀ  )	rd  r3  rÑ  rÏ  r‰   rŸ   rm   r‘  rº   r^   r^   rc   Ú_add_ica_artifact_scoresâ  s       ÿ
øzReport._add_ica_artifact_scoresc                C   sÞ   t |jd d�}t|j|d�s<tdƒ| }td|› d�ƒ dS |j|dddd	�}	t|	tƒs^|	g}	|	D ]}
t|
d
� qbd}t	|	ƒdkr´|	d }
t
|
ttd� | j|
|d ||||dd� n&| j|	d |d gt	|	ƒ d||||d�	 d S )NrÂ  rÃ  r{   rÄ  z; channel locations found, cannot create ICA component plotsr„   TF)r,  rl   Úcolorbarr�   r¾  zICA component topographiesrð   r   rÃ   rÈ  )	r5  rÉ  rl   r‡   rˆ   r‰   rŸ   rm   r‘  )r   r"  r0   r   r'   Zplot_componentsr§   r	  r>   r  r¾   rÕ   rÖ   rÀ  rÌ  )rd  r3  r,  r‰   rŸ   rm   r‘  r`   rÍ  r5  rº   rl   r^   r^   rc   Ú_add_ica_componentsõ  sX       ÿ
  ÿø÷zReport._add_ica_componentsc                C   sÔ  t |ƒrt|ƒ}|jdkr"tdƒ‚|d kr,n”t |ƒr²t|ƒ}t|dd�}| d¡rZd|d< ztf |Ž}W qÀ tk
r®   zt	|ƒ}W n$ tk
r¨   td|› d	�ƒ‚Y nX Y qÀX n|j
sÀtd
ƒ‚t |ƒrÔt|dd�}t |ƒrèt|dd�}| j|d||
|dd� |�r| j|||	|
||d� |d k	�r<| j||d|	|
||d� |�rZ| j||d|	|
||d� |d k	�r|| j||d|	|
||d� |�rš| j||d|	|
||d� | j|||	|
||d� |�rÐ| j|||||	|
||d� d S )NZunfittedz8ICA must be fitted before it can be added to the report.F©rA  Úpreload©z.fifz.fif.gzÚyesÚallow_maxshieldzThe specified file, z-, does not seem to contain Raw data or Epochsz�You passed an object to Report.add_ica() via the "inst" parameter that was not preloaded. Please preload the data  via the load_data() methodr   )rA  Ú	conditionr   r3  ©rb   rl   rm   rŸ   r‘  rŽ   )r3  rb   r‰   rŸ   rm   r‘  ZECG)r3  rÑ  rÏ  r‰   rŸ   rm   r‘  )r3  rb   rÏ  r‰   rŸ   rm   r‘  ZEOG)r3  r,  r‰   rŸ   rm   r‘  )r3  r,  rb   r  r‰   rŸ   rm   r‘  )r-   rD   Zcurrent_fitÚRuntimeErrorr¤   r  r@  r   rµ   rB   rÖ  r   Ú_add_html_reprrÁ  rÒ  rÐ  rÔ  rÎ  )rd  r3  rb   r,  Ú
ecg_evokedÚ
eog_evokedÚ
ecg_scoresÚ
eog_scoresrl   r‰   rŸ   rm   r  r‘  rA  Z
raw_kwargsr^   r^   rc   Ú_add_ica%  sÔ    
ÿ

ÿÿú
    þ
    ý    ý
    ý    ý    þ     ýzReport._add_ica)r3  )r,  rÞ  rß  rà  rá  r  rm   r‘  c       	         C   s2   t |
ƒ}
| j||||||||| j|
||	|d� dS )a  Add (a fitted) `~mne.preprocessing.ICA` to the report.

        Parameters
        ----------
        ica : path-like | instance of mne.preprocessing.ICA
            The fitted ICA to add.
        title : str
            The title to add.
        inst : path-like | mne.io.Raw | mne.Epochs | None
            The data to use for visualization of the effects of ICA cleaning.
            To only plot the ICA component topographies, explicitly pass
            ``None``.
        %(picks_ica)s  If ``None``, plot all components. This only affects
            the behavior of the component topography and properties plots.
        ecg_evoked, eog_evoked : path-line | mne.Evoked | None
            Evoked signal based on ECG and EOG epochs, respectively. If passed,
            will be used to visualize the effects of artifact rejection.
        ecg_scores, eog_scores : array of float | list of array of float | None
            The scores produced by :meth:`mne.preprocessing.ICA.find_bads_ecg`
            and :meth:`mne.preprocessing.ICA.find_bads_eog`, respectively.
            If passed, will be used to visualize the scoring for each ICA
            component.
        %(n_jobs)s
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        )r3  rb   r,  rÞ  rß  rà  rá  rl   r‰   rm   rŸ   r  r‘  N)r¶   râ  r‰   )rd  r3  rl   rb   r,  rÞ  rß  rà  rá  r  rm   r‘  r^   r^   rc   Úadd_icaŽ  s     $        ûzReport.add_ica)rl   rm   Ú
remove_allc                   s’   g ‰t | jƒD ]<\}‰ ˆ j|kr|dk	r@t‡ fdd„|D ƒƒs@qˆ |¡ qˆsVd‰n8|slˆd ‰| jˆ= n"tˆƒ‰‡fdd„t | jƒD ƒ| _ˆS )a  Remove elements from the report.

        The element to remove is searched for by its title. Optionally, tags
        may be specified as well to narrow down the search to elements that
        have the supplied tags.

        Parameters
        ----------
        title : str
            The title of the element(s) to remove.

            .. versionadded:: 0.24.0
        tags : array-like of str | str | None
             If supplied, restrict the operation to elements with the supplied
             tags.

            .. versionadded:: 0.24.0
        remove_all : bool
            Controls the behavior if multiple elements match the search
            criteria. If ``False`` (default) only the element last added to the
            report will be removed. If ``True``, all matches will be removed.

            .. versionadded:: 0.24.0

        Returns
        -------
        removed_index : int | tuple of int | None
            The indices of the elements that were removed, or ``None`` if no
            element matched the search criteria. A tuple will always be
            returned if ``remove_all`` was set to ``True`` and at least one
            element was removed.

            .. versionchanged:: 0.24.0
               Returns tuple if ``remove_all`` is ``True``.
        Nc                 3   s   | ]}|ˆ j kV  qd S r­   r{  ©r_   rs   )rh  r^   rc   r®   ã  s     z Report.remove.<locals>.<genexpr>r|  c                    s   g | ]\}}|ˆ kr|‘qS r^   r^   )r_   rƒ  r+  )Ú
remove_idxr^   rc   rd   î  s    ÿz!Report.remove.<locals>.<listcomp>)r~  r_  rž   ÚallrŠ   r±   )rd  rl   rm   rä  rƒ  r^   )rh  ræ  rc   Úremove»  s     $
ÿ
zReport.remove)r‘  c                C   sŽ   t |tƒst‚t|||||d�}dd„ | jD ƒ}||kr~|r~t| jddd… ƒD ]"\}	}
|
j|krP|| j|	<  dS qPtdƒ‚n| j |¡ dS )ae  Append HTML content report, or replace it if it already exists.

        Parameters
        ----------
        name : str
            The entry under which the content shall be listed in the table of
            contents. If it already exists, the content will be replaced if
            ``replace`` is ``True``
        %(section_report)s
        dom_id : str
            A unique element ``id`` in the DOM.
        tags : tuple of str
            The tags associated with the added element.
        html : str
            The HTML.
        replace : bool
            Whether to replace existing content.
        )rž   rŸ   r    rm   r›   c                 S   s   g | ]
}|j ‘qS r^   rf  rg  r^   r^   rc   rd     s     z*Report._add_or_replace.<locals>.<listcomp>Nr|  zThis should never happen)	r§   r¤   r/  r�   r_  r~  rž   rÜ  rŠ   )rd  rž   rŸ   r    rm   r›   r‘  Znew_contentZexisting_namesrƒ  rz  r^   r^   rc   Ú_add_or_replaceó  s     û


zReport._add_or_replacec          	      C   sJ   t |tƒrt|ƒ ¡ }|  ¡ }t|||||d�}| j||||||d� d S )N)rm   rl   r~   r’   r“   ©r    rž   rŸ   rm   r›   r‘  )r§   r   Ú	read_textrq  r”   ré  )	rd  r’   rl   r“   rŸ   rm   r‘  r    r›   r^   r^   rc   Ú	_add_code  s$    
ûúzReport._add_codeÚpython)r’   )r“   rm   r‘  c                C   s*   t |ƒ}| ¡ }| j|||d||d� dS )aú  Add a code snippet (e.g., an analysis script) to the report.

        Parameters
        ----------
        code : str | pathlib.Path
            The code to add to the report as a string, or the path to a file
            as a `pathlib.Path` object.

            .. note:: Paths must be passed as `pathlib.Path` object, since
                      strings will be treated as literal code.
        title : str
            The title corresponding to the code.
        language : str
            The programming language of ``code``. This will be used for syntax
            highlighting. Can be ``'auto'`` to try to auto-detect the language.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        N)r’   rl   r“   rŸ   rm   r‘  )r¶   Úlowerrì  )rd  r’   rl   r“   rm   r‘  r^   r^   rc   Úadd_code4  s        þzReport.add_code)zmne-sysinfoc             	   C   sF   t |ƒ}t tƒ ¡�}tƒ  W 5 Q R X | ¡ }| j||d||d� dS )a|  Add a MNE-Python system information to the report.

        This is a convenience method that captures the output of
        `mne.sys_info` and adds it to the report.

        Parameters
        ----------
        title : str
            The title to assign.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        Úshell)r’   rl   r“   rm   r‘  N)r¶   Ú
contextlibÚredirect_stdoutr   r   ré   rï  )rd  rl   rm   r‘  Úfr"  r^   r^   rc   Úadd_sys_infoV  s       þzReport.add_sys_infoc          
      C   s<   |   ¡ }t|dd||d|||d�	}	| j|||||	|d� d S )Núcustom-imageT)	r�   rŽ   r�   rl   r‹   r�   r‰   r~   rm   rê  )rq  r‘   ré  )
rd  r�   rl   r‹   r‰   rm   rŸ   r‘  r    r›   r^   r^   rc   Ú
_add_images  s(          ýúzReport._add_imagec          
   	   C   s*   t |||d�}	| j|	||||||d� d S )N©rº   r‰   rÁ   ©r�   rl   r‹   r‰   rm   rŸ   r‘  )rï   rö  )
rd  rº   rl   r‹   r‰   rm   rŸ   r‘  rÁ   r�   r^   r^   rc   rÀ  …  s      ÿ     þzReport._add_figure)zcustom-figure)r‹   r‰   rm   rŸ   r‘  c          
      C   s  t |ƒ}|dkr| j}t|dƒr6t|tjƒs6t|ƒ}n|f}|D ]}t|ƒr@td|› �ƒ‚q@~t|t	ƒrp|f}	nP|dkrŒt
|ƒdkrŒdg}	n4|dkr¸t
|ƒdkr¸dd„ tt
|ƒƒD ƒ}	nt|ƒ}	~|sÊt‚t
|ƒdkrú| j||d |	d ||||dd	� n| j|d||	d|||d|d
�
 dS )a’  Add figures to the report.

        Parameters
        ----------
        fig : matplotlib.figure.Figure | Figure3D | array | array-like of matplotlib.figure.Figure | array-like of Figure3D | array-like of array
            One or more figures to add to the report. All figures must be an
            instance of :class:`matplotlib.figure.Figure`,
            :class:`mne.viz.Figure3D`, or :class:`numpy.ndarray`. If
            multiple figures are passed, they will be added as "slides"
            that can be navigated using buttons and a slider element.
        title : str
            The title corresponding to the figure(s).
        caption : str | array-like of str | None
            The caption(s) to add to the figure(s).
        %(image_format_report)s
        %(tags_report)s
        %(section_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        Nrn  z½It seems you passed a path to `add_figure`. However, only Matplotlib figures, PyVista scenes, and NumPy arrays are accepted. You may want to try `add_image` instead. The provided path was: rð   c                 S   s   g | ]}d |d › �‘qS )zFigure rð   r^   ©r_   Úir^   r^   rc   rd   Å  s     z%Report.add_figure.<locals>.<listcomp>r   F)rl   rº   r‹   r‰   rŸ   rm   r‘  rÁ   )
r5  rÉ  rl   r‡   rˆ   r‰   rŸ   rm   rÁ   r‘  )r¶   r‰   Úhasattrr§   r¯   r°   r±   r-   r²   r¤   r  r;  r/  rÀ  rÌ  )
rd  rº   rl   r‹   r‰   rm   rŸ   r‘  r5  r‡   r^   r^   rc   Ú
add_figure‘  sX    
ÿ
     ý       ýzReport.add_figure)rõ  )r‹   rm   rŸ   r‘  c          
   	   C   sj   t |ƒ}t|ƒ ¡  ¡ }t |¡ d¡}~t|ƒj ¡ dd… }	t	d|	dd� | j
||||	|||d� dS )aÊ  Add an image (e.g., PNG or JPEG pictures) to the report.

        Parameters
        ----------
        image : path-like
            The image to add.
        title : str
            Title corresponding to the images.
        caption : str | None
            If not ``None``, the caption to add to the image.
        %(tags_report)s
        %(section_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        rÒ   rð   NzImage format)r¿   rU  rÑ   )ÚvaluerV  rø  )r¶   r   Ú
expanduserÚ
read_bytesrë   rì   rê   rC  rî  r*   rö  )
rd  Úimagerl   r‹   rm   rŸ   r‘  Z	img_bytesZ
img_base64Z
img_formatr^   r^   rc   Ú	add_imageÙ  s"    ÿùzReport.add_image)úcustom-htmlc                C   s<   t |ƒ}|  ¡ }t||||dd�}| j||d|||d� dS )a=  Add HTML content to the report.

        Parameters
        ----------
        html : str
            The HTML content to add.
        title : str
            The title corresponding to ``html``.
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        r  )r~   r›   rl   rm   rŽ   Nrê  )r¶   rq  rœ   ré  )rd  r›   rl   rm   r‘  r    Zhtml_elementr^   r^   rc   Úadd_html  s"       þúzReport.add_htmlr
   i   )rV   )r%  Údecimr  r  rm   r‘  c          	      C   s4   t |ƒ}t|dƒ}| j|||||| j|||d�	 dS )aX  Render a visualization of the boundary element model (BEM) surfaces.

        Parameters
        ----------
        subject : str
            The FreeSurfer subject name.
        title : str
            The title corresponding to the BEM image.
        %(subjects_dir)s
        decim : int
            Use this decimation factor for generating MRI/BEM images
            (since it can be time consuming).
        width : int
            The width of the MRI images (in pixels). Larger values will have
            clearer surface lines, but will create larger HTML files.
            Typically a factor of 2 more than the number of MRI voxels along
            each dimension (typically 512, default) is reasonable.
        %(n_jobs)s
        %(tags_report)s
        %(replace_report)s

        Notes
        -----
        .. versionadded:: 0.24.0
        r  )	r$  r%  r  r  r  r‰   rŸ   rm   r‘  N)r¶   r(   Ú_add_bemr‰   )	rd  r$  rl   r%  r  r  r  rm   r‘  r^   r^   rc   Úadd_bem%  s    
     üzReport.add_bemc       	      
      sÈ   |d k	r|d k	rt dƒ‚|d k	rPt|ƒt|ƒkrPt dt|ƒ› dt|ƒ› d�ƒ‚nP|d k	rˆt|ƒt|ƒkrˆt dt|ƒ› dt|ƒ› d�ƒ‚n|r ‡ ‡fdd„|D ƒ}|  ¡ }
t|
||||ˆ ||d�}||
fS )	Nz%Must only provide either figs or imgszNumber of captions (z*) must be equal to the number of figures (r™  z)) must be equal to the number of images (c                    s   g | ]}t |ˆ ˆd �‘qS )r÷  )rï   )r_   rº   rÀ   r^   rc   rd   _  s   þÿz)Report._render_slider.<locals>.<listcomp>)r~   rl   r‡   rm   r†   r‰   rˆ   r…   )rµ   r  rq  rŒ   )rd  r5  rÉ  rl   r‡   rˆ   r‰   rm   r…   rÁ   r    r›   r^   rÀ   rc   Ú_render_sliderL  s4    ÿÿþø
zReport._render_sliderr„   )r…   rÁ   c                C   s:   | j ||||||||
|d�	\}}| j||||||	d� d S )N)	r5  rÉ  rl   r‡   rˆ   r‰   rm   r…   rÁ   ©rž   rŸ   r    rm   r›   r‘  )r  ré  )rd  r5  rÉ  rl   r‡   rˆ   r‰   rm   rŸ   r‘  r…   rÁ   r›   r    r^   r^   rc   rÌ  o  s&          ý
úzReport._add_sliderc                 C   s˜   ddddddddd	d
dg}t ƒ }|D ]b}t d|› �¡ t| }|jdd�}| d¡rj| d|› d�¡ q$| d¡r$| d|› d�¡ q$d |¡| _dS )zInitialize the renderer.zjquery-3.6.0.min.jszbootstrap.bundle.min.jszbootstrap.min.cssz&bootstrap-table/bootstrap-table.min.jsz'bootstrap-table/bootstrap-table.min.cssz0bootstrap-table/bootstrap-table-copy-rows.min.jsz-bootstrap-table/bootstrap-table-export.min.jsz"bootstrap-table/tableExport.min.jsz+bootstrap-icons/bootstrap-icons.mne.min.csszhighlightjs/highlight.min.jsz,highlightjs/atom-one-dark-reasonable.min.csszEmbedding : rZ   r[   z.jsz <script type="text/javascript">
rŒ  z.cssz<style type="text/css">
rˆ  r„   N)	r	  r$   r"  Úhtml_include_dirrë  r@  rŠ   r´   ri   )rd  r%   Z
inc_fnamesri   Z	inc_fnamerA  Zfile_contentr^   r^   rc   rb  ƒ  s4    õ

ÿ

ÿzReport._init_renderc       	            sª  | j dk	st‚|D �]�‰ t dt d| j dd…  ˆ ¡› �¡ tˆ ƒj}
�ztˆ ddddgƒrz| j	ˆ |
| j
| j|d	� �nÔtˆ d
ƒrž| jˆ |
| j| jd� �n°tˆ dƒrº| jˆ |
d� �n”tˆ dƒrötˆ ƒ}‡ fdd„|D ƒ}| jˆ ||||	d� �nXtˆ dƒ�r6| jdk	�rt| jƒd }nd}| jˆ |
|d� �ntˆ dƒ�rR| jˆ |
d� nütˆ dƒ�r~| jdk	�r~| jˆ | j|
d� nÐtˆ dƒ�r¬| jdk	�r¬| j| jˆ |
|	d� n¢tˆ dƒ�rø| jdk	�rø| jdk	�rø| jdk	�rø| jˆ | j| j| j|
d� nVˆ  d¡�s4ˆ  d¡�rN| jdk	�rN| jdk	�rN| jdk	�rN| jˆ |
| j| j||d� W q tk
�r¢ } z2|d k�r†td!ˆ › d"|› d#�ƒ n|d$k�r’‚ W 5 d}~X Y qX qdS )%zParallel process in batch mode.NzRendering : u   â€¦éìÿÿÿrL   ÚsssrM   rO   )rL   rl   r�  r]  r   Zfwd)rª  rl   r$  r%  Úinv)r­  rl   Zavec                    s"   g | ]}t ˆ ƒj› d |j› �‘qS )r&  )r   rž   r˜  r—  rš  r^   rc   rd   Æ  s   ÿz)Report._iterate_files.<locals>.<listcomp>)r�  r{   r•  r–  rr  Zever·  )rQ   rl   r·  Zepo)rR   rl   r²  )r²  r"  rl   Úproj)r"  r]  rl   rr  r#  )r#  r"  r$  r%  rl   ú-lh.stcú-rh.stc)r§  rl   r$  r%  r–  r¦  r'   zFailed to process file z:
"r«   Úraise)rc  r/  r$   r"  rJ  r´   r   rž   rE  r¥  ra  r]  r¬  r$  r%  r¯  r   rž  rZ  r   r¹  r”  r´  r’  r±  r@  r©  Ú	Exceptionr'   )rd  Úfnamesr²  r·  Úraw_butterflyÚn_time_points_evokedsÚn_time_points_stcsÚon_errorr¦  rr  rl   r�  r{   r+  r^   rš  rc   Ú_iterate_files¨  s¶    
ÿ
   þ

  þ

 ÿ


þ  ý

ÿ
 ÿÿþý  ýÿþýü  ü


zReport._iterate_filesr'   )	r  r‰   Ú
render_bemr  r  r  r¦  rr  r%   c       	      
      s,  t |ddƒ t|ƒ}t| |ƒ}tdˆdddgƒ || _| jdkrVd| jd	d… › �| _|dkrnd
d„ tD ƒ}nt|tt	fƒs‚|g}tƒ }|D ],}t
| jddddd�}| tt||ƒƒ¡ qŒ|sÒ|sÒtd| j› �ƒ‚g }|D ]Â}t|dƒ�r:t|dd�}| d¡�r
d|d< tf |Ž}t|jƒdk�rœ| |jdd… ¡ qÚ| d¡�sP| d¡rÚ|}| d¡�rn| dd¡}n| dd¡}||k�rœ||k�rœ| |¡ qÚqÚqÚtt|ƒƒ}|D ]}||k�r®|| |¡= �q®~| jdk	�ròt| jdd�}|d ‰n\tdd„ |D ƒƒ�rtdƒ tdd„ |D ƒƒ�r*td ƒ td!d„ |D ƒƒ�rFtd"ƒ d#\}‰d‰ | jdk	�rht| jƒ‰ t  d$t|ƒ› d%�¡ t!| j"|t|ƒd&�\}‰}|‡ ‡‡‡‡‡‡‡‡f	d'd„t# $||¡D ƒƒ |�r| j%dk	�r| j&dk	�rt  d(¡ | j'| j&| j%d)||d*� ntd+ƒ |�r(| j(| j)t*d,�| _)dS )-aY  Render all the files in the folder.

        Parameters
        ----------
        data_path : str
            Path to the folder containing data whose HTML report will be
            created.
        pattern : None | str | list of str
            Filename pattern(s) to include in the report.
            For example, ``[\*raw.fif, \*ave.fif]`` will include `~mne.io.Raw`
            as well as `~mne.Evoked` files. If ``None``, include all supported
            file formats.

            .. versionchanged:: 0.23
               Include supported non-FIFF files by default.
        %(n_jobs)s
        mri_decim : int
            Use this decimation factor for generating MRI/BEM images
            (since it can be time consuming).
        sort_content : bool
            If ``True``, sort the content based on tags in the order:
            raw -> events -> epochs -> evoked -> covariance -> coregistration
            -> bem -> forward-solution -> inverse-operator -> source-estimate.

            .. versionadded:: 0.24.0
        on_error : str
            What to do if a file cannot be rendered. Can be 'ignore',
            'warn' (default), or 'raise'.
        %(image_format_report)s

            .. versionadded:: 0.15
        render_bem : bool
            If True (default), try to render the BEM.

            .. versionadded:: 0.16
        n_time_points_evokeds, n_time_points_stcs : int | None
            The number of equidistant time points to render for `~mne.Evoked`
            and `~mne.SourceEstimate` data, respectively. If ``None``,
            will render each `~mne.Evoked` at 21 and each `~mne.SourceEstimate`
            at 51 time points, unless the respective data contains fewer time
            points, in which call all will be rendered.

            .. versionadded:: 0.24.0
        raw_butterfly : bool
            Whether to render butterfly plots for (decimated) `~mne.io.Raw`
            data.

            .. versionadded:: 0.24.0
        %(stc_plot_kwargs_report)s

            .. versionadded:: 0.24.0
        %(topomap_kwargs)s

            .. versionadded:: 0.24.0
        %(verbose)s
        z	path-likerc  r  rË   r'   r  NzMNE Report for r
  c                 S   s   g | ]}d |› �‘qS )Ú*r^   )r_   rD  r^   r^   rc   rd   D	  s     z'Report.parse_folder.<locals>.<listcomp>rF  TzDirectory or folder)rA  rG  rH  rž   Úneed_dirzNo matching files found in )rL   r  rM   FrÕ  r×  rØ  rÙ  rð   r  r  rY  r·  c                 s   s   | ]}t |d ƒV  qdS )r²  N©rE  ©r_   rA  r^   r^   rc   r®   z	  s     z&Report.parse_folder.<locals>.<genexpr>z=`info_fname` not provided. Cannot render -cov.fif(.gz) files.c                 s   s   | ]}t |d ƒV  qdS )r#  Nr  r  r^   r^   rc   r®   }	  s     z?`info_fname` not provided. Cannot render -trans.fif(.gz) files.c                 s   s   | ]}t |d ƒV  qdS )r  Nr  r  r^   r^   rc   r®   €	  s     z>`info_fname` not provided. Cannot render -proj.fif(.gz) files.)NNzIterating over z% potential files (this may take some )rü   c                 3   s(   | ] }ˆ|ˆ ˆˆˆˆˆˆˆd �	V  qdS ))	r  r²  r·  r  r  r  r  r¦  rr  Nr^   r  ©	r²  r  r  r  r  r  r·  r¦  rr  r^   rc   r®   Ž	  s   ú    ûzRendering BEMzBEM surfaces)r$  r%  rl   r  r  zW`subjects_dir` and `subject` not provided. Cannot render MRI and -trans.fif(.gz) files.©ÚcontentÚorder)+r+   r¤   rX  r*   rc  rl   r?  r§   r	  r±   r/   r
  r  Ú_recursive_searchrÜ  rE  r  r@  r   r  Ú	filenamesZ	endswidthr‘  r€  ÚindexrZ  r   Úanyr'   r[  r   r$   r"  rH   r  r¯   r  r%  r$  r  Ú_sortr_  ÚCONTENT_ORDER)rd  rc  Úpatternr  Z	mri_decimÚsort_contentr  r‰   r  r  r  r  r¦  rr  r%   r  ÚpZfnames_to_removerA  r  rb   Zfirst_hemi_fnameZsecond_hemi_fnamer"  r  r^   r  rc   Úparse_folderú  s¶    ?

   þ
 ÿ ÿ
ÿ


  ÿ
ù
   þ ÿzReport.parse_folderc                 C   sV   t ƒ }|  ¡ D ]B}t| |ƒ}|dkrHtdd„ |D ƒƒs:t‚dd„ |D ƒ}|||< q|S )z,Get the state of the report as a dictionary.r_  c                 s   s   | ]}t  |¡V  qd S r­   )ÚdataclassesÚis_dataclass©r_   Úvalr^   r^   rc   r®   ±	  s     z&Report.__getstate__.<locals>.<genexpr>c                 S   s   g | ]}t  |¡‘qS r^   )r+  Úasdictr-  r^   r^   rc   rd   ²	  s     z'Report.__getstate__.<locals>.<listcomp>)r  ro  Úgetattrrç  r/  ©rd  rP  Ú
param_nameZ	param_valr^   r^   rc   Ú__getstate__©	  s    

zReport.__getstate__c                 C   s<   |   ¡ D ].}|| }|dkr*dd„ |D ƒ}t| ||ƒ q|S )zSet the state of the report.r_  c                 S   s   g | ]}t f |Ž‘qS r^   )r�   r-  r^   r^   rc   rd   ¾	  s     z'Report.__setstate__.<locals>.<listcomp>)ro  Úsetattrr1  r^   r^   rc   rN  ·	  s    zReport.__setstate__c             	   C   sâ  |dkr<| j dkr.t ¡ | _ td| j › d�ƒ t | j d¡}t|||d�}t |¡}|rj| j| j	t
d�| _	|s t |¡r d|› d�}t|d	d
�}| ¡ dkr d}t |¡\}}	|	 ¡ dk}
|sÊt |¡�s˜t d|› �¡ |
rþtƒ \}}|||  ¡ |dd� nšt| j| j| j| jtttd�}|  ¡ \}}}}t|||d�}tjdd��" t d¡ t t!t" #d¡d�}W 5 Q R X ||f| j$|f•}t%|ƒj&d |¡dd� t 'dd¡ ¡ dk}|�rÌ|
�sÌ|�sÌt( )d| ¡ | j*dk�rÞ|| _*|S )a}  Save the report and optionally open it in browser.

        Parameters
        ----------
        fname : path-like | None
            Output filename. If the name ends with ``.h5`` or ``.hdf5``, the
            report is saved in HDF5 format, so it can later be loaded again
            with :func:`open_report`. For any other suffix, the report will be
            saved in HTML format. If ``None`` and :meth:`Report.parse_folder`
            was **not** called, the report is saved as ``report.html`` in the
            current working directory. If ``None`` and
            :meth:`Report.parse_folder` **was** used, the report is saved as
            ``report.html`` inside the ``data_path`` supplied to
            :meth:`Report.parse_folder`.
        open_browser : bool
            Whether to open the rendered HTML report in the default web browser
            after saving. This is ignored when writing an HDF5 file.
        %(overwrite)s
        sort_content : bool
            If ``True``, sort the content based on tags before saving in the
            order:
            raw -> events -> epochs -> evoked -> covariance -> coregistration
            -> bem -> forward-solution -> inverse-operator -> source-estimate.

            .. versionadded:: 0.24.0
        %(verbose)s

        Returns
        -------
        fname : str
            The file name to which the report was saved.
        Nz `data_path` not provided. Using z insteadzreport.html)rG  rž   r  z"Report already exists at location z. Overwrite it (y/[n])? zpass overwrite=True)ZaltÚyT)z.h5z.hdf5zSaving report to : rI  )rG  rl   )rl   ri   rh   rm   rj   rk   rn   rz   )ÚrecordrË   z	%B %d, %Yrv   r„   rZ   )Údatar\   Z_MNE_BUILDING_DOCÚtruezfile://)+rc  ÚosÚgetcwdr'   rJ  r´   r/   Úrealpathr%  r_  r&  Úisfiler,   rî  Úsplitextr$   r"  r1   r3  ru   rl   ri   rh   rm   Ú
JAVASCRIPTÚCSSÚmne_logor†  r}   rã   rä   Úsimplefilterry   ÚMNE_VERSIONÚtimeÚstrftimer›   r   Ú
write_textÚgetenvÚ
webbrowserZopen_new_tabrA  )rd  rA  Úopen_browserrG  r(  r%   ÚmsgZanswerr>  rD  Zis_hdf5Z
write_hdf5Zheader_htmlr|   r{   rm   Ztoc_htmlZfooter_htmlr›   Zbuilding_docr^   r^   rc   ÚsaveÂ	  sn    #


 ÿ
ÿ    ýý
þzReport.savec                 C   s   | S )z+Do nothing when entering the context block.r^   rm  r^   r^   rc   Ú	__enter__'
  s    zReport.__enter__c                 C   s    | j dk	r| j| j ddd� dS )z/Save the report when leaving the context block.NFT)rH  rG  )rA  rJ  )rd  r³   rý  Ú	tracebackr^   r^   rc   Ú__exit__+
  s    
zReport.__exit__c                    sn   |   ¡ }g }g ‰ ~ |D ]4}t|ƒD ]&\}} || jkr"ˆ  |¡ | | ¡ q"q‡ fdd„t|ƒD ƒ}||•}|S )z.Reorder content to reflect "natural" ordering.c                    s   g | ]\}}|ˆ kr|‘qS r^   r^   )r_   rƒ  r  ©Zcontent_sorted_idxr^   rc   rd   @
  s   ÿz Report._sort.<locals>.<listcomp>)r}  r~  rm   rŠ   )r  r   Zcontent_unsortedZcontent_sortedr©   rƒ  Zcontent_remainingr^   rN  rc   r%  0
  s    


ÿzReport._sort)r  r  r  c                   sÊ   ddl }	|	 |¡}
t|
ƒd }t|ƒd }|j| }t d|ˆ ¡}t d|› dt	|ƒ› d�¡ t
|||||ddd|d�	}‡ fd	d
„tt	|ƒƒD ƒ}ttt	|ƒd ƒƒ}| j|d|||||ddd�	\}}|S )z+Render one axis of bem contours (only PNG).r   NzRendering BEM z with z slicesFÚalways)	r  r  rý   rþ   rÿ   r   r�   r  r  c                    s   g | ]}d |ˆ  › �‘qS )zSlice index: r^   rù  ©r  r^   rc   rd   \
  s     z/Report._render_one_bem_axis.<locals>.<listcomp>r
   z
bem col-mdT)	r5  rÉ  r‡   rl   r‰   rˆ   rm   r…   rÁ   )ZnibabelÚloadr"   r#   rÙ   r¯   Zaranger$   rá   r  r  r;  r‚  rË  r  )rd  rý   rþ   r‰   rÿ   r  r  r  rm   ZnibÚnimr7  r!  Zn_slicesr  r5  r‡   rˆ   r›   r>  r^   rP  rc   Ú_render_one_bem_axisH
  s@    

      ý÷
zReport._render_one_bem_axisc                C   s"   |  ¡ }| j||||||d� d S )N)r›   rl   rm   rŸ   r‘  rŽ   )Ú_repr_html_Ú_add_html_element)rd  rb   rl   rm   rŸ   r‘  rŽ   r›   r^   r^   rc   rÝ  l
  s    úzReport._add_html_reprc                   s†  |d }t  ˆjd ˆjd |¡dd… }	t  dd„ |	D ƒ¡}
t  ‡fdd„|	D ƒ¡}||
 }ˆj ¡ }zÔz¶ˆ d ¡ tdƒ�$ ˆjd	d
|
d |d |d
d�}W 5 Q R X t	|t
td� t||d�g‰ t|
dd … |dd … ƒD ]>\}}||j_||j_| ¡  |jd
d� ˆ  t||d�¡ qÞW n tk
�r8   ‚ Y nX W 5 ˆ |¡ X ~‡ fdd„ttˆ ƒƒD ƒ}| jd ˆ d|d||||d�	 d S )Nr
   r   r|  rð   c                 S   s   g | ]}t |d  dƒ‘qS )r  r   )rÚ   rå  r^   r^   rc   rd   �
  s     z6Report._add_raw_butterfly_segments.<locals>.<listcomp>c                    s    g | ]}t |d  ˆ jd ƒ‘qS )r  r|  )r·   Útimesrå  rŸ  r^   rc   rd   ‚
  s     ró   TF)r   Zshow_scrollbarsÚstartÚdurationr¡  r�   rÃ   )rº   r‰   )Úannotationsc                    s$   g | ]}d |d › dt ˆ ƒ› �‘qS )zSegment rð   z of )r  rù  )r†   r^   rc   rd   ¤
  s   ÿzTime series)	r5  rÉ  rl   r‡   rˆ   r‰   rm   rŸ   r‘  )r¯   ÚlinspacerV  ÚarrayrY  r}  Zset_annotationsr:   Úplotr¾   rÕ   rÖ   rï   r›  ZmneZt_startrX  Z_update_hscrollZ_redrawrŠ   r  r;  r  rÌ  )rd  rL   Ú
n_segmentsr¡  r‰   rm   rŸ   r‘  ÚnrV  Zt_startsZt_stopsZ	durationsZorig_annotationsrº   rW  rX  r‡   r^   )r†   rL   rc   Ú_add_raw_butterfly_segmentsy
  s^    "


    þ  ÿ"

ÿ      ýz"Report._add_raw_butterfly_segmentsc       
      
   C   s<  t |tƒr|jd }n0t|ƒ}t|dd�}| d¡r<d|d< tf |Ž}| j|d||	|
dd	� |rˆ|d
krldn|}| j||||||
|	d� t |tƒ�r|j	d dk	rÊ|j	d d }|d|j	d  krÐt
j}nt
j}|jf |ddœ|—Ž}t|d� t|ttd� | j|dd|||	|
d
d� |�r8| j|dd||||	|
d� dS )zRender raw.r   FrÕ  r×  rØ  rÙ  r   rL   rÛ  Té
   )rL   r¡  r]  r‰   rm   r‘  rŸ   ÚlowpassNé   r  r·  ©Úfmaxr�   r¾  rÃ   ÚPSDrÈ  Ú
Projectors©r"  r]  rl   r‰   rm   rr  rŸ   r‘  )r§   r   r"  r¤   r  r@  r   rÝ  r_  r"  r¯   ÚinfÚplot_psdr>   r¾   rÕ   rÖ   rÀ  r¼  )rd  rL   r¢  r’  r   r£  r‰   rm   rr  rŸ   r‘  rA  r  Zn_butterfly_segmentsrd  rº   r^   r^   rc   r¤  ­
  sx    


ú
   ü
  ÿø    üzReport._add_rawc             
   C   sò   t |tƒrn<t|dƒr8t |tƒr,|jd }	nd}	|j}n|}	t|	dd�}|d krZ|d }nt |tƒsp|}	t|	ƒ}|s|t	dƒ‚t
|d�sŽt	d	ƒ‚|  |¡}tf ||d
dddœ|—Ž}
|
 d¡ t|
d� t|
ttd� | j|
|d ||||d
d� d S )Nr"  r   r„   FrY  r]  zNo SSP projectors found)r"  zˆThe provided data does not contain digitization information (channel locations). However, this is required for rendering the projectors.TZjoint)r]  r"  rÓ  Zvlimr�   )é   ri  r¾  rÃ   rÈ  )r§   r   rû  r   r"  r"  r   r	  r!   rµ   r0   rs  r5   rò   r>   r¾   rÕ   rÖ   rÀ  )rd  r"  r]  rl   r‰   rm   rŸ   rr  r‘  rA  rº   r^   r^   rc   r¼  ó
  s^    





ÿ
   þþ

  ÿøzReport._add_projsc                C   s€   t |tƒst|ƒ}|dkr | jn|}|dkr2| jn|}|dk	rDd}	nd}	|  ¡ }
t|
| ¡ |	||d�}| j|||
|||d� dS )zRender forward solution.Nr„   )r~   r   r€   rl   rm   r  )	r§   rA   r@   r$  r%  rq  r�   rT  ré  )rd  rª  r$  r%  rl   r‰   rŸ   rm   r‘  Zsensitivity_maps_htmlr    r›   r^   r^   rc   r«  ,  s2    
ÿûúzReport._add_forwardc       	         C   sŒ   t |tƒst|ƒ}|dk	r,t |tƒs,t|ƒ}|dkr:| jn|}|dkrL| jn|}d}
|  ¡ }t|| 	¡ |
||d�}| j
||||||	d� dS )zRender inverse operator.Nr„   )r~   r   r‚   rl   rm   r  )r§   rG   rF   r   r   r$  r%  rq  rƒ   rT  ré  )rd  r­  r$  r%  r#  rl   r‰   rŸ   rm   r‘  Zsrc_img_htmlr    r›   r^   r^   rc   r®  P  s2    
ÿûúzReport._add_inverse_operatorc                C   s°   |D ]¦}t |j|d�s4tdƒ| }	td|	› d�ƒ qtdƒ�, | ¡ j|dd�jtdd�d d|d	�}
W 5 Q R X t	|
t
td
� dtdƒ| › d�}| j|
|d ||||dd� qd S )NrÃ  r{   rÄ  z2 channel locations found, cannot create joint plotFrY  T)Zgfp)Zts_argsrl   r�   Ztopomap_argsrÃ   zTime course (r™  rÈ  )r0   r"  r   r'   r.   r}  r4  Z
plot_jointr  r¾   rÕ   rÖ   rÀ  )rd  rS   Úch_typesr‰   rŸ   rm   rr  r‘  r`   rÍ  rº   rl   r^   r^   rc   Ú_add_evoked_joint‹  s8    
ü  ÿøzReport._add_evoked_jointc             
      s  dd l m} |jdt|ƒd dddgt|ƒ idt|ƒ dfd�\}‰ t|ttd	� tt|‡ fd
d„t	ddt|ƒ d dƒD ƒƒƒ}	|D ]B}
|j
f |g|
||
 ||
 |	|
 ddœ|—Ž |	|
 d  |
¡ qˆt|d� tƒ �8}|j|ddd� | |¡ | d¡ |j|dd�}W 5 Q R X |S )Nr   rð   r
   Zwidth_ratiosé   r  g      @)Zgridspec_kwÚfigsizerÃ   c                    s    g | ]}ˆ | ˆ |d   f‘qS )rð   r^   rù  ©Úaxr^   rc   rd   ¾  s     z=Report._plot_one_evoked_topomap_timepoint.<locals>.<listcomp>F)rV  r`   ÚvminÚvmaxÚaxesr�   r¾  r¿   r-  r.  )rÓ   rÔ   Úsubplotsr  r¾   rÕ   rÖ   r  r›  r;  Zplot_topomapÚ	set_titler>   r   rç   rè   r1  r2  )rd  rS   rC  rk  rq  rr  rr  rí   rº   Zch_type_ax_mapr`   r6  r7  r^   ro  rc   Ú"_plot_one_evoked_topomap_timepoint­  sX     
 ÿû
  ÿ
ÿÿÿ   ýü
ý

z)Report._plot_one_evoked_topomap_timepointc       	            sš  |d krt tˆjƒdƒ}n*|tˆjƒkrDtd|› dtˆjƒ› d�ƒ‚|dkrZˆjd g}
ntjˆjˆj|d�}
t |
¡ 	¡ }t
dd	d
d�}t
ƒ ‰t
ƒ ‰ˆ D ]|}tˆj|d�sÊtdƒ| }td|› d�ƒ qšt ˆ ¡ j|dd�j¡ ¡ ||  ˆ|< |dk�rdˆ|< qšˆ|  ˆ|< qšˆ�r$ˆ�s(d S |  ˆ¡‰t| j|t|
ƒd�\}‰}|‡ ‡‡‡‡‡fdd„|
D ƒƒ}dd„ |
D ƒ}| j|d |d|||||	d�	 d S )Né   ú%The requested number of time points (z9) exceeds the time points in the provided Evoked object (r™  rð   r   ©rW  ÚstopÚnumg    €„.Ag  @åœ0¢Bg  4&õkC)rN   ÚgradÚmagrÃ  r{   rÄ  z8 channel locations found, cannot create topography plotsFrY  r|  r9  c              	   3   s"   | ]}ˆˆ|ˆ ˆˆˆd �V  qdS ))rS   rC  rk  rq  rr  rr  Nr^   )r_   rC  ©rk  rS   r  rr  rr  rq  r^   rc   r®     s   ý    þz4Report._add_evoked_topomap_slider.<locals>.<genexpr>c                 S   s    g | ]}d t |dƒd›d�‘qS ©zTime point: rÊ   z0.3fz s©rË  rå  r^   r^   rc   rd     s     z5Report._add_evoked_topomap_slider.<locals>.<listcomp>ZTopographies©	r5  rÉ  r‡   rl   r‰   rˆ   rŸ   rm   r‘  )r·   r  rV  rµ   r¯   rZ  ÚtminÚtmaxÚabsÚargminr  r0   r"  r   r'   r}  r4  r7  rÚ   rs  rH   rv  rÌ  )rd  rS   rk  r–  r‰   rŸ   rm   rr  r  r‘  rV  Ú
t_zero_idxr¡  r`   rÍ  r  Z
fig_arraysr‡   r^   r~  rc   Ú_add_evoked_topomap_sliderØ  sl    ÿý ÿý


 þü÷z!Report._add_evoked_topomap_sliderc             
   C   s  d}|j }|d krd}tj||d�D ]}	| |	d¡}q$dd lm}
 |
jt|ƒddd�\}}t|ƒdkrl|g}t|ƒD ]`\}}t	|| 
¡ j|dd	�id ddd|| dd
� ||  |¡ |t|ƒd k rt||  d ¡ qtt|d� t|ttd� d}| j||d ||||dd� d S )Nu   \d\.\d* Ã— r„   ©r'  Ústringr   rð   T)ZsharexFrY  )r�  ÚciZtruncate_xaxisZtruncate_yaxisZlegendrs  r�   r¾  rÃ   zGlobal field powerr¿  )r˜  ÚreÚfindallr‘  rÓ   rÔ   rt  r  r~  r6   r}  r4  ru  Z
set_xlabelr>   r¾   rÕ   rÖ   rÀ  )rd  rS   rk  r‰   rŸ   rm   r‘  r'  r„  Úmatchrí   rº   rp  rƒ  r`   rl   r^   r^   rc   Ú_add_evoked_gfp!  sT     ÿ   ú
  ÿøzReport._add_evoked_gfpc          	   
   C   sH   |j |dd�}t|d� t|ttd� d}| j||d||||dd� dS )	zRender whitened evoked.F)r•  r�   r¾  rÃ   ZWhitenedNTrÈ  )Z
plot_whiter>   r¾   rÕ   rÖ   rÀ  )	rd  rS   r•  r‰   rŸ   rm   r‘  rº   rl   r^   r^   rc   Ú_add_evoked_whitenedO  s*    þ
  ÿøzReport._add_evoked_whitenedc       
         C   sœ   t |ƒ}| j|||||||
d� | j||||||||	|
d�	 | j||||||
d� |d k	rp| j||||||
d� |rŽ| j|d d|||||
d� t d¡ d S )N)rS   rk  r‰   rŸ   rm   rr  r‘  )	rS   rk  r–  r‰   rŸ   rm   rr  r  r‘  )rS   rk  r‰   rŸ   rm   r‘  )rS   r•  r‰   rŸ   rm   r‘  rf  r»  zEvoked: done)re   rl  r‡  rŽ  r�  r¼  r$   rá   )rd  rS   r•  r’  r–  r‰   rŸ   rm   rr  r  r‘  rk  r^   r^   rc   rœ  h  sd        ý    û    þú
øzReport._add_evokedc       	      
   C   sT   t |tjƒst|d�}t||||dd�}
t|
ttd� | j|
|d||||	dd� dS )zRender events.)ÚfilenameF)rQ   rµ  r·  r¶  r�   rÃ   NTrÈ  )	r§   r¯   r°   r   r2   r¾   rÕ   rÖ   rÀ  )rd  rQ   rµ  r·  r¶  rl   rŸ   r‰   rm   r‘  rº   r^   r^   rc   r¸  —  s0    
û  ÿøzReport._add_eventsc             
   C   sv  |j |j }|dkr|}nºt|ƒ| }	tt || ¡ƒ}
|
t|ƒkr^td|d›d|	d›d�ƒ‚t tjdt|ƒd |
d	�¡ 	t¡}t 
|¡}t|ƒt|ƒkrÌtt|ƒ| dƒ}td
t|ƒ› d|d›d�ƒ ~|| }|jd d krêtj}n(|jd d }|d|jd  k�rtj}|j|dd�}t|ttd� t|t|ƒ dƒ}dt|ƒ› d|d›d�}| j||d||||dd� d S )NTz0You requested to calculate PSD on a duration of ú.3fz# sec, but all your epochs are only z.1fz	 sec longr   rð   ry  zUsing z epochs, only covering z sec of datara  rb  r  r·  Frc  rÃ   zPSD calculated from z	 epochs (z sec).re  ©rº   r‰   rl   r‹   rm   rŸ   r‘  rÁ   )rƒ  r‚  r  r‚  r¯   Úceilrµ   rË  rZ  ZastypeÚuniquer'   r"  rh  ri  r¾   rÕ   rÖ   rÀ  )rd  rR   r�  r‰   rm   rŸ   r‘  Zepoch_durationZepochs_for_psdZsignal_durationZn_epochs_requiredZ
epochs_idxZepochs_idx_uniquerX  rd  rº   r‹   r^   r^   rc   Ú_add_epochs_psd´  sj    ÿÿ
ýÿú

 ÿ  ÿÿøzReport._add_epochs_psdc                C   s4   |   ¡ }t|||||d�}| j||||||d� d S )N)rŽ   r~   rm   rl   r›   r  )rq  rœ   ré  )rd  r›   rl   rm   rŸ   r‘  rŽ   r    r^   r^   rc   rU  õ  s     ûúzReport._add_html_elementc                C   s  |j  ¡ }|jjsd|j_|jjs&t‚|jj}| ¡ }|jdddddd„ dd	�}~| d
¡}d}	t	|ƒD ]Š\}
}d|kr”| 
dd|› d�¡||
< qhnd|kr¬|› d�||
< qhtj|	|d�}|rht|ƒdksÎt‚|d }| 
dd| ¡ › d�¡||
< qhd
 |¡}| jd|d|||d� d S )NzEpoch #r   FTZunsetc                 S   s   t | dƒd›S )NrÊ   r‘  r€  )Úxr^   r^   rc   Ú<lambda>  ó    z-Report._add_epochs_metadata.<locals>.<lambda>z?table table-hover table-striped table-sm table-responsive small)Úborderr#  Zshow_dimensionsÚjustifyZfloat_formatÚclassesr¬   z<th>(.*)</th>z<tablez8<table id="mytable" data-toggle="table" data-unique-id="aD  " data-search="true" data-search-highlight="true" data-show-columns="true" data-show-toggle="true" data-show-columns-toggle-all="true" data-click-to-select="true" data-show-copy-rows="true" data-show-export="true" data-export-types="[csv]" data-export-options='{"fileName": "metadata"}' data-icon-size="sm" data-height="400"z<trz2
<th data-field="state" data-checkbox="true"></th>rˆ  rð   z<th>z<th data-field="z" data-sortable="true">rR   ZMetadata)rŽ   rm   rl   r›   rŸ   r‘  )Úmetadatar}  r#  rž   Z	is_uniquer/  Zreset_indexZto_htmlr�  r~  r‘  r‹  rŒ  r  rî  r´   rU  )rd  rR   rŸ   rm   r‘  rœ  Z
index_namer›   r•   Zheader_patternrƒ  Zcol_headersZ
col_headerr^   r^   rc   Ú_add_epochs_metadata	  sZ    
ú	

þÿþ

úzReport._add_epochs_metadatac       	         C   sÌ  t |tƒr|j}
n|}
t|
dd�}| j|d|||	dd� |jdk	rT| j||||	d� t|ƒ}| ¡  |D ]¨}t	dƒ�  | 
¡ j|dd�jdd	�}W 5 Q R X t|ƒd
ksªt‚|d }t|ttd� |dkrÎd}nd|ksÚt‚d}|› dtdƒ| › d�}| j||d||||	dd� qh|j�rŒd}|j|d�dk�rH| jdd||||	d� nD|j| j|dd�}t|d� t|ttd� | j|||d|||	dd� |�r¨| j||||||	d� |�rÈ| j|dd|||||	d� dS ) zRender epochs.F)rÖ  r   rR   rÛ  N)rR   rm   rŸ   r‘  rY  )r�   rð   r   rÃ   )r}  r|  z	ERF imagerN   z	ERP imagerÇ  r{   r™  TrÈ  zDrop log)rË   zANo epochs exceeded the rejection thresholds. Nothing was dropped.)r›   rŽ   rl   rm   rŸ   r‘  )r$  rË   r�   r¾  r’  )rR   r�  r‰   rm   rŸ   r‘  ZProjectionsrg  )r§   rC   r�  rB   rÝ  rœ  r�  re   Z	load_datar.   r}  r4  Z
plot_imager  r/  r¾   rÕ   rÖ   r   rÀ  Z_bad_droppedZdrop_log_statsrU  Zplot_drop_logr$  r>   r•  r¼  )rd  rR   r�  r’  rr  r�  r‰   rŸ   rm   r‘  rA  rk  r`   r5  rº   Ztitle_startrl   r^   r^   rc   r“  U  sÈ    
ú

   ÿ
ÿ  ÿøù
  ÿ
  ÿø    þøzReport._add_epochsc                C   s„   t |tƒst|ƒ}t |tƒs$t|ƒ}t||ddd�\}}||g}	d}
t|	|
ƒD ]0\}}t|tt	d� | j
||d||||dd� qNdS )zRender covariance matrix & SVD.FT)r²  r"  r�   Zshow_svd)zCovariance matrixzSingular valuesrÃ   NrÈ  )r§   r   r   r   r   r4   r›  r¾   rÕ   rÖ   rÀ  )rd  r²  r"  r‰   rŸ   rm   r‘  Zfig_covZfig_svdr5  r{   rº   rl   r^   r^   rc   r³  Å  s2    

ÿ
  ÿøzReport._add_covc       	      
   C   st   t |tƒst|ƒ}t |tƒs$t|ƒ}t||||dddgddd�}
tf t|dœ|
—Ž\}}| j||||d||	d� d	S )
zRender trans (only PNG).TZhelmetZsensorsÚmri)r"  r#  r$  r%  ÚdigrM   Z	show_axesZcoord_frame)r  r  r¿   )r�   rl   rŸ   r‹   r‰   rm   r‘  N)	r§   r   r   r   r   r  r  r3   rö  )rd  r#  r"  r$  r%  r  rl   rŸ   rm   r‘  r  r�   r‹   r^   r^   rc   r°  â  s4    

  ý ÿÿ
ùzReport._add_transc       
         C   sÔ  t |tƒr6|dkr0| j}|s4|j}|s4tdƒ‚qF|}n|}t||d�}|dkrT| jn|}|dkrrtt|jƒdƒ}n*|t|jƒkrœtd|› dt|jƒ› d�ƒ‚|dkr²|jd	 g}nt	j
|jd	 |jd
 |d�}t	 |¡ ¡ }d	dlm} td|	ƒ}	|	j||d� tƒ dk	�r.|jf |	Ž}|jj d	d	¡ d}nd}g }|D �]H}t ¡ ��2 tjddtd� |�rÐ| |¡ |jdd�\}}| |jddd�¡ | d¡ t|d� t ||	d d	 t!d� | "|¡ | #|¡ n¨| $¡ }| $¡ }|jdd|d|||d�}|jdd|||d|d �}t|d� t|d� t ||	d d	 t!d� t ||	d d	 t!d� | "|¡ | "|¡ | #|¡ | #|¡ W 5 Q R X �q:|�r–| #¡  n| #¡  | #¡  d!d"„ |D ƒ}| j%|d|||||||
d#�	 dS )$zRender STC.NzŽPlease specify the subject name, as it  cannot be found in stc.subject. You may wish to pass the "subject" parameter to read_source_estimate())rA  r$  é3   rx  z6) exceeds the time points in the provided STC object (r™  rð   r   r|  ry  Zreport_stc_plot_kwargs)r$  r%  TFrË   z%More than 20 figures have been openedrÌ   )ç      @r¡  )rn  Úrgb)Ztime_viewerÚmodeÚoffr¾  r  rÃ   ZlatZlhró   )r(  ÚhemiÚinitial_timerÅ   r$  r%  rÈ   Zrh)r(  r¥  r¦  r$  r%  rÅ   rÈ   c                 S   s    g | ]}d t |dƒd›d�‘qS r  r€  rå  r^   r^   rc   rd   w  s     z#Report._add_stc.<locals>.<listcomp>r�  )&r§   r   r$  rµ   r   r%  r·   r  rV  r¯   rZ  r„  r…  rÓ   rÔ   r   Úupdater8   r\  Z	_rendererZplotterZsubplotrã   rä   rå   ÚRuntimeWarningZset_timert  ZimshowZ
screenshotr!  r>   r¾   rÖ   rŠ   rè   rÈ   rÌ  )rd  r§  rl   r$  r%  r–  r‰   rŸ   rm   r¦  r‘  rA  rV  r†  rí   ÚbrainZbackend_is_3dr5  rs   rº   rp  Zfig_lhZfig_rhZbrain_lhZbrain_rhr‡   r^   r^   rc   r¨  ý  sâ    
ÿÿÿý ÿ
ý



ý
 ú ú


ý
ý



÷zReport._add_stc)r  c       	         C   s  |dkr| j }t|dd�}t ||dd¡}
t |
¡sDtd|
› d�ƒ t ||d¡}t|ƒ}|sftd	ƒ tƒ }tD ]"}| j	|
|||||||d
�||< qpd|kr¤|d nd}d|kr¸|d nd}d|krÌ|d nd}|  
¡ }t|d|||||d�}| j|d||||	d� dS )zRender mri+bem (only PNG).NT)Zraise_errorrž  rP   z
MRI file "z" does not existrV   z*No BEM surfaces found, rendering empty MRI)rý   rþ   rÿ   r  r  r  r‰   rm   rI   r„   rJ   rK   )r~   rŽ   r—   r˜   r™   rm   rl   r  )r%  r&   rJ  r´   r<  r'   r<   r  Ú
_BEM_VIEWSrS  rq  rš   ré  )rd  r$  r%  r  r  r  r‰   rŸ   rm   r‘  rý   Zbem_pathrþ   r•   rÿ   r—   r˜   r™   r    r›   r^   r^   rc   r  „  sV    
    ü	ù	úzReport._add_bem)	NNNNNNr¿   FF)T)N)N)NNr
   T)NTFF)Rr¡   r¢   r£   Ú__doc__r%   re  rl  rn  Ústaticmethodro  rq  rs  rv  r†  Úpropertyr›   rm   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  r  r  rÌ  rb  r  r*  r3  rN  rJ  rK  rM  r%  rS  rÝ  r   r_  r¤  r¼  r«  r®  rl  rv  r‡  rŽ  r�  rœ  r¸  r•  rU  r�  r“  r³  r°  r¨  r  r^   r^   r^   rc   rM  k  s¬  S             þý

	

K

	    þ5     ýQ     þ9   ý.  þ"  ý+   þ- ÿ  þ' ÿ<0i     ý,8ÿ+ þ!   þG  þ) ÿ!    þ&% þ$R  ÿ    û /  ÿÿd
 þ$ÿ4F9$;"+I./ALp 	ÿrM  c                 C   s&   t | tƒr| f} tdd„ | D ƒƒ}|S )Nc                 s   s   | ]}t  d d|¡V  qdS )z[\s*]r=  N)r‹  Úsubr¨   r^   r^   rc   r®   Á  s     z_clean_tags.<locals>.<genexpr>)r§   r¤   r±   )rm   Ztags_cleanedr^   r^   rc   Ú_clean_tags¼  s    
r¯  c              
   C   sT   t ƒ }t | ¡D ]>\}}}t ||¡D ]&}| t¡r&| t 	t 
||¡¡¡ q&q|S )z9Auxiliary function for recursive_search of the directory.)r	  r9  ÚwalkÚfnmatchÚfilterr@  ÚVALID_EXTENSIONSrŠ   rJ  r;  r´   )Úpathr'  Zfiltered_filesÚdirpathÚdirnamesÚfilesró  r^   r^   rc   r!  Å  s    
r!  zð
.. only:: builder_html

    .. container:: row

        .. rubric:: The `HTML document <{0}>`__ written by :meth:`mne.Report.save`:

        .. raw:: html

            <iframe class="sg_report" sandbox="allow-scripts" src="{0}"></iframe>

aŠ  <svg class="sg_report" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="#dec" d="M149.9 349.1l-.2-.2-32.8-28.9 32.8-28.9c3.6-3.2 4-8.8.8-12.4l-.2-.2-17.4-18.6c-3.4-3.6-9-3.7-12.4-.4l-57.7 54.1c-3.7 3.5-3.7 9.4 0 12.8l57.7 54.1c1.6 1.5 3.8 2.4 6 2.4 2.4 0 4.8-1 6.4-2.8l17.4-18.6c3.3-3.5 3.1-9.1-.4-12.4zm220-251.2L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM256 51.9l76.1 76.1H256zM336 464H48V48h160v104c0 13.3 10.7 24 24 24h104zM209.6 214c-4.7-1.4-9.5 1.3-10.9 6L144 408.1c-1.4 4.7 1.3 9.6 6 10.9l24.4 7.1c4.7 1.4 9.6-1.4 10.9-6L240 231.9c1.4-4.7-1.3-9.6-6-10.9zm24.5 76.9l.2.2 32.8 28.9-32.8 28.9c-3.6 3.2-4 8.8-.8 12.4l.2.2 17.4 18.6c3.3 3.5 8.9 3.7 12.4.4l57.7-54.1c3.7-3.5 3.7-9.4 0-12.8l-57.7-54.1c-3.5-3.3-9.1-3.2-12.4.4l-17.4 18.6c-3.3 3.5-3.1 9.1.4 12.4z" class=""></path></svg>c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú_ReportScraperzŸScrape Report outputs.

    Only works properly if conf.py is configured properly and the file
    is written to the same directory as the example script.
    c                 C   s   d | _ tƒ | _d S r­   )Úappr  r·  rm  r^   r^   rc   re  ì  s    z_ReportScraper.__init__c                 C   s   dS )Nz<ReportScraper>r^   rm  r^   r^   rc   rl  ð  s    z_ReportScraper.__repr__c              
   C   sü   |d   ¡ D ]ê}t|tƒr|jd k	r|j d¡r|d dkr|d }t|ƒ}| dd¡}t|dƒ�}| t	¡ W 5 Q R X t
 |j¡}t
 | jjjt
 t
 |d	 ¡| jjj¡¡}	tj|	d
d� t
 |	|¡}
t
 |j¡sØt‚|
| j|j< t |¡}|  S qdS )NZexample_globalsz.htmlZbuilder_namer›   Úimage_path_iteratorz.pngz.svgÚwZtarget_fileT)Úexist_okr„   )Úvaluesr§   rM  rA  r@  Únextr‘  ÚopenÚwriteÚ_FA_FILE_CODErJ  Úbasenamer´   r¹  ZbuilderZoutdirÚrelpathÚdirnameÚsrcdirr9  Úmakedirsr<  r/  r·  Ú_SCRAPER_TEXTrÐ   )rd  ÚblockZ
block_varsZgallery_confrR  rº  Z	img_fnameZfidZ
html_fnameZout_dirZ	out_fnamer7  r^   r^   rc   Ú__call__ó  s6    
ÿ
þ
ýÿþ

z_ReportScraper.__call__c                 O   s"   | j  ¡ D ]\}}t||ƒ q
d S r­   )r·  rt  r	   )rd  Úargsr  Úkeyrý  r^   r^   rc   Ú	copyfiles  s    z_ReportScraper.copyfilesN)r¡   r¢   r£   r«  re  rl  rÉ  rÌ  r^   r^   r^   rc   r¸  å  s
   r¸  )¥r«  r0  r+  r   Útypingr   r   Úcollections.abcr   rë   r   r   rñ  r9  Úos.pathr´  rJ  Úpathlibr   r±  r‹  Úshutilr	   rC  rã   rG  Únumpyr¯   r„   r   rB  Úfixesr   r   r   r   r   r   r   r   r   r   r   r   Zchannelsr   Údefaultsr   r   r   r   Zio._read_rawr   Zextension_reader_mapZio.pickr    r  r!   Z_freesurferr"   r#   Úutilsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r  r2   r3   r4   r5   r6   r7   r8   r9   r:   Zviz.miscr;   r<   Z	viz.utilsr=   r>   Zviz._scraperr?   rª  r@   rA   rR   rB   rC   Zpreprocessing.icarD   rE   Zminimum_normrF   rG   r  rH   rª  r±   rL  r?  ZRAW_EXTENSIONSrD  rŠ   r³  r&  Ú__file__Úparentr	  Ztemplate_dirrë  r>  r?  rÖ   rÕ   re   ru   ry   r}   r�   rƒ   rŒ   r‘   r”   r–   rš   rœ   r�   r¤   r¶   r¾   rï   rù   r  r  r  r<  rE  rS  ÚparentsZmne_logo_pathrì   rÿ  rê   r@  rT  rX  rM  r¯  r!  rÇ  rÁ  Úobjectr¸  r^   r^   r^   rc   Ú<module>   sð   4@,
	÷



ÿ			,A")00
                        h	