U
    f»{j˜t  ã                   @   s  d dl ZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZmZmZmZ dd
lmZmZmZmZ ddlmZ G dd„ dƒZdd„ ZeG dd„ deeƒƒZG dd„ deƒZeG dd„ deƒƒZeG dd„ deƒƒZG dd„ deeƒZeG dd„ deƒƒZdS )é    Né   )ÚTransformerMixin)ÚBaseEstimatoré   )Ú
pick_types)Úfilter_data)Úpsd_array_multitaper)Úfill_docÚ_check_optionÚ_validate_typeÚverbose)Ú	pick_infoÚ_pick_data_channelsÚ_picks_by_typeÚ_picks_to_idx)Ú_check_scalings_userc                   @   s@   e Zd ZdZddd„Zddd„Zdd	„ Zdd
d„Zddd„ZdS )Ú_ConstantScalerz*Scale channel types using constant values.Tc                 C   s   || _ || _|| _d S ©N)Ú	_scalingsÚ_infoÚ_do_scaling)ÚselfÚinfoÚscalingsZ
do_scaling© r   úW/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/decoding/transformer.pyÚ__init__   s    z_ConstantScaler.__init__Nc                 C   s    t | jƒ}tt| jt| jdd�ƒƒ}t tdd„ |D ƒƒ¡}|j	d t
|ƒkrftdt
|ƒt
|ƒf ƒ‚| jrŠ|D ]\}}d||  ||< qp|| _t |¡| _| S )Nr   )Úexcludec                 s   s   | ]}t |d  ƒV  qdS )r   N)Úlen)Ú.0Úpr   r   r   Ú	<genexpr>"   s     z&_ConstantScaler.fit.<locals>.<genexpr>r   z/info had %d data channels but X has %d channelsç      ð?)r   r   r   r   r   r   ÚnpZonesÚsumÚshaper   Ú
ValueErrorr   Ústd_Z
zeros_likeZmean_)r   ÚXÚyr   Zpicks_by_typeZstdÚkindÚpicksr   r   r   Úfit   s     
 ÿÿz_ConstantScaler.fitc                 C   s
   || j  S r   ©r'   ©r   r(   r   r   r   Ú	transform-   s    z_ConstantScaler.transformc                 C   s
   || j  S r   r-   ©r   r(   r)   r   r   r   Úinverse_transform0   s    z!_ConstantScaler.inverse_transformc                 C   s   |   ||¡ |¡S r   ©r,   r/   r0   r   r   r   Úfit_transform3   s    z_ConstantScaler.fit_transform)T)N)N)N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r,   r/   r1   r3   r   r   r   r   r      s   


r   c                 O   s‚   t |tjƒstdt|ƒ ƒ‚|j}t | ddd¡d|d f¡}| |f|ž|Ž}|r~|d |d |d f|_| ddd¡}|S dS )z"Reshape epochs and apply function.z%data should be an np.ndarray, got %s.r   r   r   éÿÿÿÿN)Ú
isinstancer#   Úndarrayr&   Útyper%   ÚreshapeÚ	transpose)ÚfuncZreturn_resultr(   ÚargsÚkwargsZ
orig_shaper   r   r   Ú_sklearn_reshape_apply7   s    rA   c                   @   s>   e Zd ZdZddd„Zddd„Zdd	„ Zdd
d„Zdd„ ZdS )ÚScaleru©  Standardize channel data.

    This class scales data for each channel. It differs from scikit-learn
    classes (e.g., :class:`sklearn.preprocessing.StandardScaler`) in that
    it scales each *channel* by estimating Î¼ and Ïƒ using data from all
    time points and epochs, as opposed to standardizing each *feature*
    (i.e., each time point for each channel) by estimating using Î¼ and Ïƒ
    using data from all epochs.

    Parameters
    ----------
    %(info)s Only necessary if ``scalings`` is a dict or None.
    scalings : dict, str, default None
        Scaling method to be applied to data channel wise.

        * if scalings is None (default), scales mag by 1e15, grad by 1e13,
          and eeg by 1e6.
        * if scalings is :class:`dict`, keys are channel types and values
          are scale factors.
        * if ``scalings=='median'``,
          :class:`sklearn.preprocessing.RobustScaler`
          is used (requires sklearn version 0.17+).
        * if ``scalings=='mean'``,
          :class:`sklearn.preprocessing.StandardScaler`
          is used.

    with_mean : bool, default True
        If True, center the data using mean (or median) before scaling.
        Ignored for channel-type scaling.
    with_std : bool, default True
        If True, scale the data to unit variance (``scalings='mean'``),
        quantile range (``scalings='median``), or using channel type
        if ``scalings`` is a dict or None).
    NTc                 C   sÞ   || _ || _|| _|| _|d ks>t|ttfƒs>tdt|ƒ ƒ‚t|tƒrXt	d|ddgƒ |d ksjt|tƒr”|d kr‚tdt|ƒ ƒ‚t
