U
    f»{jß» ã                   @   sæ  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	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 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$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddlm2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> ddl?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG ddlHmIZImJZJ dd„ ZKdd„ ZLdldd„ZMdd„ ZNdd„ ZOdmdd„ZPdndd!d&œd'd(„ZQd)d*„ ZRd+d,„ ZSd-d.„ ZTdod/d0„ZUe6dpddd1œd2d3„ƒZVdd4dd5ddddd6gddd!dd7dd d!fd8d9„ZWe:dqd=d>„ƒZXd?d@„ ZYe6drdAdB„ƒZZe6dsdCdD„ƒZ[e:dtdGdH„ƒZ\dudJdK„Z]dLdM„ Z^dNdO„ Z_dPdQ„ Z`dRdS„ ZadTdU„ ZbdVdW„ ZcdXdY„ ZddZd[„ Zed\d]„ Zfdvd^d_„Zgdwd`da„Zhdxdbdc„Ziddde„ Zjdfdg„ Zkdhdi„ Zle:dydjdk„ƒZmdS )zz;Functions to plot evoked M/EEG data (besides topographies).é    )Údeepcopy)Úpartial)Úcycle)ÚIntegralNé   ©Ú_is_last_row)	Úchannel_typeÚ_VALID_CHANNEL_TYPESÚchannel_indices_by_typeÚ_DATA_CH_TYPES_SPLITÚ
_pick_instÚ_get_channel_typesÚ_PICK_TYPES_DATA_DICTÚ_picks_to_idxÚ	pick_info)Ú_handle_defaulté   )Ú_draw_proj_checkboxÚtight_layoutÚ_check_delayed_sspÚplt_showÚ_process_timesÚDraggableColorbarÚ_setup_cmapÚ_setup_vmin_vmaxÚ
_check_covÚ_make_combine_callableÚ_validate_if_list_of_axesÚ_triage_rank_sssÚ_connection_lineÚ_get_color_listÚ_setup_ax_spinesÚ_setup_plot_projectorÚ_prepare_joint_axesÚ_check_optionÚ_set_title_multiple_electrodesÚ_check_time_unitÚ_plot_masked_imageÚ_trim_ticksÚ_set_window_titleÚ_prop_kw)ÚloggerÚ_clean_namesÚwarnÚ_plÚverboseÚ_validate_typeÚ_check_if_nanÚ_check_ch_locsÚfill_docÚ_is_numericÚ_to_rgb)Ú_plot_evoked_topo)Ú_prepare_topomap_plotÚplot_topomapÚ_get_pos_outlinesÚ_draw_outlinesÚ_prepare_topomapÚ_set_contour_locatorÚ_check_sphereÚ_make_head_outlines)Ú_pair_grad_sensorsÚfind_layoutc                    s  d|d< ˆj j‰ t ‡ fdd„|d D ƒ¡d }t|ƒdkr@dS |d }t ‡fdd„|d	 | D ƒ¡d d }|d
 |d | |  }|d | }ˆj  ¡ ˆjd  }ˆj  ¡ ˆjd  }| |¡ | 	|¡ | 
|¡ | ˆj  ¡ ¡ | d¡ | tˆ jƒ¡ | |d ¡ dS )zAdd a channel name on click.TÚ	need_drawc                    s   g | ]}ˆ |k‘qS © rC   )Ú.0Úa©ÚaxrC   úM/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/viz/evoked.pyÚ
<listcomp>3   s     z%_butterfly_onpick.<locals>.<listcomp>Úaxesr   Nc                    s   g | ]}|ˆ j k‘qS rC   )Úartist©rD   Úline©ÚeventrC   rH   rI   8   s    ÚlinesÚch_namesÚidxsÚtextsç      ð?Úpath_effects)rK   rJ   ÚnpÚwhereÚlenZ	get_xdataÚindZ	get_ydataZset_xZset_yZset_textZ	set_colorÚ	get_colorÚ	set_alphaÚ
set_zorderrP   Úset_path_effects)rO   ÚparamsZax_idxZlidxZch_nameÚtextÚxÚyrC   )rG   rO   rH   Ú_butterfly_onpick/   s0     
ÿÿÿ



rb   c                    sz   |d rˆ j  ¡  nZt ‡ fdd„|d D ƒ¡d }t|ƒdkrn|d |d  }| d¡ | g ¡ ˆ j  ¡  d	|d< d
S )zOnly draw once for picking.rB   c                    s   g | ]}ˆ j |k‘qS rC   )Zinaxes©rD   rG   rN   rC   rH   rI   O   s     z._butterfly_on_button_press.<locals>.<listcomp>rJ   r   r   rS   ç        FN)ÚcanvasÚdrawrV   rW   rX   r[   r]   )rO   r^   Úidxr_   rC   rN   rH   Ú_butterfly_on_button_pressJ   s     


rh   FÚsc
           %      C   sì  ddl m}
 dd„ |D ƒ}t|ƒdkr.tdƒ‚d|krftt|ddd�ƒd	k rf| d¡ t|ƒdkrfdS tƒ }|dk	rÞ| d
¡ |j}| 	|j
| ddd�¡ | 	|j
|ddd�¡ |j| |ddd�}|
 ¡ }|j ¡  |j ¡  t ||  ¡ ¡ }t || ¡ ¡ }|
jdt|ƒddt|ƒ dfd�\}}t|ƒD �]4\}}|dk�rH�q0t|||	d�\}}}}}}}t||d|ƒ}t|ƒd	k �r–| |d | ¡ �q0||||…f }|�rìd	dlm} |�rÂdnd}|||g |d�\}}d|| ¡ f }n|}tj|dd�}|d |  |¡ |�rt|ƒnd} |�r0t|ƒnd}!|�r>dnd}"t|||"| |!|d | d||d�	 �q0|�rrdn|}#|j d| |#||#f d d!� t!d"|d#� t"ƒ  |dk	�rè| d¡ t#t$|||d$�}$|j %d%|$¡ |j ¡  |j ¡  dS )&z%Draw topomaps from the selected area.r   Nc                 S   s   g | ]}|d kr|‘qS )©ÚeegÚgradÚmagrC   )rD   Útype_rC   rC   rH   rI   \   s      z'_line_plot_onselect.<locals>.<listcomp>z;Interactive topomaps only allowed for EEG and MEG channels.rl   F)Ztopomap_coordsZraise_errorr   TÚred)ÚzorderÚcolorçš™™™™™É?Úgreen)Úalpharq   r   é   )ZsqueezeÚfigsizerj   ©ÚsphereÚhead)Ú_merge_ch_dataÚmeanZrms)Úmethodz%s %s©ÚaxisZReds)ÚcmapÚvminÚvmaxrJ   Úshowrx   ÚoutlinesZHzzAverage over %.2f%s - %.2f%sçš™™™™™¹?)ra   ç       @)ÚpadÚfig)rG   rP   ÚfillZclose_event)&Úmatplotlib.pyplotÚpyplotrX   Ú
ValueErrorr@   ÚremoveÚlistÚset_visiblerJ   ÚappendÚaxvlineZaxvspanZgcfre   rf   Zflush_eventsrV   ÚabsZargminÚsubplotsÚ	enumerater8   r?   ZdelaxesÚchannels.layoutrz   ÚupperZaverageÚ	set_titleÚminÚmaxr9   Úsuptitler   r   r   Ú_topo_closedÚmpl_connect)%ZxminÚxmaxÚch_typesÚinfoÚdataÚtimesr_   ÚpsdÚ	time_unitrx   ÚpltZ
vert_linesrG   rˆ   Z
evoked_figZminidxZmaxidxr‡   Zaxarrrg   Úch_typeÚpicksÚposÚmerge_channelsÚ_Zthis_sphereZclip_originrƒ   Z	this_datarz   r|   Útitler€   r�   r   ÚunitZclose_callbackrC   rC   rH   Ú_line_plot_onselectX   s�    ÿÿÿ



ÿ

ÿÿ

  þ
ÿ

ÿ
r«   c                 C   s4   |D ]}|j  |¡ q|j |¡ | ¡ j ¡  dS )z3Remove lines from evoked plot as topomap is closed.N)rP   rŒ   ZpatchesÚ
get_figurere   rf   )ÚeventsrG   rP   rˆ   rM   rC   rC   rH   rš       s    rš   c                 C   s:   t  | ||g¡j}|| d¡8 }|t  | d¡d¡ }|S )z)Transform x, y, z values into RGB colors.r   g¼‰Ø—²Òœ<)rV   ÚarrayÚTr—   Úmaximumr˜   )r`   ra   ÚzÚrgbrC   rC   rH   Ú_rgb¨   s    r³   é   c                 C   sÖ   ddl m} | ¡ j ¡  | ¡ }|j|j }	||t||	 ƒd t|ƒd |d�}
|
 	d¡ |
 
d¡ t| |
dd� | j\}}|
j||||d	 d
dd� |rÈt |¡}|
j|| || |d d
ddd� t|
|ƒ dS )z;Plot (possibly colorized) channel legends for evoked plots.r   )Ú
inset_axesú%)ÚwidthÚheightÚlocÚboxÚequalF)Zcheck_nonzeroçš™™™™™é?Ú.r   )rq   ri   Úmarkerrp   é   Úw)ri   r¾   rq   rp   N)Z%mpl_toolkits.axes_grid1.inset_locatorrµ   r¬   re   rf   Zget_window_extentr·   r¸   ÚstrZset_adjustableZ
set_aspectr<   r¯   ZscatterrV   r®   r;   )r¦   Úcolorsr~   Úbadsrƒ   r¹   Úsizerµ   ZbboxÚratiorG   Zpos_xZpos_yrC   rC   rH   Ú_plot_legend°   s(    
 ÿ



 ÿrÆ   rÃ   TÚtightÚ	butterflyÚunsortedç      Ð?)Ú	highlightrf   c          6         sp  ddl m}  |dk�r¶t|tƒ�r¶|dkrNtƒ }|D ]‰|  ¡  |  ¡ |ˆ< q4t|tƒs`tdƒ‚tt| 	¡ ƒƒ t
dd„ | 	¡ D ƒƒ}!|D ]¨‰ˆ|kr¢tˆd ƒ‚|ˆ }"|dkrÊ‡ ‡fdd	„|ˆ D ƒn|}#tˆ |ˆ ˆ|||||||	|
|#|"||||||||||||||d
d� |!rŠt|"ƒsŠ|" g ¡ |" d¡ qŠdd„ | 	¡ D ƒ}$t dd„ |$D ƒ¡}%|% ¡ |% ¡  }&}'|$D ]}(|( |&|'¡ �qpdd„ | 	¡ D ƒ})tt|)ƒƒdk�r°|)d S |)S nt|tƒ�rÊtdƒ‚t|ˆ jƒ\}}*ˆ  ¡ ‰ ˆ j‰|dk	�r|dk�rtdƒ‚td|dd
dgƒ |dk	�rZtj|td�}t |¡}|jd dk�rZtd|j› d�ƒ‚td|
ƒ}
td|ƒ}td|	ƒ}	|dk�r |dk	�r t|tƒ�s tdƒ‚t ˆ|dd d!�}t|ƒtt|ƒƒk�rÎtd"ƒ‚‡fd#d„ˆd$ D ƒ}+tˆƒdk�rbtˆt!ƒ�rˆd$k�r|+‰n<tˆtƒ�rBt"d%d&„ ˆD ƒƒ�rB‡fd'd„ˆD ƒ‰ntd(ƒ‚t ‡fd)d„|D ƒ¡}t t#ˆ|ƒt!¡},tƒ }-t$D ]}.|.|,k�r~|- %|.¡ �q~d}/|dk�rø|  &t|-ƒd¡\}/}|/j'd*d+d,d-d.d/� t|| j(ƒ�rä|g}|/ )d0dt|ƒ ¡ t|| j(ƒ�r|g}nt|tj*ƒ�r$t|ƒ}|/dk�r:|d  +¡ }/|dk	�rNt,|/|ƒ t|ƒt|-ƒk�r~td1t|ƒt|-ƒt-|-ƒf ƒ‚td2|d3ƒ t.|ˆƒ}|d4k�r°|dk	�r°td5ƒ‚t/ˆ||dkˆ j0d6�\}0}1t|1ƒdk�rÜd
}|0dk	�rþt 1|0ˆ j2¡ˆ j2dd…< |d4k�rˆ  3¡ ‰ |d7k�rrt4ˆ j2ˆ||/||||	|
|||,||||*|+||-|d
d8ˆ j0|||d9� | j5|d:|› d;�d<� n‚|dk�rôt6t7||-ƒƒD ]h\}2\}"}.|2dk�r¦ˆ j0nd}3t||,|.k ƒ}4t8ˆ j2|"|.|4|||	|
|*|||||||||3||ˆ j9d=� �qŠ|dk�r4t:ˆ ƒ tˆ |/ˆd> ||,|	|
||-|t;|d?�}5t<d|5ƒ | j5|/jdt|-ƒd … dd<� |�rd|/j= >¡  t?|ƒ |/S )@a  Aux function for plot_evoked and plot_evoked_image (cf. docstrings).

    Extra params are:

    plot_type : str, value ('butterfly' | 'image')
        The type of graph to plot: 'butterfly' plots each channel as a line
        (x axis: time, y axis: amplitude). 'image' plots a 2D image where
        color depicts the amplitude of each channel at a given time point
        (x axis: time, y axis: channel). In 'image' mode, the plot is not
        interactive.
    draw : bool
        If True, draw at the end.
    r   NÚimagez?If `group_by` is a dict, `axes` must be a dict of axes or None.c                 S   s   g | ]}t |ƒ‘qS rC   r   rc   rC   rC   rH   rI   ì   s     z _plot_evoked.<locals>.<listcomp>z/ present in `group_by`, but not found in `axes`c                    s   i | ]}t ˆ j|ƒˆ“qS rC   )r	   rž   ©rD   rg   )ÚevokedÚselrC   rH   Ú
