U
    f»{j�é  ã                   @   s  d dl ZddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZmZmZmZ ddlmZmZmZ dd	lmZ d[d
d„Zdd„ Zdd„ Ze	rÌeƒ d\dd„ƒZeƒ dd„ ƒZeƒ dd„ ƒZneZeZeZeƒ dd„ ƒZ eƒ dd„ ƒZ!eƒ dd„ ƒZ"dd„ Z#dd„ Z$d d!„ Z%d]d"d#„Z&d^d$d%„Z'd_d'd(„Z(d`d*d+„Z)d,d-„ Z*d.d/„ Z+d0d1„ Z,d2d3„ Z-d4d5„ Z.d6d7„ Z/d8d9„ Z0d:d;„ Z1dad<d=„Z2d>d?„ Z3d@dA„ Z4dbdCdD„Z5edcdHdI„ƒZ6edddJdK„ƒZ7ededLdM„ƒZ8edfdNdO„ƒZ9dgdPdQ„Z:edhdRdS„ƒZ;dTdU„ Z<didYdZ„Z=dS )jé    Né   )Úf_onewayÚttest_1samp_no_pé   )Úparallel_func)ÚjitÚ	has_numba)	Ú
split_listÚloggerÚverboseÚProgressBarÚwarnÚ_plÚcheck_random_stateÚ_check_optionÚ_validate_type)ÚSourceEstimateÚVolSourceEstimateÚMixedSourceEstimate)ÚSourceSpacesc                 C   sL   |d krt  | ¡d }n|| |  }|t j|| |dd� }d| |< | ¡ S )Nr   T)Zassume_uniqueF)ÚnpÚwhereZin1dÚtolist)ÚrÚsÚ	neighborsÚindicesÚbuddies© r   úV/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/stats/cluster_level.pyÚ_get_buddies_fallback   s    r    c                 C   st   |t || | dƒ }|t|| | d t|ƒd ƒ }|||… }	|	| |	  }
|
|| ||
 k }
d| |
< |
 ¡ S ©Nr   r   F)ÚmaxÚminÚlenr   )r   r   ÚindÚindsÚtÚt_borderÚmax_stepÚstartÚstopr   Úselvesr   r   r   Ú_get_selves_fallback#   s    "r-   c                 C   s   t t | ¡ƒ}|dkrd}|S )Nr   éÿÿÿÿ)Úintr   Úargmax)ÚxÚnext_indr   r   r   Ú_where_first_fallback-   s    r3   c           
      C   sŒ   t ƒ }|d krt| ƒ}nt|ƒ}t|ƒD ]^}|d kr:|}n|| }| | r(|| }tt|ƒƒD ]&}	|||	 kr^| |¡ d| |<  q(q^q(|S )NF)Úlistr$   ÚrangeÚappend)
r   r   r   r   r   Zn_checkÚiiÚthis_idxZthis_sÚnir   r   r   Ú_get_buddies8   s     

r:   c                 C   s„   t ƒ }|t|| | dƒ }|t|| | d t|ƒd ƒ }	t||	ƒD ]6}
||
 }| | rH|| || krH| |¡ d| |< qH|S r!   )r4   r"   r#   r$   r5   r6   )r   r   r%   r&   r'   r(   r)   r,   r*   r+   r7   r8   r   r   r   Ú_get_selvesO   s    "

r;   c                 C   s&   t t| ƒƒD ]}| | r|  S qdS )Nr.   )r5   r$   )r1   r7   r   r   r   Ú_where_first[   s    
r<   c                 C   s   t  | | ¡S ©N)r   Úsum)r1   Úcr   r   r   Ú_masked_sumh   s    r@   c                 C   s&   t  t  | | ¡t  | | ¡|  ¡S r=   )r   r>   ÚsignÚabs)r1   r?   Út_powerr   r   r   Ú_masked_sum_powerm   s    rD   c                 C   s   t  | ¡t  | dk¡ | S )Nr   )r   rA   Úlogical_not)ÚdataÚtstepr   r   r   Ú_sum_cluster_datar   s    rH   c           	      C   sœ   t  | jt¡}tƒ }| jdkr"dnd}|dkr˜|g}d||< d}|t|ƒkr€||d  }t|| || |  ƒ}| |¡ |d7 }q@t	|ƒ}| 
| | ¡ q&|S )z¼Form spatial clusters using neighbor lists.

    This is equivalent to _get_components with n_times = 1, with a properly
    reconfigured adjacency matrix (formed as "neighbors" list)
    r   r.   r   )r   ÚonesÚshapeÚboolr4   Úsizer$   r:   Úextendr<   r6   )	r   r   r   Úclustersr2   Út_indsÚicountr%   r   r   r   r   Ú_get_clusters_spatialw   s    	

rQ   c                 C   sL   || | |k< t  ||d  ||d  f¡||d < t jg td�||d < dS )zReassign cluster numbers.r   ©ÚdtypeN)r   ÚconcatenateÚarrayr/   )ÚcheckrN   ÚbaseÚnumr   r   r   Ú	_reassign“   s
    
ÿrY   c                    s\  t |ƒ‰t | ƒ}d}tj|ˆftd�}tƒ }t| ƒD ]\\‰ }t||ƒ}t|ƒD ]\}}	|| |ˆ |	f< qN|t |ƒ7 }‡ ‡fdd„|D ƒ}||7 }q4t|dd… |dd… | dd… ƒD ]’\}
}}||| |
|  dk }|
| }|| }t |¡}|D ]P}|||k }t 	|¡}t |||k ¡D ]}t
|
|||ƒ �q"t
||||ƒ qöq¶dd„ |D ƒ}|S )	a  Directly calculate clusters.

    This uses knowledge that time points are
    only adjacent to immediate neighbors for data organized as time x space.

    This algorithm time increases linearly with the number of time points,
    compared to with the square for the standard (graph) algorithm.

    This algorithm creates clusters for each time point using a method more
    efficient than the standard graph method (but otherwise equivalent), then
    combines these clusters across time points in a reasonable way.
    r   rR   c                    s   g | ]}|ˆ ˆ  ‘qS r   r   ©Ú.0Úcl©r7   Ún_srcr   r   Ú