||| jƒ| _nF|dkr¼ddlm} || j| jd�| _ndd	lm} || j| jd
�| _d S )Nz2scalings type should be dict, str, or None, got %sr   ÚmeanZmedianz'Need to specify "info" if scalings is%sr   )ÚStandardScaler)Ú	with_meanÚwith_std)ÚRobustScaler)Zwith_centeringZwith_scaling)r   rE   rF   r   r9   ÚdictÚstrr&   r;   r
   r   Ú_scalerZsklearn.preprocessingrD   rG   )r   r   r   rE   rF   rD   rG   r   r   r   r   i   s6    ÿ
ÿ ÿ
 ÿzScaler.__init__c                 C   sR   t |tjdƒ |jdkr&|dtjf }|jdks:t|jƒ‚t| jj	d||d� | S )as  Standardize data across channels.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data to concatenate channels.
        y : array, shape (n_epochs,)
            The label for each epoch.

        Returns
        -------
        self : instance of Scaler
            The modified instance.
        Úepochs_datar   .é   F)r)   )
r   r#   r:   ÚndimÚnewaxisÚAssertionErrorr%   rA   rJ   r,   ©r   rK   r)   r   r   r   r,   ƒ   s    
z
Scaler.fitc                 C   sp   t |tjdƒ |jdkrL| jdk	r>t| jd ƒ|jd ks>t‚|dtjf }|jdks`t|jƒ‚t	| j
jd|ƒS )	aÒ  Standardize data across channels.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels[, n_times])
            The data.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The data concatenated over channels.

        Notes
        -----
        This function makes a copy of the data before the operations and the
        memory usage may be large with big data.
        rK   r   NZch_namesr   .rL   T)r   r#   r:   rM   r   r   r%   rO   rN   rA   rJ   r/   ©r   rK   r   r   r   r/   ™   s    


ÿzScaler.transformc                 C   s   |   ||¡ |¡S )a§  Fit to data, then transform it.

        Fits transformer to epochs_data and y and returns a transformed version
        of epochs_data.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data.
        y : None | array, shape (n_epochs,)
            The label for each epoch.
            Defaults to None.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The data concatenated over channels.

        Notes
        -----
        This function makes a copy of the data before the operations and the
        memory usage may be large with big data.
        r2   rP   r   r   r   r3   ´   s    zScaler.fit_transformc                 C   s$   |j dkst|jƒ‚t| jjd|ƒS )aÞ  Invert standardization of data across channels.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The data concatenated over channels.

        Notes
        -----
        This function makes a copy of the data before the operations and the
        memory usage may be large with big data.
        rL   T)rM   rO   r%   rA   rJ   r1   rQ   r   r   r   r1   Î   s    
ÿzScaler.inverse_transform)NNTT)N)N)	r4   r5   r6   r7   r   r,   r/   r3   r1   r   r   r   r   rB   D   s   #  ÿ


rB   c                   @   s4   e Zd ZdZddd„Zdd„ Zddd„Zd	d
„ ZdS )Ú
VectorizeraÝ  Transform n-dimensional array into 2D array of n_samples by n_features.

    This class reshapes an n-dimensional array into an n_samples * n_features
    array, usable by the estimators and transformers of scikit-learn.

    Attributes
    ----------
    features_shape_ : tuple
         Stores the original shape of data.

    Examples
    --------
    clf = make_pipeline(SpatialFilter(), _XdawnTransformer(), Vectorizer(),
                        LogisticRegression())
    Nc                 C   s   t  |¡}|jdd… | _| S )aG  Store the shape of the features of X.

        Parameters
        ----------
        X : array-like
            The data to fit. Can be, for example a list, or an array of at
            least 2d. The first dimension must be of length n_samples, where
            samples are the independent samples used by the estimator
            (e.g. n_epochs for epoched data).
        y : None | array, shape (n_samples,)
            Used for scikit-learn compatibility.

        Returns
        -------
        self : instance of Vectorizer
            Return the modified instance.
        r   N)r#   Úasarrayr%   Úfeatures_shape_r0   r   r   r   r,   ö   s    
zVectorizer.fitc                 C   s6   t  |¡}|jdd… | jkr&tdƒ‚| t|ƒd¡S )aï  Convert given array into two dimensions.

        Parameters
        ----------
        X : array-like
            The data to fit. Can be, for example a list, or an array of at
            least 2d. The first dimension must be of length n_samples, where
            samples are the independent samples used by the estimator
            (e.g. n_epochs for epoched data).

        Returns
        -------
        X : array, shape (n_samples, n_features)
            The transformed data.
        r   Nz1Shape of X used in fit and transform must be samer8   )r#   rS   r%   rT   r&   r<   r   r.   r   r   r   r/     s    
zVectorizer.transformc                 C   s   |   |¡ |¡S )aF  Fit the data, then transform in one step.

        Parameters
        ----------
        X : array-like
            The data to fit. Can be, for example a list, or an array of at
            least 2d. The first dimension must be of length n_samples, where
            samples are the independent samples used by the estimator
            (e.g. n_epochs for epoched data).
        y : None | array, shape (n_samples,)
            Used for scikit-learn compatibility.

        Returns
        -------
        X : array, shape (n_samples, -1)
            The transformed data.
        r2   r0   r   r   r   r3   "  s    zVectorizer.fit_transformc                 C   s>   t  |¡}|jdkr$td|jf ƒ‚| |jdd… | j ¡S )a~  Transform 2D data back to its original feature shape.

        Parameters
        ----------
        X : array-like, shape (n_samples,  n_features)
            Data to be transformed back to original shape.

        Returns
        -------
        X : array
            The data transformed into shape as used in fit. The first
            dimension is of length n_samples.
        )r   rL   z1X should be of 2 or 3 dimensions but has shape %sNr8   )r#   rS   rM   r&   r%   r<   rT   r.   r   r   r   r1   6  s    

ÿzVectorizer.inverse_transform)N)N)r4   r5   r6   r7   r,   r/   r3   r1   r   r   r   r   rR   å   s
   

rR   c                	   @   sL   e Zd ZdZedej dejdddddfddœd	d
„ƒZdd„ Z	dd„ Z
dS )ÚPSDEstimatora#  Compute power spectral density (PSD) using a multi-taper method.

    Parameters
    ----------
    sfreq : float
        The sampling frequency.
    fmin : float
        The lower frequency of interest.
    fmax : float
        The upper frequency of interest.
    bandwidth : float
        The bandwidth of the multi taper windowing function in Hz.
    adaptive : bool
        Use adaptive weights to combine the tapered spectra into PSD
        (slow, use n_jobs >> 1 to speed up computation).
    low_bias : bool
        Only use tapers with more than 90%% spectral concentration within
        bandwidth.
    n_jobs : int
        Number of parallel jobs to use (only used if adaptive=True).
    %(normalization)s
    %(verbose)s

    See Also
    --------
    mne.time_frequency.psd_multitaper
    r   r   NFTÚlength©r   c	          
      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S r   )ÚsfreqÚfminÚfmaxÚ	bandwidthÚadaptiveÚlow_biasÚn_jobsÚnormalization)
r   rX   rY   rZ   r[   r\   r]   r^   r_   r   r   r   r   r   i  s    zPSDEstimator.__init__c                 C   s    t |tjƒstdt|ƒ ƒ‚| S )a€  Compute power spectral density (PSD) using a multi-taper method.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data.
        y : array, shape (n_epochs,)
            The label for each epoch.

        Returns
        -------
        self : instance of PSDEstimator
            The modified instance.
        ú/epochs_data should be of type ndarray (got %s).)r9   r#   r:   r&   r;   rP   r   r   r   r,   v  s
    ÿzPSDEstimator.fitc                 C   sN   t |tjƒstdt|ƒ ƒ‚t|| j| j| j| j	| j
| j| j| jd�	\}}|S )aF  Compute power spectral density (PSD) using a multi-taper method.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data.

        Returns
        -------
        psd : array, shape (n_signals, n_freqs) or (n_freqs,)
            The computed PSD.
        r`   )rX   rY   rZ   r[   r\   r]   r_   r^   )r9   r#   r:   r&   r;   r   rX   rY   rZ   r[   r\   r]   r_   r^   )r   rK   ZpsdÚ_r   r   r   r/   ‹  s     ÿ     ü
