CoolFace
Apppublic

Aluode/PerceptionLabPortable

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

2'�Yi�A�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl3mZmZddl
mZddlmZddlmZmZddlmZddlmZdd	lmZddlZdd4lmZddlmZm Z m!Z!dd
l"m#Z#m$Z$dd�Z%d?dd�Z&d@dd�Z'dAdd�Z(dd�Z)Gdd�d�Z*Gdd �d e+�Z,d!d"�Z-d#d$�Z.e dBd&d'��Z/edCd)d*��Z0dDd,d-�Z1d.d/�Z2d0d1�Z3d2d3�Z4dd4�d5d6�Z5dEd7d8�Z6d9d:�Z7d;d<�Z8d=d>�Z9dS)Fz%Some miscellaneous utility functions.�N)�	ExitStack�contextmanager)�files)�log)�Empty�Queue)�	Formatter)�dedent)�Thread)�
FunctionMaker�)�logger�verbose�warn)�
_check_option�_validate_typecCs|S�N�)�xrr�xE:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/utils/misc.py�_identity_functionsr�md5cCs*tt|�}dt�|�jvr|dd�S|�S)N�usedforsecurityF)r)�getattr�hashlib�inspect�	signature�5parameters)�kind�funcrrr�_empty_hash$s67r ��scCs,t|ttjB�r8|nt|�}|dkr|S|S)z#Determine if plural should be used.r)�9isinstance�int�npZgeneric�len)rZnon_pl�plZlen_xrrr�_pl,sr(������> cCs\t��\}}}t�t�|�||��}d�|��d�t�||�}d|d|�|�}|S)zExplain an exception.r!�10�:11)�sys�exc_info�	traceback�format_list�12extract_tb�join�split�format_exception_only)�start�stop�prefix�etype�value�tb�stringrrr�_explain_exception2s13r<cs6t|����t�dd��D��}�fdd�|D���S)zSort and return keys of dict.cS�g|]}t|��qSr��str)�.0�krrr�14<listcomp>?�z_sort_keys.<locals>.<listcomp>csg|]}�|�qSrr)r@�ii��keysrrrB@rC)�listrFr%Zargsort)r�idxrrEr�15_sort_keys<srIc@s"eZdZdZdd�Zddd�ZdS)	�_DefaultEventParserzParse none standard events.cCst�|_dSr)�dict�	event_ids)�selfrrr�__init__G�z_DefaultEventParser.__init__rcCs(||jvr|t|j�|j|<|j|Sr)rLr&)rM�description�offsetrrr�__call__Js1617z_DefaultEventParser.__call__N)r)�__name__�18__module__�__qualname__�__doc__rNrRrrrrrJDsrJc@seZdZdZdd�ZdS)�_FormatDictzHelp pformat() work properly.cCsd|dS)N�{�}r)rM�keyrrr�__missing__TrOz_FormatDict.__missing__N)rSrTrUrVr[rrrrrWQsrWcKst�}t|�}|�|d|�S)zqFormat a template string partially.19 20    Examples21    --------22    >>> pformat("{a}_{b}", a='x')23    'x_{b}'24    r)rrW�vformat)�temp�fmt�	formatter�mappingrrr�pformatXsracCs t|jd�D]}|�|�qdS)N�)�iter�readline�put)�out�queue�linerrr�_enqueue_outputes�riFc	Os�d}d}t�}t�}d|v}	d|v}25t|g|�Ri|����}|	r0tt|j|fd�}d|_|��|26rBtt|j|fd�}
d|
_|
��	|��du}	z|j	dd�}Wn	t27y[Ynw|�d	�}|�d28�}t
�|�||7}qJ	z|j	dd�}Wn	t29y�Ynw|�d	�}|�d30�}t
�|�||7}qq|r�nqCWd�n1s�wY||f}|r�||jf}|S|jr�|	r�|nd}|31r�|nd}tj|j|||d��|S)a�Run command using subprocess.Popen.32 33    Run command and wait for command to complete. If the return code was zero34    then return, otherwise raise CalledProcessError.35    By default, this will also add stdout= and stderr=subproces.PIPE36    to the call to Popen to suppress printing to the terminal.37 38    Parameters39    ----------40    command : list of str | str41        Command to run as subprocess (see subprocess.Popen documentation).42    return_code : bool43        If True, return the return code instead of raising an error if it's44        non-zero.45 46        .. versionadded:: 0.2047    %(verbose)s48    *args, **kwargs : arguments49        Additional arguments to pass to subprocess.Popen.50 51    Returns52    -------53    stdout : str54        Stdout returned by the process.55    stderr : str56        Stderr returned by the process.57    code : int58        The return code, only returned if ``return_code == True``.59    r!�stdout�stderr)�target�argsTNg{�G�z�?)�timeoutzutf-8r+)�outputrk)r�running_subprocessr60rirj�daemonr5rk�poll�getr�decode�removesuffixr
�info�warning�61returncode�62subprocess�CalledProcessError)�commandZreturn_coderrm�kwargsZall_outZall_errZout_qZerr_qZcontrol_stdoutZcontrol_stderr�pZout_tZerr_tZdo_breakrfZlog_out�errZerr_outrorjrkrrr�run_subprocessjsn�636465��666768��!�+�69�r�waitc
	os��t|td�td|gd��t�}dD]}||vr$tj||<|�|�q|�dtj	�}t70dd�|d�tj�D��r?t