<listcomp>¶   s     z*_get_clusters_st_1step.<locals>.<listcomp>Nr.   r   c                 S   s   g | ]}t |ƒd kr|‘qS ©r   ©r$   rZ   r   r   r   r_   É   s      )r$   r   Úzerosr/   r4   Ú	enumeraterQ   ÚzipÚuniquer#   rY   )Úkeepersr   Ún_timesZenum_offsetrV   rN   Úkr?   Úcir\   Zcheck1Zcheck2r&   Zcheck1_dÚnZnextsrX   ZprevsrW   Úprr   r]   r   Ú_get_clusters_st_1step�   s2    

.

rl   c                 C   sl  t |ƒ}t | ƒ}tƒ }| d¡ t| ƒD ].\}}|||  | |< | || t |ƒ ¡ q(t |¡}t | ¡} | }t||ƒ\}	}
tj|	j	t
d�}tƒ }t |d || ¡}|
jdkr¶dnd}|dk�rh|g}d||< d}|t |ƒk�rP||d  }t||
|||	||ƒ}|||	|  ||	| d  … }t||
||
|  |ƒ}||| 7 }|d7 }qÖt|ƒ}| || ¡ qº|S )a,  Directly calculate clusters.

    This uses knowledge that time points are
    only adjacent to immediate neighbors for data organized as time x space.

    This algorithm time increases linearly with the number of time points,
    compared to with the square for the standard (graph) algorithm.
    r   rR   r.   Fr   )r$   r4   r6   rc   r   rU   rT   ÚdivmodrI   rJ   rK   ÚarangerL   r;   r:   r<   )rf   r   r)   r^   rg   r(   Zkirh   Úvr'   r   r   rN   r&   r2   rO   rP   r%   r,   Z
these_indsr   r   r   r   Ú_get_clusters_st_multistepÍ   s:    	



 
rp   c                 C   s(  t |ƒ}| j| }t | ¡d }t |ƒdk�r tjg td�g| }t |||f¡\}}dg}	t|tƒrt|g}|g}nLt |¡}
||
 }||
 }|	t t 	|¡dk¡d d  
¡ 7 }	|	 t |ƒ¡ t|	dd… |	dd… ƒD ]"\}}t |||… ¡||| < qÚ|dk�rt||ƒS t|||ƒS ng S dS )z"Choose the most efficient version.r   rR   r   Nr.   )r$   rL   r   r   rU   r/   Úunravel_indexÚ
isinstanceZargsortÚdiffr   r6   rd   Úsortrl   rp   )Úx_inr   r)   r^   rg   Zcl_goodsrf   ÚrowÚcolZlimsÚorderr*   Úendr   r   r   Ú_get_clusters_stý   s.    


$"

ÿrz   Tc                 C   sr  ddl m} |dkr$t t| ƒ¡}n²ddlm} t | |j | |j	 ¡}|j
| }|j| }|j	| }	|j}
t | ¡d }t ||f¡}t |	|f¡}	t |tjt|ƒ|jd�f¡}|j|||	ff|
d�}||ƒ\}}|�rjt |¡}t |¡}dd„ t||d	 d	ƒD ƒ}tjt|ƒtd�}t|ƒD ],\}}||  |¡ ||  | | 7  < �q$d
d„ t||ƒD ƒ}|S |S dS )z<Get connected components from a mask and a adjacency matrix.r   ©ÚsparseF)Úconnected_componentsrR   ©rJ   c                 S   s   g | ]
}t ƒ ‘qS r   )r4   ©r[   Úir   r   r   r_   0  s     z#_get_components.<locals>.<listcomp>r   c                 S   s   g | ]\}}|rt  |¡‘qS r   ©r   rU   )r[   rh   Úmr   r   r   r_   5  s      N)Úscipyr|   r   rn   r$   Zscipy.sparse.csgraphr}   Úlogical_andrv   rw   rF   rJ   r   rT   rI   rS   Ú
coo_matrixr#   r"   r5   rb   rK   rc   r6   rd   )ru   Ú	adjacencyZreturn_listr|   Ú
componentsr}   ÚmaskrF   rv   rw   rJ   ÚidxÚ_r*   r+   Z	comp_listr7   ÚcomprN   r   r   r   Ú_get_components  s4    




rŒ   Fc	              
      sþ  ddl m}	 td|dddgƒ t | ¡} t ˆ¡�s‚tˆtƒsFtdƒ‚t	‡fdd„d	D ƒƒsdt