<dictcomp>ó   s   ÿ
 z _plot_evoked.<locals>.<dictcomp>F)r   ÚgfpÚwindow_titleÚ
selectableÚ	noise_covÚcolorbarÚmaskÚ
mask_styleÚ	mask_cmapÚ
mask_alphar¢   Ú
show_namesrx   rf   Ú c                 S   s   g | ]}|j d  ‘qS ©r   )Úimagesrc   rC   rC   rH   rI     s     c                 S   s   g | ]}|  ¡ ‘qS rC   )Zget_clim)rD   ÚimrC   rC   rH   rI     s     c                 S   s   g | ]}|  ¡ ‘qS rC   )r¬   rc   rC   rC   rH   rI     s     r   z>If `group_by` is not a dict, `axes` must not be a dict either.ÚinteractivezOCurrently only single axis figures are supported for interactive SSP selection.rÑ   TÚonly©Zdtyper   zF"highlight" must be reshapable into a 2D array with shape (n, 2). Got r½   ÚscalingsÚtitlesÚunitsz6`clim` must be a dict. E.g. clim = dict(eeg=[-20, 20])ÚallrC   )ÚnoneÚexcludez1`picks` are not unique. Please remove duplicates.c                    s&   g | ]}|ˆ d  krˆ d    |¡‘qS ©rQ   ©Úindex©rD   Úch©rž   rC   rH   rI   1  s    ÿrÃ   c                 s   s   | ]}t |tƒV  qd S ©N)Ú
isinstancerÁ   rë   rC   rC   rH   Ú	<genexpr>7  s     z_plot_evoked.<locals>.<genexpr>c                    s   g | ]}ˆ d    |¡‘qS rè   ré   rë   rí   rC   rH   rI   8  s     z3exclude has to be a list of channel names or "bads"c                    s   g | ]}|ˆ kr|‘qS rC   rC   )rD   Úpick)rç   rC   rH   rI   =  s      g      À?r„   g333333ï?gq=
×£pí?g)\�Âõ(ä?)ÚleftÚbottomÚrightÚtopÚhspaceçš™™™™™@z?Number of axes (%g) must match number of channel types (%d: %s)Úproj)TFrß   Úreconstructrù   z8Cannot use proj="reconstruct" when noise_cov is not None)rø   ÚnaverÈ   rT   )Ú
line_alpharú   r¢   rx   rË   úTime (ú))Úxlabel)	rÕ   rÖ   r×   rØ   rÙ   rú   r¢   rÚ   rQ   Úprojs)rÎ   r‡   rÿ   rJ   Útypesrä   râ   rª   Úch_types_usedr¥   Zplot_update_proj_callbackÚ	plot_type)@r‰   rŠ   rï   ÚdictÚfigurerJ   r‹   r   r�   ÚvaluesÚanyÚ_plot_evokedr   Zset_xticklabelsZ
set_xlabelrV   r®   r—   r˜   Zset_climrX   Úsetr'   r    Úcopyrž   ÚRuntimeErrorr%   ÚfloatZ
atleast_2dÚshaper   r   rÁ   rå   r   r
   r�   r’   Úsubplots_adjustÚAxesZset_size_inchesÚndarrayr¬   r*   Úsortedr   r#   rú   ÚdotrŸ   Ú_reconstruct_projÚ_plot_linesZsetpr“   ÚzipÚ_plot_imagerQ   r   Ú_plot_update_evokedr   re   rf   r   )6rÎ   r¥   rç   rª   r‚   Úylimrø   ÚxlimÚhlinerä   râ   rã   rJ   r  r   rÑ   rÒ   Úspatial_colorsrÓ   rp   rÔ   rÕ   rÖ   r×   rØ   rÙ   r¢   rÚ   Úgroup_byrx   rË   rf   r£   Zremove_xlabelsrG   r©   ZimsZclimsr—   r˜   rÞ   Úfigsr    Ú
bad_ch_idxr   r  Ú	this_typer‡   Z	projectorZwhitened_ch_namesÚaiZuse_naveZ
this_picksr^   rC   )rÎ   rç   rž   rÏ   rH   r  Ä   sŽ   
ÿÿÿ             ÷



ÿ



ÿÿ

ÿ


ÿÿ
   ÿ



               ü
          û

    ü
 
r  c          H         s  ddl m}m} ddlm} t|ƒt|ƒks0t‚tƒ }tƒ }tƒ }t|ˆ ƒ}|j	dddd�g} |j	dddd�g}!|rät
jt|ƒtd	�}"t|ƒD ]T\}#}$|||$k }%t|%ƒdk sÂ|$d
krŽt|%ƒdk rŽ|$tkrÚt d|$f ¡ d|"|#< qŽ|�r0t|||ˆ d |d| d�}&|j dtt|&d�¡ |j dtt|&d�¡ tt||ƒƒD �]þ\}'\}(}$tƒ })|dk�rfd}*d}+n|dk�rtdn||$ }*||$ }+t|||$k ƒ}%| |%¡ t|%ƒdk�r2|*| |%dd…f  },t|,ƒ |
dk}-|-�sz‡ fdd„|%D ƒ}.t
 dd„ |.D ƒ¡}/|dk�r$tˆ |%d��s$tdƒ d }}|dk�rjt|%ƒdk�rj|/j\}0}1}2t|0|1|2ƒ}3t|3ˆ |%|$||(|ƒ nNt |t!t"fƒ�r‚|g}4ndg}4|4t|%ƒ }3|D ]}5|5|%k�r˜d|3|% #|5¡< �q˜|d k�rÔ|,j$dd!� %¡ }6nH|d"k�ròtt&|,j'd ƒƒ}6n*t(|ƒ�sd#}7t)|7 *t+|ƒ¡ƒ‚n||,ƒ}6t|6ƒD ]T\}8}2|) |(j,||,|8 d|dk�rP|2d nd|3|8 |d$d%�d ¡ |)d&  -d'¡ �q$|
�rž|
d(k�rÊ|$d)k�r¨|,j$ddd*�}9d+}:n"t
j.j/|,dd!�t
 0t|,ƒ¡ }9d,}:|dk�rØd-nd.};|dk�sô|$| 1¡ k�rü|( 2¡ n||$ }<|-�rd/}=n|<d }=|9|=7 }9|(j3||=|9d0|;dd1d2� |) |(j,||9|;d3|d4�d ¡ |(j4|d d5|d& |d    |9d d6t
 5|( 2¡ ¡d   |:d|;|!d7� t|%|)ƒD ]2\}>}?|>|k�r¨|? 6d¡ |dk�r¨|? 7d8¡ �q¨|( 8|+¡ | |(j4ddd9d3d:d;d<ddd=�	¡ |dk	�r6|d>k�r,|d |d& f}|( 9|¡ |dk	�rX|$|k�rX|( :||$ ¡ |(j;d?||$ t|,ƒt<t|,ƒƒf d@� |'dk�r’t=|(|ƒ |	dk	�rÌ|	D ]*}@|dk�r²dAnd}A|(j>|@d8d|AdB� �q |dk	�r2|dk�sî|$| 1¡ k�rö|( 2¡ n||$ }<|D ]$}B|(j?|<|Bd |Bd dCdDdEdF� �q|( :|<¡ | |)¡ �q>|�rt
 |¡|" D ]º}(t|(j@ƒdk�rl�qT|(jAdGdHdIdJdKd3dL�}C|C Bd¡ ttC|ˆ | ||C|||dM�	}D| D¡ dNk�r¸dnd}Et|ƒdk �rÎdn|d |d  }FtEdOtd$dPdQ�ƒ}G||(|DdRf|F|EdSœ|G—Ž|(_F�qTdS )TzPlot data as butterfly plot.r   )ÚpatheffectsrŠ   )ÚSpanSelectorr   rÀ   ç      è?)Ú	linewidthÚ
foregroundrt   é   rá   rl   é   zNNeed more than one channel to make topography for %s. Disabling interactivity.FrQ   )rJ   rS   rP   rQ   rR   rB   rU   Z
pick_event©r^   Zbutton_press_eventrT   ÚNANrà   c                    s   g | ]}ˆ d  | ‘qS )ÚchsrC   ©rD   Úirí   rC   rH   rI   Ä  s     z_plot_lines.<locals>.<listcomp>c                 S   s   g | ]}|d  dd… ‘qS )r¹   Nru   rC   rë   rC   rC   rH   rI   Å  s     T©rž   r¥   z:Channel locations not available. Disabling spatial colors.r   ÚkÚrÚstdr}   rÉ   z:`zorder` must be a function, "std" or "unsorted", not {0}.ç      à?)Zpickerrp   rq   rt   r#  éÿÿÿÿg      @)Trà   rk   )r~   ZddofZGFPZRMS)rd   rd   rd   )rd   rT   rd   rd   ræ   rr   )rq   Ú	facecolorrp   rt   ru   )rq   rp   rt   ç{®Gáz„?gš™™™™™©?)rp   rq   rU   ú--rÛ   Zbaselinerò   Úbold)rp   ÚverticalalignmentÚhorizontalalignmentZ
fontweightrt   Úclip_onrÇ   ú%s (%d channel%s)©r©   Úgrey)Ú	linestyler#  rq   Zorangeg333333Ã?éc   )r2  rt   rp   z
Loading...)r3  r„   úaxes fractioné   rs   )ÚxyÚxycoordsZfontsizerq   rp   )r�   rž   rŸ   r    r_   r¡   r¢   rx   ZMacOSXÚrectro   )rt   r2  Ú
horizontal)ÚminspanZuseblit)GÚ
matplotlibr   rŠ   Zmatplotlib.widgetsr!  rX   ÚAssertionErrorr�   r>   Z
withStrokerV   ZonesÚboolr“   r   r,   rž   r  re   r›   r   rb   rh   r  r�   r2   r®   r3   r.   r¯   r³   Ú_handle_spatial_colorsrï   ÚtuplerÁ   rê   r/  ZargsortÚranger  ÚcallableÚ	TypeErrorÚformatÚtypeÚplotZset_pickradiusZlinalgÚnormÚsqrtÚkeysÚget_ylimÚfill_betweenr_   Údiffr\   Zset_linestyleZ
set_ylabelÚset_xlimÚset_ylimr  r/   Ú	_add_naveÚaxhlineZfill_betweenxrP   ÚannotaterŽ   r«   Úget_backendr+   Z_span_selector)HrŸ   rž   r¥   r‡   rJ   r  rª   rä   râ   r  rÑ   r   rp   r  r  r    r  rã   r  rÓ   r¡   rû   rú   r¢   rx   rË   r   r£   r!  rS   rR   rP   rU   Zgfp_path_effectsZselectablesZtype_idxr  rg   r^   r  rG   Z	line_listÚthis_scalingÚch_unitÚDZgfp_onlyr)  Zlocs3dr`   ra   r±   rÂ   Úcolr+  Zz_ordÚerrorZch_idxZthis_gfpÚlabelZ	gfp_colorZ	this_ylimZy_offsetÚiirM   ÚhÚcZthis_highlightr_   Zcallback_onselectZblitrD  Zrect_kwrC   rí   rH   r  �  sž   
ÿÿ þ
  þ
ÿÿÿ



ÿ ÿ



 ýýÿ

ÿÿ  ÿ ÿÿ  ý



 ü


ÿ



ÿÿ    þ

  þ
    ü"  ÿþþr  c              	   C   s(   |dk	r$| j d| ddddddd	� dS )
zAdd nave to axes.NzN$_{\mathrm{ave}}$=%drò   ró   )r   r   r>  )r   r%  zoffset pixels)ZhaÚvar@  rA  ZxytextZ
textcoords)rZ  )rG   rú   rC   rC   rH   rX  I  s        ýrX  c                    s`   t  t|d ƒ¡| ‰ ‡ fdd„|d D ƒ}t|||d�\}}	|rFdnd}
t|| |||	|
ƒ dS )	zSet up spatial colors.rQ   c                    s*   g | ]"}|ˆ krt  ˆ |k¡d  d  ‘qS rÜ   ©rV   rW   )rD   Úbad©Zused_nmrC   rH   rI   V  s
     ÿ z*_handle_spatial_colors.<locals>.<listcomp>rÃ   rw   r   r   N)rV   r®   r-   r:   rÆ   )rÂ   rž   rg   r¤   r¡   rG   rx   rÃ   r¦   rƒ   r¹   rC   rh  rH   rH  R  s
    rH  c           !      C   s  ddl m} |dk	st‚|dkrB|dk	r>t|ƒdk r8dnd}nd}t|ƒ}|| }|| }|dkrjd}d	}|dk	rŠ| | } |dk	rŠ|| }||  } |