zPSDEstimator.transform)r4   r5   r6   r7   r   r#   ÚpiÚinfr   r,   r/   r   r   r   r   rU   K  s     þþrU   c                   @   s0   e Zd ZdZdddœdd„Zd	d
„ Zdd„ ZdS )ÚFilterEstimatoraq  Estimator to filter RtEpochs.

    Applies a zero-phase low-pass, high-pass, band-pass, or band-stop
    filter to the channels selected by "picks".

    l_freq and h_freq are the frequencies below which and above which,
    respectively, to filter out of the data. Thus the uses are:

        - l_freq < h_freq: band-pass filter
        - l_freq > h_freq: band-stop filter
        - l_freq is not None, h_freq is None: low-pass filter
        - l_freq is None, h_freq is not None: high-pass filter

    If n_jobs > 1, more memory is required as "len(picks) * n_times"
    additional time points need to be temporarily stored in memory.

    Parameters
    ----------
    %(info_not_none)s
    %(l_freq)s
    %(h_freq)s
    %(picks_good_data)s
    %(filter_length)s
    %(l_trans_bandwidth)s
    %(h_trans_bandwidth)s
    n_jobs : int | str
        Number of jobs to run in parallel.
        Can be 'cuda' if ``cupy`` is installed properly and method='fir'.
    method : str
        'fir' will use overlap-add FIR filtering, 'iir' will use IIR
        forward-backward filtering (via filtfilt).
    iir_params : dict | None
        Dictionary of parameters to use for IIR filtering.
        See mne.filter.construct_iir_filter for details. If iir_params
        is None and method="iir", 4th order Butterworth will be used.
    %(fir_design)s
    %(verbose)s

    See Also
    --------
    TemporalFilter

    Notes
    -----
    This is primarily meant for use in conjunction with
    :class:`mne_realtime.RtEpochs`. In general it is not recommended in a
    normal processing pipeline as it may result in edge artifacts. Use with
    caution.
    NÚautoÚfirÚfirwinrW   c                C   sL   || _ || _|| _t||ƒ| _|| _|| _|| _|| _|	| _	|
