U
    f»{j´  ã                	   @   sH  d dl mZ d dlZd dlZd dlZd dlmZ d dlm	Z	 dZ
dZdZejjeejjƒeejjdd	�eejjdd
d
d�ejjejjdœZdddddddgiZdddddddgdddgdœZdd iZd!Zejjjd
d"�Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Z d+d,„ Z!d-d.„ Z"d/d0„ Z#d=d1d2„Z$d3d4„ Z%d5d6„ Z&d>d7d8„Z'd9d:„ Z(d;d<„ Z)dS )?é    )ÚpartialN)ÚFIFF)Úobject_diff)Zfile_idZhpi_resultsÚhpi_measZmeas_idZ	meas_dateZhighpassZlowpassZsubject_infoZhpi_subsystemZexperimenterÚdescriptionZproj_idZ	proj_nameZ	line_freqZgantry_angleZ
dev_head_tZbadsZ
ctf_head_tZ	dev_ctf_t)	ZlognoÚcalÚrangeZscannoZ	coil_typeÚkindÚlocZcoord_frameÚunit)r   ZprojsT)Zclean_namesF)Zhead_shape_fnameZrename_channelsZsort_by_ch_name)Zneuromag306ÚCNTZCTFÚBTIÚEGIÚeximiar   ZMUzZMLxZMLyZMUxZMUyZMLzúSTI 014ZDIN1ZDIN3ZDIN7ZDIN4ZDIN5ZDIN2ZGateInZTrig1ZTrig2)r   r   r   é   z]The Pandas library is not installed. Not returning the original trialinfo matrix as metadata.)Údownloadc                 C   s2   d| kr.| d D ]}t D ]}||kr||= qqd S )NZchs)Úch_ignore_fields)ÚinfoZcur_chÚ	cur_field© r   ú]/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/io/fieldtrip/tests/helpers.pyÚ_remove_ignored_ch_fields5   s
    r   c                 C   s   t D ]}|| kr| |= qd S ©N)Úinfo_long_fields©r   r   r   r   r   Ú_remove_long_info_fields=   s    r   c                 C   s,   t D ]}|| kr| |= qt| ƒ t| ƒ d S r   )Úinfo_ignored_fieldsr   Ú_remove_bad_dig_fieldsr   r   r   r   Ú_remove_ignored_info_fieldsC   s
    r   c              	   C   s:   | d d k	r6|   ¡ � dd„ | d D ƒ| d< W 5 Q R X d S )NÚdigc                 S   s*   g | ]"}|d  t jkr|d dkr|‘qS )r	   Úidentr   )r   ZFIFFV_POINT_EEG)Ú.0Údr   r   r   Ú
<listcomp>R   s    þz*_remove_bad_dig_fields.<locals>.<listcomp>)Ú_unlock)r   r   r   r   r   L   s    
r   c                 C   s   t d d |  S )z"Return common paths for all tests.Z	fieldtripZft_test_data)Útesting_path)Úsystemr   r   r   Úget_data_pathsW   s    r(   c                 C   s.   ddl m} |tj t| ƒd¡dgƒd }|S )z&Return cfg_local field for the system.r   )Úread_matz
raw_v7.matÚ	cfg_local)Zpymatreaderr)   ÚosÚpathÚjoinr(   )r'   r)   r*   r   r   r   Úget_cfg_local\   s    ÿÿr.   c              	   C   sP   t | ƒ}tj t|d ¡}t|  }||dd�j}| ¡ � g |d< W 5 Q R X |S )z%Return the info dict of the raw data.Ú	file_nameF©ZpreloadÚcomps)r.   r+   r,   r-   r&   Úsystem_to_reader_fn_dictr   r%   )r'   r*   Úraw_data_fileÚreader_functionr   r   r   r   Úget_raw_infoe   s    
r5   c              	   C   s(  t | ƒ}tj t|d ¡}t|  }||dd�}t|d t |j	¡ƒ}| dkrb|dd|j
d   8 }| d	|¡ | d
¡ |j
 ¡ � g |j