dks¢||
kr¸t | ¡ ¡ }| }n|
| \}}t| ƒ t	|| ||d|d |||||d
�\}}|	dkrþdn|	}	|	dk	�r| 
|	¡ |�rL|j||d�}|j |¡ |d �rLt||ƒ|_|�rVdnd}|| dt| ƒt| ƒf  | }|j|d|› d�|d� t||ƒ t t|ƒ¡}|dk�rÐt t | ¡ ¡ t¡|¡}|�rät |¡| nt |¡} |j|| | d� dS )zPlot images.r   NÚautoé   rå   TFrT   r(  )Zyvalsr   r€   r�   r×   rÙ   rØ   rÇ   rF   r   ZChannelszChannel (index)z (%d channel%srü   rý   )Úylabelrþ   r©   )ÚyticksÚyticklabels)r‰   rŠ   rF  rX   r   rV   r‘   r˜   r2   r(   rV  rÕ   rG   r–   r   ZCBr/   r  rX  ZarangeÚintersect1dÚroundÚ
get_yticksZastypeÚintr®   )!rŸ   rG   r  r¥   r   rª   rä   râ   r    r  r  rã   rÕ   rÖ   rØ   r×   rÙ   rú   r¢   rÚ   rQ   r£   r]  r\  r�   r€   rÞ   Zt_endÚcbarrk  Útrl  rm  rC   rC   rH   r  ]  sh            ý



 

r  )rË   r0   c                C   s6   t | |||||||||	|
||d|||||||||d�S )uþ  Plot evoked data using butterfly plots.

    Left click to a line shows the channel name. Selecting an area by clicking
    and holding left mouse button plots a topographic map of the painted area.

    .. note:: If bad channels are not excluded they are shown in red.

    Parameters
    ----------
    evoked : instance of Evoked
        The evoked data.
    %(picks_all)s
    exclude : list of str | 'bads'
        Channels names to exclude from being shown. If 'bads', the
        bad channels are excluded.
    unit : bool
        Scale plot with channel (SI) unit.
    show : bool
        Show figure if True.
    ylim : dict | None
        Y limits for plots (after scaling has been applied). e.g.
        ylim = dict(eeg=[-20, 20])
        Valid keys are eeg, mag, grad, misc. If None, the ylim parameter
        for each channel equals the pyplot default.
    xlim : 'tight' | tuple | None
        X limits for plots.
    %(proj_plot)s
    hline : list of float | None
        The values at which to show an horizontal line.
    units : dict | None
        The units of the channel types used for axes labels. If None,
        defaults to ``dict(eeg='ÂµV', grad='fT/cm', mag='fT')``.
    scalings : dict | None
        The scalings of the channel types to be applied for plotting. If None,
        defaults to ``dict(eeg=1e6, grad=1e13, mag=1e15)``.
    titles : dict | None
        The titles associated with the channels. If None, defaults to
        ``dict(eeg='EEG', grad='Gradiometers', mag='Magnetometers')``.
    axes : instance of Axes | list | None
        The axes to plot to. If list, the list must be a list of Axes of
        the same length as the number of channel types. If instance of
        Axes, there must be only one channel type plotted.
    gfp : bool | 'only'
        Plot the global field power (GFP) or the root mean square (RMS) of the
        data. For MEG data, this will plot the RMS. For EEG, it plots GFP,
        i.e. the standard deviation of the signal across channels. The GFP is
        equivalent to the RMS of an average-referenced signal.

        - ``True``
            Plot GFP or RMS (for EEG and MEG, respectively) and traces for all
            channels.
        - ``'only'``
            Plot GFP or RMS (for EEG and MEG, respectively), and omit the
            traces for individual channels.

        The color of the GFP/RMS trace will be green if
        ``spatial_colors=False``, and black otherwise.

        .. versionchanged:: 0.23
           Plot GFP for EEG instead of RMS. Label RMS traces correctly as such.
    window_title : str | None
        The title to put at the top of the figure.
    spatial_colors : bool
        If True, the lines are color coded by mapping physical sensor
        coordinates into color values. Spatially similar channels will have
        similar colors. Bad channels will be dotted. If False, the good
        channels are plotted black and bad channels red. Defaults to False.
    zorder : str | callable
        Which channels to put in the front or back. Only matters if
        ``spatial_colors`` is used.
        If str, must be ``std`` or ``unsorted`` (defaults to ``unsorted``). If
        ``std``, data with the lowest standard deviation (weakest effects) will
        be put in front so that they are not obscured by those with stronger
        effects. If ``unsorted``, channels are z-sorted as in the evoked
        instance.
        If callable, must take one argument: a numpy array of the same
        dimensionality as the evoked raw data; and return a list of
        unique integers corresponding to the number of channels.

        .. versionadded:: 0.13.0

    selectable : bool
        Whether to use interactive features. If True (default), it is possible
        to paint an area to draw topomaps. When False, the interactive features
        are disabled. Disabling interactive features reduces memory consumption
        and is useful when using ``axes`` parameter to draw multiaxes figures.

        .. versionadded:: 0.13.0

    noise_cov : instance of Covariance | str | None
        Noise covariance used to whiten the data while plotting.
        Whitened data channel names are shown in italic.
        Can be a string to load a covariance from disk.
        See also :meth:`mne.Evoked.plot_white` for additional inspection
        of noise covariance properties when whitening evoked data.
        For data processed with SSS, the effective dependence between
        magnetometers and gradiometers may introduce differences in scaling,
        consider using :meth:`mne.Evoked.plot_white`.

        .. versionadded:: 0.16.0
    %(time_unit)s

        .. versionadded:: 0.16
    %(sphere_topomap_auto)s
    highlight : array-like of float, shape(2,) | array-like of float, shape (n, 2) | None
        Segments of the data to highlight by means of a light-yellow
        background color. Can be used to put visual emphasis on certain
        time periods. The time periods must be specified as ``array-like``
        objects in the form of ``(t_start, t_end)`` in the unit given by the
        ``time_unit`` parameter.
        Multiple time periods can be specified by passing an ``array-like``
        object of individual time periods (e.g., for 3 time periods, the shape
        of the passed object would be ``(3, 2)``. If ``None``, no highlighting
        is applied.

        .. versionadded:: 1.1
    %(verbose)s

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        Figure containing the butterfly plots.

    See Also
    --------
    mne.viz.plot_evoked_white
    rÈ   )rÎ   r¥   rç   rª   r‚   r  rø   r  r  rä   râ   rã   rJ   r  rÑ   rÒ   r  rÓ   rp   rÔ   r¢   rx   rË   ©r  )rÎ   r¥   rç   rª   r‚   r  r  rø   r  rä   râ   rã   rJ   rÑ   rÒ   r  rp   rÓ   rÔ   r¢   rx   rË   r0   rC   rC   rH   Úplot_evokedž  s4                      úru  g=