d
ƒ‚d}
| t | ¡ }|jdkrˆtdƒ‚|dkrÄˆd dkr¤tdƒ‚ˆd dkr¸tdƒ‚t |¡}n,|dkrØt |¡}ntt |¡t |¡ ƒ}~t ˆd |ˆd t¡}ˆ dd¡}ˆ dd¡}|dk�rtt|ƒdk�rPtdˆd |f ƒ n$t dt|ƒ|d |d ||f ¡ t | j¡}n
ˆg}d}
|dk�r¦tj| jtd�}|dk�rÎt 	t |¡dk¡�sÎtdƒ‚|dk�röt 	t |¡dk ¡�sötdƒ‚tƒ ‰ tƒ }t|ƒD �]^\}}tƒ ‰ |dk�rHt | |k|¡t | | k |¡g}n0|dk�rft | |k |¡g}nt | |k|¡g}|D ]@}t  |¡�r|t!| ||||||	ƒ}ˆ |d 7 ‰ | "|d ¡ �q||
�r
|dk�rØt#|ƒ}nt#|||d   ƒ}|| }ˆ D ]n}t|t$ƒ�r|j%|j& }n6t|t'ƒ�r,t|ƒ}n |j(tk�rDt )|¡}nt|ƒ}||  |||  7  < �qø�q
|�r|t *|¡nt +g ¡}|
�röt | j¡‰ |dk�s¬|dk�rä| j,dk�rÈdd„ ˆ D ƒ‰ n‡ fdd„t-tˆ ƒƒD ƒ‰ nd d„ ˆ D ƒ‰ |}ˆ |fS )!a  Find all clusters which are above/below a certain threshold.

    When doing a two-tailed test (tail == 0), only points with the same
    sign will be clustered together.

    Parameters
    ----------
    x : 1D array
        Data
    threshold : float | dict
        Where to threshold the statistic. Should be negative for tail == -1,
        and positive for tail == 0 or 1. Can also be an dict for
        threshold-free cluster enhancement.
    tail : -1 | 0 | 1
        Type of comparison
    adjacency : scipy.sparse.coo_matrix, None, or list
        Defines adjacency between features. The matrix is assumed to
        be symmetric and only the upper triangular half is used.
        If adjacency is a list, it is assumed that each entry stores the
        indices of the spatial neighbors in a spatio-temporal dataset x.
        Default is None, i.e, a regular lattice adjacency.
        False means no adjacency.
    max_step : int
        If adjacency is a list, this defines the maximal number of steps
        between vertices along the second dimension (typically time) to be
        considered adjacent.
    include : 1D bool array or None
        Mask to apply to the data of points to cluster. If None, all points
        are used.
    partitions : array of int or None
        An array (same size as X) of integers indicating which points belong
        to each partition.
    t_power : float
        Power to raise the statistical values (usually t-values) by before
        summing (sign will be retained). Note that t_power == 0 will give a
        count of nodes in each cluster, t_power == 1 will weight each node by
        its statistical score.
    show_info : bool
        If True, display information about thresholds used (for TFCE). Should
        only be done for the standard permutation.

    Returns
    -------
    clusters : list of slices or list of arrays (boolean masks)
        We use slices for 1D signals and mask to multidimensional
        arrays.
    sums : array
        Sum of x values in clusters.
    r   )ÚndimageÚtailr.   r   zLthreshold must be a number, or a dict for threshold-free cluster enhancementc                 3   s   | ]}|ˆ kV  qd S r=   r   )r[   Úkey)Ú	thresholdr   r   Ú	<genexpr>w  s     z!_find_clusters.<locals>.<genexpr>)r*   Ústepz9threshold, if dict, must have at least "start" and "step"Tz7No finite values found in the observed statistic valuesr*   z.threshold["start"] must be <= 0 for tail == -1r’   z,threshold["step"] must be < 0 for tail == -1Úh_powerr   Úe_powerç      à?zWthreshold["start"] (%s) is more extreme than data statistics with most extreme value %sz[Using %d thresholds from %0.2f to %0.2f for TFCE computation (h_power=%0.2f, e_power=%0.2f)FNrR   )r   r   z+Thresholds must be monotonically increasingz+Thresholds must be monotonically decreasingc                 S   s   g | ]}t ||d  ƒ‘qS ©r   ©Úslice©r[   r?   r   r   r   r_   Ø  s     z"_find_clusters.<locals>.<listcomp>c                    s   g | ]}ˆ |k  ¡ ‘qS r   )Úravel)r[   r7   )rN   r   r   r_   Û  s   ÿc                 S   s   g | ]}t  |g¡‘qS r   r�   r™   r   r   r   r_   Þ  s     ).rƒ   r�   r   r   Z
asanyarrayZisscalarrr   ÚdictÚ	TypeErrorÚallÚKeyErrorÚisfiniterL   ÚRuntimeErrorÚ
ValueErrorr#   r"   rn   ÚfloatÚgetr$   r   r
   Úinforb   rI   rJ   rK   rs   r4   rc   r„   ÚanyÚ_find_clusters_1dir_partsr6   rB   r˜   r+   r*   ÚtuplerS   r>   rT   rU   Úndimr5   )r1   r�   rŽ   r†   r)   ÚincludeÚ
partitionsrC   Ú	show_infor�   ZtfceZuse_xr+   Z
thresholdsr“   r”   ZscoresÚsumsÚtiZthreshZx_insru   ÚoutÚhr?   Zlen_cr   )rN   r�   r   Ú_find_clusters;  sÂ    3


ÿ ÿ

þ ÿþ
  
ÿ
  þ


 

ÿr°   c                 C   s’   |dkr t | |||||ƒ\}}njtƒ }tƒ }tt |¡d ƒD ]@}	t |||	k¡}
t | |
||||ƒ}||d 7 }| |d ¡ q>t |¡}||fS )z?Deal with partitions, and pass the work to _find_clusters_1dir.Nr   r   )Ú_find_clusters_1dirr4   r5   r   r"   r„   r6   rT   )r1   ru   r†   r)   rª   rC   r�   rN   r¬   ÚpZx_ir®   r   r   r   r¦   ã  s     
 ÿ
ÿ
r¦   c                    s²  ddl m} |dk�r| |¡\}}ˆjdkr˜| ||¡}	|	sFtƒ }
nPttd|d ƒƒ}ˆ dkrr|jˆ||d�}
n$|jt 	ˆ¡t 
ˆ¡ˆ   ||d�}
n~tƒ }	t |¡}
t|ƒD ]d}||d k}|	 | ¡ ¡ ˆ dkrêt ˆ| ¡|
|< q°t t 	ˆ| ¡t 
ˆ| ¡ˆ   ¡|
|< q°nŒˆjdk�r,tdƒ‚t||jƒ�sD|dk�rPt||ƒ}	n"t|tƒ�rjt|||ƒ}	ntdƒ‚ˆ dk�r�‡fd	d
„|	D ƒ}
n‡ ‡fdd
„|	D ƒ}
|	t |
¡fS )z'Actually call the clustering algorithm.r   r{   Nr   )Úindexz<Data should be 1D when using a adjacency to define clusters.Fz)adjacency must be a sparse matrix or listc                    s   g | ]}t ˆ |ƒ‘qS r   )r@   r™   )r1   r   r   r_   !  s     z'_find_clusters_1dir.<locals>.<listcomp>c                    s   g | ]}t ˆ|ˆ ƒ‘qS r   )rD   r™   ©rC   r1   r   r   r_   #  s     )rƒ   r|   Úlabelr¨   Zfind_objectsr4   r5   r>   r   rA   rB   Úemptyr6   rš   Ú	Exceptionrr   ZspmatrixrŒ   rz   r¡   Z
atleast_1d)r1   ru   r†   r)   rC   r�   r|   ÚlabelsZn_labelsrN   r¬   r³   rµ   r?   r   r´   r   r±   ÷  sF    

 ÿ
ÿ
r±   c                 C   s4   t | ƒD ]&\}}tj|td�| |< d| | |< q| S )ú>Convert to the old format of clusters, which were bool arrays.rR   T)rc   r   rb   rK   )r‡   Zn_totri   r?   r   r   r   Ú_cluster_indices_to_mask(  s    rº   c                 C   sÆ   t | ƒD ]¸\}}t|tjƒr2t | |¡¡| |< qt|tƒrRt |j|j	¡| |< qt|t
ƒshtt|ƒƒ‚t|ƒ}t |ƒD ]:\}}t|tƒr t |j|j	¡||< qxt |¡d ||< qxt
|ƒ| |< q| S )r¹   r   )rc   rr   r   Úndarrayr   Úreshaper˜   rn   r*   r+   r§   ÚAssertionErrorÚtyper4   )r‡   rJ   ri   r?   r7   Úccr   r   r   Ú_cluster_mask_to_indices0  s    