| _
|| _d S r   )r   Úl_freqÚh_freqr   r+   Úfilter_lengthÚl_trans_bandwidthÚh_trans_bandwidthr^   ÚmethodÚ
iir_paramsÚ
fir_design)r   r   rh   ri   r+   rj   rk   rl   r^   rm   rn   ro   r   r   r   r   r   ×  s    zFilterEstimator.__init__c              	   C   sˆ  t |tjƒstdt|ƒ ƒ‚| jdkr<t| jdddg d�| _| jdkrLd| _| j	dk	rp| j	| jd d krpd| _	| jdk	r’t | jt
ƒs’t
| jƒ| _| j	dk	r´t | j	t
ƒs´t
| j	ƒ| _	| jd	 dksø| j	dk	�r| jdksæ| j| j	k �r| j	| jd	 k �r| j ¡ � | j	| jd	< W 5 Q R X | jd
 dk�sb| jdk	�r„| j	dk�sP| j| j	k �r„| j| jd
 k�r„| j ¡ � | j| jd
< W 5 Q R X | S )aO  Filter data.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data.
        y : array, shape (n_epochs,)
            The label for each epoch.

        Returns
        -------
        self : instance of FilterEstimator
            The modified instance.
        r`   NTF)ZmegZeegZref_megr   r   rX   g       @ZlowpassZhighpass)r9   r#   r:   r&   r;   r+   r   r   rh   ri   ÚfloatZ_unlockrP   r   r   r   r,   ç  sP    ÿ

 ÿ
ÿ
þÿýÿ
þÿýzFilterEstimator.fitc                 C   sd   t |tjƒstdt|ƒ ƒ‚t |¡}t|| jd | j| j	| j
| j| j| j| j| j| jd| jdd�S )a  Filter data.

        Parameters
        ----------
        epochs_data : array, shape (n_epochs, n_channels, n_times)
            The data.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The data after filtering.
        r`   rX   F)rm   rn   r^   Úcopyro   r   )r9   r#   r:   r&   r;   Z
