U
    f»{j*U  ã                   @   s6  d Z ddlZddlmZ ddlZddlZddlmZ ddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlmZmZmZmZ ddlmZ ddlmZmZ dadd	„ Zd
d„ ZdZdZd)dd„Z d*dd„Z!d+dd„Z"d,dd„Z#d-dd„Z$d.dd„Z%ed/dd„ƒZ&dd„ Z'd d!„ Z(d"Z)d#d$„ Z*d0d%d&œd'd(„Z+dS )1zThe config functions.é    N)Úpartialé   )Ú_validate_typeÚ_check_qt_versionÚ_check_optionÚ_check_fname)Úfill_doc)ÚwarnÚloggerc                 C   s0   | dk	rt  | ¡std|  ƒ‚td| dd� dS )aj  Set the directory to be used for temporary file storage.

    This directory is used by joblib to store memmapped arrays,
    which reduces memory requirements and speeds up parallel
    computation.

    Parameters
    ----------
    cache_dir : str or None
        Directory to use for temporary file storage. None disables
        temporary file storage.
    NzDirectory %s does not existÚMNE_CACHE_DIRF©Úset_env)ÚopÚexistsÚIOErrorÚ
set_config)Ú	cache_dir© r   úO/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/utils/config.pyÚset_cache_dir   s    r   c                 C   s@   | dk	r.t | tƒstdƒ‚| d dkr.tdƒ‚td| dd� dS )	aU  Set the minimum size for memmaping of arrays for parallel processing.

    Parameters
    ----------
    memmap_min_size : str or None
        Threshold on the minimum size of arrays that triggers automated memory
        mapping for parallel processing, e.g., '1M' for 1 megabyte.
        Use None to disable memmaping of large arrays.
    Nz%'memmap_min_size' has to be a string.éÿÿÿÿ)ÚKÚMÚGzMThe size has to be given in kilo-, mega-, or gigabytes, e.g., 100K, 500M, 1G.ÚMNE_MEMMAP_MIN_SIZEFr   )Ú
isinstanceÚstrÚ
ValueErrorr   )Zmemmap_min_sizer   r   r   Úset_memmap_min_size1   s    