×£p=î?ræ   rd   rÀ   c                 C   s  t | ƒttfkr| g} t|dd�}t |¡dk }|rB|}|}d}n|}|}d}t|ttfƒrvt|ƒt| ƒkrÜtdƒ‚nf|dkrÀ|r�dgt	ƒ  }nt	ƒ }|t| ƒt|ƒ d  }|dt| ƒ… }nt|t
ƒsÒtd	ƒ‚t|gƒ}t| |||||||||	||
||||||||d
�S )ae  Plot 2D topography of evoked responses.

    Clicking on the plot of an individual sensor opens a new figure showing
    the evoked response for the selected sensor.

    Parameters
    ----------
    evoked : list of Evoked | Evoked
        The evoked response to plot.
    layout : instance of Layout | None
        Layout instance specifying sensor positions (does not need to
        be specified for Neuromag data). If possible, the correct layout is
        inferred from the data.
    layout_scale : float
        Scaling factor for adjusting the relative size of the layout
        on the canvas.
    color : list of color | color | None
        Everything matplotlib accepts to specify colors. If not list-like,
        the color specified will be repeated. If None, colors are
        automatically drawn.
    border : str
        Matplotlib borders style to be used for each sensor plot.
    ylim : dict | None
        Y limits for plots (after scaling has been applied). The value
        determines the upper and lower subplot limits. e.g.
        ylim = dict(eeg=[-20, 20]). Valid keys are eeg, mag, grad, misc.
        If None, the ylim parameter for each channel type is determined by
        the minimum and maximum peak.
    scalings : dict | None
        The scalings of the channel types to be applied for plotting. If None,`
        defaults to ``dict(eeg=1e6, grad=1e13, mag=1e15)``.
    title : str
        Title of the figure.
    proj : bool | 'interactive'
        If true SSP projections are applied before display. If 'interactive',
        a check box for reversible selection of SSP projection vectors will
        be shown.
    vline : list of float | None
        The values at which to show a vertical line.
    fig_background : None | ndarray
        A background image for the figure. This must work with a call to
        plt.imshow. Defaults to None.
    merge_grads : bool
        Whether to use RMS value of gradiometer pairs. Only works for Neuromag
        data. Defaults to False.
    legend : bool | int | str | tuple
        If True, create a legend based on evoked.comment. If False, disable the
        legend. Otherwise, the legend is created and the parameter value is
        passed as the location parameter to the matplotlib legend call. It can
        be an integer (e.g. 0 corresponds to upper right corner of the plot),
        a string (e.g. 'upper right'), or a tuple (x, y coordinates of the
        lower left corner of the legend in the axes coordinate system).
        See matplotlib documentation for more details.
    axes : instance of matplotlib Axes | None
        Axes to plot into. If None, axes will be created.
    background_color : color
        Background color. Typically 'k' (black) or 'w' (white; default).

        .. versionadded:: 0.15.0
    noise_cov : instance of Covariance | str | None
        Noise covariance used to whiten the data while plotting.
        Whitened data channel names are shown in italic.
        Can be a string to load a covariance from disk.

        .. versionadded:: 0.16.0
    exclude : list of str | 'bads'
        Channels names to exclude from the plot. If 'bads', the
        bad channels are excluded. By default, exclude is set to 'bads'.
    show : bool
        Show figure if True.

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        Images of evoked responses at sensor locations.
    Úbackground_color)Únamer0  rÀ   r-  z<Lists of evoked objects and colors must have the same lengthNr   z0color must be of type tuple, list, str, or None.)rÎ   ÚlayoutÚlayout_scalerq   Úborderr  râ   r©   rø   ÚvlineÚfig_facecolorÚfig_backgroundÚaxis_facecolorÚ
font_colorr§   ÚlegendrJ   rç   r‚   rÔ   )rN  rI  r�   r6   rV   r{   rï   rX   r‹   r!   rÁ   r   r7   )rÎ   rx  ry  rq   rz  r  râ   r©   rø   r{  r}  Zmerge_gradsr€  rJ   rv  rÔ   rç   r‚   Zdark_backgroundr|  r~  r  rC   rC   rH   Úplot_evoked_topo-  sZ    R

ÿ
        ör�  ÚRdBu_rÚGreysri  c                 C   s8   t | |||||||d||	|
|d||||||||||d�S )up  Plot evoked data as images.

    Parameters
    ----------
    evoked : instance of Evoked
        The evoked data.
    %(picks_all)s
        This parameter can also be used to set the order the channels
        are shown in, as the channel image is sorted by the order of picks.
    exclude : list of str | 'bads'
        Channels names to exclude from being shown. If 'bads', the
        bad channels are excluded.
    unit : bool
        Scale plot with channel (SI) unit.
    show : bool
        Show figure if True.
    clim : dict | None
        Color limits for plots (after scaling has been applied). e.g.
        ``clim = dict(eeg=[-20, 20])``.
        Valid keys are eeg, mag, grad, misc. If None, the clim parameter
        for each channel equals the pyplot default.
    xlim : 'tight' | tuple | None
        X limits for plots.
    proj : bool | 'interactive'
        If true SSP projections are applied before display. If 'interactive',
        a check box for reversible selection of SSP projection vectors will
        be shown.
    units : dict | None
        The units of the channel types used for axes labels. If None,
        defaults to ``dict(eeg='ÂµV', grad='fT/cm', mag='fT')``.
    scalings : dict | None
        The scalings of the channel types to be applied for plotting. If None,`
        defaults to ``dict(eeg=1e6, grad=1e13, mag=1e15)``.
    titles : dict | None
        The titles associated with the channels. If None, defaults to
        ``dict(eeg='EEG', grad='Gradiometers', mag='Magnetometers')``.
    axes : instance of Axes | list | dict | None
        The axes to plot to. If list, the list must be a list of Axes of
        the same length as the number of channel types. If instance of
        Axes, there must be only one channel type plotted.
        If ``group_by`` is a dict, this cannot be a list, but it can be a dict
        of lists of axes, with the keys matching those of ``group_by``. In that
        case, the provided axes will be used for the corresponding groups.
        Defaults to ``None``.
    cmap : matplotlib colormap | (colormap, bool) | 'interactive'
        Colormap. If tuple, the first value indicates the colormap to use and
        the second value is a boolean defining interactivity. In interactive
        mode the colors are adjustable by clicking and dragging the colorbar
        with left and right mouse button. Left mouse button moves the scale up
        and down and right mouse button adjusts the range. Hitting space bar
        resets the scale. Up and down arrows can be used to change the
        colormap. If 'interactive', translates to ``('RdBu_r', True)``.
        Defaults to ``'RdBu_r'``.
    colorbar : bool
        If True, plot a colorbar. Defaults to True.

        .. versionadded:: 0.16
    mask : ndarray | None
        An array of booleans of the same shape as the data. Entries of the
        data that correspond to ``False`` in the mask are masked (see
        ``do_mask`` below). Useful for, e.g., masking for statistical
        significance.

        .. versionadded:: 0.16
    mask_style : None | 'both' | 'contour' | 'mask'
        If ``mask`` is not None: if 'contour', a contour line is drawn around
        the masked areas (``True`` in ``mask``). If 'mask', entries not
        ``True`` in ``mask`` are shown transparently. If 'both', both a contour
        and transparency are used.
        If ``None``, defaults to 'both' if ``mask`` is not None, and is ignored
        otherwise.

         .. versionadded:: 0.16
    mask_cmap : matplotlib colormap | (colormap, bool) | 'interactive'
        The colormap chosen for masked parts of the image (see below), if
        ``mask`` is not ``None``. If None, ``cmap`` is reused. Defaults to
        ``Greys``. Not interactive. Otherwise, as ``cmap``.
    mask_alpha : float
        A float between 0 and 1. If ``mask`` is not None, this sets the
        alpha level (degree of transparency) for the masked-out segments.
        I.e., if 0, masked-out segments are not visible at all.
        Defaults to .25.

        .. versionadded:: 0.16
    time_unit : str
        The units for the time axis, can be "ms" or "s" (default).

        .. versionadded:: 0.16
    show_names : bool | 'auto' | 'all'
        Determines if channel names should be plotted on the y axis. If False,
        no names are shown. If True, ticks are set automatically by matplotlib
        and the corresponding channel names are shown. If "all", all channel
        names are shown. If "auto", is set to False if ``picks`` is ``None``,
        to ``True`` if ``picks`` contains 25 or more entries, or to "all"
        if ``picks`` contains fewer than 25 entries.
    group_by : None | dict
        If a dict, the values must be picks, and ``axes`` must also be a dict
        with matching keys, or None. If ``axes`` is None, one figure and one
        axis will be created for each entry in ``group_by``.Then, for each
        entry, the picked channels will be plotted to the corresponding axis.
        If ``titles`` are None, keys will become plot titles. This is useful
        for e.g. ROIs. Each entry must contain only one channel type.
        For example::

            group_by=dict(Left_ROI=[1, 2, 3, 4], Right_ROI=[5, 6, 7, 8])

        If None, all picked channels are plotted to the same axis.
    %(sphere_topomap_auto)s

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        Figure containing the images.
    NrÌ   )rÎ   r¥   rç   rª   r‚   r  rø   r  r  rä   râ   rã   rJ   r  r   rÕ   rÖ   r×   rØ   rÙ   r¢   rÚ   r  rx   rt  )rÎ   r¥   rç   rª   r‚   Zclimr  rø   rä   râ   rã   rJ   r   rÕ   rÖ   r×   rØ   rÙ   r¢   rÚ   r  rx   rC   rC   rH   Úplot_evoked_image¬  s,    z
             ùr„  c                    s  ‡fdd„dD ƒ\‰}‡ fdd„t ˆd ƒD ƒ}ˆ ˆd< | ¡ }g |jd< | |¡ | ¡  tˆd ˆd ƒD ]†\}‰ˆd	 ˆ }‡‡‡fd
d„ttˆƒƒD ƒ}||j|dd…f  }ˆd dkrät|j	|ƒD ]\}	}
|	 
|
¡ qÎqn|jd  |¡ qnˆd j ¡  dS )zUpdate the plot evoked lines.c                    s   g | ]}ˆ | ‘qS rC   rC   )rD   r-  r'  rC   rH   rI   2  s     z'_plot_update_evoked.<locals>.<listcomp>)r¥   rÎ   c                    s&   g | ]\}}|t  ˆ ¡d  kr|‘qS rÜ   rf  )rD   rb  rø   )ÚboolsrC   rH   rI   3  s    ÿrÿ   Z
proj_boolsrJ   r  râ   c                    s$   g | ]}ˆ d  | ˆkrˆ| ‘qS )r   rC   r*  )r^   r¥   rs  rC   rH   rI   <  s      Nr  rÈ   r   r‡   )r“   r	  rž   Zadd_projÚ
apply_projr  rJ  rX   rŸ   rP   Z	set_ydatarÝ   Úset_datare   rf   )r^   r…  rÎ   rÿ   Z
new_evokedrG   r\  rg   r^  rM   ZdirC   )r…  r^   r¥   rs  rH   r  0  s     

r  c           4   	      sv  ddl m‰m}m}	 ddlm‰ t|ˆ jƒ\}}
t|t	t
|dfƒ t|t	t
fƒsV|g}t|ƒD ]&\}}|	|| d|› d�dd	�||< q^ˆ  ¡ ‰ d
d„ tˆ jd ƒD ƒ}|ddd… D ]}ˆ  |¡ q´ˆ jf dddœt—Ž tˆ j||dd�\}}}}|�rt d¡ ‡ ‡fdd„t||ƒD ƒ}dPdd„}t|ƒdk�r@d}d}nd}d}|| }t|ƒdk�rf||fn|f}t|t	t
tjdfdƒ |dk�r®ˆj||dddd| fd�\}}n
t |¡}t|jƒD ]\}}t|ˆjd|f ƒ �qÂ|j|k�rtd|› d|j› �ƒ‚|jd j}|dk�r8d|d  dd ¡ }|  |¡ t!|dk�oJ|dk|dk�oZ|dkfƒ�r||d|… }|dd… }n>|dk�r²|dk�r²|d|…df }|dd…df }nt"d!ƒ‚t#d"ƒ} |�rÐd#| d$< ‡fd%d„t $dd&t|ƒ¡D ƒ}!t#d'dƒ}"t||||!ƒ}#|�s,|d j%d|d(d)gd|d*� n|t||ƒD ]p\\}$}%}|j%|
|d j&|% j'd+d&d,� d-D ]}&|j(|&d.d/dd0� �qd|j)d1| |$ t|%ƒt*t|%ƒƒf d2� �q6|#D �]0\}'}}(})d}*|D �]\}+},|(|+ }-d3 +|dk�rê| |+ n|+|-|dk�rüd4nd5¡}.| dd ¡}/||* }| ,|dk�r(|.nd6|/ ¡ |'j&|, }0||0|-d7�}1|+d$k�rVd8n|+}2|j%|
|1|dk�rp|/n|.|dk�r€|)n|"|2 d&d9� |j)d:|› d;�d<|
d |
d gd=d>� |j(dd.d/d?d0� |dk�rÂ|*d7 }*�qÂ�q¬|d }|dk�r
|j-d@dAt.dBdC�dD� nV|j-d@t.dEdC�dF� t.dGdHdIg|d  dJdKdLg|d  dM�}3|�rTdN|3dO< |j/f |3Ž |j0 1¡  t2|ƒ |S )QuÕ  Plot whitened evoked response.

    Plots the whitened evoked response and the whitened GFP as described in
    :footcite:`EngemannGramfort2015`. This function is especially useful for
    investigating noise covariance properties to determine if data are
    properly whitened (e.g., achieving expected values in line with model
    assumptions, see Notes below).

    Parameters
    ----------
    evoked : instance of mne.Evoked
        The evoked response.
    noise_cov : list | instance of Covariance | path-like
        The noise covariance. Can be a string to load a covariance from disk.
    show : bool
        Show figure if True.
    %(rank_none)s
    time_unit : str
        The units for the time axis, can be "ms" or "s" (default).

        .. versionadded:: 0.16
    %(sphere_topomap_auto)s
    axes : list | None
        List of axes to plot into.

        .. versionadded:: 0.21.0
    %(verbose)s

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        The figure object containing the plot.

    See Also
    --------
    mne.Evoked.plot

    Notes
    -----
    If baseline signals match the assumption of Gaussian white noise,
    values should be centered at 0, and be within 2 standard deviations
    (Â±1.96) for 95%% of the time points. For the global field power (GFP),
    we expect it to fluctuate around a value of 1.

    If one single covariance object is passed, the GFP panel (bottom)
    will depict different sensor types. If multiple covariance objects are
    passed as a list, the left column will display the whitened evoked
    responses for each channel based on the whitener from the noise covariance
    that has the highest log-likelihood. The left column will depict the
    whitened GFPs based on each estimator separately for each sensor type.
    Instead of numbers of channels the GFP display shows the estimated rank.
    Note. The rank estimation will be printed by the logger
    (if ``verbose=True``) for each noise covariance estimator that is passed.

    References
    ----------
    .. [1] Engemann D. and Gramfort A. (2015) Automated model selection in
           covariance estimation and spatial whitening of MEG and EEG
           signals, vol. 108, 328-342, NeuroImage.
    r   )Úwhiten_evokedÚ
