CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_testing.cpython-310.pyc102 linesDownload Raw Back to __pycache__
1o

2'�Yi�6�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl3mZddlZ
ddlmZmZddlmZdd	lmZmZdd4lmZddlmZddlmZdGdd�ZGdd�de�Zdd�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$Gdd �d �Z%d!d"�Z&d#d$�Z'd%d&�Z(dHd'd(�Z)d)d*d+�d,d-�Z*d.d/�Z+d0d1�Z,dId3d4�Z-	dJd6d7�Z.d8d9�Z/d:d;�Z0d<d=�Z1dKd>d?�Z2dLd@dA�Z3dBdC�Z4dMdEdF�Z5dS)NzTesting functions.�N��wraps)�rmtree)�SkipTest)�assert_allclose�assert_array_equal)�linalg�)�ClosingStringIO�warn)�
check_version)�run_subprocess��object_diff������> cCs\t��\}}}t�t�|�||��}d�|��d�t�||�}d|d|�|�}|S)zExplain an exception.��5�:6)�sys�exc_info�	traceback�format_list�7extract_tb�join�split�format_exception_only)�start�stop�prefix�etype�value�tb�string�r$�|E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/utils/_testing.py�_explain_exceptions8r&c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_TempDira�Create and auto-destroy temp dir.9 10    This is designed to be used with testing modules. Instances should be11    defined inside test functions. Instances defined at module level can not12    guarantee proper destruction of the temporary directory.13 14    When used at module level, the current use of the __del__() method for15    cleanup can fail because the rmtree function may be cleaned up before this16    object (an alternative could be using the atexit module instead).17    cCst�|tjdd��}|S)NZtmp_mne_tempdir_)r)�str�__new__�tempfile�mkdtemp)�self�newr$r$r%r)0sz_TempDir.__new__cCs|��|_dS�N)�__str__�_path�r,r$r$r%�__init__4sz_TempDir.__init__cCst|jdd�dS)NT)�
ignore_errors)rr0r1r$r$r%�__del__7sz_TempDir.__del__N)�__name__�18__module__�__qualname__�__doc__r)r2r4r$r$r$r%r'$s19r'cCs20t�|�S)z%Decorate a function as requiring MNE.)�requires_mne_mark)�funcr$r$r%�requires_mne;�21r;cCsddl}|jjt�dd�S)z%Mark pytest tests that require MNE-C.rNzRequires MNE-C��reason)�pytest�mark�skipif�	has_mne_c�r?r$r$r%r9@sr9cCs ddl}|jjtdd�dd�S)z(Mark pytest tests that require OpenMEEG.rNZopenmeegz2.5.6zRequires OpenMEEG >= 2.5.6r=)r?r@rArrCr$r$r%�requires_openmeeg_markGs�rDcCsxddl}d}t|t�r0|d|��7}zt|dg�Wnty%d}Ynwd}|jj||d�S|jjt�dd�|�S)	zRequire Freesurfer.rNzRequires Freesurferz22 command: z	--versionTFr=)r?�23isinstancer(r
�	Exceptionr@rA�has_freesurfer)�argr?r>�skipr$r$r%�requires_freesurferPs24��rJcCs*ddl}|jjttj�dd��dd�|�S)NrZMNE_SKIP_NETWORK_TESTSzMNE_SKIP_NETWORK_TESTS is setr=)r?r@rA�int�os�environ�get)r:r?r$r$r%�requires_good_networkhs��rOcCs.t��jj}|�dd�dkr|d�dSdS)z%Run a given command if it's __main__.r5r�__main__�runN)�inspect�currentframe�f_back�f_localsrN)�25local_varsr$r$r%�run_command_if_mainqs�rWc@s*eZdZdZddd�Zdd�Zdd	�Zd26S)�27ArgvSetterzTemporarily set sys.argv.r$TcCs<td|�|_|rt�ntj|_|rt�|_dStj|_dS)N)�python)�list�argvr28r�stdout�stderr)r,�argsZdisable_stdoutZdisable_stderrr$r$r%r2{szArgvSetter.__init__cCs4tj|_|jt_tj|_|jt_tj|_|jt_|Sr.)rr[�	orig_argvr\�orig_stdoutr]�orig_stderrr1r$r$r%�	__enter__�szArgvSetter.__enter__cGs|jt_|jt_|jt_dSr.)r_rr[r`r\rar])r,r^r$r$r%�__exit__�szArgvSetter.__exit__N)r$TT)r5r6r7r8r2rbrcr$r$r$r%rXxs2930	rXcC�31dtjvS)zCheck for MNE-C.ZMNE_ROOT�rLrMr$r$r$r%rB�r<rBcCrd)zCheck for Freesurfer.ZFREESURFER_HOMErer$r$r$r%rG�r<rGcst���fdd��}|S)z>Decorate tests that make calls to SVD and intermittently fail.c32sPz�|i|��WStjjy'}zdt|�vr"d}t|�t|���d}~ww)NzSVD did not convergez7Intel MKL SVD convergence error detected, skipping test)�nprZLinAlgErrorr(rr)r^�kwargs�exp�msg��functionr$r%�dec�s��zbuggy_mkl_svd.<locals>.decr)rkrlr$rjr%�
buggy_mkl_svd�s33rmcCs|d}ddlm}t||�r|j}dD])}t�|j|�d�k�d}t|�|ks6Jdt|��d|�d	|����|�|�qd34S)z;Assert that there are boundary annotations and remove them.T���BaseRaw)ZEDGE�BADz	 boundaryrzGot z 'z! boundary' annotations, expected N)	�iorprE�annotationsrf�where�description�len�delete)rs�n�__tracebackhide__rp�key�idxr$r$r%� assert_and_remove_boundary_annot�s35��r|zObject mismatchF)�err_msg�allclosecCs0d}t|||d�}|dksJ|�d|����dS)zAssert two objects are equal.T)r~rrNr)�a�br}r~ry�dr$r$r%�assert_object_equal�sr�c	Cs�ddlm}ddlm}m}ddlm}|ddd�}|t�d�|dd	�}|dur,||�}|j	j36d37d��
||j	d<Wd�n1sCwY|d
gdgdg|�}|j|d�|S)Nrn)�create_info)�Annotations�_handle_meas_date)�RawArray�38g$@)�ch_namesZsfreq)r�r�)�data�infoZ39first_sampT)Zcheck_after�	meas_dateg�?g�������?�dummy)rs)�_fiff.meas_infor�rsr�r�rrr�rf�emptyr�Z_unlockZset_annotations)	r�Z	orig_timer�r�r�r�r��rawZannotr$r$r%�40_raw_annot�s�r�cCsFddlm}ddlm}t||�r||dSt||�r!|j|SdS)z#Get the (n_ch, n_times) data array.rn)�EvokedrorN)Zevokedr�rrrprEr�)�xZch_idxr�rpr$r$r%�	_get_data�s414243�r��MEGcCsd}t||�}t||�}	t�tj|	|	dd��}44||	}t�tj||dd��}tj|dtj|d�|45|}
|
��}|
|k��}|dkrJd|�d�n|}|d	ksgJd46|d�d|d�d
|�dt|��d|��47��t�	|
�}||ks�J|�d|d�d|d�|����dS)z#Check the SNR of a set of channels.Tr	)Zaxisg&����y3)�outrz (�)rzSNR (worst z0.2fz) < z for �/z	 channelsz SNR median z < N)48r�rf�sqrt�meanZclip�inf�min�sumrvZmedian)�actual�desired�picks�min_tol�med_tolri�kindryZactual_dataZdesired_dataZ	bench_rms�errorZ	error_rmsZsnrs�snrZ	bad_countr$r$r%�49_check_snr�s,505152����53,r��@@c	Cs@d}ddlm}||jdgd�}||jdgd�}	t||	dd�||jddgd�}54||jddgd�}|d	ur<t|55|d56d�t�t�t|j��t�	||57g��}t�t�t|j��t�	|	|g��}
t||
dd�t|�dkrzt58t||�t||�d
ddd�t||||||dd�|d	ur�t|59�dkr�t|||60d||dd�d	Sd	Sd	S)z�Assert channel SNR of a certain level.61 62    Mostly useful for operations like Maxwell filtering that modify63    MEG channels while leaving EEG and others intact.64    Trn)�65pick_types)�meg�excludezMEG pick mismatch�r}F)r�Zchpir�NzcHPI pick mismatchzOther pick mismatchrg�dy���=��h㈵��>znon-MEG channel mismatch)�atol�rtolr}r�)r��ZcHPI)
Z66_fiff.pickr�r�rrfZ	setdiff1dZarangervr�Zconcatenaterr�r�)r�r�r�r�Zchpi_med_tolriryr�r�Z
picks_desiredZchpisZ
chpis_desiredZothersZothers_desiredr$r$r%�assert_meg_snr�s8����r�cCspd}tjdd��tj|dd�tj||dd�}Wd�n1s#wY||ks6Jd|�d|����dS)	z?Assert actual and desired arrays are within some SNR tolerance.T�ignore)�divideZfro)�ordNzsnr=z < tol=)rfZerrstaterZnorm)r�r�Ztolryr�r$r$r%�67assert_snrs68"� r�cCs�d}t|j|jdd�t|j|jdd�t|jd|jddd�t|jd|jddd�t|j|jd	d�t|j|jd69d�dS)zCheck that two STC are equal.TzTimes mismatchr�z
Data mismatchrzLeft vertices mismatchr	zRight vertices mismatchz
tmin mismatchztstep mismatchN)r�timesr�rZverticesZtminZtstep)Zstc1Zstc2ryr$r$r%�assert_stcs_equal%s��r�cCs|d|dfS)zSort dig keys.r��identr$)�digr$r$r%�
_dig_sort_key9sr�c
sd}ddlm�ddlm}ddlm}ddlm}||}}t||�r7t||�s-Jd��|d|d}}nt||�s@Jd��t||�sIJd��|j	|j	}}d	}}t|t70�s]Jd71��t|t72�sfJd��t|td�}t|td�}t
|�t
|�ks~Jd
��tt|d	|�|d	|���D]7\}	\}73}dD]}|74|||ks�Jd|�d|	����q�t|75d|dddd|	�d|76d�d|d��d�q�t�fdd�|D���r|d	u�r||ddd�\}
}}||ddd�\}}}t||
ddd�t||dddd�t||ddd d�d	Sd	Sd	S)!zAssert dig allclose.Trn��FIFF)�Info)�fit_sphere_to_headshape)�77DigMontagezBoth must be Info or DigMontager�Nzdig_py must be a listzdig_bin must be a list)rzzDifferent number of dig points)r�r�Zcoord_framezkey=z mismatch on point �rr�zFailure on rr)r�r�r}c3s�|]78}|d�jkVqdS)r�N)ZFIFFV_POINT_EXTRA)�.0r�r�r$r%�	<genexpr>`s�z&assert_dig_allclose.<locals>.<genexpr>�mr�)Zunits�verboseg�����ư>zSphere radius mismatch)r�r}zSphere device origin mismatchzSphere origin mismatch)Z_fiff.constantsr�r�r�Zbemr�Zchannels.montager�rEr�rZ�sortedr�rv�	enumerate�zipr�any)Zinfo_pyZinfo_bin�limitryr�r�r�Zdig_pyZdig_bin�iiZd_pyZd_binrzZr_binZ79o_head_binZ	o_dev_binZr_pyZ	o_head_pyZo_dev_pyr$r�r%�assert_dig_allclose>sf8081*&�"���82��r�cCs`ddlm}|j��|jj��|}|��}|j�	�}|j83�	�}|||jj||fd|d�dS)z>Click on a channel name in a raw/epochs/ICA browse-style plot.rn)�_fake_clickZpix)Zxform�buttonN)Z	viz.utilsr�ZcanvasZdrawZmneZax_mainZget_yticklabelsZget_window_extentZ	intervalxr�Z	intervaly)�figZch_indexr�r��textZbboxr��yr$r$r%�_click_ch_namexs848586r�cCs tdd�r	|��S|jd��S)z/Get fig suptitle (shim for matplotlib < 3.8.0).Z87matplotlibz3.8r)rZget_suptitleZtextsZget_text)r�r$r$r%�
_get_suptitle�s88r�r�c	Csd}ddlm}m}t||�r8t||�sJd��|d|dks$Jd��|d|dks0Jd��|d	}|d	}t|tj�sBJd89��t|tj�sLJd��|jdksUJd
��|jdks^Jd��|||ddd�\}}||ks|Jd|d�dd|d�d���||ks�J|d�d|d�d���dS)NTrn)�	Transform�angle_distance_between_rigidz!Both must be Transform or ndarray�fromz'from' frame mismatch�toz'to' frame mismatchZtranszactual should be ndarrayzdesired should be ndarray)�r�zactual.shape should be (4, 4)zdesired.shape should be (4, 4)�degr�)Zangle_unitsZdistance_unitsi�z0.3fz > z mm translationu° rotation)Z90transformsr�r�rErfZndarray�shape)	r�r�Zdist_tolZ	angle_tolryr�r�Zangle�distr$r$r%�assert_trans_allclose�s&919293�$r�)rNr)r	)r�)r�r�Nr.)rr	)r�r�)6r8rRrLrr*r�	functoolsr�shutilrZunittestr�numpyrfZ
numpy.testingrrZscipyrZ_loggingr94r�checkr�miscr
Znumericsrr&r(r'r;r9rDrJrOrWrXrBrGrmr|r�r�r�r�r�r�r�r�r�r�r�r�r$r$r$r%�<module>sT9596		979899�'	100101:102 
Aluode/PerceptionLabPortable · CoolFace