CoolFace
Apppublic

Aluode/PerceptionLabPortable

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

2'�Yi.&�@s�ddlZddlmZmZddlmZddlmZddl	m3Z4mZmZm
Z
ddlmZe
				5						dd
d��Ze
ddddd�dd��Zdd�Ze
								6								ddd��ZdS)�N�)�
pick_channels�7pick_types)�Epochs��filter_data)�_pl�_validate_type�logger�verbose�)�peak_finder���8�10sFc9
Cs�t||�}10t�|j�|11}t�d|12���|rdnd}|j|13|dd�\}}
|
|jd|j}
t||||||jd|j||||	d�}t�	|
|dd�df|j��14t�|dd�df<|S)	a�Locate EOG artifacts.15 16    .. note:: To control true-positive and true-negative detection rates, you17              may adjust the ``thresh`` parameter.18 19    Parameters20    ----------21    raw : instance of Raw22        The raw data.23    event_id : int24        The index to assign to found events.25    l_freq : float26        Low cut-off frequency to apply to the EOG channel in Hz.27    h_freq : float28        High cut-off frequency to apply to the EOG channel in Hz.29    filter_length : str | int | None30        Number of taps to use for filtering.31    %(ch_name_eog)s32    tstart : float33        Start detection after tstart seconds.34    reject_by_annotation : bool35        Whether to omit data that is annotated as bad.36    thresh : float | None37        Threshold to trigger the detection of an EOG event. This controls the38        thresholding of the underlying peak-finding algorithm. Larger values39        mean that fewer peaks (i.e., fewer EOG events) will be detected.40        If ``None``, use the default of ``(max(eog) - min(eog)) / 4``,41        with ``eog`` being the filtered EOG signal.42    %(verbose)s43 44    Returns45    -------46    eog_events : array47        Events.48 49    See Also50    --------51    create_eog_epochs52    compute_proj_eog53    z'EOG channel index for this subject is: ZomitNT)�picks�reject_by_annotationZreturn_timesZsfreq)54�ch_names�event_id�l_freq�h_freq�
sampling_rate�55first_samp�
filter_length�tstart�threshrr)�_get_eog_channel_index�np�arrayrr56�info�get_datar�_find_eog_events�roundZastype�int)�rawrrrr�ch_namerrrr�eog_indsZ	eog_names�eog�times�57eog_events�r*�E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/preprocessing/eog.py�find_eog_eventss.58659��2r,g)rrrrc60
sdt�d�t�d�dd��t����fdd�|D��}t�tj|ddd	��}t�|�}
|d61ur=t�d||
�d��t||
�||d62�d
d
dddd�}t�d�|t�	|�}t63�|�}t�t�|��t�t�
|��kr~t||d64�|	dd�\}}n
t||d65�|	dd�\}}||7}t|�}t�d|���t�||t�|t66�|t�|t67�g�j}|S)zFind EOG events.zOFiltering the data to remove DC offset to help distinguish blinks from saccades�-g@g�?cs,g|]}t|�d�d�ddddddd��qS)rN��?�zero-double�hann�firwin2F)�phase�68fir_window�69fir_designrr)�.0�x�rZfmaxrr*r+�70<listcomp>{s"���z$_find_eog_events.<locals>.<listcomp>rr)ZaxisNzSelecting channel z for blink detectionr.r/r0r1)r2r3r4z8Now detecting blinks and generating corresponding events)Zextrema�����zNumber of EOG events detected: )r71rr�minimumr�sqrt�sumZargmaxr�meanr#�abs�max�minr
�lenZzerosZones�T)r'rrrrrrrrrrZfilteog�tempZindexmaxZn_samples_startr)�_Zn_eventsr*r7r+r!asX���72�73 74���r!cs�t|dttfdd�|dur/t�jddddddddd�	}|jdkr%td	���fd75d�|D�}n
t|t�r8|g}n|��}|dura�fdd�|D�}|rZt	d
t76|��dd�|�����t�j
|d�}t�dt77|��dd�|����|S)zGet EOG channel indices.Nr%)�typesZ	item_nameFTZbads)ZmegZeegZstimr'ZecgZemgZref_meg�excluderzNo EOG channel(s) foundcsg|]}�j|�qSr*�r)r5�i��instr*r+r8�sz*_get_eog_channel_index.<locals>.<listcomp>csg|]	}|�jvr|�qSr*rG)r5r%rIr*r+r8�szThe specified EOG channelz cannot be found: z, )�includezUsing EOG channelz: )r	�str�listrr�size�RuntimeError�78isinstance�copy�79ValueErrorr�joinrrr80)r%rJr&r�	not_foundr*rIr+r�s<�8182�� r��r.TcCs<t|||||||
d�}t|||||d||	||83|||d�
}|S)az	Conveniently generate epochs around EOG artifact events.84 85    %(create_eog_epochs)s86 87    Parameters88    ----------89    raw : instance of Raw90        The raw data.91    %(ch_name_eog)s92    event_id : int93        The index to assign to found events.94    %(picks_all)s95    tmin : float96        Start time before event.97    tmax : float98        End time after event.99    l_freq : float100        Low pass frequency to apply to the EOG channel while finding events.101    h_freq : float102        High pass frequency to apply to the EOG channel while finding events.103    reject : dict | None104        Rejection parameters based on peak-to-peak amplitude.105        Valid keys are 'grad' | 'mag' | 'eeg' | 'eog' | 'ecg'.106        If reject is None then no rejection is done. Example::107 108            reject = dict(grad=4000e-13, # T / m (gradiometers)109                          mag=4e-12, # T (magnetometers)110                          eeg=40e-6, # V (EEG channels)111                          eog=250e-6 # V (EOG channels)112                          )113 114    flat : dict | None115        Rejection parameters based on flatness of signal.116        Valid keys are 'grad' | 'mag' | 'eeg' | 'eog' | 'ecg', and values117        are floats that set the minimum acceptable peak-to-peak amplitude.118        If flat is None then no rejection is done.119    baseline : tuple or list of length 2, or None120        The time interval to apply rescaling / baseline correction.121        If None do not apply it. If baseline is (a, b)122        the interval is between "a (s)" and "b (s)".123        If a is None the beginning of the data is used124        and if b is None then b is set to the end of the interval.125        If baseline is equal to (None, None) all the time126        interval is used. If None, no correction is applied.127    preload : bool128        Preload epochs or not.129    %(reject_by_annotation_epochs)s130 131        .. versionadded:: 0.14.0132    thresh : float133        Threshold to trigger EOG event.134    %(decim)s135 136        .. versionadded:: 0.21.0137    %(verbose)s138 139    Returns140    -------141    eog_epochs : instance of Epochs142        Data epoched around EOG events.143 144    See Also145    --------146    find_eog_events147    compute_proj_eog148 149    Notes150    -----151    Filtering is only applied to the EOG channel while finding events.152    The resulting ``eog_epochs`` will have no filtering applied (i.e., have153    the same filter properties as the input ``raw`` instance).154    )r%rrrrrF)�eventsr�tmin�tmaxZproj�reject�flatr�baseline�preloadr�decim)r,r)r$r%rrrWrXrrrYrZr[r\rrr]rrVZ155eog_epochsr*r*r+�create_eog_epochs�s2[��r^)	rrrrNrFNN)NrNrUr.rrNNNTTNrN)�numpyrZ156_fiff.pickrrZepochsr�filterr�utilsrr	r157rZ_peak_finderr
r,r!rr^r*r*r*r+�<module>sR�R158�X'�
Aluode/PerceptionLabPortable · CoolFace