CovarianceÚ_ensure_covr   Nz	path-likez
noise_cov[ú]F)r0   c                 S   s   g | ]\}}|d  s|‘qS )ZactiverC   )rD   rg   rø   rC   rC   rH   rI   ‘  s    ÿz%plot_evoked_white.<locals>.<listcomp>rÿ   r1  rÃ   )Zref_megrç   )râ   zESSS has been applied to data. Showing mag and grad whitening jointly.c                    s    g | ]\}}ˆˆ |d |d�‘qS )N)r¥   ÚrankrC   )rD   Úcovr.  )rÎ   rˆ  rC   rH   rI   Ÿ  s   ÿc                 S   s&   t j| d dd�|dkr t| ƒn| S )z½Whitened Global Field Power.

        The MNE inverse solver assumes zero mean whitened data as input.
        Therefore, a chi^2 statistic will be best to detect model violations.
        r   r   r}   N)rV   ÚsumrX   )r`   rŒ  rC   rC   rH   Úwhitened_gfp¢  s    z'plot_evoked_white.<locals>.whitened_gfpr   rJ   Tgš™™™™™!@gš™™™™™@)ZsharexZshareyrv   zaxes.flat[%d]zaxes must have shape z, got zfWhitened evoked (left, best estimator = "%s")
and global field power (right, comparison of estimators)r|   Z	empiricalzWrong axes inputsrã   zMEG (combined)Zmegc                    s   g | ]}ˆ j  |¡‘qS rC   )ÚcmZSet1r*  ©r£   rC   rH   rI   Ö  s     r0  rq   ç\�Âõ(\ÿ¿ç\�Âõ(\ÿ?)rª   rJ   r  r‚   r¢   r-  )rq   Úlw)r’  r“  ro   r4  )rq   r<  r”  r9  r:  z{0} ({2}{1})zrank rÛ   zWhitened GFP, method = "%s")rŒ  rm   )ra  rq   r”  rü   rý   zGFP ($\chi^2$))r   é
   )rþ   rk  r  r  r…   úupper right)g\�Âõ(\ï?çÍÌÌÌÌÌì?é   ©rÄ   )r¹   Úbbox_to_anchorÚpropr•  )r¹   r›  g®Gázæ?g=
×£p=ê?g×£p=
×ë?g)\�Âõ(Ì?g¤p=
×£À?g
×£p=
·?)rõ   ró   g\�Âõ(\ß?rö   )N)3r�  rˆ  r‰  rŠ  r‰   rŠ   r'   r    r1   r�   rI  rï   r“   r	  rž   Zdel_projZ
pick_typesr   r   r,   r  rX   rV   r  r’   r®   Zflatr  r  r‹   r  Úgetr™   r  r
  r   ÚlinspacerO  rŸ   r¯   rY  r  r/   rM  r–   r€  r  r  re   rf   r   )4rÎ   rÔ   r‚   rŒ  r¢   rx   rJ   r0   r‰  rŠ  r    Úcird  Zpassive_idxrg   Z	n_ch_usedZ	rank_listZ
picks_listZhas_sssZevokeds_whiter�  Ú	n_columnsZn_extra_rowZn_rowsZ
want_shaper¨   r  rG   r‡   r™   Zaxes_evokedZax_gfpZtitles_rÂ   Z	ch_colorsZiter_gfpr¤   r¥   r  Zevoked_whiteZrank_rq   r+  rì   Z	sub_picksZ	this_rankr©   ra  rŸ   rÑ   Zcolor_chr^   rC   )rÎ   r£   rˆ  rH   Úplot_evoked_whiteF  s   ? 
 ÿ   ÿ
ÿ
	
  
þ

ý
ÿ 
 þÿÿ þÿ
ý ÿ

  ÿÿ
r   c                 C   sH  ddl m} ddlm} || |ƒ\}}t|d|jfƒ |dkrP| dd¡\}	}
n|}
~|
j}t 	| j
ddg d| ¡ gg¡}|
jddddd	� |
jddddd	� tƒ }d
}| |
j| j
|dddgd�d ¡ | |
j| j
|d dddgd�d ¡ |
j|dd… |dd… ddd� | jdk	�r,|
 | j¡ |
j||dd� t|ƒ |S )a%  Plot a data SNR estimate.

    Parameters
    ----------
    evoked : instance of Evoked
        The evoked instance. This should probably be baseline-corrected.
    inv : instance of InverseOperator
        The minimum-norm inverse operator.
    show : bool
        Show figure if True.
    axes : instance of Axes | None
        The axes to plot into.

        .. versionadded:: 0.21.0
    %(verbose)s

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        The figure object containing the plot.

    Notes
    -----
    The bluish green line is the SNR determined by the GFP of the whitened
    evoked data. The orange line is the SNR estimated based on the mismatch
    between the data and the data re-estimated from the regularized inverse.

    .. versionadded:: 0.9.0
    r   Nr   )Úestimate_snrr   r1  r-  ú:)rq   Úlsr”  )ZInversezWhitened GFPrd   g333333ã?r0  )rq   r¼   gš™™™™™Ù?ZSNRzTime (s))r  r  rk  rþ   zEstimation methodr:  )r‰   rŠ   Zminimum_normr¡  r1   r  r’   r  rV   Úconcatenater    r˜   r�   rY  r�   r�   rO  r  Úcommentr–   r€  r   )rÎ   Úinvr‚   rJ   r0   r£   r¡  ZsnrZsnr_estr¨   rG   r‡   ZlimsÚhsÚlabelsrC   rC   rH   Úplot_snr_estimate  sH       ÿÿ  ÿÿÿr©  ÚpeaksrÛ   c           %         s\  ddl m} |dk	r0t|tƒs0tdt|ƒf ƒ‚|dkr>tƒ n| ¡ }t| dd¡| j	ƒ\|d< }	|dkrptƒ n| ¡ }d}
ddd	h}||fD ]2‰ t
‡ fd
d„|D ƒƒrŽtd d t|ƒ¡¡ƒ‚qŽd|ksÔd|k�r>d|kräd|ksìtdƒ‚t|d gdƒ |dk�rd}nt|tƒ�rt‚t|ƒd }tt|d ƒ|ƒ d}
| dd¡}| dd¡}||k�rvtd|› d|› d�ƒ‚td|dƒ |  ¡ } |�rª|  ¡  |dk�rª|  ¡  d |d< |d< t| ||dd�} | j‰tˆddd�}t|ƒdk�rt|
�rútdƒ‚tƒ }|D ]j‰|  ¡  ‡‡fdd„tˆd  ƒD ƒ¡}tt|jdd!�ƒdk�rNtd"ƒ‚| t|||||tƒ |d#�¡ �q|S t| |dd$�}~t|d |ƒ\}	}|
�s¶t t|ƒd%d&�\‰‰}}n6|d ‰|d= |d dd'… }|d d' }|d= |j!‰tdddd(ddddddddd)ddd*�}| "|¡ t#| fˆdd+g d,œ|—Ž ˆ $¡ }ˆ %d-¡ |dk	�r�ˆ &dd.d/¡}|d-k�rn|}|j'd0d0||j(d1d1d2� | )d3¡ | d4d5¡}| *¡ }ˆ +¡ \}}|d6k}|�rÂdn|}t,| j-|||ƒ\}}t|tt.j/fƒ�sþt0|||ƒ\}}nd}|d7k�rtd8d9�ntƒ }| "|¡ | d:d;¡|d:< ||d4< | j1f ||ddd<œ|—Ž | d=d¡�rÖdd>l2m3}  | 4d¡ |j5|d j6d |d?�}!t|tt.j/fƒ�r²|! 7|¡ n|dk�rÈ| j8d@dA�}||!_9|! :¡  |
�sü|j;dBdCdD|dk	�rôdEndFdG� ‡‡fdHd„t<||ƒD ƒ}"|"D ]}#ˆj= |#¡ �q|D ]}$ˆj>|$dIdJdKdLddM� �q2t?|ƒ ˆS )Na}	  Plot evoked data as butterfly plot and add topomaps for time points.

    .. note:: Axes to plot in can be passed by the user through ``ts_args`` or
              ``topomap_args``. In that case both ``ts_args`` and
              ``topomap_args`` axes have to be used. Be aware that when the
              axes are provided, their position may be slightly modified.

    Parameters
    ----------
    evoked : instance of Evoked
        The evoked instance.
    times : float | array of float | "auto" | "peaks"
        The time point(s) to plot. If ``"auto"``, 5 evenly spaced topographies
        between the first and last time instant will be shown. If ``"peaks"``,
        finds time points automatically by checking for 3 local maxima in
        Global Field Power. Defaults to ``"peaks"``.
    title : str | None
        The title. If ``None``, suppress printing channel type title. If an
        empty string, a default title is created. Defaults to ''. If custom
        axes are passed make sure to set ``title=None``, otherwise some of your
        axes may be removed during placement of the title axis.
    %(picks_all)s
    exclude : None | list of str | 'bads'
        Channels names to exclude from being shown. If ``'bads'``, the
        bad channels are excluded. Defaults to ``None``.
    show : bool
        Show figure if ``True``. Defaults to ``True``.
    ts_args : None | dict
        A dict of ``kwargs`` that are forwarded to :meth:`mne.Evoked.plot` to
        style the butterfly plot. If they are not in this dict, the following
        defaults are passed: ``spatial_colors=True``, ``zorder='std'``.
        ``show`` and ``exclude`` are illegal.
        If ``None``, no customizable arguments will be passed.
        Defaults to ``None``.
    topomap_args : None | dict
        A dict of ``kwargs`` that are forwarded to
        :meth:`mne.Evoked.plot_topomap` to style the topomaps.
        If it is not in this dict, ``outlines='skirt'`` will be passed.
        ``show``, ``times``, ``colorbar`` are illegal.
        If ``None``, no customizable arguments will be passed.
        Defaults to ``None``.

    Returns
    -------
    fig : instance of matplotlib.figure.Figure | list
        The figure object containing the plot. If ``evoked`` has multiple
        channel types, a list of figures, one for each channel type, is
        returned.

    Notes
    -----
    .. versionadded:: 0.12.0
    r   Nz)ts_args must be dict or None, got type %sr¢   ri   Fr‚   r    rç   c                 3   s   | ]}|ˆ kV  qd S rî   rC   )rD   r`   )ÚargsrC   rH   rð   ™  s     z$plot_evoked_joint.<locals>.<genexpr>zDon't pass any of {} as *_args.ú, rJ   zLIf one of `ts_args` and `topomap_args` contains 'axes', the other must, too.r   )Nrª  r&  Trø   z(topomap_args["proj"] (default True, got z0) must match ts_args["proj"] (default True, got rý   ztopomap_args["proj"])TFrù   rù   )r	  )ÚuniqueZonly_data_chszoCurrently, passing axes manually (via `ts_args` or `topomap_args`) is not supported for multiple channel types.c                    s&   g | ]}t ˆ |ƒˆkrˆ d  | ‘qS rè   )r	   rÍ   )rž   r  rC   rH   rI   È  s    ÿz%plot_evoked_joint.<locals>.<listcomp>Znchan)r­  zsPossibly infinite loop due to channel selection problem. This should never happen! Please check your channel types.)r    r©   r‚   Úts_argsrç   Útopomap_args)Úfew)g       @gÍÌÌÌÌÌ@©rv   r1  rÇ   r/  )r¥   rª   r  r  rø   r  rä   râ   rã   rÑ   rÒ   r  rp   rx   rf   rÈ   )rJ   r‚   r  rç   rÛ   ru   r   r0  Úcenter)Ú	transformr7  r6  ÚoffÚcontoursr¿   rl   ZseegÚlocal)Zextrapolaterƒ   Zskirt)r    rJ   r‚   rÕ   rÕ   )Úticker)Úcaxr%  )Znbinsr„   gÃõ(\�Âí?gìQ¸…ëÁ?rT   g333333ó?)rò   rô   ró   rõ   c                    s   g | ]\}}t |ˆ ˆ|ƒ‘qS rC   )r    )rD   Ú	timepointZmap_ax_)r‡   Úts_axrC   rH   rI   &  s   ÿr;  ú-g      ø?g…ëQ¸å?)rq   r<  r#  rt   rp   )@r‰   rŠ   rï   r  rL  rN  r	  r'   rœ  r    r  r‹   rM  Újoinr�   r   rÁ   rF  rX   r%   r†  r  r   rž   r   ÚNotImplementedErrorZpick_channelsrJ  r
  r�   Úplot_evoked_jointr   r$   r  Úupdater  Z	get_titler–   Zadd_subplotr_   Ú	transAxesr~   ÚpoprS  r   rŸ   rV   r  r=   r9   rE  r·  ÚgridrÕ   rÝ   Ú	set_ticksZMaxNLocatorÚlocatorZupdate_ticksr  r  rP   r�   r   )%rÎ   r    r©   r¥   rç   r‚   r®  r¯  r£   r¨   Zgot_axesZillegal_argsZ
n_topomapsrø   Zproj_tsr�   r  Zev_Z	times_secZtimes_tsZmap_axZcbar_axZts_args_defZ	old_titleZtitle_axrµ  r¤   r€   r�   rP  rÄ  Ztopomap_args_passr·  rr  rP   rM   r¹  rC   )r«  r‡   rž   r  rº  rH   r¾  S  s<   9ÿ
 ÿ
ÿ

ÿ
ÿÿ     þÿÿ
       ü
ÿÿ


þ
ÿ
ÿÿ


ÿÿ
  ÿ
r¾  úyour choicec                 C   sx   dddœ  ||¡}t| ttjfƒr*| r*|} dddddddd	d
ddœ
}|  | | ¡}|tdƒkrttt| ƒd | d ƒ‚|S )z:Check if loc is a legal location for MPL subordinate axes.r   r   )r€  Úshow_sensorsru   r&  r%  r¿   é   é   é	   r•  )
r–  z
upper leftz
lower leftúlower rightrô   zcenter leftzcenter rightzlower centerzupper centerr²  é   z8 is not a legal MPL loc, please supplyanother value for r½   )rœ  rï   rG  rV   Zbool_rJ  r‹   rÁ   )r¹   ÚwhatÚdefaultZtrue_defaultZloc_dictZloc_rC   rC   rH   Ú_check_loc_legal9  s(        ýÿÿrÎ  c                 C   s  t | ƒ} t| ƒ | |¡¡s0td t| ƒ|¡ƒ‚|D ]¬}|| krLtƒ | |< njd| | krp| |  d¡| | d< nFd| | kr”| |  d¡| | d< n"d| | kr¶| |  d¡| | d< | 	d¡D ]}|| krÀ| |  
| | ¡ qÀq4t| ƒD ]}||krê| |= qê| S )	z3Validate styles dict keys for plot_compare_evokeds.z@The keys in "styles" ({}) must match the keys in "evokeds" ({}).rd  rq   r£  r<  r”  r#  ú/)r   r  ÚissubsetÚunionr‹   rM  r�   r  rÁ  Úsplitr¿  )ÚstylesÚ
conditionsÚtagsÚcondÚtagÚkeyrC   rC   rH   Ú_validate_style_keys_pceI  s,     ÿrÙ  c                 C   sª  d}| dkr0|dkr t ƒ } d}nttt|ƒƒƒ} t| tttjfƒrzt|ƒt| ƒkrltd 	t|ƒt| ƒ|¡ƒ‚t
t|| ƒƒ} t| t
ƒs˜td 	t| ƒj¡ƒ‚t| ƒ | |¡¡sÀtd 	t| ƒ|¡ƒ‚t|  ¡ ƒ}tdd„ |D ƒƒ}|dk	rþ|sþtd	 	d
 |¡¡ƒ‚tdd„ |D ƒƒ}|�rˆt| ƒ} dd„ ttt|ƒƒƒD ƒ}|  ¡ D ]\}	}
