U
    f»{j½  ã                   @   sˆ   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZ e	jdd	�Ze	jd
d„ ƒZe	jdd„ ƒZdS )é    N)Úassert_array_almost_equal)Úread_raw_nihonÚread_raw_edf)Ú_test_raw_reader)Útesting)Ú_read_nihon_headerÚ_read_nihon_metadataÚ_read_nihon_annotations)ÚnihonF)Údownloadc               	   C   s:  t d d } t|  ¡ dd�}dt|ƒks,t‚tt| dd� t d d }t|dd�}|jj|jjksft‚|j	d	 |j	d	 ks~t‚d
d„ |j
D ƒ}| |¡ |j
|j
ks¨t‚t|jƒD ]b\}}|j|d d  }|d |d ksàt‚|d |d ksôt‚|d  dd¡}|d |ks²t‚q²t|j|jƒ tjtdd�� t|dd�}W 5 Q R X tjtdd�� t|ƒ}W 5 Q R X t d d }	d}
tjt|
d��  t|	ƒ}t|ƒdk�s¦t‚W 5 Q R X d}
tjt|
d��* t|	ƒ}tdd„ | ¡ D ƒƒ�sèt‚W 5 Q R X d|j
k�st‚dd„ |j
D ƒ}|j|d�}td d„ |D ƒƒ�s6t‚d!S )"z$Test reading Nihon Kohden EEG files.ÚNihonKohdenúMB0400FU.EEGT)ZpreloadZRawNihonF)ÚfnameZtest_scalingzMB0400FU.EDFZsfreqc                 S   s$   i | ]}||  d ¡d  dd¡“qS )ú é   z-RefÚ )ÚsplitÚreplace©Ú.0Úx© r   ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/io/nihon/tests/test_nihon.pyÚ
<dictcomp>   s   ÿ z"test_nihon_eeg.<locals>.<dictcomp>é   r   ZonsetÚdurationÚdescriptionz	Segment: r   z!Not a valid Nihon Kohden EEG file©ÚmatchZeximiaztext_eximia.nxez*No PNT file exists. Metadata will be blankr   z0No LOG file exists. Annotations will not be readc                 s   s   | ]}t |ƒd kV  qdS )r   N)Úlenr   r   r   r   Ú	<genexpr>?   s     z!test_nihon_eeg.<locals>.<genexpr>z$A1c                 S   s   g | ]}|  d ¡r|‘qS )ú$)Ú
startswith©r   Úchr   r   r   Ú
<listcomp>E   s     
 z"test_nihon_eeg.<locals>.<listcomp>)Úpicksc                 s   s   | ]}|d kV  qdS )ÚmiscNr   r#   r   r   r   r    G   s     N)Ú	data_pathr   Úas_posixÚreprÚAssertionErrorr   r   Ú_dataÚshapeÚinfoÚch_namesZrename_channelsÚ	enumerateÚannotationsr   r   ÚpytestZraisesÚ
ValueErrorr   ÚwarnsÚRuntimeWarningr   r   r	   ÚallÚvaluesZget_channel_types)r   ÚrawZ	fname_edfZraw_edfZedf_ch_namesÚiZan1Zan2Zt_descZ	bad_fnameÚmsgÚmetaZannotr&   Zch_typesr   r   r   Útest_nihon_eeg   sJ    ÿ
&r<   c              	   C   sp   t d d }dd„ }|  td|¡ tt |¡ƒttt |¡ƒƒksFt‚d}tjt	|d�� t
|ƒ W 5 Q R X dS )	z$Test deduplication of channel names.r   r   c                 S   s   t j}|d |d< |S )Nr   r   )r
   Z_default_chan_labels)r   r/   r   r   r   Úreturn_channel_duplicatesO   s    z@test_nihon_duplicate_channels.<locals>.return_channel_duplicatesÚ_read_21e_filezeChannel names are not unique, found duplicates for: {'FP1'}. Applying running numbers for duplicates.r   N)r(   Úsetattrr
   r   r>   Úsetr+   r2   r4   r5   r   )Zmonkeypatchr   r=   r:   r   r   r   Útest_nihon_duplicate_channelsJ   s    ÿrA   )r2   Znumpy.testingr   Zmne.ior   r   Zmne.io.tests.test_rawr   Zmne.datasetsr   Zmne.io.nihon.nihonr   r   r	   Zmne.io.nihonr
   r(   Zrequires_testing_datar<   rA   r   r   r   r   Ú<module>   s   
7