U
    f»{j  ã                   @   sz   d dl ZddlmZmZmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ dd	lmZ ddd„Zddd„Zddd„ZdS )é    Né   )Ú_create_infoÚ	_set_tminÚ_create_eventsÚ_create_event_metadataÚ_validate_ft_structé   )Ú_check_fnameÚ_import_pymatreader_funcsé   )ÚRawArray)ÚEpochsArray)ÚEvokedArrayÚdatac                 C   sœ   t dƒ}t| ddd�} || dg|gd�}|| }t|ƒ t||ƒ}t |d ¡}|jdkrdt |¡}|jd	kr||tjd
f }|jdkrŽt	dƒ‚t
||ƒ}|S )a—  Load continuous (raw) data from a FieldTrip preprocessing structure.

    This function expects to find single trial raw data (FT_DATATYPE_RAW) in
    the structure data_name is pointing at.

    .. warning:: FieldTrip does not normally store the original information
                 concerning channel location, orientation, type etc. It is
                 therefore **highly recommended** to provide the info field.
                 This can be obtained by reading the original raw data file
                 with MNE functions (without preload). The returned object
                 contains the necessary info field.

    Parameters
    ----------
    fname : str
        Path and filename of the .mat file containing the data.
    info : dict or None
        The info dict of the raw data file corresponding to the data to import.
        If this is set to None, limited information is extracted from the
        FieldTrip structure.
    data_name : str
        Name of heading dict/ variable name under which the data was originally
        saved in MATLAB.

    Returns
    -------
    raw : instance of RawArray
        A Raw Object containing the loaded data.
    úFieldTrip I/OÚreadT)Ú	overwriteZ
must_existÚprevious©Zignore_fieldsZvariable_namesÚtrialr   r   .z<The data you are trying to load does not seem to be raw data)r
   r	   r   r   ÚnpÚarrayÚndimZsqueezeZnewaxisÚRuntimeErrorr   )ÚfnameÚinfoÚ	data_nameÚread_matÚ	ft_structr   Úraw© r    úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/io/fieldtrip/fieldtrip.pyÚread_raw_fieldtrip   s$    þ





r"   c                 C   s‚   t dƒ}|| dg|gd�}|| }t|ƒ t||ƒ}t |d ¡}t||ƒ}|dk	r^t|ƒ}nd}t|ƒ}	t|||	||dd�}
|
S )aD  Load epoched data from a FieldTrip preprocessing structure.

    This function expects to find epoched data in the structure data_name is
    pointing at.

    .. warning:: Only epochs with the same amount of channels and samples are
                 supported!

    .. warning:: FieldTrip does not normally store the original information
                 concerning channel location, orientation, type etc. It is
                 therefore **highly recommended** to provide the info field.
                 This can be obtained by reading the original raw data file
                 with MNE functions (without preload). The returned object
                 contains the necessary info field.

    Parameters
    ----------
    fname : str
        Path and filename of the .mat file containing the data.
    info : dict or None
        The info dict of the raw data file corresponding to the data to import.
        If this is set to None, limited information is extracted from the
        FieldTrip structure.
    data_name : str
        Name of heading dict/ variable name under which the data was originally
        saved in MATLAB.
    trialinfo_column : int
        Column of the trialinfo matrix to use for the event codes.

    Returns
    -------
    epochs : instance of EpochsArray
        An EpochsArray containing the loaded data.
    r   r   r   r   NF)r   r   ÚtminÚeventsÚmetadataZproj)	r
   r   r   r   r   r   r   r   r   )r   r   r   Ztrialinfo_columnr   r   r   r$   r%   r#   Úepochsr    r    r!   Úread_epochs_fieldtripL   s(    $þ


  ÿr'   c                 C   sN   t dƒ}|| dg|gd�}|| }t|ƒ t||ƒ}|d }t|||d�}|S )a¾  Load evoked data from a FieldTrip timelocked structure.

    This function expects to find timelocked data in the structure data_name is
    pointing at.

    .. warning:: FieldTrip does not normally store the original information
                 concerning channel location, orientation, type etc. It is
                 therefore **highly recommended** to provide the info field.
                 This can be obtained by reading the original raw data file
                 with MNE functions (without preload). The returned object
                 contains the necessary info field.

    Parameters
    ----------
    fname : str
        Path and filename of the .mat file containing the data.
    info : dict or None
        The info dict of the raw data file corresponding to the data to import.
        If this is set to None, limited information is extracted from the
        FieldTrip structure.
    comment : str
        Comment on dataset. Can be the condition.
    data_name : str
        Name of heading dict/ variable name under which the data was originally
        saved in MATLAB.

    Returns
    -------
    evoked : instance of EvokedArray
        An EvokedArray containing the loaded data.
    r   r   r   Úavg)Úcomment)r
   r   r   r   )r   r   r)   r   r   r   Zdata_evokedÚevokedr    r    r!   Úread_evoked_fieldtripˆ   s    !þ
r+   )r   )r   r   )Nr   )Únumpyr   Úutilsr   r   r   r   r   r	   r
   Zarray.arrayr   r&   r   r*   r   r"   r'   r+   r    r    r    r!   Ú<module>   s   
;  ÿ
<  ÿ