atleast_3dr   r   rh   ri   r+   rj   rk   rl   rm   rn   r^   ro   rQ   r   r   r   r/     s*    ÿ
         ûzFilterEstimator.transform)Nre   re   re   Nrf   Nrg   )r4   r5   r6   r7   r   r,   r/   r   r   r   r   rd   £  s   2          ýý2rd   c                   @   sF   e Zd ZdZddd„Zddd„Zddd	„Zd
d„ Zdd„ Zdd„ Z	dS )ÚUnsupervisedSpatialFilteraL  Use unsupervised spatial filtering across time and samples.

    Parameters
    ----------
    estimator : instance of sklearn.base.BaseEstimator
        Estimator using some decomposition algorithm.
    average : bool, default False
        If True, the estimator is fitted on the average across samples
        (e.g. epochs).
    Fc                 C   sJ   dD ]}t ||ƒstd| ƒ‚qt|tƒs:tdttƒ ƒ‚|| _|| _d S )N)r,   r/   r3   z?estimator must be a scikit-learn transformer, missing %s methodz6average parameter must be of bool type, got %s instead)Úhasattrr&   r9   Úboolr;   Ú	estimatorÚaverage)r   ru   rv   Úattrr   r   r   r   >  s    
ÿ
ÿz"UnsupervisedSpatialFilter.__init__Nc                 C   sP   | j rtj|dd�j}n(|j\}}}t |d¡ ||| f¡j}| j |¡ | S )a„  Fit the spatial filters.

        Parameters
        ----------
        X : array, shape (n_epochs, n_channels, n_times)
            The data to be filtered.
        y : None | array, shape (n_samples,)
            Used for scikit-learn compatibility.

        Returns
        -------
        self : instance of UnsupervisedSpatialFilter
            Return the modified instance.
        r   )Zaxis)r   r   r   )	rv   r#   rC   ÚTr%   r=   r<   ru   r,   )r   r(   r)   Ún_epochsÚ