r   )GZMNE_3D_OPTION_ANTIALIASZMNE_3D_OPTION_DEPTH_PEELINGZMNE_3D_OPTION_MULTI_SAMPLESZMNE_3D_OPTION_SMOOTH_SHADINGZMNE_3D_OPTION_THEMEZMNE_BROWSE_RAW_SIZEZMNE_BROWSER_BACKENDZMNE_BROWSER_OVERVIEW_MODEZMNE_BROWSER_PRECOMPUTEZMNE_BROWSER_THEMEZMNE_BROWSER_USE_OPENGLr   ZMNE_COREG_ADVANCED_RENDERINGZMNE_COREG_COPY_ANNOTZMNE_COREG_FULLSCREENZMNE_COREG_GUESS_MRI_SUBJECTZMNE_COREG_HEAD_HIGH_RESZMNE_COREG_HEAD_OPACITYZMNE_COREG_HEAD_INSIDEZMNE_COREG_INTERACTIONZMNE_COREG_MARK_INSIDEZMNE_COREG_PREPARE_BEMZMNE_COREG_ORIENT_TO_SURFACEZMNE_COREG_SCALE_LABELSZMNE_COREG_SCALE_BY_DISTANCEZMNE_COREG_SCENE_SCALEZMNE_COREG_WINDOW_HEIGHTZMNE_COREG_WINDOW_WIDTHZMNE_COREG_SUBJECTS_DIRZMNE_CUDA_DEVICEZMNE_CUDA_IGNORE_PRECISIONZMNE_DATAZMNE_DATASETS_BRAINSTORM_PATHZMNE_DATASETS_EEGBCI_PATHÚMNE_DATASETS_EPILEPSY_ECOG_PATHZMNE_DATASETS_HF_SEF_PATHZMNE_DATASETS_MEGSIM_PATHZMNE_DATASETS_MISC_PATHZMNE_DATASETS_MTRF_PATHZMNE_DATASETS_SAMPLE_PATHZMNE_DATASETS_SOMATO_PATHZMNE_DATASETS_MULTIMODAL_PATHZMNE_DATASETS_FNIRS_MOTOR_PATHZMNE_DATASETS_OPM_PATHZ$MNE_DATASETS_SPM_FACE_DATASETS_TESTSZMNE_DATASETS_SPM_FACE_PATHZMNE_DATASETS_TESTING_PATHZ&MNE_DATASETS_VISUAL_92_CATEGORIES_PATHZMNE_DATASETS_KILOWORD_PATHZMNE_DATASETS_FIELDTRIP_CMC_PATHZMNE_DATASETS_PHANTOM_4DBTI_PATHZMNE_DATASETS_LIMO_PATHZMNE_DATASETS_REFMEG_NOISE_PATHZMNE_DATASETS_SSVEP_PATHZMNE_DATASETS_ERP_CORE_PATHr   ZMNE_FORCE_SERIALZMNE_KIT2FIFF_STIM_CHANNELSZ MNE_KIT2FIFF_STIM_CHANNEL_CODINGZMNE_KIT2FIFF_STIM_CHANNEL_SLOPEZ#MNE_KIT2FIFF_STIM_CHANNEL_THRESHOLDZMNE_LOGGING_LEVELr   ZMNE_SKIP_FTP_TESTSZMNE_SKIP_NETWORK_TESTSZMNE_SKIP_TESTING_DATASET_TESTSÚMNE_STIM_CHANNELZMNE_TQDMZMNE_USE_CUDAZMNE_USE_NUMBAÚSUBJECTS_DIR)r    ZMNE_DATASETS_FNIRSZMNE_NIRSFc              	   C   s`   t | dƒ�L}zt |¡}W n6 tk
rP   d|  }|r>t|ƒ‚t|ƒ tƒ }Y nX W 5 Q R X |S )zSafely load a config file.ÚrzOThe MNE-Python config file (%s) is not a valid JSON file and might be corrupted)ÚopenÚjsonÚloadr   ÚRuntimeErrorr	   Údict)Úconfig_pathÚraise_errorÚfidÚconfigÚmsgr   r   r   Ú_load_config˜   s    ÿr-   c                 C   s   t  t| d�d¡}|S )aÀ  Get path to standard mne-python config file.

    Parameters
    ----------
    home_dir : str | None
        The folder that contains the .mne config folder.
        If None, it is found automatically.

    Returns
    -------
    config_path : str
        The path to the mne-python configuration file. On windows, this
        will be '%USERPROFILE%\.mne\mne-python.json'. On every other
        system, this will be ~/.mne/mne-python.json.
    ©Úhome_dirzmne-python.json)r   ÚjoinÚ_get_extra_data_path)r/   Úvalr   r   r   Úget_config_path¨   s    ÿr3   Tc                 C   s  t | ttdƒfddƒ | dkr"tS |rB| dk	rB| tjkrBtj|  S t|d�}t |¡s\i }nt	|ƒ}| dkrž|ršt
|ƒ t¡ tj¡}| dd„ |D ƒ¡ |S |dkrø| |krø|r¶d	nd}|rÆd
|  nd}	|rÒdnd}
d|  }td| |||	||
f ƒ‚n| | |¡S dS )a'  Read MNE-Python preferences from environment or config file.

    Parameters
    ----------
    key : None | str
        The preference key to look for. The os environment is searched first,
        then the mne-python config file is parsed.
        If None, all the config parameters present in environment variables or
        the path are returned. If key is an empty string, a list of all valid
        keys (but not values) is returned.
    default : str | None
        Value to return if the key is not found.
    raise_error : bool
        If True, raise an error if the key is not found (instead of returning
        default).
    home_dir : str | None
        The folder that contains the .mne config folder.
        If None, it is found automatically.
    use_env : bool
        If True, consider env vars, if available.
        If False, only use MNE-Python configuration file values.

        .. versionadded:: 0.18

    Returns
    -------
    value : dict | str | None
        The preference key value.

    See Also
    --------
    set_config
    NÚkeyzstring or NoneÚ r.   c                 S   s   i | ]}|t j| “qS r   )ÚosÚenviron)Ú.0r4   r   r   r   Ú
