CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mne

MNE-Python provides comprehensive tools for analyzing MEG, EEG, and other neuroimaging data with advanced source estimation and connectivity analysis.

Pending
Overview
Eval results
Files

preprocessing.mddocs/

Preprocessing

Comprehensive preprocessing tools for cleaning and preparing neuroimaging data for analysis. Includes filtering, artifact detection and removal, independent component analysis (ICA), Maxwell filtering, and signal space projection (SSP).

Capabilities

Artifact Detection and Annotation

Detect and annotate various artifacts in neuroimaging data for subsequent removal or rejection.

def annotate_amplitude(raw: Raw, peak: Optional[float] = None, flat: Optional[float] = None,
                      bad_percent: float = 5.0, min_duration: float = 0.002,
                      verbose: Optional[Union[bool, str, int]] = None) -> Annotations:
    """
    Detect amplitude-based artifacts and create annotations.
    
    Parameters:
    - raw: Raw data instance
    - peak: Peak amplitude threshold
    - flat: Flat signal threshold
    - bad_percent: Percentage of channels required to be bad
    - min_duration: Minimum duration of detected artifacts
    - verbose: Verbosity level
    
    Returns:
    Annotations object with detected artifacts
    """

def annotate_nan(raw: Raw, verbose: Optional[Union[bool, str, int]] = None) -> Annotations:
    """
    Annotate NaN values in raw data.
    
    Parameters:
    - raw: Raw data instance
    - verbose: Verbosity level
    
    Returns:
    Annotations object marking NaN periods
    """

def annotate_muscle_zscore(raw: Raw, threshold: float = 4.0, ch_type: str = 'eeg',
                          filter_freq: Tuple[float, float] = (110, 140),
                          n_jobs: int = 1, verbose: Optional[Union[bool, str, int]] = None) -> Tuple[Annotations, ArrayLike]:
    """
    Annotate muscle artifacts using z-score of filtered data.
    
    Parameters:
    - raw: Raw data instance
    - threshold: Z-score threshold for detection
    - ch_type: Channel type to analyze
    - filter_freq: Frequency range for muscle activity
    - n_jobs: Number of parallel jobs
    - verbose: Verbosity level
    
    Returns:
    Tuple of (annotations, z_scores)
    """

Independent Component Analysis (ICA)

Decompose signals into independent components for artifact identification and removal.