rÀ   c                    s`   |dkr"t  ‡ fdd„| D ƒ¡}n:|dkrDt  ‡ fdd„| D ƒ¡}nt  ‡ fdd„| D ƒ¡}|S )z®Get p-values from stats values given an H0 distribution.

    For each stat compute a p-value as percentile of its statistics
    within all statistics in surrogate data
    r.   c                    s   g | ]}t  ˆ |k¡‘qS r   ©r   Úmean©r[   r'   ©ÚH0r   r   r_   K  s     z(_pval_from_histogram.<locals>.<listcomp>r   c                    s   g | ]}t  ˆ |k¡‘qS r   rÁ   rÃ   rÄ   r   r   r_   M  s     c                    s"   g | ]}t  tˆ ƒt|ƒk¡‘qS r   )r   rÂ   rB   rÃ   rÄ   r   r   r_   O  s     r�   )ÚTrÅ   rŽ   Zpvalr   rÄ   r   Ú_pval_from_histogramC  s    rÇ   c                    s¤   ddl m} | ˆ ¡stdƒ‚ˆ jd |kr6ˆ  ¡ ‰ njt|ˆ jd ƒ\}}||ksZ|dkrptdˆ jd |f ƒ‚ˆ ˆ  ¡   ¡ ‰ ‡ fdd„t	t
ˆ jƒd ƒD ƒ‰ ˆ S )Nr   r{   z?If adjacency matrix is given, it must be a SciPy sparse matrix.a  adjacency (len %d) must be of the correct size, i.e. be equal to or evenly divide the number of tests (%d).

If adjacency was computed for a source space, try using the fwd["src"] or inv["src"] as some original source space vertices can be excluded during forward computationc                    s*   g | ]"}ˆ j ˆ j| ˆ j|d   … ‘qS r–   )r   Úindptrr   ©r†   r   r   r_   g  s   ÿz$_setup_adjacency.<locals>.<listcomp>r   )rƒ   r|   Úissparser¡   rJ   Ztocoorm   Z	transposeZtocsrr5   r$   rÈ   )r†   Ún_testsrg   r|   Z	got_timesÚmodr   rÉ   r   Ú_setup_adjacencyT  s"    

ûÿ
þrÍ   c                    sš  ˆ j \}}ˆd k	r|ˆkrd ‰tjt|
ƒtjd�}ˆd k	rN‡ ‡fdd„|D ƒ}t|
ƒD �]<\}‰ˆd k	slt‚‡fdd„|D ƒ}ˆd kr¢‡ fdd„|D ƒ}||Ž }nŽtj|ˆ jd�}td|ˆƒD ]p}t	|ˆ |ƒ| }t|ƒD ]0\}}ˆ |||| …f || d d …d |…f< qÜ||Ž }|d |… |||| …< q¾|d k�r@||_ t
||||||||	d�}|d }t|ƒdk�r~t |¡||< nd||< | |d ¡ qV|S )	NrR   c                    s(   g | ] }t jtˆ | ƒˆfˆ jd �‘qS )rR   )r   r¶   r$   rS   ©r[   r   )ÚX_fullÚbuffer_sizer   r   r_   z  s   ÿz$_do_permutations.<locals>.<listcomp>c                    s   g | ]}ˆ | ‘qS r   r   rÎ   )rx   r   r   r_   €  s     c                    s   g | ]}ˆ |d d …f ‘qS r=   r   )r[   r‰   )rÏ   r   r   r_   „  s     r   ©r�   rŽ   r)   r†   rª   r©   rC   r   )rJ   r   r¶   r$   Údoublerc   r½   rS   r5   r#   r°   r"   Úupdate)rÏ   Úslicesr�   rŽ   r†   Ústat_funr)   r©   rª   rC   ÚordersÚsample_shaperÐ   Úprogress_barÚn_sampÚn_varsÚmax_cluster_sumsZX_bufferÚseed_idxZidx_shuffle_listZX_shuffle_listÚ
t_obs_surrÚposÚ
n_var_loopr€   r‰   Útmpr®   Úperm_clusters_sumsr   )rÏ   rÐ   rx   r   Ú_do_permutationsm  sJ    
ÿ
ÿ
  ýrâ   c                 C   sü  | j \}}|d kst‚|d k	r*||kr*d }tjt|
ƒtjd�}|d k	rZtj||f| jd�}t|
ƒD �]’\}}t|tj	ƒs|t‚|j
|ksŠt‚d|d d …d f  t¡ d }t t t |¡d¡¡sÈtdƒ‚|d k�r| jjrô| |9 } || ƒ}| |9 } n|| | ƒ}n‚tj|| jd�}td||ƒD ]d}t|| |ƒ| }|| d d …||| …f  |d d …d |…f< ||ƒ}|d |… |||| …< �q|d k�r”||_ t||||||||	d�}|d }t|ƒdk�ràt t |¡¡}|| ||< nd||< | |d ¡ qb|S )NrR   r   r   zsigns from rng must be +/- 1r   rÑ   )rJ   r½   r   r¶   r$   rÒ   rS   rc   rr   r»   rL   Úastyper/   r�   ÚequalrB   r¡   ÚflagsZ	writeabler5   r#   r°   r0   rÓ   )ÚXrÔ   r�   rŽ   r†   rÕ   r)   r©   rª   rC   rÖ   r×   rÐ   rØ   rÙ   rÚ   rÛ   ZX_flip_bufferrÜ   rx   ÚsignsrÝ   rÞ   rß   rà   r®   rá   Zidx_maxr   r   r   Ú_do_1samp_permutations¬  sT    


ÿ
  ýrè   c                 C   sˆ   d|  }t  || ft|ƒ¡}| |¡ |d }|||d…df< td| ƒD ]:}|ddd…|d f }||d|…|f< |||d…|f< qH|S )aû  Ndim permutations with repetitions of (a,b).

    Returns an array with all the possible permutations with repetitions of
    (0,1) in ndim dimensions.  The array is shaped as (2**ndim,ndim), and is
    ordered with the last index changing fastest.  For examble, for ndim=3:

    Examples
    --------
    >>> bin_perm_rep(3)
    array([[0, 0, 0],
           [0, 0, 1],
           [0, 1, 0],
           [0, 1, 1],
           [1, 0, 0],
           [1, 0, 1],
           [1, 1, 0],
           [1, 1, 1]])
    r   Nr   r   )r   r¶   r¾   Úfillr5   )r¨   ÚaÚbZnpermsZpermsZ
half_pointÚjZhalf_colr   r   r   Úbin_perm_repó  s    
rí   c                    s<  dˆ |dk  d }d}t |tƒr6|dkr2tdƒ‚|}t|ƒ}||k r`d}tˆ ƒd|d … }nÒˆ dkr�|j||d d	d
�}‡ fdd„|D ƒ}n¢t |d ˆ ft¡}i }d}ˆ |dk }	||d k �r2t|j	|	d�dk  
t¡ƒ}
|
|kr¸|
||d|	…f< |dk�r | 	¡ dk �r d||  ||< d||
< |d7 }q¸|||fS )zGet the 1samp orders.r   r   r   Ú r�   z(n_permutations as a string must be "all"z (exact test)é   F)Úreplacec                    s&   g | ]}t jt  |d  ˆ ¡td�‘qS )r   rR   )r   ZfromiterZbinary_reprr/   rÎ   ©Ú	n_samplesr   r   r_   '  s   ÿz%_get_1samp_orders.<locals>.<listcomp>)rL   r•   N)rr   Ústrr¡   r/   rí   Úchoicer   rb   r§   Úuniformrã   )rò   Ún_permutationsrŽ   ÚrngZ	max_permsÚextrarÖ   Úhashesr7   Zuse_samplesrç   r   rñ   r   Ú_get_1samp_orders  s8    