n_channelsÚn_timesr   r   r   r,   L  s    ÿ
zUnsupervisedSpatialFilter.fitc                 C   s   |   |¡ |¡S )a¤  Transform the data to its filtered components after fitting.

        Parameters
        ----------
        X : array, shape (n_epochs, n_channels, n_times)
            The data to be filtered.
        y : None | array, shape (n_samples,)
            Used for scikit-learn compatibility.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The transformed data.
        r2   r0   r   r   r   r3   e  s    z'UnsupervisedSpatialFilter.fit_transformc                 C   s   |   |d¡S )a4  Transform the data to its spatial filters.

        Parameters
        ----------
        X : array, shape (n_epochs, n_channels, n_times)
            The data to be filtered.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The transformed data.
        r/   ©Ú_apply_methodr.   r   r   r   r/   v  s    z#UnsupervisedSpatialFilter.transformc                 C   s   |   |d¡S )a=  Inverse transform the data to its original space.

        Parameters
        ----------
        X : array, shape (n_epochs, n_components, n_times)
            The data to be inverted.

        Returns
        -------
        X : array, shape (n_epochs, n_channels, n_times)
            The transformed data.
        r1   r|   r.   r   r   r   r1   …  s    z+UnsupervisedSpatialFilter.inverse_transformc                 C   sl   |j \}}}t |dddg¡}t |||| g¡j}t| j|ƒ}||ƒ}t |jd||g¡ dddg¡}|S )aB  Vectorize time samples as trials, apply method and reshape back.

        Parameters
        ----------
        X : array, shape (n_epochs, n_dims, n_times)
            The data to be inverted.

        Returns
        -------
        X : array, shape (n_epochs, n_dims, n_times)
            The transformed data.
        r   r   r   r8   )r%   r#   r=   r<   rx   Úgetattrru   )r   r(   rm   ry   rz   r{   r   r   r   r}   ”  s     z'UnsupervisedSpatialFilter._apply_method)F)N)N)
r4   r5   r6   r7   r   r,   r3   r/   r1   r}   r   r   r   r   rr   2  s   


rr   c                   @   s6   e Zd ZdZedddœd	d
„ƒZddd„Zdd„ ZdS )ÚTemporalFilteraÜ  Estimator to filter data array along the last dimension.

    Applies a zero-phase low-pass, high-pass, band-pass, or band-stop
    filter to the channels.

    l_freq and h_freq are the frequencies below which and above which,
    respectively, to filter out of the data. Thus the uses are:

        - l_freq < h_freq: band-pass filter
        - l_freq > h_freq: band-stop filter
        - l_freq is not None, h_freq is None: low-pass filter
        - l_freq is None, h_freq is not None: high-pass filter

    See :func:`mne.filter.filter_data`.

    Parameters
    ----------
    l_freq : float | None
        Low cut-off frequency in Hz. If None the data are only low-passed.
    h_freq : float | None
        High cut-off frequency in Hz. If None the data are only
        high-passed.
    sfreq : float, default 1.0
        Sampling frequency in Hz.
    filter_length : str | int, default 'auto'
        Length of the FIR filter to use (if applicable):

            * int: specified length in samples.
            * 'auto' (default in 0.14): the filter length is chosen based
              on the size of the transition regions (7 times the reciprocal
              of the shortest transition band).
            * str: (default in 0.13 is "10s") a human-readable time in
              units of "s" or "ms" (e.g., "10s" or "5500ms") will be
              converted to that number of samples if ``phase="zero"``, or
              the shortest power-of-two length at least that duration for
              ``phase="zero-double"``.

    l_trans_bandwidth : float | str
        Width of the transition band at the low cut-off frequency in Hz
        (high pass or cutoff 1 in bandpass). Can be "auto"
        (default in 0.14) to use a multiple of ``l_freq``::

            min(max(l_freq * 0.25, 2), l_freq)

        Only used for ``method='fir'``.
    h_trans_bandwidth : float | str
        Width of the transition band at the high cut-off frequency in Hz
        (low pass or cutoff 2 in bandpass). Can be "auto"
        (default in 0.14) to use a multiple of ``h_freq``::

            min(max(h_freq * 0.25, 2.), info['sfreq'] / 2. - h_freq)

        Only used for ``method='fir'``.
    n_jobs : int | str, default 1
        Number of jobs to run in parallel.
        Can be 'cuda' if ``cupy`` is installed properly and method='fir'.
    method : str, default 'fir'
        'fir' will use overlap-add FIR filtering, 'iir' will use IIR
        forward-backward filtering (via filtfilt).
    iir_params : dict | None, default None
        Dictionary of parameters to use for IIR filtering.
        See mne.filter.construct_iir_filter for details. If iir_params
        is None and method="iir", 4th order Butterworth will be used.
    fir_window : str, default 'hamming'
        The window to use in FIR design, can be "hamming", "hann",
        or "blackman".
    fir_design : str
        Can be "firwin" (default) to use :func:`scipy.signal.firwin`,
        or "firwin2" to use :func:`scipy.signal.firwin2`. "firwin" uses
        a time-domain design technique that generally gives improved
        attenuation using fewer samples than "firwin2".

        .. versionadded:: 0.15
    %(verbose)s

    See Also
    --------
    FilterEstimator
    Vectorizer
    mne.filter.filter_data
    Nr"   re   rf   Úhammingrg   rW   c                C   sn   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