||
 | |	< �q@|dk�rˆt ƒ }|  ¡ D ]\}}|| | |< �qpt|  ¡ ƒ}|�r¢t|ƒ}| |fS )z1Check and assign colors for plot_compare_evokeds.rÛ   Nz in the default color cyclez]Trying to plot {} conditions, but there are only {} colors{}. Please specify colors manually.z/"colors" must be a dict, list, or None; got {}.zUIf "colors" is a dict its keys ({}) must match the keys/conditions in "evokeds" ({}).c                 s   s   | ]}t |ƒV  qd S rî   )r5   ©rD   Ú_colorrC   rC   rH   rð   �  s     z'_validate_colors_pce.<locals>.<genexpr>zcif "cmap" is specified, then "colors" must be None or a (list or dict) of (ints or floats); got {}.r¬  c                 S   s   g | ]}t |tƒ‘qS rC   ©rï   r   rÚ  rC   rC   rH   rI   ‡  s     z(_validate_colors_pce.<locals>.<listcomp>c                 S   s   i | ]\}}||“qS rC   rC   )rD   ZixÚvalrC   rC   rH   rÐ   Š  s      z(_validate_colors_pce.<locals>.<dictcomp>)r!   r�   rJ  rX   rï   rI  rV   r  r‹   rM  r  r  rL  rN  Ú__name__r  rÐ  rÑ  r  rå   r¼  r   r“   r  Úitems)rÂ   r   rÔ  rÕ  Z
err_suffixÚ
color_valsZall_numericÚall_intZranksrØ  Zorig_intZ
color_listrÖ  Z	color_intrC   rC   rH   Ú_validate_colors_pcef  sV      þ
ÿ þþ
râ  c                 C   sœ   ddl m} ddlm} tdd„ |D ƒƒ}|r6t|ƒnd}d}t| ttt	j
fƒrdt| ƒdkrd| \}} t| tƒr||| |d	�} nt| |ƒr”|r”|  |¡} | |fS )
z3Check and assign colormap for plot_compare_evokeds.r   )Úget_cmap)ÚColormapc                 S   s   g | ]}t |tƒ‘qS rC   rÜ  rÚ  rC   rC   rH   rI   �  s     z&_validate_cmap_pce.<locals>.<listcomp>NrÛ   r   )Úlut)Zmatplotlib.cmrã  Zmatplotlib.colorsrä  rå   rX   rï   r�   rI  rV   r  rÁ   Z	_resample)r   rÂ   rà  rã  rä  rá  rå  Úcolorbar_titlerC   rC   rH   Ú_validate_cmap_pce™  s    

rç  c              	   C   sà   | dkrdgt |ƒ } t| tttjfƒr^t |ƒt | ƒkrPtd t |ƒt | ƒ¡ƒ‚tt	|| ƒƒ} t| tƒs|t
d t| ƒj¡ƒ‚t| ƒ | |¡¡s¤td t| ƒ|¡ƒ‚ddddddddd	œ}|  ¡ D ]\}}| ||¡| |< qÂ| S )
z5Check and assign linestyles for plot_compare_evokeds.NzcTrying to plot {} conditions, but there are only {} linestyles. Please specify linestyles manually.z3"linestyles" must be a dict, list, or None; got {}.zYIf "linestyles" is a dict its keys ({}) must match the keys/conditions in "evokeds" ({}).©r   rC   )r   )rT   gffffffú?)r   )gš™™™™™@çš™™™™™ù?)r   )r÷   ré  rT   ré  )ÚsolidZdottedZdashedZdashdotr»  r¢  r4  z-.)rX   rï   r�   rI  rV   r  r‹   rM  r  r  rL  rN  rÞ  r  rÐ  rÑ  rß  rœ  )Ú
linestylesrÔ  rÕ  Zlinestyle_maprÖ  Z_lsrC   rC   rH   Ú_validate_linestyles_pce©  s<     ý
ÿ þùrì  c                 C   s¤   t ddd�}| |d¡dkr z||  ||< W nr tk
rž   |  d¡D ]R}z|| ||< W n  tk
rz   || ||< Y qFX |dkr”|dk	r”||d<  qšqFY nX |S )zDTransfer styles into condition_styles dict for plot_compare_evokeds.Úgrayrè  ©rq   r<  NrÏ  rq   Ú
cmap_label)r  rœ  ÚKeyErrorrÒ  )Ú	conditionZcondition_stylesÚ
style_nameZ
style_dictr   Údefaultsr×  rC   rC   rH   Ú_populate_style_dict_pceÎ  s    rô  c                 C   sD  t | ƒ} tdd„ |D ƒƒ}| dkr0dd„ |D ƒ} t| ||ƒ} t||||ƒ\}}tdd„ |D ƒƒ}t|||ƒ\}}t|||ƒ}|dkrˆdntƒ }	t 	dd	d
t
|ƒ d	 ¡d	dd
… }
t||d�}|  ¡ D ]l\}}| ¡ D ]\}}t|||||ƒ}qÖ|dk	rÆ|d }||ƒ|d< |�r|
| n|}| d|¡}||	|< qÆ| |||||	fS )z1Check and assign styles for plot_compare_evokeds.c                 s   s"   | ]}|  d ¡D ]
}|V  qqdS )rÏ  N)rÒ  )rD   rÖ  r×  rC   rC   rH   rð   î  s       z%_handle_styles_pce.<locals>.<genexpr>Nc                 S   s   i | ]}|t ƒ “qS rC   )r  ©rD   rÖ  rC   rC   rH   rÐ   ð  s      z&_handle_styles_pce.<locals>.<dictcomp>c                 S   s   g | ]}t |tƒ‘qS rC   rÜ  rÚ  rC   rC   rH   rI   ô  s     z&_handle_styles_pce.<locals>.<listcomp>r   r   r   rî  rq   rï  )r   r  rÙ  râ  rå   rç  rì  r  rV   r�  rX   rß  rô  rÁ  )rÓ  rë  rÂ   r   rÔ  rÕ  rà  rá  ræ  Úcolorbar_ticksZ	tick_locsZcolor_and_linestylerÖ  Úcond_stylesÚ_nameÚ_styleÚcolor_numberZtick_locrØ  rC   rC   rH   Ú_handle_styles_pceê  s2    $ ÿ
rû  c           	   	   C   sl   |dkr*t  | ¡ ¡\}}||kr&dnd}t| ||d�\}}t|dƒ}t|dgt|ƒ |tƒ ||dd� d	S )
z>Show sensor legend (location of a set of sensors on the head).TrÊ  r–  rw   rÆ  r-  rj  r™  N)rV   r‘   rS  r:   rÎ  rÆ   rX   r�   )	rž   r¥   ÚyminÚymaxrÆ  rG   rx   r¦   rƒ   rC   rC   rH   Ú_evoked_sensor_legend  s    
 ÿrþ  c                 C   sÔ  ddl m} ddlm} ddlm} |  ¡ }|| ƒ}	|	jdddd�}
|
j 	¡  ||
|d	d
d�}| 
|¡ tt| ¡ ƒƒ}dgt|ƒ }| ¡ D ]>\}}| |¡}t|| ƒrÄd || |g¡||< qŽ|||< qŽtdd„ |D ƒƒsät‚| |¡ | |¡ t| ¡ ƒ}tdd„ |D ƒƒ�rÐ|  ¡ }|j ¡  tj| ¡ Ž }|  ¡ }d|j|j  }tdtdd„ |D ƒƒƒ}t|ƒ| | | }|j| }|j|j | d }|j}|| }|||g||ggƒ}|
  d	¡ |
 !|¡ d	S )z'Draw colorbar for plot_compare_evokeds.r   )Úmake_axes_locatable)ÚColorbarBase)ÚBboxrô   z5%r„   )rÄ   r†   NÚvertical)r   rP  ZorientationrÛ   Ú
c                 s   s   | ]}t |ƒV  qd S rî   )rX   ©rD   ra  rC   rC   rH   rð   2  s     z%_draw_colorbar_pce.<locals>.<genexpr>c                 S   s   g | ]}t |tƒ‘qS rC   rÜ  rÚ  rC   rC   rH   rI   7  s     z&_draw_colorbar_pce.<locals>.<listcomp>r"  r   c                 S   s   g | ]}t | d ¡ƒ‘qS )r  )rX   rÒ  r  rC   rC   rH   rI   >  s     )"Zmpl_toolkits.axes_grid1rÿ  Zmatplotlib.colorbarr   Zmatplotlib.transformsr  Zget_positionZappend_axesZyaxisZ
tick_rightZ	set_labelr  r  r  rX   rß  rê   r¼  rå   rF  rÃ  Zset_ticklabelsr¬   re   rf   rV   ÚdivideZget_size_inchesrœ   r˜   rý  rü  Zset_axes_locatorZset_position)rG   rÂ   r   ræ  rö  rÿ  r   r  Z	orig_bboxÚdividerr¸  ÚcbZticksZ
ticklabelsra  Ztickrg   rà  r‡   Z
fig_aspectZnew_bboxZ	cax_widthZh_multZ
cax_heightZx0Zy0Úx1Úy1rC   rC   rH   Ú_draw_colorbar_pce  sF    








r
  c                 C   s–  ddl m} tƒ }	|dkr"|dk	}tt| ¡ ƒƒ}
tt| ¡ ƒƒ}|dkoN| }|dkob|ob|
dk}|dksp|ov|dk}|r²| ¡ D ]*\}}|jg g fd|i|—Ž}|	 |¡ q„nj|ræ| ¡ D ]&\}}|jg g |d|d�}|	 |¡ q¾|�r| ¡ D ]&\}}|jg g ||dd�}|	 |¡ qôdt|	ƒd  }t	| d	ƒ}t
|d
|d�}|�rdt| tƒ�rd|jddd� t|||gƒ�r’dd„ |	D ƒ}|j|	|f|Ž dS )z%Draw legend for plot_compare_evokeds.r   Nr   ra  rê  )ra  r<  rq   Úblackr%  r€  T)r¹   ZframeonÚncolrÊ  )r   r   )r¹   rš  c                 S   s   g | ]}|  ¡ ‘qS rC   )Z	get_labelrL   rC   rC   rH   rI   o  s     z$_draw_legend_pce.<locals>.<listcomp>)Zmatplotlib.linesrP   r�   rX   r  r  rß  ZLine2Dr�   rÎ  r  rï   rG  r¿  r  r€  )r€  Úsplit_legendrÓ  rë  rÂ   r   Údo_toporG   ZmlinesrP   Zn_colorsZn_linestylesZdraw_stylesZdraw_colorsZdraw_linestylesra  r÷  rM   rq   r<  r  r¹   Zlegend_paramsr¨  rC   rC   rH   Ú_draw_legend_pceI  sB    ÿÿ
r  c                 C   s  ||kr|d7 }||kr |d7 }|   ||¡ | j d¡ t ||g¡ ¡ sNdS |  ||¡ ||f}|dkrndn|}|rÚt|tƒrªt 	||g¡d }d}t 
|| ¡| }n0|dkrÌt|  ¡ ||ƒdd	g }ntd
 |¡ƒ‚t| ||||d |d ||	|||