ÿ
rú   c           (         sÄ  t d|ddgƒ t dˆdddgƒ tˆtƒsttˆƒ‰ˆdk rDˆdksdˆdkrTˆdk sdˆdkrtˆdk rttdˆˆf ƒ‚d	d
„ | D ƒ} | d jd }| d jd }| d jdd… ‰	| D ]}|jdd… ˆ	kr´tdƒ‚q´dd
„ | D ƒ} | d jd }ˆdk	�rˆdk	�rtˆ||ƒ‰|	dk	�r.|	j|k�s.tdƒ‚ˆ| Ž }t|t	j
dƒ t dt	 |¡t	 |¡f ¡ ˆdk	�rÊt	 |¡}td|ˆƒD ]*‰ˆ‡‡fdd
„| D ƒŽ |ˆˆˆ …< �q‚t	 ||k¡�sÊtdƒ d‰|jt	 ˆ	¡k�rðtd|jˆˆ	f ƒ‚ˆdk�sˆdk�r
ˆ	|_|	dk	�r t	 |	¡}nd}|dk�rNˆdk	�rNˆdk	�rNtˆ|ƒ‰nd‰t d¡ t|ˆˆˆˆ|ˆˆdd�	}|\}}ˆ	|_tˆtƒ�r¦| |j¡t	 |¡ }t dt|ƒ› dt|ƒ› �¡ ˆdk	�rîˆdk	�rî|dk�rt||ƒ}n|dk�rt||jƒ}d}t|ƒ‰~t| ƒdk�rFt}| d ‰ d‰
t||ˆˆƒ\}}}nrt |ƒ}t!}t	j"| dd�‰ dd
„ | D ƒ}t	 #dgt	 $|¡¡‰‡fdd
„tt| ƒƒD ƒ‰
‡ ‡fdd
„t|d ƒD ƒ}Št%||dd�\}‰}t|ƒdk�rtd ƒ |t	 &g ¡t	 &g ¡t	 &g ¡fS d}d}d} d}!|dk�r®|dk	�rD| dk	�r>t	 '|| ¡‰n|‰n| ‰t(tt|ƒƒd!|› �d"��@‰|‡ ‡‡‡‡‡‡‡	‡
‡‡‡‡‡fd#d$„t)||dd%�D ƒƒ}"W 5 Q R X ˆdk�r¼| ¡ }#n ˆdk�rÐ| ¡ }#nt*|ƒ ¡ }#|" +d|#g¡ t	 "|"¡}"t ,d&¡ t-||"ˆƒ}$t	 .|$|
k ¡d }%|%j| }|%j}t	j/|t0d'�} |%D ]}&d| ||& < �q>ˆdk�rlˆdk	�rlˆ	| _|!d7 }!|
dk�r|!dk�rŒd(nd}'t d)|!||'t|ƒf ¡ �qt1|ˆ	ƒ}|||$|"fS )*z²Aux Function.

    Note. X is required to be a list. Depending on the length of X
    either a 1 sample t-test or an F test / more sample permutation scheme
    is elicited.
    Úout_typerˆ   r   rŽ   r.   r   r   z4incompatible tail and threshold signs, got %s and %sc                 S   s,   g | ]$}|j d kr$|dd…tjf n|‘qS )r   N)r¨   r   Znewaxis©r[   r1   r   r   r   r_   T  s     z-_permutation_cluster_test.<locals>.<listcomp>Nz#All samples mush have the same sizec                 S   s"   g | ]}t  ||jd  df¡‘qS )r   r.   )r   r¼   rJ   rü   r   r   r   r_   ^  s     Fz&exclude must be the same shape as X[0]zreturn value of stat_funzstat_fun(H1): min=%f max=%fc                    s$   g | ]}|d d …ˆˆˆ  …f ‘qS r=   r   rü   )rÐ   rÞ   r   r   r_   r  s     zVProvided stat_fun does not treat variables independently. Setting buffer_size to None.zQt_obs.shape %s provided by stat_fun %s is not compatible with the sample shape %sTu   Running initial clustering â€¦)r)   r©   rª   rC   r«   zFound z clusterrî   ©Zaxisc                 S   s   g | ]}|j d  ‘qS r`   r~   rü   r   r   r   r_   ¶  s     c                    s"   g | ]}t ˆ | ˆ |d   ƒ‘qS r–   r—   )r[   rh   )Ú
splits_idxr   r   r_   ¸  s   ÿc                    s   g | ]}ˆ  tˆ ƒ¡‘qS r   )Zpermutationr$   )r[   rŠ   )rÏ   r÷   r   r   r_   º  s   ÿ)r   z?No clusters found, returning empty H0, clusters, and cluster_pvZ	Permuting)ÚiterableZmesgc                 3   s:   | ]2\}}ˆˆ ˆˆˆˆˆ	ˆˆˆˆ
|ˆˆˆ  |¡ƒV  qd S r=   )Zsubset)r[   r‰   rx   )rÏ   r†   rÐ   r)   Úmy_do_perm_funcrª   rØ   r×   rÔ   rÕ   rC   rŽ   Úthis_includer�   r   r   r‘   Ú  s   ü      ýz,_permutation_cluster_test.<locals>.<genexpr>)r‰   zComputing cluster p-valuesrR   zadditional z[Step-down-in-jumps iteration #%i found %i %scluster%s to exclude from subsequent iterations)2r   rr   r›   r¢   r¡   rJ   rÍ   rL   r   r   r»   r
   r¤   r#   r"   Z
zeros_liker5   Zalltruer   ÚprodrE   Ú_get_partitions_from_adjacencyr°   r¼   rA   r$   r   rº   rÀ   r   rè   rú   r/   râ   rT   r6   Zcumsumr   rU   r„   r   r	   rB   ÚinsertÚdebugrÇ   r   rI   rK   Ú_reshape_clusters)(ræ   r�   rö   rŽ   rÕ   r†   Ún_jobsÚseedr)   ÚexcludeÚstep_down_prC   rû   Úcheck_disjointrÐ   rò   rg   r1   rË   Út_obsZt_obs_bufferr©   r®   rN   Zcluster_statsrø   Zdo_perm_funcrÖ   Zn_samples_per_conditionÚparallelZ	n_removedZtotal_removedZstep_down_includeZn_step_downsrÅ   ÚorigZ
cluster_pvZ	to_remover­   Za_textr   )rÏ   r†   rÐ   r)   r   rª   rÞ   rØ   r÷   r×   rÔ   rþ   rÕ   rC   rŽ   r  r�   r   Ú_permutation_cluster_test@  s$   

 ÿÿÿ