<dictcomp>õ   s      zget_config.<locals>.<dictcomp>Tzthe environment or in the z=either os.environ["%s"] = VALUE for a temporary solution, or zA You can also set the environment variable before running python.zCmne.utils.set_config("%s", VALUE, set_env=True) for a permanent onezDKey "%s" not found in %sthe mne-python config file (%s). Try %s%s.%s)r   r   ÚtypeÚknown_config_typesr6   r7   r3   r   Úisfiler-   ÚsetÚunionÚintersectionÚupdateÚKeyErrorÚget)r4   Údefaultr)   r/   Zuse_envr(   r+   Zenv_keysZloc_envZmeth_envZ	extra_envZ	meth_filer   r   r   Ú
get_config½   sJ    #


ÿÿÿÿÿÿÿ
ÿýrD   c              	      s  t ˆ ddƒ t |tdtdƒfdƒ |dk	r2t|ƒ}ˆ tkr\t‡ fdd„tD ƒƒs\tdˆ  ƒ t|d	�}t 	|¡r~t
|d
d�}ntƒ }t d| ¡ |dkr¾| ˆ d¡ |rÔˆ tjkrÔtjˆ = n||ˆ < |rÔ|tjˆ < t |¡}t |¡sòt |¡ t|dƒ�}tj||d
dd� W 5 Q R X dS )a5  Set a MNE-Python preference key in the config file and environment.

    Parameters
    ----------
    key : str
        The preference key to set.
    value : str |  None
        The value to assign to the preference key. If None, the key is
        deleted.
    home_dir : str | None
        The folder that contains the .mne config folder.
        If None, it is found automatically.
    set_env : bool
        If True (default), update :data:`os.environ` in addition to
        updating the MNE-Python config file.

    See Also
    --------
    get_config
    r   r4   ú	path-likeNÚvaluec                 3   s   | ]}ˆ   |¡V  qd S ©N)Ú
startswith)r8   Úk©r4   r   r   Ú	<genexpr>%  s     zset_config.<locals>.<genexpr>z&Setting non-standard config type: "%s"r.   T©r)   z:Attempting to create new mne-python configuration file:
%sÚwr   )Ú	sort_keysÚindent)r   r   r:   r;   ÚanyÚknown_config_wildcardsr	   r3   r   r<   r-   r'   r
   ÚinfoÚpopr6   r7   ÚdirnameÚisdirÚmkdirr#   r$   Údump)r4   rF   r/   r   r(   r+   Ú	directoryr*   r   rJ   r   r     s6    ÿ

ÿ




r   c                 C   s¾   | dkrt j d¡} | dkr²dt j ¡ krZt t t  d¡d¡¡rNt  d¡} q¢t  d¡} nHt  dd¡d	kr–t	dkr�t
 ¡ a	t ttjt	d
d�¡ t	} nt j d¡} | dkr²tdƒ‚t | d¡S )z.Get path to extra data (config, tables, etc.).NZ_MNE_FAKE_HOME_DIRÚntÚAPPDATAz.mneÚUSERPROFILEZMNE_DONTWRITE_HOMEr5   ÚtrueT)Úignore_errorsú~zfmne-python config file path could not be determined, please report this error to mne-python developers)r6   r7   rB   ÚnameÚlowerr   rU   r0   ÚgetenvÚ_temp_home_dirÚtempfileÚmkdtempÚatexitÚregisterr   ÚshutilÚrmtreeÚpathÚ
expanduserr   r.   r   r   r   r1   B  s$    ÿr1   c                 C   sB   t | dddd� | dkr$td|d�} | dk	r>t| dd	d	dd
�} | S )aË  Safely use subjects_dir input to return SUBJECTS_DIR.

    Parameters
    ----------
    subjects_dir : str | None
        If a value is provided, return subjects_dir. Otherwise, look for
        SUBJECTS_DIR config and return the result.
    raise_error : bool
        If True, raise a KeyError if no value for SUBJECTS_DIR can be found
        (instead of returning None).

    Returns
    -------
    value : str | None
        The SUBJECTS_DIR value.
    )rE   NÚsubjects_dirzstr or path-like)ÚitemÚtypesZ	item_nameÚ	type_nameNr!   rL   ÚreadT)ÚfnameÚ	overwriteZ
must_existÚneed_dirr_   )r   rD   r   )rk   r)   r   r   r   Úget_subjects_dirf  s     ÿ   þrs   c                    s   | dk	r>t | tƒs$t| ddƒ | g} | D ]}t|ddƒ q(| S tƒ } d}tdƒ}|dk	r„|ˆ d kr„|  |¡ |d7 }td	| ƒ}qP|dkr�| S d
ˆ d kr¢d
gS dˆ d kr´dgS ddlm} |ˆ dddd�} t| ƒdkrð‡ fdd„| D ƒ} n|rütdƒ‚| S )a  Determine the appropriate stim_channel.

    First, 'MNE_STIM_CHANNEL', 'MNE_STIM_CHANNEL_1', 'MNE_STIM_CHANNEL_2', etc.
    are read. If these are not found, it will fall back to 'STI 014' if
    present, then fall back to the first channel of type 'stim', if present.

    Parameters
    ----------
    stim_channel : str | list of str | None
        The stim channel selected by the user.
    %(info_not_none)s

    Returns
    -------
    stim_channel : str | list of str
        The name of the stim channel(s) to use
    Nr   zStim channelzEach provided stim channelr   r    Úch_namesr   zMNE_STIM_CHANNEL_%dZSTI101zSTI 014é   )Ú