|d� dS )z;Position, draw, and truncate axes for plot_compare_evokeds.gVçž¯Ò<g•Ö&è.>r   Nri  Tr…   rÊ   r1  z/"truncate_yaxis" must be bool or "auto", got {}r   )r¢   )rV  Úpatchr[   rV   Úisfiniterå   rW  rï   rG  r®   ro  r)   rp  r‹   rM  r"   )rG   rü  rý  Útruncate_yaxisÚtruncate_xaxisÚinvert_yÚvlinesÚtminÚtmaxrª   Úskip_axlabelr¢   ZyboundsZtrunc_yÚ	precisionrC   rC   rH   Ú_draw_axes_pces  s8    
ÿ   þr  c                    s„   t  ˆ ¡ ¡ ‰ t  ‡ ‡fdd„| D ƒ¡}|dk	rHt d |¡¡ ||ƒ}|dk	rX||ƒ}t j|dd�}t|ƒ |dkr||fS ||fS )z@Compute (sensor-aggregated, scaled) time series and possibly CI.c                    s   g | ]}|j ˆ  ˆ ‘qS rC   )rŸ   )rD   Úevk©r¥   ÚscalingrC   rH   rI   œ  s     z$_get_data_and_ci.<locals>.<listcomp>Nzcombining channels using "{}"r   r}   )rV   r®   Úflattenr,   rž   rM  r{   r2   )rÎ   ÚcombineÚcombine_funcr¥   r  Úci_funrŸ   rž  rC   r  rH   Ú_get_data_and_ci—  s    r"  c                 C   s€   | dkrdS t | ƒr| S t| tƒr*| s*dS t| tƒr8d} t| tƒrhddlm} |rVdnd}t|| |d�S td t	| ƒj
¡ƒ‚dS )	z:Get confidence interval function for plot_compare_evokeds.Nçffffffî?r   )Ú_ciZ
parametricZ	bootstrap)rž  r|   z2"ci" must be None, bool, float or callable, got {})rK  rï   rG  r  Ústatsr$  r   rL  rM  rN  rÞ  )rž  r  r$  r|   rC   rC   rH   Ú_get_ci_function_pceª  s    

ÿr&  c	              
   C   s¤   |D ]v}	||	 j }
| j||
fd|	ddœ||	 —Ž | |	d¡dk	r||	 }| j||d  ¡ |d  ¡ d||	 d d	dd
� q|r–| jdd|| jd� n
|  |¡ dS )z>Plot evokeds (to compare them; with CIs) based on a data_dict.iè  F)rp   ra  r8  Nr   r   rÉ  rq   g333333Ó?)rp   rq   rt   r8  gš™™™™™¹¿)r³  )r¯   rO  rœ  rT  r  r_   rÀ  r–   )rG   Ú	data_dictrÔ  r    Úci_dictrÓ  r©   Zall_positiveÚtoporñ  ZdatZci_rC   rC   rH   Ú_plot_compare_evokeds½  s     
ÿ 
 þr*  c                 C   sŒ   | dkr(|rt dƒ |d¡n
t| ||ƒ} |p6t|ƒdk}| dk	rˆt| ƒrˆt|tƒrˆ|rˆ|dkrf| ¡ n|}|dkrvdn|}| d |¡7 } | S )z&Format title for plot_compare_evokeds.Nrã   r   rÑ   r/  z	std. dev.z ({}))r   rœ  r&   rX   rï   rÁ   r•   rM  )r©   Úpicked_typesr¥   rQ   r  Z
do_combineZ_combrC   rC   rH   Ú_title_helper_pceÑ  s    
ÿÿr,  c                 C   s8   | dkrdS |   dd¡} |  d¡r4d| dd… › �} | S )z—Replace ASCII-encoded "minus-hyphen" characters with Unicode minus.

    Aux function for ``plot_compare_evokeds`` to prettify ``Evoked.comment``.
    Nz - u    âˆ’ r»  u   âˆ’r   )ÚreplaceÚ
