CoolFace
Apppublic

Aluode/PerceptionLabPortable

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

2'�Yi�,�@s�ddlZddlZddlmZmZddlmZmZm	Z	e�3d�Ze�4d�Ze	d!dd��Z
e	d"d5d��Zdd
�Zdd�Zddd�dd�Zdd�Zdddddd�dd�Zdd�Zdd�Zdd�Zdd �ZdS)#�N�)�
_picks_to_idx�6pick_types)�
_check_option�_validate_type�fill_doczS(\d+)_D(\d+) (\d+\.?\d*)zS(\d+)_D(\d+) (\w+)cs$t��fdd�t�|gd�D�t�S)a9Determine the distance between NIRS source and detectors.7 8    Parameters9    ----------10    %(info_not_none)s11    %(picks_all_data)s12 13    Returns14    -------15    dists : array of float16        Array containing distances in meters.17        Of shape equal to number of channels, or shape of picks if supplied.18    c	sBg|]}tj�tj�d|ddd��dd�dd�d��qS)�chs�locr�	�r)Zaxis)�npZlinalgZnorm�diffZreshape��.0�pick��info���E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/preprocessing/nirs/nirs.py�19<listcomp>!s�,��z-source_detector_distances.<locals>.<listcomp>)�exclude)r�arrayr�float)r�picksrrr�source_detector_distancess20��r�{�G�z�?cCst|�|kS)a�Determine which NIRS channels are short.21 22    Channels with a source to detector distance of less than23    ``threshold`` are reported as short. The default threshold is 0.01 m.24 25    Parameters26    ----------27    %(info_not_none)s28    threshold : float29        The threshold distance for what is considered short in meters.30 31    Returns32    -------33    short : array of bool34        Array indicating which channels are short.35        Of shape equal to number of channels.36    )r)r�	thresholdrrr�short_channels+src	CsXt|ddggdd�}t�}|D]}|�ttt�|d|���d���qt�	|t37�S)z,Return the light frequency for each channel.�fnirs_cw_amplitude�fnirs_odT�r�allow_empty�ch_namesr)r�list�append�roundr�	_S_D_F_RE�match�groupsrr�int)rr�freqsrrrr�_channel_frequenciesAs�*r+cCsBt|ddggdd�}g}|D]}|�|d|�d�d�q|S)z'Return the chromophore of each channel.�hbo�hbrTr r"� �)rr$�split)rrZchroma�iirrr�_channel_chromophoreMs38r2T��throw_errors�39check_badscs�t�ddggdd�}t�ddggdd�}t|�dkt|�dk@r%td|�}t|�r0d	}t}|}nd40}t}|}t�|�}|jdkrLtd|�d
t	|�����|j41jdk}	t	|�}|	rj|ddgkritd|�d|�d���nt�t�
|�|�s~td|�d|�d���t|�ddkr�tdt�j��d�|�}�fdd�|D�}42t�t�|43��r�td|44�d�|�}|D]A}|��d|d�}t|�s�tdt�j|���|�}n"|��d}
t|�r�|
}
q�|
dvr�td�d|d��|�}nq�|t��fdd�|D��}t|d d d�|d!d d��D]\}}�d|d}�d|d}|�|�}|�|�}|��d d"�\}}}|��d d"�\}}}t|��rOt|�t|�}}||k�sg||k�sg||dk�sg||d!k�r�td#|�d$|d�d%|d!�d&|�d'|�d(t|��d)t|���|�}n�q
|�r�t|d d d�|d!d d��D]+\}}�j|�j|g}t	t�d*��|��}t|�d!k�r�td+|�d,|�����q�|S)-aiCheck channels follow expected fNIRS format.45 46    If the channels are correctly ordered then an array of valid picks47    will be returned.48 49    If throw_errors is True then any errors in fNIRS formatting will be50    thrown to inform the user. If throw_errors is False then an empty array51    will be returned if the channels are not sufficiently formatted.52    rrTr r,r-rzqMNE does not support a combination of amplitude, optical density, and haemoglobin data in the same raw structure.Zfrequencies�chromophore)rzExactly two z must exist in info, got �UzThe z) in info must be ["hbo", "hbr"], but got z insteadz0 in info must be unique and sorted, but got got rzRNIRS channels not ordered correctly. An even number of NIRS channels is required. z channels wereprovidedcs g|]}�d|dd�qS)rr	r53r)rr1rrrr�� z+_check_channels_ordered.<locals>.<listcomp>zjNIRS channels is missing wavelength information in the info["chs"] structure. The encoded wavelengths are �.rZch_namez^NIRS channels have specified naming conventions. The provided channel name can not be parsed: )r,r-z{NIRS channels have specified naming conventions.Chromophore data must be labeled either hbo or hbr. The failing channel is c�g|]}�d|�qS�r"rrrrrr��Nr/rzhNIRS channels not ordered correctly. Channels must be ordered as source detector pairs with alternating r.z & z, but got SZ_Dz pair z and �badsz,NIRS bad labelling is not consistent, found z but needed )r�len�_throw_or_return_emptyr&�	_S_D_H_RErr�shape�54ValueErrorr#Zdtype�kindZarray_equal�uniquer"�any�isnanr'�bool�reprr(Zargsort�zipr�set�intersection�RuntimeError)r�	pair_valsr4r5�55picks_wave�picks_chromarZ56error_wordZuse_REZis_strZ	all_freqsrZch_name_info�valuer1�jj�ch1_name�ch2_nameZch1_reZch2_reZch1_SZch1_DZ	ch1_valueZch2_SZch2_DZ	ch2_valueZwant�gotrrr�_check_channels_orderedWs���5758���������������59&6061626364���������&���rUcCs|rt|��gS�N)rB)�msgr4rrrr?�sr?)r4�fnirs�whichr5r!cCs�t|dtfd�tdddd�}td|dt|��|dur@||}|dkr)d	d65gnd|��}tt||d��s@t|�d
|�d���t�	t66|��}|jdkrO|}	nt�	t|��}	t
||	||d�}67|68S)zCApply all checks to fNIRS info. Works on all continuous wave types.NrXzoptical densityzcontinuous waver6)ZodZcw_amplitude�hbrVrZr,r-Zfnirs_)rXz must operate on z data, but none was found.rr3)r�str�dictr�tupler>rrLrrDr+�sizer2rU)rr4rXrYr5r!�kindsrCr*rM�outrrr�_validate_nirs_info�s,69��70�racCs�t|dd�}t|d�}t|ddd�|ddd��D]"\}}|j||j|}}||vr4|�|�q||vr=|�|�qt|�|d<|S)z*Spread bad labeling across fnirs channels.F)r5r=Nrr/)rarJrIr"�add�sorted)rrZnew_badsr1rQrRrSrrr�_fnirs_spread_badss&71�rdcs�t|ddggdd�}t|ddggdd�}t|�dkrt�n
t|�dkr&t�nggfSt��fdd	�|jD��}t��fd72d	�|jD��}dd	�|D�}dd	�|D�}||fS)
z#Return list of unique optode names.rrTr r,r-rc�"g|]
}t��|���d��qS)r�r)r'r(�r�ch��regexrrr0�"z'_fnirs_optode_names.<locals>.<listcomp>cre)r/rfrgrirrr1rkcS�g|]}d|���qS)�Sr)r�srrrr3�cSrl)�Dr)r�drrrr4ro)rr>r&r@rrDr")rrNrO�sourcesZ	detectorsZ	src_namesZ	det_namesrrir�_fnirs_optode_names"s�rscsT�fdd�|jD��d�}d�vrtdd�}n	d�vr tdd�}|d	|d73|S)zFind the position of an optode.csg|]}�|v�qSrr)r�a��optoderrr;sz$_optode_position.<locals>.<listcomp>Trmr�rpr74rr	)r"�index�range)rrv�idxZloc_idxrrur�_optode_position9s75r{csZ|j�t�dgd�}�fdd�|D���fdd�|D�}t|�fdd�d�}|�|�dS)	NT)rXrcs g|]}�d|��d�qS)r"r)r0rrrrrJr8z!_reorder_nirx.<locals>.<listcomp>cr:r;rrrrrrKr<cs"��|��d�|jdd�dfS)Nrr/)�maxsplit)rxr0)�name)�prefixesrr�<lambda>Nrkz_reorder_nirx.<locals>.<lambda>)�key)rrrcZreorder_channels)�rawrZ76nirs_namesZnirs_sortedr)rr~r�
_reorder_nirxEs77�r�rV)r)�re�numpyrZ78_fiff.pickrr�utilsrrr�compiler&r@rrr+r2rUr?rardrsr{r�rrrr�<module>s279808182�#
Aluode/PerceptionLabPortable · CoolFace