t| jtƒsj| jdkrjtdt| jƒ ƒ‚d S )NÚcudaz-n_jobs must be int or "cuda", got %s instead.)rh   ri   rX   rj   rk   rl   r^   rm   rn   Ú
fir_windowro   r9   Úintr&   r;   )r   rh   ri   rX   rj   rk   rl   r^   rm   rn   r‚   ro   r   r   r   r   r     s    ÿzTemporalFilter.__init__c                 C   s   | S )a  Do nothing (for scikit-learn compatibility purposes).

        Parameters
        ----------
        X : array, shape (n_epochs, n_channels, n_times) or or shape (n_channels, n_times)
            The data to be filtered over the last dimension. The channels
            dimension can be zero when passing a 2D array.
        y : None
            Not used, for scikit-learn compatibility issues.

        Returns
        -------
        self : instance of TemporalFilter
            The modified instance.
        r   r0   r   r   r   r,     s    zTemporalFilter.fitc                 C   sz   t  |¡}|jdkr"td|j ƒ‚|j}| d|d ¡}t|| j| j| j	| j
| j| j| j| j| jd| j| jd�}| |¡S )a‹  Filter data along the last dimension.

        Parameters
        ----------
        X : array, shape (n_epochs, n_channels, n_times) or shape (n_channels, n_times)
            The data to be filtered over the last dimension. The channels
            dimension can be zero when passing a 2D array.

        Returns
        -------
        X : array
            The data after filtering.
        rL   zFArray must be of at max 3 dimensions instead got %s dimensional matrixr8   F)	rj   rk   rl   r^   rm   rn   rq   r‚   ro   )r#   Z
atleast_2drM   r&   r%   r<   r   rX   rh   ri   rj   rk   rl   r^   rm   rn   r‚   ro   )r   r(   r%   r   r   r   r/   )  s&    

ÿ   úzTemporalFilter.transform)NNr"   re   re   re   Nrf   Nr€   rg   )N)r4   r5   r6   r7   r   r   r,   r/   r   r   r   r   r   ­  s    R              ýü
r   ) Únumpyr#   Zmixinr   Úbaser   Ú r   Úfilterr   Ztime_frequency.psdr   Úutilsr	   r
   r   r   Zio.pickr   r   r   r   Zcovr   r   rA   rB   rR   rU   rd   rr   r   r   r   r   r   Ú<module>   s,   ! !fW {