ÿ
þ
ÿ

  ý

   ÿ

ÿ
ÿ  ÿ



þ&û







ÿþ

r  Úwithinc                 C   sT  ddl m} |dkr |jj}|dkrŽ|dk	rB|tk	rBtd|f ƒ dd|dk  }t| ƒ}|||d ƒ }t |¡dk r~| }t	 
d |¡¡ |dkrštn|}n¬|d	ks¬t‚|jj}|dk�r:|dk	rÞ|tk	rÞtd
|f ƒ n|dkrîtdƒ d}t| ƒd }	t dd„ | D ƒ¡t| ƒ }
|d| |	|
ƒ}t	 
d |¡¡ |dk�rHtn|}||fS )z(Check the stat_fun and threshold values.r   )Ústatsr  NzQAutomatic threshold is only valid for stat_fun=None (or ttest_1samp_no_p), got %sçš™™™™™©?r   zUsing a threshold of {:.6f}ÚbetweenzIAutomatic threshold is only valid for stat_fun=None (or f_oneway), got %sz4Ignoring argument "tail", performing 1-tailed F-testc                 S   s   g | ]}t |ƒ‘qS r   ra   rü   r   r   r   r_     s     z_check_fun.<locals>.<listcomp>ç      ð?)rƒ   r  r'   Úppfr   r   r$   r   rA   r
   r¤   Úformatr½   Úfr   r>   )ræ   rÕ   r�   rŽ   Úkindr  r  Úp_threshrò   ÚdfnZdfdr   r   r   Ú
_check_fun  s>    ÿ
ÿr  é   r   éè  c                 C   s:   t | |||dƒ\}}t| |||||||||	|
||||d�S )a�  Cluster-level statistical permutation test.

    For a list of :class:`NumPy arrays <numpy.ndarray>` of data,
    calculate some statistics corrected for multiple comparisons using
    permutations and cluster-level correction. Each element of the list ``X``
    should contain the data for one group of observations (e.g., 2D arrays for
    time series, 3D arrays for time-frequency power values). Permutations are
    generated with random partitions of the data. For details, see
    :footcite:p:`MarisOostenveld2007,Sassenhagen2019`.

    Parameters
    ----------
    X : list of array, shape (n_observations, p[, q][, r])
        The data to be clustered. Each array in ``X`` should contain the
        observations for one group. The first dimension of each array is the
        number of observations from that group; remaining dimensions comprise
        the size of a single observation. For example if ``X = [X1, X2]``
        with ``X1.shape = (20, 50, 4)`` and ``X2.shape = (17, 50, 4)``, then
        ``X`` has 2 groups with respectively 20 and 17 observations in each,
        and each data point is of shape ``(50, 4)``. Note: that the
        *last dimension* of each element of ``X`` should correspond to the
        dimension represented in the ``adjacency`` parameter
        (e.g., spectral data should be provided as
        ``(observations, frequencies, channels/vertices)``).
    %(threshold_clust_f)s
    %(n_permutations_clust_int)s
    %(tail_clust)s
    %(stat_fun_clust_f)s
    %(adjacency_clust_n)s
    %(n_jobs)s
    %(seed)s
    %(max_step_clust)s
    %(exclude_clust)s
    %(step_down_p_clust)s
    %(f_power_clust)s
    %(out_type_clust)s
    %(check_disjoint_clust)s
    %(buffer_size_clust)s
    %(verbose)s

    Returns
    -------
    F_obs : array, shape (p[, q][, r])
        Statistic (F by default) observed for all variables.
    clusters : list
        List type defined by out_type above.
    cluster_pv : array
        P-value for each cluster.
    H0 : array, shape (n_permutations,)
        Max cluster level stats observed under permutation.

    Notes
    -----
    %(threshold_clust_f_notes)s

    References
    ----------
    .. footbibliography::
    r  ©ræ   r�   rö   rŽ   rÕ   r†   r  r  r)   r	  r
  rC   rû   r  rÐ   ©r  r  ©ræ   r�   rö   rŽ   rÕ   r†   r  r  r)   r	  r
  rC   rû   r  rÐ   r   r   r   r   Úpermutation_cluster_test$  s$    A          ûr!  c                 C   s:   t | |||ƒ\}}t| g|||||||||	|