d< W 5 Q R X | |d ¡ | dkrÚ|jd	d…dd…f d |jd	d…dd…f< | dkrî|jd |_| tk�r| t|  ¡ | tk�r$|�r$| t|  ¡ |S )z$Find, load and process the raw data.r/   Tr0   Úcropr   g      à?g      ð?Zsfreqr   Úallr1   Zremoved_chan_names)r   éÿÿÿÿNg    €„.A)r   )r.   r+   r,   r-   r&   r2   ÚminÚnpÚmaxÚtimesr   r6   Zdel_projr%   Zdrop_channelsÚ_dataÚignore_channels_dictÚdrop_extra_chans_dict)r'   Zdrop_extra_chsr*   r3   r4   Úraw_datar6   r   r   r   Úget_raw_datar   s*    
,
rA   c                    sÜ   t | ƒ}t| ƒ}|d |jkr(|d }nd}| dkrdt |¡\‰ }ˆ dd…df d ˆ dd…df< nTtj||dd�‰ t|d tjƒr˜t	|d  
d	¡ƒ}nt|d ƒg}‡ fd
d„|D ƒ}tj|ˆ ||d  |d dd�}|S )z(Find, load and process the epoched data.Z	eventtyper   r   Nr   é   )Ústim_channelZshortest_eventZ
eventvalueÚintc                    s$   g | ]}|ˆ d d …df kr|‘qS )Nr   r   )r"   Úid©Úeventsr   r   r$   ¨   s      zget_epochs.<locals>.<listcomp>ZprestimZpoststim)rG   Úevent_idZtminZtmaxZbaseline)r.   rA   Úch_namesÚmneZevents_from_annotationsZfind_eventsÚ
isinstancer:   ZndarrayÚlistZastyperD   ZEpochs)r'   r*   r@   rC   rH   Úepochsr   rF   r   Ú
get_epochs’   s,    
"ÿ ýrN   c                 C   s    t | ƒ}|jt t|jƒ¡d�S )z$Find, load and process the avg data.)Zpicks)rN   Zaverager:   ZarangeÚlenrI   )r'   rM   r   r   r   Ú
get_evoked²   s    rP   c              
   C   s�   | j  ¡ } |j  ¡ }|s(t| ƒ t|ƒ t| ƒ t|ƒ | |fD ],}|d dkr@| ¡ � g |d< W 5 Q R X q@t|| dd�}|dksŒt|ƒ‚dS )zG
    Check if info fields are equal.

    Some fields are ignored.
    r    NT)ZallcloseÚ )r   Úcopyr   r   r%   r   ÚAssertionError)ÚexpectedÚactualZhas_raw_infoZignore_longÚobjr#   r   r   r   Úcheck_info_fields¸   s    


rW   c                 C   s*   d}|t krt | }tjj| ||d� dS )zCheck data for equality.é   )ÚdecimalN)Úsystem_decimal_accuracy_dictr:   ÚtestingZassert_almost_equal)rT   rU   r'   rY   r   r   r   Ú
check_dataÓ   s    r\   c                 C   s   dd„ |D ƒ}| |kst ‚dS )z0Assert that a warning message is in the records.c                 S   s   g | ]}t |jƒ‘qS r   )ÚstrÚmessage)r"   Úwr   r   r   r$   Þ   s     z,assert_warning_in_record.<locals>.<listcomp>N)rS   )Zwarning_messageZwarn_recordZall_messagesr   r   r   Úassert_warning_in_recordÜ   s    r`   )F)T)*Ú	functoolsr   r+   Únumpyr:   rJ   Zmne.io.constantsr   Z	mne.utilsr   r   r   r   ÚioZread_raw_fifZread_raw_cntZread_raw_ctfZread_raw_btiZread_raw_egiZread_raw_eximiar2   r>   r?   rZ   Zpandas_not_found_warning_msgZdatasetsr[   Z	data_pathr&   r   r   r   r   r(   r.   r5   rA   rN   rP   rW   r\   r`   r   r   r   r   Ú<module>   s\   
ÿý÷   ÿþ		
  
	