class ICA:
    """
    Independent Component Analysis for artifact removal.
    
    Decomposes multichannel data into independent components to identify
    and remove artifacts like eye blinks, heartbeat, and muscle activity.
    """
    
    def __init__(self, n_components: Optional[int] = None, algorithm: str = 'fastica',
                fun: str = 'logcosh', fun_args: Optional[Dict] = None,
                max_iter: int = 1000, tol: float = 1e-4, w_init: Optional[ArrayLike] = None,
                whiten: str = 'unit-variance', random_state: Optional[int] = None,
                method: str = 'fastica', fit_params: Optional[Dict] = None,
                max_pca_components: Optional[int] = None, n_pca_components: Optional[Union[int, float]] = None,
                noise_cov: Optional[Covariance] = None, verbose: Optional[Union[bool, str, int]] = None):
        """
        Initialize ICA object.
        
        Parameters:
        - n_components: Number of components to extract
        - algorithm: ICA algorithm ('fastica', 'infomax', 'picard')
        - fun: Functional form for FastICA
        - fun_args: Arguments for functional form
        - max_iter: Maximum iterations
        - tol: Tolerance for convergence
        - w_init: Initial unmixing matrix
        - whiten: Whitening method
        - random_state: Random state for reproducibility
        - method: ICA method
        - fit_params: Additional fit parameters
        - max_pca_components: Maximum PCA components
        - n_pca_components: Number of PCA components to keep
        - noise_cov: Noise covariance matrix
        - verbose: Verbosity level
        """
    
    def fit(self, inst: Union[Raw, Epochs], picks: Optional[Union[str, List]] = None,
           start: Optional[float] = None, stop: Optional[float] = None,
           decim: Optional[int] = None, reject: Optional[Dict] = None,
           flat: Optional[Dict] = None, tstep: float = 2.0, 
           reject_by_annotation: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> 'ICA':
        """
        Fit ICA on data.
        
        Parameters:
        - inst: Raw or Epochs instance to fit
        - picks: Channel selection
        - start: Start time for fitting
        - stop: Stop time for fitting
        - decim: Decimation factor
        - reject: Rejection criteria
        - flat: Flat channel detection criteria
        - tstep: Time step for data chunks
        - reject_by_annotation: Reject based on annotations
        - verbose: Verbosity level
        
        Returns:
        Fitted ICA object
        """
    
    def apply(self, inst: Union[Raw, Epochs], include: Optional[List[int]] = None,
             exclude: Optional[List[int]] = None, n_pca_components: Optional[int] = None,
             verbose: Optional[Union[bool, str, int]] = None) -> Union[Raw, Epochs]:
        """
        Apply ICA transformation to remove components.
        
        Parameters:
        - inst: Instance to transform
        - include: Components to include (if None, use all except excluded)
        - exclude: Components to exclude
        - n_pca_components: Number of PCA components
        - verbose: Verbosity level
        
        Returns:
        Transformed instance with artifacts removed
        """
    
    def find_bads_ecg(self, inst: Union[Raw, Epochs], ch_name: Optional[str] = None,
                     threshold: str = 'auto', start: Optional[float] = None,
                     stop: Optional[float] = None, l_freq: float = 5, h_freq: float = 35,
                     method: str = 'corrcoef', reject_by_annotation: bool = True,
                     measure: str = 'zscore', verbose: Optional[Union[bool, str, int]] = None) -> List[int]:
        """
        Find ECG-related components automatically.
        
        Parameters:
        - inst: Raw or Epochs instance
        - ch_name: ECG channel name
        - threshold: Threshold for component selection
        - start: Start time
        - stop: Stop time  
        - l_freq: Low frequency for ECG filtering
        - h_freq: High frequency for ECG filtering
        - method: Method for finding components
        - reject_by_annotation: Reject based on annotations
        - measure: Measure for thresholding
        - verbose: Verbosity level
        
        Returns:
        List of ECG component indices
        """
    
    def find_bads_eog(self, inst: Union[Raw, Epochs], ch_name: Optional[Union[str, List[str]]] = None,
                     threshold: float = 3.0, start: Optional[float] = None,
                     stop: Optional[float] = None, l_freq: float = 1, h_freq: float = 10,
                     reject_by_annotation: bool = True, measure: str = 'zscore',
                     verbose: Optional[Union[bool, str, int]] = None) -> List[int]:
        """
        Find EOG-related components automatically.
        
        Parameters:
        - inst: Raw or Epochs instance
        - ch_name: EOG channel name(s)
        - threshold: Threshold for component selection
        - start: Start time
        - stop: Stop time
        - l_freq: Low frequency for EOG filtering  
        - h_freq: High frequency for EOG filtering
        - reject_by_annotation: Reject based on annotations
        - measure: Measure for thresholding
        - verbose: Verbosity level
        
        Returns:
        List of EOG component indices
        """
    
    def plot_components(self, picks: Optional[Union[int, List[int]]] = None,
                       ch_type: Optional[str] = None, res: int = 64,
                       vmin: Optional[float] = None, vmax: Optional[float] = None,
                       colorbar: bool = True, title: Optional[str] = None,
                       show: bool = True, outlines: str = 'head',
                       contours: int = 6, image_interp: str = 'bilinear',
                       inst: Optional[Union[Raw, Epochs]] = None) -> Figure:
        """
        Plot ICA component topographies.
        
        Parameters:
        - picks: Components to plot
        - ch_type: Channel type
        - res: Resolution of topomaps
        - vmin: Minimum value for colormap
        - vmax: Maximum value for colormap
        - colorbar: Show colorbar
        - title: Plot title
        - show: Show plot immediately
        - outlines: Outline style
        - contours: Number of contour lines
        - image_interp: Image interpolation method
        - inst: Instance for additional channel info
        
        Returns:
        Figure object
        """
    
    def plot_sources(self, inst: Union[Raw, Epochs], picks: Optional[Union[int, List[int]]] = None,
                    start: Optional[float] = None, stop: Optional[float] = None,
                    show: bool = True, title: Optional[str] = None, block: bool = False) -> Figure:
        """
        Plot ICA component time series.
        
        Parameters:
        - inst: Instance to plot sources from
        - picks: Components to plot
        - start: Start time
        - stop: Stop time
        - show: Show plot immediately
        - title: Plot title
        - block: Block execution until plot is closed
        
        Returns:
        Figure object
        """

EOG Regression and Advanced Artifact Removal

Advanced methods for removing eye movement and other artifacts using regression techniques.

class EOGRegression:
    """
    EOG artifact removal using regression techniques.
    
    Removes eye movement artifacts by regressing out EOG signals from EEG channels.
    """
    
    def __init__(self, picks_artifact: Optional[Union[str, List]] = None,
                picks_target: Optional[Union[str, List]] = None) -> None:
        """
        Initialize EOG regression object.
        
        Parameters:
        - picks_artifact: Channels containing artifacts (EOG)
        - picks_target: Target channels to clean (EEG)
        """
    
    def fit(self, epochs: Epochs) -> 'EOGRegression':
        """
        Fit regression model to remove EOG artifacts.
        
        Parameters:
        - epochs: Epochs containing both EOG and target channels
        
        Returns:
        Fitted EOGRegression object
        """
    
    def apply(self, inst: Union[Raw, Epochs]) -> Union[Raw, Epochs]:
        """
        Apply EOG regression to remove artifacts.
        
        Parameters:
        - inst: Data instance to clean
        
        Returns:
        Cleaned data instance
        """

class Xdawn:
    """
    Spatial filtering using xDAWN algorithm.
    
    Enhances event-related responses while suppressing noise and artifacts
    using spatial filters optimized for signal-to-noise ratio.
    """
    
    def __init__(self, n_components: int = 2, signal_cov: Optional[ArrayLike] = None,
                correct_overlap: str = 'auto', reg: Optional[Union[str, float]] = None) -> None:
        """
        Initialize xDAWN spatial filter.
        
        Parameters:
        - n_components: Number of components to extract
        - signal_cov: Signal covariance matrix
        - correct_overlap: Method for correcting overlap
        - reg: Regularization parameter
        """
    
    def fit(self, epochs: Epochs, y: Optional[ArrayLike] = None) -> 'Xdawn':
        """
        Fit xDAWN spatial filters.
        
        Parameters:
        - epochs: Epochs to fit filters on
        - y: Target variable (not used)
        
        Returns:
        Fitted Xdawn object
        """
    
    def apply(self, inst: Union[Raw, Epochs]) -> Union[Raw, Epochs]:
        """
        Apply xDAWN spatial filtering.
        
        Parameters:
        - inst: Data instance to filter
        
        Returns:
        Spatially filtered data instance
        """

ECG and EOG Event Detection

Detect heartbeat and eye movement events for artifact analysis and removal.

def find_ecg_events(raw: Raw, event_id: int = 999, ch_name: Optional[str] = None,
                   tstart: float = 0.0, l_freq: float = 5, h_freq: float = 35,
                   qrs_threshold: Union[float, str] = 'auto', filter_length: str = '10s',
                   return_ecg: bool = False, reject_by_annotation: bool = True,
                   verbose: Optional[Union[bool, str, int]] = None) -> Union[ArrayLike, Tuple[ArrayLike, ArrayLike]]:
    """
    Find ECG events in raw data.
    
    Parameters:
    - raw: Raw data instance
    - event_id: Event ID for ECG events
    - ch_name: ECG channel name
    - tstart: Start time for event detection
    - l_freq: Low frequency for ECG filtering
    - h_freq: High frequency for ECG filtering
    - qrs_threshold: QRS detection threshold
    - filter_length: Filter length
    - return_ecg: Return filtered ECG signal
    - reject_by_annotation: Reject based on annotations
    - verbose: Verbosity level
    
    Returns:
    ECG events array, optionally with filtered ECG signal
    """

def find_eog_events(raw: Raw, event_id: int = 998, ch_name: Optional[Union[str, List[str]]] = None,
                   tstart: float = 0.0, l_freq: float = 1, h_freq: float = 10,
                   reject_by_annotation: bool = True, thresh: Optional[float] = None,
                   verbose: Optional[Union[bool, str, int]] = None) -> ArrayLike:
    """
    Find EOG events in raw data.
    
    Parameters:
    - raw: Raw data instance
    - event_id: Event ID for EOG events
    - ch_name: EOG channel name(s)
    - tstart: Start time for event detection
    - l_freq: Low frequency for EOG filtering
    - h_freq: High frequency for EOG filtering
    - reject_by_annotation: Reject based on annotations
    - thresh: Threshold for EOG detection
    - verbose: Verbosity level
    
    Returns:
    EOG events array
    """

def create_ecg_epochs(raw: Raw, ch_name: Optional[str] = None, event_id: int = 999,
                     picks: Optional[Union[str, List]] = None, tmin: float = -0.5, tmax: float = 0.5,
                     l_freq: float = 8, h_freq: float = 16, reject: Optional[Dict] = None,
                     flat: Optional[Dict] = None, baseline: Optional[Tuple[float, float]] = None,
                     preload: bool = True, keep_ecg: bool = False,
                     reject_by_annotation: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
    """
    Create epochs around ECG events.
    
    Parameters:
    - raw: Raw data instance
    - ch_name: ECG channel name
    - event_id: Event ID for ECG events
    - picks: Channel selection
    - tmin: Start time relative to events
    - tmax: End time relative to events
    - l_freq: Low frequency for filtering
    - h_freq: High frequency for filtering
    - reject: Rejection criteria
    - flat: Flat channel detection criteria
    - baseline: Baseline correction period
    - preload: Load data into memory
    - keep_ecg: Keep ECG channel in epochs
    - reject_by_annotation: Reject based on annotations
    - verbose: Verbosity level
    
    Returns:
    Epochs around ECG events
    """

def create_eog_epochs(raw: Raw, ch_name: Optional[Union[str, List[str]]] = None, event_id: int = 998,
                     picks: Optional[Union[str, List]] = None, tmin: float = -0.5, tmax: float = 0.5,
                     l_freq: float = 1, h_freq: float = 10, reject: Optional[Dict] = None,
                     flat: Optional[Dict] = None, baseline: Optional[Tuple[float, float]] = None,
                     preload: bool = True, reject_by_annotation: bool = True,
                     verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
    """
    Create epochs around EOG events.
    
    Parameters:
    - raw: Raw data instance
    - ch_name: EOG channel name(s)
    - event_id: Event ID for EOG events
    - picks: Channel selection
    - tmin: Start time relative to events
    - tmax: End time relative to events
    - l_freq: Low frequency for filtering
    - h_freq: High frequency for filtering
    - reject: Rejection criteria
    - flat: Flat channel detection criteria
    - baseline: Baseline correction period
    - preload: Load data into memory
    - reject_by_annotation: Reject based on annotations
    - verbose: Verbosity level
    
    Returns:
    Epochs around EOG events
    """

Maxwell Filtering (Signal Space Separation)

Remove external magnetic interference and compensate for head movements in MEG recordings.

def maxwell_filter(raw: Raw, origin: Union[str, Tuple[float, float, float]] = 'auto',
                  int_order: int = 8, ext_order: int = 3, calibration: Optional[str] = None,
                  cross_talk: Optional[str] = None, st_duration: Optional[float] = None,
                  st_correlation: float = 0.98, coord_frame: str = 'head',
                  destination: Optional[Union[str, ArrayLike]] = None,
                  regularize: str = 'in', ignore_ref: bool = False,
                  bad_condition: str = 'error', head_pos: Optional[ArrayLike] = None,
                  st_fixed: bool = True, st_only: bool = False,
                  mag_scale: Union[float, str] = 100.0, skip_by_annotation: Union[str, List[str]] = 'edge',
                  extended_proj: List = (), verbose: Optional[Union[bool, str, int]] = None) -> Raw:
    """
    Apply Maxwell filtering (Signal Space Separation) to MEG data.
    
    Parameters:
    - raw: Raw MEG data
    - origin: Head origin for coordinate system
    - int_order: Internal multipole order
    - ext_order: External multipole order
    - calibration: Calibration file path
    - cross_talk: Cross-talk file path
    - st_duration: Duration for spatiotemporal processing
    - st_correlation: Correlation threshold for tSSS
    - coord_frame: Coordinate frame
    - destination: Destination for head position
    - regularize: Regularization method
    - ignore_ref: Ignore reference channels
    - bad_condition: How to handle bad conditions
    - head_pos: Head position array
    - st_fixed: Use fixed correlation window
    - st_only: Apply only spatiotemporal processing
    - mag_scale: Magnetometer scaling
    - skip_by_annotation: Annotations to skip
    - extended_proj: Extended projections
    - verbose: Verbosity level
    
    Returns:
    Maxwell filtered Raw object
    """

def compute_maxwell_basis(info: Info, origin: Union[str, Tuple[float, float, float]],
                         int_order: int = 8, ext_order: int = 3, 
                         regularize: str = 'in', ignore_ref: bool = False,
                         verbose: Optional[Union[bool, str, int]] = None) -> Dict:
    """
    Compute Maxwell filtering basis.
    
    Parameters:
    - info: Measurement info
    - origin: Head origin
    - int_order: Internal multipole order
    - ext_order: External multipole order
    - regularize: Regularization method
    - ignore_ref: Ignore reference channels
    - verbose: Verbosity level
    
    Returns:
    Dictionary containing Maxwell basis
    """

def find_bad_channels_maxwell(raw: Raw, origin: Union[str, Tuple[float, float, float]] = 'auto',
                             int_order: int = 8, ext_order: int = 3,
                             calibration: Optional[str] = None, cross_talk: Optional[str] = None,
                             coord_frame: str = 'head', regularize: str = 'in',
                             ignore_ref: bool = False, bad_condition: str = 'error',
                             skip_by_annotation: Union[str, List[str]] = 'edge',
                             h_freq: Optional[float] = 40, verbose: Optional[Union[bool, str, int]] = None) -> List[str]:
    """
    Find bad MEG channels using Maxwell filtering.
    
    Parameters:
    - raw: Raw MEG data
    - origin: Head origin
    - int_order: Internal multipole order
    - ext_order: External multipole order
    - calibration: Calibration file path
    - cross_talk: Cross-talk file path
    - coord_frame: Coordinate frame
    - regularize: Regularization method
    - ignore_ref: Ignore reference channels
    - bad_condition: How to handle bad conditions
    - skip_by_annotation: Annotations to skip
    - h_freq: High-pass filter frequency
    - verbose: Verbosity level
    
    Returns:
    List of bad channel names
    """

Artifact Detection and Annotation

Automatically detect and mark various types of artifacts in continuous data.

def annotate_amplitude(raw: Raw, peak: Optional[float] = None, flat: Optional[float] = None,
                      bad_percent: float = 5.0, min_duration: float = 0.002,
                      verbose: Optional[Union[bool, str, int]] = None) -> Annotations:
    """
    Annotate segments with large amplitude artifacts.
    
    Parameters:
    - raw: Raw data instance
    - peak: Peak amplitude threshold
    - flat: Flat signal threshold
    - bad_percent: Percentage of bad channels to trigger annotation
    - min_duration: Minimum duration of artifacts
    - verbose: Verbosity level
    
    Returns:
    Annotations object with artifact segments
    """

def annotate_break(raw: Raw, min_break_duration: float = 15.0, t_start_after_previous: float = 5.0,
                  t_stop_before_next: float = 5.0, ignore: Union[str, List[str]] = (),
                  verbose: Optional[Union[bool, str, int]] = None) -> Annotations:
    """
    Annotate breaks in data acquisition.
    
    Parameters:
    - raw: Raw data instance
    - min_break_duration: Minimum break duration to annotate
    - t_start_after_previous: Time after previous segment
    - t_stop_before_next: Time before next segment
    - ignore: Existing annotations to ignore
    - verbose: Verbosity level
    
    Returns:
    Annotations object with break segments
    """

def annotate_muscle_zscore(raw: Raw, threshold: float = 4, ch_type: str = 'eeg',
                          l_freq: float = 110, h_freq: float = 140,
                          n_jobs: int = 1, verbose: Optional[Union[bool, str, int]] = None) -> Annotations:
    """
    Annotate muscle artifacts using z-score of high-frequency power.
    
    Parameters:
    - raw: Raw data instance
    - threshold: Z-score threshold for muscle detection
    - ch_type: Channel type to analyze
    - l_freq: Low frequency for muscle band
    - h_freq: High frequency for muscle band
    - n_jobs: Number of parallel jobs
    - verbose: Verbosity level
    
    Returns:
    Annotations object with muscle artifact segments
    """

def annotate_movement(raw: Raw, pos: ArrayLike, rotation_velocity_limit: Optional[float] = None,
                     translation_velocity_limit: Optional[float] = None,
                     mean_distance_limit: Optional[float] = None, 
                     verbose: Optional[Union[bool, str, int]] = None) -> Annotations:
    """
    Annotate movement artifacts from head position data.
    
    Parameters:
    - raw: Raw data instance
    - pos: Head position array
    - rotation_velocity_limit: Maximum rotation velocity
    - translation_velocity_limit: Maximum translation velocity
    - mean_distance_limit: Maximum mean distance from origin
    - verbose: Verbosity level
    
    Returns:
    Annotations object with movement artifact segments
    """

Signal Space Projection (SSP)

Remove artifacts using signal space projection methods.

def compute_proj_epochs(epochs: Epochs, n_grad: int = 2, n_mag: int = 2, n_eeg: int = 2,
                       n_jobs: int = 1, desc_prefix: Optional[str] = None,
                       verbose: Optional[Union[bool, str, int]] = None) -> List[Projection]:
    """
    Compute SSP projectors from epochs.
    
    Parameters:
    - epochs: Epochs object
    - n_grad: Number of gradient projectors
    - n_mag: Number of magnetometer projectors  
    - n_eeg: Number of EEG projectors
    - n_jobs: Number of parallel jobs
    - desc_prefix: Description prefix for projectors
    - verbose: Verbosity level
    
    Returns:
    List of Projection objects
    """

def compute_proj_raw(raw: Raw, start: float = 0, stop: Optional[float] = None,
                    duration: float = 1, n_grad: int = 2, n_mag: int = 2, n_eeg: int = 2,
                    reject_by_annotation: bool = True, n_jobs: int = 1,
                    verbose: Optional[Union[bool, str, int]] = None) -> List[Projection]:
    """
    Compute SSP projectors from raw data.
    
    Parameters:
    - raw: Raw data instance
    - start: Start time
    - stop: Stop time
    - duration: Duration of data segments
    - n_grad: Number of gradient projectors
    - n_mag: Number of magnetometer projectors
    - n_eeg: Number of EEG projectors
    - reject_by_annotation: Reject annotated segments
    - n_jobs: Number of parallel jobs
    - verbose: Verbosity level
    
    Returns:
    List of Projection objects
    """

def compute_proj_evoked(evoked: Evoked, n_grad: int = 2, n_mag: int = 2, n_eeg: int = 2,
                       desc_prefix: Optional[str] = None, verbose: Optional[Union[bool, str, int]] = None) -> List[Projection]:
    """
    Compute SSP projectors from evoked data.
    
    Parameters:
    - evoked: Evoked data instance
    - n_grad: Number of gradient projectors
    - n_mag: Number of magnetometer projectors
    - n_eeg: Number of EEG projectors
    - desc_prefix: Description prefix
    - verbose: Verbosity level
    
    Returns:
    List of Projection objects
    """

Referencing and Channel Operations

Set reference schemes and manipulate channel configurations for optimal signal quality.

def set_eeg_reference(inst: Union[Raw, Epochs, Evoked], ref_channels: Union[str, List[str]] = 'average',
                     copy: bool = True, projection: bool = False, ch_type: str = 'auto',
                     forward: Optional[Forward] = None, joint: bool = False,
                     verbose: Optional[Union[bool, str, int]] = None) -> Union[Raw, Epochs, Evoked]:
    """
    Set EEG reference for data.
    
    Parameters:
    - inst: Instance to re-reference
    - ref_channels: Reference channel(s) or 'average'
    - copy: Make copy of instance
    - projection: Use projection for re-referencing
    - ch_type: Channel type to re-reference
    - forward: Forward solution for REST referencing
    - joint: Use joint reference for MEG and EEG
    - verbose: Verbosity level
    
    Returns:
    Re-referenced instance
    """

def set_bipolar_reference(inst: Union[Raw, Epochs, Evoked], anode: Union[str, List[str]],
                         cathode: Union[str, List[str]], ch_name: Optional[Union[str, List[str]]] = None,
                         ch_info: Optional[Dict] = None, drop_refs: bool = True,
                         copy: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> Union[Raw, Epochs, Evoked]:
    """
    Set bipolar reference.
    
    Parameters:
    - inst: Instance to re-reference
    - anode: Anode channel name(s)
    - cathode: Cathode channel name(s)
    - ch_name: New channel name(s)
    - ch_info: Channel info dict
    - drop_refs: Drop reference channels
    - copy: Make copy of instance
    - verbose: Verbosity level
    
    Returns:
    Bipolar referenced instance
    """

def add_reference_channels(inst: Union[Raw, Epochs, Evoked], ref_channels: Union[str, List[str]],
                          copy: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> Union[Raw, Epochs, Evoked]:
    """
    Add reference channels to data.
    
    Parameters:
    - inst: Instance to modify
    - ref_channels: Reference channel name(s) to add
    - copy: Make copy of instance
    - verbose: Verbosity level
    
    Returns:
    Instance with added reference channels
    """

Usage Examples

Basic Filtering

import mne

# Load raw data
raw = mne.io.read_raw_fif('sample_audvis_raw.fif', preload=True)

# Apply band-pass filter (1-40 Hz)
raw.filter(l_freq=1.0, h_freq=40.0, fir_design='firwin')

# Remove 60 Hz line noise
raw.notch_filter(freqs=60, fir_design='firwin')

# Resample to lower sampling rate
raw.resample(sfreq=250)

ICA Artifact Removal

import mne
from mne.preprocessing import ICA

# Load and filter data
raw = mne.io.read_raw_fif('sample_audvis_raw.fif', preload=True)
raw.filter(l_freq=1.0, h_freq=40.0)

# Setup and fit ICA
ica = ICA(n_components=20, random_state=97)
ica.fit(raw)

# Find and exclude ECG artifacts
ecg_indices, ecg_scores = ica.find_bads_ecg(raw, method='corrcoef')
ica.exclude = ecg_indices

# Find and exclude EOG artifacts  
eog_indices, eog_scores = ica.find_bads_eog(raw)
ica.exclude.extend(eog_indices)

# Apply ICA to remove artifacts
raw_clean = ica.apply(raw)

Automatic Artifact Detection

import mne

# Load raw data
raw = mne.io.read_raw_fif('sample_audvis_raw.fif', preload=True)

# Detect amplitude artifacts
amp_annot = annotate_amplitude(raw, peak=150e-6, flat=1e-6)

# Detect muscle artifacts
muscle_annot = annotate_muscle_zscore(raw, threshold=4)

# Combine annotations
all_annot = amp_annot + muscle_annot
raw.set_annotations(all_annot)

Types

class Annotations:
    """Container for temporal annotations."""
    onset: ArrayLike  # Onset times in seconds
    duration: ArrayLike  # Duration in seconds  
    description: List[str]  # Annotation descriptions
    
    def __add__(self, other: 'Annotations') -> 'Annotations': ...
    def save(self, fname: str) -> None: ...

class Projection:
    """Signal space projection operator."""
    data: Dict  # Projection data
    kind: int  # Projection type
    desc: str  # Description
    active: bool  # Whether projection is active
    
    def plot_topomap(self, info: Info, **kwargs) -> Figure: ...

class Covariance:
    """Data covariance matrix."""
    data: ArrayLike  # Covariance matrix
    ch_names: List[str]  # Channel names
    nfree: int  # Degrees of freedom
    
    def plot(self, info: Info, **kwargs) -> Figure: ...

Install with Tessl CLI

npx tessl i tessl/pypi-mne

docs

data-io.md

datasets.md

index.md

machine-learning.md

preprocessing.md

source-analysis.md

statistics.md

time-frequency.md

visualization.md

tile.json