||||d�S )aÇ
  Non-parametric cluster-level paired t-test.

    For details, see :footcite:p:`MarisOostenveld2007,Sassenhagen2019`.

    Parameters
    ----------
    X : array, shape (n_observations, p[, q][, r])
        The data to be clustered. The first dimension should correspond to the
        difference between paired samples (observations) in two conditions.
        The subarrays ``X[k]`` can be 1D (e.g., time series), 2D (e.g.,
        time series over channels), or 3D (e.g., time-frequencies over
        channels) associated with the kth observation. For spatiotemporal data,
        see also :func:`mne.stats.spatio_temporal_cluster_1samp_test`.
    %(threshold_clust_t)s
    %(n_permutations_clust_all)s
    %(tail_clust)s
    %(stat_fun_clust_t)s
    %(adjacency_clust_1)s
    %(n_jobs)s
    %(seed)s
    %(max_step_clust)s
    %(exclude_clust)s
    %(step_down_p_clust)s
    %(t_power_clust)s
    %(out_type_clust)s
    %(check_disjoint_clust)s
    %(buffer_size_clust)s
    %(verbose)s

    Returns
    -------
    t_obs : array, shape (p[, q][, r])
        T-statistic observed for all variables.
    clusters : list
        List type defined by out_type above.
    cluster_pv : array
        P-value for each cluster.
    H0 : array, shape (n_permutations,)
        Max cluster level stats observed under permutation.

    Notes
    -----
    From an array of paired observations, e.g. a difference in signal
    amplitudes or power spectra in two conditions, calculate if the data
    distributions in the two conditions are significantly different.
    The procedure uses a cluster analysis with permutation test
    for calculating corrected p-values. Randomized data are generated with
    random sign flips. See :footcite:`MarisOostenveld2007` for more
    information.

    Because a 1-sample t-test on the difference in observations is
    mathematically equivalent to a paired t-test, internally this function
    computes a 1-sample t-test (by default) and uses sign flipping (always)
    to perform permutations. This might not be suitable for the case where
    there is truly a single observation under test; see :ref:`disc-stats`.
    %(threshold_clust_t_notes)s

    If ``n_permutations`` exceeds the maximum number of possible permutations
    given the number of observations, then ``n_permutations`` and ``seed``
    will be ignored since an exact test (full permutation test) will be
    performed (this is the case when
    ``n_permutations >= 2 ** (n_observations - (tail == 0))``).

    If no initial clusters are found because all points in the true
    distribution are below the threshold, then ``clusters``, ``cluster_pv``,
    and ``H0`` will all be empty arrays.

    References
    ----------
    .. footbibliography::
    r  r  r   r   r   r   Úpermutation_cluster_1samp_testn  s$    M          ûr"  c                 C   sX   |	dk	r.t t | jdd… ¡| jd |	dƒ}nd}t| ||||||||||
||||d�S )u¯  Non-parametric cluster-level paired t-test for spatio-temporal data.

    This function provides a convenient wrapper for
    :func:`mne.stats.permutation_cluster_1samp_test`, for use with data
    organized in the form (observations Ã— time Ã— space),
    (observations Ã— frequencies Ã— space), or optionally
    (observations Ã— time Ã— frequencies Ã— space). For details, see
    :footcite:p:`MarisOostenveld2007,Sassenhagen2019`.

    Parameters
    ----------
    X : array, shape (n_observations, p[, q], n_vertices)
        The data to be clustered. The first dimension should correspond to the
        difference between paired samples (observations) in two conditions.
        The second, and optionally third, dimensions correspond to the
        time or time-frequency data. And, the last dimension should be spatial.
    %(threshold_clust_t)s
    %(n_permutations_clust_all)s
    %(tail_clust)s
    %(stat_fun_clust_t)s
    %(adjacency_clust_st1)s
    %(n_jobs)s
    %(seed)s
    %(max_step_clust)s
    spatial_exclude : list of int or None
        List of spatial indices to exclude from clustering.
    %(step_down_p_clust)s
    %(t_power_clust)s
    %(out_type_clust)s
    %(check_disjoint_clust)s
    %(buffer_size_clust)s
    %(verbose)s

    Returns
    -------
    t_obs : array, shape (p[, q], n_vertices)
        T-statistic observed for all variables.
    clusters : list
        List type defined by out_type above.
    cluster_pv : array
        P-value for each cluster.
    H0 : array, shape (n_permutations,)
        Max cluster level stats observed under permutation.

    Notes
    -----
    %(threshold_clust_t_notes)s

    References
    ----------
    .. footbibliography::
    Nr   r.   T©r�   rÕ   rŽ   rö   r†   r  r  r)   r	  r
  rC   rû   r  rÐ   )Ú_st_mask_from_s_indsr   r  rJ   r"  ©ræ   r�   rö   rŽ   rÕ   r†   r  r  r)   Zspatial_excluder
  rC   rû   r  rÐ   r   r	  r   r   r   Ú"spatio_temporal_cluster_1samp_testÄ  s2    <   ÿ          ûr&  c                 C   s`   |	dk	r6t t | d jdd… ¡| d jd |	dƒ}nd}t| ||||||||||
||||d�S )uG  Non-parametric cluster-level test for spatio-temporal data.

    This function provides a convenient wrapper for
    :func:`mne.stats.permutation_cluster_test`, for use with data
    organized in the form (observations Ã— time Ã— space),
    (observations Ã— time Ã— space), or optionally
    (observations Ã— time Ã— frequencies Ã— space). For more information,
    see :footcite:p:`MarisOostenveld2007,Sassenhagen2019`.

    Parameters
    ----------
    X : list of array, shape (n_observations, p[, q], n_vertices)
        The data to be clustered. Each array in ``X`` should contain the
        observations for one group. The first dimension of each array is the
        number of observations from that group (and may vary between groups).
        The second, and optionally third, dimensions correspond to the
        time or time-frequency data. And, the last dimension should be spatial.
        All dimensions except the first should match across all groups.
    %(threshold_clust_f)s
    %(n_permutations_clust_int)s
    %(tail_clust)s
    %(stat_fun_clust_f)s
    %(adjacency_clust_stn)s
    %(n_jobs)s
    %(seed)s
    %(max_step_clust)s
    spatial_exclude : list of int or None
        List of spatial indices to exclude from clustering.
    %(step_down_p_clust)s
    %(f_power_clust)s
    %(out_type_clust)s
    %(check_disjoint_clust)s
    %(buffer_size_clust)s
    %(verbose)s

    Returns
    -------
    F_obs : array, shape (p[, q], n_vertices)
        Statistic (F by default) observed for all variables.
    clusters : list
        List type defined by out_type above.
    cluster_pv: array
        P-value for each cluster.
    H0 : array, shape (n_permutations,)
        Max cluster level stats observed under permutation.

    Notes
    -----
    %(threshold_clust_f_notes)s

    References
    ----------
    .. footbibliography::
    Nr   r   r.   Tr#  )r$  r   r  rJ   r!  r%  r   r   r   Úspatio_temporal_cluster_test  s2    >   ÿ          ûr'  c                 C   s@   t j| |ftd�}d|dd…|f< | ¡ }|dkr<t  |¡}|S )aØ  Compute mask to apply to a spatio-temporal adjacency matrix.

    This can be used to include (or exclude) certain spatial coordinates.
    This is useful for excluding certain regions from analysis (e.g.,
    medial wall vertices).

    Parameters
    ----------
    n_times : int
        Number of time points.
    n_vertices : int
        Number of spatial points.
    vertices : list or array of int
        Vertex numbers to set.
    set_as : bool
        If True, all points except "vertices" are set to False (inclusion).
        If False, all points except "vertices" are set to True (exclusion).

    Returns
    -------
    mask : array of bool
        A (n_times * n_vertices) array of boolean values for masking
    rR   TNF)r   rb   rK   rš   rE   )rg   Ú