d�t|t�rG|}nd	d71�|D�}d�dd�|D��}t�d
|���ztj|g|�Ri|��}	Wn ty�t|t�r�|��d}72n|d}73t�d|74����wz=t��}|D]75}|�t|	|��q�|	VWd�n1s�wYWt|	|��|	��dSWt|	|��|	��dSt|	|��|	��w)a�Context manager to do something with a command running via Popen.76 77    Parameters78    ----------79    command : list of str | str80        Command to run as subprocess (see :class:`python:subprocess.Popen`).81    after : str82        Can be:83 84        - "wait" to use :meth:`~python:subprocess.Popen.wait`85        - "communicate" to use :meth:`~python.subprocess.Popen.communicate`86        - "terminate" to use :meth:`~python:subprocess.Popen.terminate`87        - "kill" to use :meth:`~python:subprocess.Popen.kill`88 89    %(verbose)s90    *args, **kwargs : arguments91        Additional arguments to pass to subprocess.Popen.92 93    Returns94    -------95    p : instance of Popen96        The process.97    �after)r��	terminate�kill�communicate)rkrj�envcss�|]}|�d�VqdS)�~N)�98startswith)r@r}rrr�	<genexpr>�s�z%running_subprocess.<locals>.<genexpr>�PATHz�Your PATH environment variable contains at least one path starting with a tilde ("~") character. Such paths are not interpreted correctly from within Python. It is recommended that you use "$HOME" instead of "~".cSr=rr>�r@r"rrrrB�rCz&running_subprocess.<locals>.<listcomp>� css�|]}|VqdSrrr�rrrr��s�zRunning subprocess: rzCommand not found: N)rr?rrGry�PIPE�appendrs�os�environ�anyr3�pathseprr#r2r
rv�Popen�	Exception�errorr�
enter_contextrr�)
r{r�rrmr|ZcontextsZstdxxxr�Zcommand_strr}Zcommand_name�stack�contextrrrrp�sR�99100��101102����103rpTcCs|g}|D]+}d|vr|r|�dd�}d|vr|r|�d�d}|�d�r*|dd�}|�|�qtt|��t|�kr<|S|S)a�Remove white-space on topo matching.104 105    This function handles different naming conventions for old VS new VectorView systems106    (`remove_whitespace`) and removes system specific parts in CTF channel names107    (`before_dash`).108 109    Usage110    -----111    # for new VectorView (only inside layout)112    ch_names = _clean_names(epochs.ch_names, remove_whitespace=True)113 114    # for CTF115    ch_names = _clean_names(epochs.ch_names, before_dash=True)116    r�r!�-r�_vN�����)�replacer3�endswithr�r&�set)�namesZremove_whitespaceZbefore_dash�cleaned�namerrr�_clean_names
s117r�cCs�t��}z$td�D]}|j}q	|jj}t�|d�sW~dSt�|�\}}}}W~n~wt�}|D]}||||<q0|�	dd�|S)z>Return all arguments (except self) and values of read_raw_xxx.�z118*/mne/io/*NrM)119r�currentframe�range�f_back�f_code�co_filename�fnmatch�getargvaluesrK�pop)�frame�_�fnamerm�values�params�argrrr�_get_argvalues,s�r�cCs�gd�}gd�}|dkr6ttt|d��t|�d�}t|�d|}||}||}d|�d�}|�||�S|dkr<dS|dkrBd	Sd120S)z�Turn number of bytes into human-readable str.121 122    Parameters123    ----------124    num : int125        The number of bytes.126 127    Returns128    -------129    size : str130        The size in human-readable format.131    )�bytes�KiB�MiB�GiB�TiB�PiB)rrr�r�r�riz{0:.zf} {1}rz0 bytesz1 byteN)�minr$rr&�float�format)�numZunitsZdecimals�exponentZquotient�unitZnum_decimals�
format_stringrrr�132sizeof_fmtCs
�r�cst�fdd�dD��S)Nc3s �|]}tt�|d��VqdSr)�callabler)r@r���objrrr�fs�z_file_like.<locals>.<genexpr>)�read�seek)�allr�rr�r�133_file_like_sr���referentc	Cs�|j}|j}|j}|dkr|�d|��}|durat|ttB�r9t|�D]\}}||ur6|d|�d�7}|Sq#|St|t�ra|��D]\}}||urQ|d7}|S||ur`|d|�d�7}|SqB|S)N�builtins�.�[�]z-key)	�	__class__rTrUr#rG�tuple�	enumeraterK�items)	r�r��klass�moduler�rD�itemrZr9rrr�	_fullnameis4	�134���r�c135Csd}d}t�}t��t��}|D]�}zt||�}Wnty%d}Ynw|r�|jdkr9|�dt|dd����t�	|�}d}	|D]�}136|137|ur�|138t139�ur�|140t�ur�t�
|141�s�t|142|d�}t|143ttBtB�r�dt|144���}t�	|145�}
t�}|
D]}|�t||146d��qwd	�t|��}|d147t|
��d|��7}~
n0d}|t|148�dd
��dd�7}|�d�r�z|dt|149j�dd
��d�7}Wn	ty�Ynw|�|�d|���|	d7}	~150qB~||	dk7}~q~t��|dks�Jd|�d|j�d|�d�d�|���dS)NTrFZBrainzBrain._cleaned = Z_cleanedr�zlen=z / z | z referrers: zrepr=�dr+r�z	<cell at z (�)z with rz @ r,)rG�gcZcollectZget_objectsr#r�rSr�rZ
get_referrers�globals�localsr�isframer�rKr�r&r2�sorted�reprr�r��
cell_contents)�cls�whenZ__tracebackhide__�n�refZobjsr��checkZrr�count�rr��repZr_�typesrrrr�_assert_no_instances�sb�151152153154�155156"�4r�cCst|��|�S)ahReturn a full system path to a package resource (AKA a file).157 158    Parameters159    ----------160    submodule : str161        An import-style module or submodule name162        (e.g., "mne.datasets.testing").163    filename : str164        The file whose full path you want.165 166    Returns167    -------168    path : str169        The full system path to the requested file.170    )r�joinpath)�	submodule�filenamerrr�_resource_path�sr�csddlm���fdd�}|S)a�Decorate _repr_html_ methods.171 172    If a _repr_html_ method is decorated with this decorator, the repr in a173    notebook will show HTML or plain text depending on the config value174    MNE_REPR_HTML (by default "true", which will render HTML).175 176    Parameters177    ----------178    f : function179        The function to decorate.180 181    Returns182    -------183    wrapper : function184        The decorated function.185    r�)�186get_configcsN�dd���dkr ddl}d|�t|d��d}|�dd�S�|i|��S)	NZ
MNE_REPR_HTML�true�falserz<pre>z</pre>r+z<br/>)�lower�html�escaper�r�)rmr|r�r���fr�rr�wrapper�s187zrepr_html.<locals>.wrapper)�utilsr�)r�r�rr�r�	repr_html�s	r�c	Cs|jj}t|�t|j�ksJ�t�}t|d�}t||j�D]\}}t�|j�||<qt	t188�|��}|��}t
|�D]\}}|�d�rJ||d�}nq9d�|�}	d}|D]}|d|�dt|��d|�d	�7}qT||	}t|�}189|190j||d191d�}|j�|j�|jdus�J|j��|S)a�Create weakrefs to self (or other free vars in __closure__) then evaluate.192 193    When a nested function is defined within an instance method, and the function makes194    use of ``self``, it creates a reference cycle that the Python garbage collector is195    not smart enough to resolve, so the parent object is never GC'd. (The reference to196    ``self`` becomes part of the ``__closure__`` of the nested function).197 198    This decorator allows the nested function to access ``self`` without increasing the199    reference counter on ``self``, which will prevent the memory leak. If the referent200    is not found (usually because already GC'd) it will short-circuit the decorated201    function and return ``None``.202    )�__weakref_values__r�Nr+zdef %(name)s(%(signature)s):203z204    z = __weakref_values__[z]()205    if z is None:206        return207T)Z	addsource)�__code__�co_freevarsr&�__closure__rK�zip�weakrefr�r�r	r�	getsource�208splitlinesr�r�r2r�r�make�__globals__�update)�functionr�r�Zevaldictr�r9�bodyZlirhZold_body�fmZfunrrr�
_auto_weakref�s:
209210�211���r)r)r!r")r)Nr*)FN)r�N)FT)r!):rVr�r�rrr�ryr-r/r��212contextlibrr�importlib.resourcesr�mathrrgrrr;r�textwrapr	�	threadingr213�numpyr%�	decoratorrZ_loggingr
rrr�rrrr r(r<rIrJrKrWrarirrpr�r�r�r�r�r�r�r�rrrrr�<module>sV214215216217

^218C219 2205