pick_typesFT)ZmegZref_megZstimc                    s   g | ]}ˆ d  | ‘qS )rt   r   )r8   Zch_©rR   r   r   Ú
<listcomp>²  s     z%_get_stim_channel.<locals>.<listcomp>z]No stim channels found. Consider specifying them manually using the 'stim_channel' parameter.)	r   Úlistr   rD   ÚappendZio.pickrv   Úlenr   )Zstim_channelrR   r)   ZchannelZch_countÚchrv   r   rw   r   Ú_get_stim_channel…  s6    

r}   c                     sZ   t  t  t  t¡d¡¡} t  | d¡‰ t  t  ˆ d¡¡rVt‡ fdd„dD ƒƒrVt  ˆ ¡} | S )z*Get as close to the repo root as possible.z..zsetup.pyc                 3   s    | ]}t  t  ˆ |¡¡V  qd S rG   )r   rU   r0   )r8   Úx©Zup_dirr   r   rK   ½  s    z _get_root_dir.<locals>.<genexpr>)ÚmneZexamplesÚdoc)r   Úabspathr0   rT   Ú__file__r<   Úall)Úroot_dirr   r   r   Ú_get_root_dir¹  s    ÿ
r†   c               
   C   sÚ   ddl m}  | dd��}t ¡  W 5 Q R X | ¡  d¡}| ¡  g }t|ƒD ]~\}}dD ]p}| d| ¡rX||d  }d|kr„d	}n2z| d
¡d  d¡d }W n t	k
r´   Y nX |d||f g7 }qXqLd 
|¡}|S )Nr   )ÚSilenceStdoutF)ÚcloseÚ
)ZlapackZblasz%s_opt_infozNOT AVAILABLEÚunknownú[ú'z%s=%sz, )Z_testingr‡   ÚnpZshow_configÚgetvalueÚsplitrˆ   Ú	enumeraterH   Ú
IndexErrorr0   )r‡   ÚcaptureÚlinesÚlibsZliÚliner4   Úlibr   r   r   Ú_get_numpy_libsÃ  s&    
r—   zRfrom pyvista import GPUInfo; gi = GPUInfo(); print(gi.version); print(gi.renderer)c                  C   sN   t jtjdtgddd�} | j ¡  ¡  dd¡ 	d¡}| j
sFt|ƒdkrJd	S |S )
Nz-cFT)ÚcheckÚcapture_outputúr5   r‰   ru   )NN)Ú
subprocessÚrunÚsysÚ
executableÚ_gpu_cmdÚstdoutÚdecodeÚstripÚreplacer�   Ú
returncoder{   )ÚprocÚoutr   r   r   Ú_get_gpu_infoá  s    
  ÿr§   Úuser)Údependenciesc             	   C   s^  t |tƒ td|dƒ |dkr"dnd}t ¡ }t ¡ dkr„tjdd… d	k r„t ¡ d
 }t 	d|¡}|r€|d
 }d|› d|› �}~~t