n_verticesÚverticesZset_asrˆ   r   r   r   r$  X  s    
r$  c                 C   s
  ddl m} t| tƒrpt t| ƒ¡}tjt| ƒt| ƒfdd�}tt| ƒƒD ]}d|| | |f< qJ|j	|dd�}nt | j
d ¡}| }t|dd|ƒd }t|ƒdkrøt dt|ƒ ¡ tjt|ƒd	d�}t|ƒD ]\}	}
|	||
< qÎt| tƒröt ||¡}nt d
¡ d}|S )z@Specify disjoint subsets (e.g., hemispheres) based on adjacency.r   r{   rK   rR   Tr¢   r   z %i disjoint adjacency sets foundr/   z No disjoint adjacency sets foundN)rƒ   r|   rr   r4   r   rI   r$   rb   r5   r…   rJ   r°   r
   r¤   rc   Ztile)r†   rg   r   r|   ÚtestZtest_adjÚviZpart_clustsrª   r7   Zpcr   r   r   r  x  s,    
ÿ


r  c                    sT   t | ƒdkrPt| d tjƒrP| d jtkr>‡ fdd„| D ƒ} n‡ fdd„| D ƒ} | S )z<Reshape cluster masks or indices to be of the correct shape.r   c                    s   g | ]}|  ˆ ¡‘qS r   )r¼   r™   ©r×   r   r   r_   ›  s     z%_reshape_clusters.<locals>.<listcomp>c                    s   g | ]}t  |ˆ ¡‘qS r   )r   rq   r™   r,  r   r   r_   �  s     )r$   rr   r   r»   rS   rK   )rN   r×   r   r,  r   r  –  s
    r  r  r  Ú	fsaveragec                 C   s”  t |dttfdƒ |dkr4t d¡t d¡g}t}nDt|tƒrbtttt	d�|j
 }dd„ |D ƒ}nttdœ t|ƒt	¡}tdd	„ |D ƒƒ}| \}}	}
}|j\}}||kr¾td
|› d|› d�ƒ‚t |
|k ¡d }t|ƒdkrätdƒ‚t ||f¡}t |t|ƒd f¡}t|ƒD ]X\}}| d¡ |	| \}}|||f |||f< tjt||ƒdd�|dd…|d f< �qtj|dd�|dd…df< ||||||ƒS )aS  Assemble summary SourceEstimate from spatiotemporal cluster results.

    This helps visualizing results from spatio-temporal-clustering
    permutation tests.

    Parameters
    ----------
    clu : tuple
        The output from clustering permutation tests.
    p_thresh : float
        The significance threshold for inclusion of clusters.
    tstep : float
        The time step between samples of the original :class:`STC
        <mne.SourceEstimate>`, in seconds (i.e., ``1 / stc.sfreq``). Defaults
        to ``1``, which will yield a colormap indicating cluster duration
        measured in *samples* rather than *seconds*.
    tmin : float | int
        The time of the first sample.
    subject : str
        The name of the subject.
    vertices : list of array | instance of SourceSpaces | None
        The vertex numbers associated with the source space locations. Defaults
        to None. If None, equals ``[np.arange(10242), np.arange(10242)]``.
        Can also be an instance of SourceSpaces to get vertex numbers from.

        .. versionchanged:: 0.21
           Added support for SourceSpaces.

    Returns
    -------
    out : instance of SourceEstimate
        A summary of the clusters. The first time point in this SourceEstimate
        object is the summation of all the clusters. Subsequent time points
        contain each individual cluster. The magnitude of the activity
        corresponds to the duration spanned by the cluster (duration units are
        determined by ``tstep``).

        .. versionchanged:: 0.21
           Added support for volume and mixed source estimates.
    Nr)  i(  )ZsurfaceÚvolumeÚmixedc                 S   s   g | ]}|d  ‘qS )Zvertnor   rÎ   r   r   r   r_   Ó  s     z*summarize_clusters_stc.<locals>.<listcomp>)r   r   c                 s   s   | ]}t |ƒV  qd S r=   ra   )r[   ro   r   r   r   r‘   ×  s     z)summarize_clusters_stc.<locals>.<genexpr>zNumber of cluster vertices (z') did not match the provided vertices (ú)r   zcNo significant clusters available. Please adjust your threshold or check your statistical analysis.r   rý   )r   r4   r   r   rn   r   rr   r›   r   r   r  r£   r$   r>   rJ   r¡   r   r    rb   rc   ré   rH   )Zclur  rG   ZtminÚsubjectr)  ÚklassZn_vertices_needr  rN   Z	clu_pvalsrŠ   rg   r(  Zgood_cluster_indsrF   Zdata_summaryr7   Zcluster_indrO   Zv_indsr   r   r   Úsummarize_clusters_stc¡  sN    *
þþÿ ÿ
ÿ
ÿr3  )N)N)r   )r   )T)r   Nr   NNr   F)r   r   )r   r  )Nr  r   NNNNr   Nr   r   r   Fr  N)Nr  r   NNNNr   Nr   r   r   Fr  N)Nr  r   NNNNr   Nr   r   r   Fr  N)Nr  r   NNNNr   Nr   r   r   Fr  N)T)N)r  r  r   r-  N)>Únumpyr   Z
parametricr   r   r  r   Úfixesr   r   Úutilsr	   r
   r   r   r   r   r   r   r   Zsource_estimater   r   r   Zsource_spacer   r    r-   r3   r:   r;   r<   r@   rD   rH   rQ   rY   rl   rp   rz   rŒ   r°   r¦   r±   rº   rÀ   rÇ   rÍ   râ   rè   rí   rú   r  r  r!  r"  r&  r'  r$  r  r  r3  r   r   r   r   Ú<module>   sþ   ,








0
0

         ÿ
 )1?G
$) C
"                          üI                          üU                         ûH                         ûJ
     ÿ