startswith)ri   rC   rC   rH   Ú_ascii_minus_to_unicodeà  s    
r/  c           g         sŽ	  ddl m‰ ddlm}m} t| |ƒr,| g} t| ttfƒr®|  ¡ }t	ƒ } dd„ |D ƒ}t
t||ƒƒD ]F\}\}}t|d ƒ}|r¢| |¡dkr”|}n|› d|› �}|| |< qd~t| t	ƒsÌtd	 t| ƒj¡ƒ‚t| ƒ} |  ¡ D ]H\}}t|d
dƒ t||ƒ�r|g| |< | | D ]}t||ddƒ �qqÜt|  ¡ g ƒ} || ƒ ~ t| ƒ}!| |!d  d }"|"j}#|"j}$tˆ|$ƒ‰t||"jƒ\}}#|#d |#d  }%}&|
dk�ržt	ƒ }
|dk�rÎ|%d  k �rÀ|&k �rÊn ndgng }t|ttfddƒ t|ƒ}'t|$|dd�\}}(t |"j¡|  ¡ })dd„ t |$|dd�D ƒ}*t!|$|ƒ‰ t‡ fdd„|*D ƒg ƒ}+t "||+¡}|dk�rjt#|ƒdk}t|ddtfdd� t#|ƒdk �rª|dk	�rªt$d t#|ƒ|¡ƒ t|tƒ�o¼|dk},|dk�ràt#|ƒdk�rà|,�sàd}t%|ƒ}-t&||(|'|)|d�}|,�r,d}t#|ƒd k�rt' d!¡ dgt#|*ƒ }nB|dk�rJ‡fd"d#„|*D ƒ}n$t|ˆj(ƒ�rn|g}t)|t#|*ƒd$� t#|*ƒdk�rt' d%¡ tƒ }.t|*|ƒD ]x\}/}0ˆ |/ }1t |"j¡|1  ¡ }2|(�rÄ|/n|1}1t&||(|1|2dd�}3|. *t+| |1||||||||
||||0|3||ˆd&�¡ �q–|.S t,|||||!ƒ\}4}5}6}7}8}9t#|*ƒdk�sBt-‚|*d }/t.d'ƒ|/ }:t.d(ƒ|/ };|}<t/|$|dd)�}$|$d* }=|,�s¬d+d„ |D ƒ}t |¡j0dk �rÚ|g}�n.dd,l1m2}> ˆj3d-d.�}?| ||||||||	|
||||||f‡fd/d0„	}@t4|$ƒ}Ad1}Bd2}C|Aj5d3 }D|Aj5d4 }E|Aj5dd…df  6¡ }F|Aj5dd…df  7¡ |D }G|Aj5dd…df  6¡ }H|Aj5dd…df  7¡ |E }Id5d|B  |G|F  }Jd6d|C  |I|H  }K|Aj5dd…df |F |J |B d7 |Aj5dd…df< |Aj5dd…df |H |K |C d7 |Aj5dd…df< |Aj5dd…df }L|Aj5dd…df }M|L 7¡ }N|M 6¡ }Ot 8t 9t 9|L|Nk|N|L|D k¡t 9|M|Ok|O|M|E k¡¡¡}P|N|D }G|G|L 6¡  |D }Q|Q|Qd  }R|P�r´|Aj5dd…ddgf  |R9  < t|>|$|A|@|?d8d8d9ddd:�	ƒ}t|ƒ}~$|,�rædn|-}Stƒ }Ttƒ }Ut||ƒD ]¤\}1\}0}t	ƒ }Vt	ƒ }W|!D ]p}| | }Xt:||,d;�}Yt;|ƒ�sTt#|Xƒdk�rP|Ynd}Yt<|X||S|1|;|Yd<�}Z|Zd |V|< |Ydk	�r|Zd |W|< �q|T =|V¡ |U =|W¡ �q ~ tƒ }[|TD ]*}\t|\ ¡ ƒD ]}]|[ =|]tj> ¡ �qÂ�q²|UD ]}\|[ *t|\ ¡ ƒ¡ �qât ?|[¡}[t @|[dk¡}^|
 A|/ddg¡\}_}`tB|[|_|`|^ƒ\}a}b~[|,�rt|T =d=d>„ |VD ƒ¡ |U =d?d>„ |WD ƒ¡ |= =d@¡ t||T|UƒD ]t\\}0}}c}d|,�rœ|=| }|dk�rªg n|#}etC|0|c|!|e|d|4||^|,ƒ	 |,�oÒ|dk}ftD|0|a|b||	|||%|&|:|f|ƒ �q€|�	rHt|tjEtFttdƒfdAdBƒ tG|"j|<dC��	s2t$dDƒ ntH|"j|<|a|b||0ˆƒ |�	rdtI|||4|5|6|7|,|0ƒ |dk	�	r~tJ|0|6|7|8|9ƒ tK|ƒ |0j3gS )Eu¹0  Plot evoked time courses for one or more conditions and/or channels.

    Parameters
    ----------
    evokeds : instance of mne.Evoked | list | dict
        If a single Evoked instance, it is plotted as a time series.
        If a list of Evokeds, the contents are plotted with their
        ``.comment`` attributes used as condition labels. If no comment is set,
        the index of the respective Evoked the list will be used instead,
        starting with ``1`` for the first Evoked.
        If a dict whose values are Evoked objects, the contents are plotted as
        single time series each and the keys are used as labels.
        If a [dict/list] of lists, the unweighted mean is plotted as a time
        series and the parametric confidence interval is plotted as a shaded
        area. All instances must have the same shape - channel numbers, time
        points etc.
        If dict, keys must be of type str.
    %(picks_all_data)s

        * If picks is None or a (collection of) data channel types, the
          global field power will be plotted for all data channels.
          Otherwise, picks will be averaged.
        * If multiple channel types are selected, one
          figure will be returned for each channel type.
        * If the selected channels are gradiometers, the signal from
          corresponding (gradiometer) pairs will be combined.

    colors : list | dict | None
        Colors to use when plotting the ERP/F lines and confidence bands. If
        ``cmap`` is not ``None``, ``colors`` must be a :class:`list` or
        :class:`dict` of :class:`ints <int>` or :class:`floats <float>`
        indicating steps or percentiles (respectively) along the colormap. If
        ``cmap`` is ``None``, list elements or dict values of ``colors`` must
        be :class:`ints <int>` or valid :doc:`matplotlib colors
        <matplotlib:tutorials/colors/colors>`; lists are cycled through
        sequentially,
        while dicts must have keys matching the keys or conditions of an
        ``evokeds`` dict (see Notes for details). If ``None``, the current
        :doc:`matplotlib color cycle
        <matplotlib:gallery/color/color_cycle_default>`
        is used. Defaults to ``None``.
    linestyles : list | dict | None
        Styles to use when plotting the ERP/F lines. If a :class:`list` or
        :class:`dict`, elements must be valid :doc:`matplotlib linestyles
        <matplotlib:gallery/lines_bars_and_markers/linestyles>`. Lists are
        cycled through sequentially; dictionaries must have keys matching the
        keys or conditions of an ``evokeds`` dict (see Notes for details). If
        ``None``, all lines will be solid. Defaults to ``None``.
    styles : dict | None
        Dictionary of styles to use when plotting ERP/F lines. Keys must match
        keys or conditions of ``evokeds``, and values must be a :class:`dict`
        of legal inputs to :func:`matplotlib.pyplot.plot`. Those values will be
        passed as parameters to the line plot call of the corresponding
        condition, overriding defaults (e.g.,
        ``styles={"Aud/L": {"linewidth": 3}}`` will set the linewidth for
        "Aud/L" to 3). As with ``colors`` and ``linestyles``, keys matching
        conditions in ``/``-separated ``evokeds`` keys are supported (see Notes
        for details).
    cmap : None | str | tuple | instance of matplotlib.colors.Colormap
        Colormap from which to draw color values when plotting the ERP/F lines
        and confidence bands. If not ``None``, ints or floats in the ``colors``
        parameter are mapped to steps or percentiles (respectively) along the
        colormap. If ``cmap`` is a :class:`str`, it will be passed to
        :func:`matplotlib.cm.get_cmap`; if ``cmap`` is a tuple, its first
        element will be used as a string to label the colorbar, and its
        second element will be passed to :func:`matplotlib.cm.get_cmap` (unless
        it is already an instance of :class:`~matplotlib.colors.Colormap`).

        .. versionchanged:: 0.19
            Support for passing :class:`~matplotlib.colors.Colormap` instances.

    vlines : "auto" | list of float
        A list in seconds at which to plot dashed vertical lines.
        If "auto" and the supplied data includes 0, it is set to [0.]
        and a vertical bar is plotted at time 0. If an empty list is passed,
        no vertical lines are plotted.
    ci : float | bool | callable | None
        Confidence band around each ERP/F time series. If ``False`` or ``None``
        no confidence band is drawn. If :class:`float`, ``ci`` must be between
        0 and 1, and will set the threshold for a bootstrap
        (single plot)/parametric (when ``axes=='topo'``)  estimation of the
        confidence band; ``True`` is equivalent to setting a threshold of 0.95
        (i.e., the 95%% confidence band is drawn). If a callable, it must take
        a single array (n_observations Ã— n_times) as input and return upper and
        lower confidence margins (2 Ã— n_times). Defaults to ``True``.
    truncate_yaxis : bool | 'auto'
        Whether to shorten the y-axis spine. If 'auto', the spine is truncated
        at the minimum and maximum ticks. If ``True``, it is truncated at the
        multiple of 0.25 nearest to half the maximum absolute value of the
        data. If ``truncate_xaxis=False``, only the far bound of the y-axis
        will be truncated. Defaults to 'auto'.
    truncate_xaxis : bool
        Whether to shorten the x-axis spine. If ``True``, the spine is
        truncated at the minimum and maximum ticks. If
        ``truncate_yaxis=False``, only the far bound of the x-axis will be
        truncated. Defaults to ``True``.
    ylim : dict | None
        Y-axis limits for plots (after scaling has been applied). :class:`dict`
        keys should match channel types; valid keys are eeg, mag, grad, misc
        (example: ``ylim=dict(eeg=[-20, 20])``). If ``None``, the y-axis limits
        will be set automatically by matplotlib. Defaults to ``None``.
    invert_y : bool
        Whether to plot negative values upward (as is sometimes done
        for ERPs out of tradition). Defaults to ``False``.
    show_sensors : bool | int | str | None
        Whether to display an inset showing sensor locations on a head outline.
        If :class:`int` or :class:`str`, indicates position of the inset (see
        :func:`mpl_toolkits.axes_grid1.inset_locator.inset_axes`). If ``None``,
        treated as ``True`` if there is only one channel in ``picks``. If
        ``True``, location is upper or lower right corner, depending on data
        values. Defaults to ``None``.
    legend : bool | int | str
        Whether to show a legend for the colors/linestyles of the conditions
        plotted. If :class:`int` or :class:`str`, indicates position of the
        legend (see :func:`mpl_toolkits.axes_grid1.inset_locator.inset_axes`).
        If ``True``, equivalent to ``'upper left'``. Defaults to ``True``.
    split_legend : bool | None
        Whether to separate color and linestyle in the legend. If ``None``,
        a separate linestyle legend will still be shown if ``cmap`` is
        specified. Defaults to ``None``.
    axes : None | Axes instance | list of Axes | 'topo'
        :class:`~matplotlib.axes.Axes` object to plot into. If plotting
        multiple channel types (or multiple channels when ``combine=None``),
        ``axes`` should be a list of appropriate length containing
        :class:`~matplotlib.axes.Axes` objects. If ``'topo'``, a new
        :class:`~matplotlib.figure.Figure` is created with one axis for each
        channel, in a topographical layout. If ``None``, a new
        :class:`~matplotlib.figure.Figure` is created for each channel type.
        Defaults to ``None``.
    title : str | None
        Title printed above the plot. If ``None``, a title will be
        automatically generated based on channel name(s) or type(s) and the
        value of the ``combine`` parameter. Defaults to ``None``.
    show : bool
        Whether to show the figure. Defaults to ``True``.
    %(combine)s
        If callable, the callable must accept one positional input (data of
        shape ``(n_evokeds, n_channels, n_times)``) and return an
        :class:`array <numpy.ndarray>` of shape ``(n_epochs, n_times)``. For
        example::

            combine = lambda data: np.median(data, axis=1)

        If ``combine`` is ``None``, channels are combined by computing GFP,
        unless ``picks`` is a single channel (not channel type) or
        ``axes='topo'``, in which cases no combining is performed. Defaults to
        ``None``.
    %(sphere_topomap_auto)s
    %(time_unit)s

        .. versionadded:: 1.1

    Returns
    -------
    fig : list of Figure instances
        A list of the figure(s) generated.

    Notes
    -----
    If the parameters ``styles``, ``colors``, or ``linestyles`` are passed as
    :class:`dicts <python:dict>`, then ``evokeds`` must also be a
    :class:`python:dict`, and
    the keys of the plot-style parameters must either match the keys of
    ``evokeds``, or match a ``/``-separated partial key ("condition") of
    ``evokeds``. For example, if evokeds has keys "Aud/L", "Aud/R", "Vis/L",
    and "Vis/R", then ``linestyles=dict(L='--', R='-')`` will plot both Aud/L
    and Vis/L conditions with dashed lines and both Aud/R and Vis/R conditions
    with solid lines. Similarly, ``colors=dict(Aud='r', Vis='b')`` will plot
    Aud/L and Aud/R conditions red and Vis/L and Vis/R conditions blue.

    Color specification depends on whether a colormap has been provided in the
    ``cmap`` parameter. The following table summarizes how the ``colors``
    parameter is interpreted:

    .. cssclass:: table-bordered
    .. rst-class:: midvalign

    +-------------+----------------+------------------------------------------+
    | ``cmap``    | ``colors``     | result                                   |
    +=============+================+==========================================+
    |             | None           | matplotlib default color cycle; unique   |
    |             |                | color for each condition                 |
    |             +----------------+------------------------------------------+
    |             |                | matplotlib default color cycle; lowest   |
    |             | list or dict   | integer mapped to first cycle color;     |
    |             | of integers    | conditions with same integer get same    |
    | None        |                | color; unspecified conditions are "gray" |
    |             +----------------+------------------------------------------+
    |             | list or dict   | ``ValueError``                           |
    |             | of floats      |                                          |
    |             +----------------+------------------------------------------+
    |             | list or dict   | the specified hex colors; unspecified    |
    |             | of hexadecimal | conditions are "gray"                    |
    |             | color strings  |                                          |
    +-------------+----------------+------------------------------------------+
    |             | None           | equally spaced colors on the colormap;   |
    |             |                | unique color for each condition          |
    |             +----------------+------------------------------------------+
    |             |                | equally spaced colors on the colormap;   |
    |             | list or dict   | lowest integer mapped to first cycle     |
    | string or   | of integers    | color; conditions with same integer      |
    | instance of |                | get same color                           |
    | matplotlib  +----------------+------------------------------------------+
    | Colormap    | list or dict   | floats mapped to corresponding colormap  |
    |             | of floats      | values                                   |
    |             +----------------+------------------------------------------+
    |             | list or dict   |                                          |
    |             | of hexadecimal | ``TypeError``                            |
    |             | color strings  |                                          |
    +-------------+----------------+------------------------------------------+
    r   Nr   )ÚEvokedÚ_check_evokeds_ch_names_timesc                 S   s   g | ]}t t|d dƒƒ‘qS )r¥  N)r/  Úgetattr)rD   Z_evkrC   rC   rH   rI   ×  s   ÿz(plot_compare_evokeds.<locals>.<listcomp>r   z: zA"evokeds" must be a dict, list, or instance of mne.Evoked; got {}rÁ   Z
ConditionszAll evokeds entries r0  r1  ri  rd   r  zlist or tupleT)Zreturn_kindc                 S   s   g | ]}|t d  kr|‘qS ))Úmisc)r   )rD   rs  rC   rC   rH   rI   	  s    ÿ)r¥   r­  c                    s   g | ]}ˆ | ‘qS rC   rC   )rD   r¤   )Úpicks_by_typerC   rH   rI   	  s     rK  r  )r   Z	item_namez:Only {} channel in "picks"; cannot combine by method "{}".r)  rÑ   )r¥   rQ   r  FéF   z˜You are plotting to a topographical layout with >70 sensors. This can be extremely slow. Consider using mne.viz.plot_topo, which is optimized for speed.c                 3   s   | ]}ˆ j d d�d V  qdS ))rÈ  r¿   r±  r   N)r’   )rD   r¨   r‘  rC   rH   rð   *	  s     z'plot_compare_evokeds.<locals>.<genexpr>)Zobligatory_lenz?Multiple channel types selected, returning one figure per type.)r¥   rÂ   r   rë  rÓ  r  rž  r  r  r  r€  rÆ  rJ   r©   r  r‚   rx   rä   râ   )rÏ   r	  rQ   c                 S   s   g | ]}|d f‘qS rÜ   rC   rc   rC   rC   rH   rI   W	  s     )Úiter_topography)é   é   r±  c                    s6   t ||||||||	|
||||||| || dˆ d� d S )NT)ÚevokedsrÂ   rë  rÓ  r   r  rž  r  r  r  r  rÆ  r€  r  r¥   r  rJ   r‚   rx   )Úplot_compare_evokeds)Zax_Zpick_r9  rÂ   rë  rÓ  r   r  rž  r  r  r  r  rÆ  r€  r  r¥   r  rw   rC   rH   Ú
click_func^	  s*                ùz(plot_compare_evokeds.<locals>.click_funcgÇqÇqŒ?g’$I’$I’?)r   r   )r   ru   r#  r—  gš™™™™™™?rÀ   r-  )rx  Zon_pickr‡   r|  r~  Zaxis_spinecolorry  r€  )r  )r¥   r  r!  c                 S   s   i | ]}|t  g ¡“qS rC   )rV   r®   rõ  rC   rC   rH   rÐ   Ä	  s      z(plot_compare_evokeds.<locals>.<dictcomp>c                 S   s   i | ]
}|d “qS rî   rC   rõ  rC   rC   rH   rÐ   Å	  s      rÛ   rÆ  znumeric, str, None or boolr,  zWCannot find channel coordinates in the supplied Evokeds. Not showing channel locations.)Lr‰   rŠ   rÎ   r0  r1  rï   r�   rI  r	  r  r“   r  rÁ   ÚcountrL  rM  rN  rÞ  r   rß  r1   rŽ  r  r    rž   r>   r'   r   rV   r®   rQ   Útolistr   r   rn  rX   r.   r   r,  r,   r  r   Úextendr:  rû  rF  r   r   Úndimr)  r6  r  rA   r¦   r—   r˜   r  Úlogical_andr&  rK  r"  r�   Znewaxisr¤  rå   rœ  r   r*  r  Zint64rG  r3   rþ  r  r
  r   )gr9  r¥   rÂ   rë  rÓ  r   r  rž  r  r  r  r  rÆ  r€  r  rJ   r©   r‚   r  rx   r¢   r0  r1  Zevokeds_copyÚcommentsrg   r¥  Z_evokedrØ  rÖ  rÎ   r  Z
all_evokedrÔ  Z
one_evokedr    rž   r  r  Z
orig_picksr+  rQ   r�   Z
good_picksr  r   r  r¤   rG   Z_picksZ	_ch_namesÚ_titleÚ_stylesZ_linestylesÚ_colorsZ_cmapræ  rö  rä   râ   Z	pos_picksZall_ch_namesr6  r‡   r;  rx  Zw_marginZh_marginZ
axes_widthZaxes_heightZ	left_edgeZ
right_edgeZbottom_edgeZtop_edgeZw_scaleZh_scaleZ
data_leftsZdata_bottomsZlegend_leftZlegend_bottomZoverlaprŸ  Zscale_factorZc_funcZall_dataZall_cisr'  r(  Zthis_evokedsr!  ÚresZ	allvaluesÚ_dictZ_arrayrP  Z	orig_yminZ	orig_ymaxrü  rý  rŸ   ZcisZ_timesr  rC   )r4  r£   rx   rH   r:  ñ  s&    \
ÿ

ÿ



&

 ÿ ÿ


 ÿ            ú
ÿÿ
          ú

ÿÿÿÿ
þ
þü	      ý

 ÿ



  ÿ     þ ÿ
  ÿ  ÿ
r:  )NFri   N)r´   )NrÃ   TTNFrÇ   NNNNNrÈ   NFNFTrÉ   NTNNNrÊ   ri   FNN)	TNNNrÊ   Nri   FN)NrÃ   TTNrÇ   FNNNNNFNFrÉ   TNri   N)NrÃ   TTNrÇ   FNNNNr‚  TNNrƒ  rÊ   ri   ri  NN)TNri   NNN)TNN)rª  rÛ   NNTNN)rÅ  r   )Tri   )r   N)F)NNNNNri  Tri  TNFNTNNNTNNri   )nÚ__doc__r	  r   Ú	functoolsr   Ú	itertoolsr   Únumbersr   ÚnumpyrV   Úfixesr   Zio.pickr	   r
   r   r   r   r   r   r   r   ró  r   Úutilsr   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/   r0   r1   r2   r3   r4   r5   r6   r)  r7   Ztopomapr8   r9   r:   r;   r<   r=   r>   r?   r”   r@   rA   rb   rh   r«   rš   r³   rÆ   r  r  rX  rH  r  ru  r�  r„  r  r   r©  r¾  rÎ  rÙ  râ  rç  rì  rô  rû  rþ  r
  r  r  r"  r&  r*  r,  r/  r:  rC   rC   rC   rH   Ú<module>   sz  ,h	4(      ÿ
H
                                           ø	 ÷ J =	               ý
A                             ü û           û
                               ú       ÿ P<       þ f
3%&,+   ÿ
$  ÿ

                               ú