td| d�}|d |¡| d ƒ |d |¡ttjƒ dd¡ d ƒ |d |¡tj d ƒ |d |¡t ¡ › d� ƒ zd
dl}W n tk
�r*   |dƒ Y nX || ¡ › d�ƒ |d |¡ƒ zd
dl}	W n tk
�rv   |dƒ Y n X ||	 ¡ jtdƒ d›d�ƒ |dƒ tƒ }
d}|dk�rº|d7 }|D �]˜}|dk�rÚ|dƒ �q¾||› d � |¡ƒ zt|ƒ}W n  tk
�r   |d!ƒ Y �q¾X |d"k�rt| ¡ }d#D ]6}t||ƒ�r2t||ƒƒ }|dk�r2||ƒ  �q~�q2|d$ƒ n
||jƒ |d%k�rš|d&|
› d'�ƒ nŽ|d(k�rÊtd)d*�\}}|d&|› d+|› d'�ƒ n^|d,k�rê|d-|  ¡ › d'�ƒ n>|d.k�r(t!ƒ \}}|dk�r|d/ƒ n|d0|› d1|› d'�ƒ |�rN|dd| › d2t" #|j$¡› �ƒ |dƒ �q¾dS )3a…  Print the system information for debugging.

    This function is useful for printing system information
    to help triage bugs.

    Parameters
    ----------
    fid : file-like | None
        The file to write to. Will be passed to :func:`print()`.
        Can be None to use :data:`sys.stdout`.
    show_paths : bool
        If True, print paths for each module.
    dependencies : 'user' | 'developer'
        Show dependencies relevant for users (default) or for developers
        (i.e., output includes additional dependencies).

        .. versionadded:: 0.24

    Examples
    --------
    Running this function with no arguments prints an output that is
    useful when submitting bug reports::

        >>> import mne
        >>> mne.sys_info() # doctest: +SKIP
        Platform:      Linux-4.15.0-1067-aws-x86_64-with-glibc2.2.5
        Python:        3.8.1 (default, Feb  2 2020, 08:37:37)  [GCC 8.3.0]
        Executable:    /usr/local/bin/python
        CPU:           : 36 cores
        Memory:        68.7 GB

        mne:           0.21.dev0
        numpy:         1.19.0 {blas=openblas, lapack=openblas}
        scipy:         1.5.1
        matplotlib:    3.2.2 {backend=Qt5Agg}

        sklearn:       0.23.1
        numba:         0.50.1
        nibabel:       3.1.1
        nilearn:       0.7.0
        dipy:          1.1.1
        cupy:          Not found
        pandas:        1.0.5
        pyvista:       0.25.3 {pyvistaqt=0.1.1, OpenGL 3.3 (Core Profile) Mesa 18.3.6 via llvmpipe (LLVM 7.0, 256 bits)}
        vtk:           9.0.1
        qtpy:          2.0.1 {PySide6=6.2.4}
        pyqtgraph:     0.12.4
        pooch:         v1.5.1
    r©   )r¨   Ú	developerrª   é   é   ÚDarwinNru   )é   é   r   zDarwin-.*?-(.*)zmacOS-ú-r5   )ÚendÚfilez	Platform:r‰   zPython:ú zExecutable:zCPU:z: zFnumber of processors unavailable (requires "multiprocessing" package)
z cores
zMemory:z'Unavailable (requires "psutil" package)i   @z0.1fz GB
)r€   ÚnumpyZscipyÚ
matplotlibr5   ZsklearnZnumbaZnibabelZnilearnZdipyZcupyZpandasÚpyvistaZ	pyvistaqtZ
ipyvtklinkÚvtkÚqtpyZipymplZ	pyqtgraphZpoochr5   Zmne_bidsZmne_nirsZmne_featuresZmne_qt_browserZmne_connectivityZmne_icalabel)r5   ZsphinxZsphinx_galleryZnumpydocZpydata_sphinx_themeZpytestZnbclientú:z
Not found
r·   )ZGetVTKVersionFullZGetVTKVersionrŠ   r´   z {Ú}r¸   T)Z
return_apiú=rµ   z
 {backend=r¶   z" {OpenGL could not be initialized}z	 {OpenGL z via u   â€¢)%r   r   r   ÚplatformÚsystemr�   Úversion_infoÚmac_verÚreÚfindallr   ÚprintÚljustÚversionr£   rž   Ú	processorÚmultiprocessingÚImportErrorÚ	cpu_countÚpsutilZvirtual_memoryÚtotalÚfloatr—   Ú
__import__Ú	ExceptionZ
vtkVersionÚhasattrÚgetattrÚ__version__r   Úget_backendr§   r   rT   rƒ   )r*   Z
show_pathsr©   rÃ   Zplatform_strZ	macos_verZmacos_architecturer¦   rÆ   rÉ   r”   Zuse_mod_namesÚmod_nameÚmodZvtk_versionÚattrrÄ   ÚapiÚrendererr   r   r   Úsys_infoì  s„    2
$














 r×   )F)N)NNFNT)NT)N)NF)T)NF),Ú__doc__re   Ú	functoolsr   r$   r6   Úos.pathri   r   r¼   rg   r›   r�   rc   rÀ   r´   r�   r˜   r   r   r   r   Údocsr   Z_loggingr	   r
   rb   r   r   r;   rQ   r-   r3   rD   r   r1   rs   r}   r†   r—   rŸ   r§   r×   r   r   r   r   Ú<module>   sF   K

  ÿ
K
:
$
3
