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

data-io.mddocs/

Data Input/Output

Complete support for neuroimaging file formats with unified interfaces for reading, writing, and converting between formats. MNE-Python supports over 20 different file formats commonly used in MEG, EEG, and neuroimaging research.

Capabilities

Raw Data Reading

Read continuous neuroimaging data from various file formats with consistent interfaces and automatic format detection.

def read_raw(fname: str, preload: bool = False, verbose: Optional[Union[bool, str, int]] = None, **kwargs) -> Raw:
    """
    Read raw data from file, auto-detecting the format.
    
    Parameters:
    - fname: Path to the raw data file
    - preload: Load data into memory immediately
    - verbose: Verbosity level
    - **kwargs: Additional format-specific parameters
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_fif(fname: str, allow_maxshield: bool = False, preload: bool = False, 
                on_split_missing: str = 'raise', verbose: Optional[Union[bool, str, int]] = None) -> Raw:
    """
    Read FIF format raw data.
    
    Parameters:
    - fname: Path to the .fif file
    - allow_maxshield: Allow reading MaxShield processed data
    - preload: Load data into memory immediately
    - on_split_missing: How to handle missing split files
    - verbose: Verbosity level
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_edf(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
                stim_channel: str = 'auto', exclude: List[str] = (), preload: bool = False) -> Raw:
    """
    Read European Data Format (EDF/EDF+) files.
    
    Parameters:
    - fname: Path to the .edf file
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels
    - stim_channel: Name of stimulus channel
    - exclude: List of channels to exclude
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_brainvision(vhdr_fname: str, eog: Union[List[str], str] = None, 
                        misc: Union[List[str], str] = None, scale: float = 1.0,
                        preload: bool = False) -> Raw:
    """
    Read BrainVision format files (.vhdr, .vmrk, .eeg).
    
    Parameters:
    - vhdr_fname: Path to the .vhdr file
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels  
    - scale: Scaling factor for data
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_eeglab(input_fname: str, eog: Union[List[str], str] = None,
                   preload: bool = False, uint16_codec: Optional[str] = None) -> Raw:
    """
    Read EEGLAB .set files.
    
    Parameters:
    - input_fname: Path to the .set file
    - eog: Names of EOG channels
    - preload: Load data into memory immediately
    - uint16_codec: Codec for uint16 data
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_ctf(directory: str, system_clock: str = 'truncate', preload: bool = False,
                clean_names: bool = False) -> Raw:
    """
    Read CTF MEG data from directory containing .ds dataset.
    
    Parameters:
    - directory: Path to .ds directory
    - system_clock: How to handle system clock issues
    - preload: Load data into memory immediately
    - clean_names: Clean channel names
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_kit(sqd_fname: str, mrk: Optional[str] = None, elp: Optional[str] = None,
                hsp: Optional[str] = None, stim: Union[List[int], int] = None,
                slope: str = '-', stimthresh: float = 1.0, preload: bool = False) -> Raw:
    """
    Read KIT/Yokogawa MEG data.
    
    Parameters:
    - sqd_fname: Path to SQD file
    - mrk: Marker file path
    - elp: Electrode position file path
    - hsp: Head shape file path
    - stim: Stimulus channels
    - slope: Direction of trigger slope
    - stimthresh: Threshold for stimulus detection
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_ant(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
                preload: bool = False) -> Raw:
    """
    Read ANT Neuro format (.cnt) files.
    
    Parameters:
    - fname: Path to the .cnt file
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_artemis123(fname: str, preload: bool = False) -> Raw:
    """
    Read ARTEMIS123 format (.bin) files.
    
    Parameters:
    - fname: Path to the .bin file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_bdf(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
                stim_channel: str = 'auto', exclude: List[str] = (), preload: bool = False) -> Raw:
    """
    Read BDF format (Biosemi variant of EDF) files.
    
    Parameters:
    - fname: Path to the .bdf file
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels
    - stim_channel: Name of stimulus channel
    - exclude: List of channels to exclude
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_boxy(fname: str, preload: bool = False) -> Raw:
    """
    Read BOXY format (.txt) files.
    
    Parameters:
    - fname: Path to the .txt file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_bti(pdf_fname: str, config_fname: str, head_shape_fname: Optional[str] = None,
                rotation_x: float = 0.0, translation: Tuple[float, float, float] = (0.0, 0.02, 0.11),
                convert: bool = True, rename_channels: bool = True, sort_by_ch_name: bool = True,
                preload: bool = False) -> Raw:
    """
    Read BTI/4D Neuroimaging MEG data.
    
    Parameters:
    - pdf_fname: Path to PDF file
    - config_fname: Path to config file
    - head_shape_fname: Path to head shape file
    - rotation_x: Rotation around x-axis
    - translation: Translation vector
    - convert: Convert to MNE coordinate system
    - rename_channels: Rename channels to MNE convention
    - sort_by_ch_name: Sort channels by name
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_cnt(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
                ecg: Union[List[str], str] = None, emg: Union[List[str], str] = None,
                data_format: str = 'auto', date_format: str = 'mm/dd/yy', preload: bool = False) -> Raw:
    """
    Read Neuroscan CNT format files.
    
    Parameters:
    - fname: Path to the .cnt file
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels
    - ecg: Names of ECG channels
    - emg: Names of EMG channels
    - data_format: Data format ('auto', 'int16', 'int32')
    - date_format: Date format in header
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_curry(fname: str, preload: bool = False) -> Raw:
    """
    Read Curry format (.dat/.dap/.rs3/.cdt/.cef) files.
    
    Parameters:
    - fname: Path to the Curry file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_egi(fname: str, events_as_annotations: bool = True, event_id: Optional[Dict] = None,
                include: Optional[List[str]] = None, exclude: Optional[List[str]] = None,
                preload: bool = False) -> Raw:
    """
    Read EGI format (.mff) files.
    
    Parameters:
    - fname: Path to the .mff directory
    - events_as_annotations: Store events as annotations
    - event_id: Event ID mapping
    - include: Channels to include
    - exclude: Channels to exclude
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_eximia(fname: str, preload: bool = False) -> Raw:
    """
    Read Eximia format (.nxe) files.
    
    Parameters:
    - fname: Path to the .nxe file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_eyelink(fname: str, create_annotations: List[str] = None, apply_offsets: bool = False,
                    find_overlaps: bool = False, overlap_threshold: float = 0.05, 
                    preload: bool = False) -> Raw:
    """
    Read EyeLink format (.asc) files.
    
    Parameters:
    - fname: Path to the .asc file
    - create_annotations: Events to create annotations from
    - apply_offsets: Apply time offsets
    - find_overlaps: Find overlapping fixations and saccades
    - overlap_threshold: Overlap threshold in seconds
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_fieldtrip(fname: str, info: Optional[Info] = None, data_name: str = 'data',
                      preload: bool = False) -> Raw:
    """
    Read FieldTrip format (.mat) files.
    
    Parameters:
    - fname: Path to the .mat file
    - info: Measurement info object
    - data_name: Name of data field in .mat file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_fil(fname: str, preload: bool = False) -> Raw:
    """
    Read UCL FIL OPM format (.bin) files.
    
    Parameters:
    - fname: Path to the .bin file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_gdf(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
                stim_channel: str = 'auto', exclude: List[str] = (), preload: bool = False) -> Raw:
    """
    Read GDF (General Data Format) files.
    
    Parameters:
    - fname: Path to the .gdf file
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels
    - stim_channel: Name of stimulus channel
    - exclude: List of channels to exclude
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_hitachi(fname: str, subject_info: Optional[Dict] = None, preload: bool = False) -> Raw:
    """
    Read Hitachi NIRS format files.
    
    Parameters:
    - fname: Path to the Hitachi file
    - subject_info: Subject information dictionary
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_nedf(fname: str, preload: bool = False) -> Raw:
    """
    Read NEDF format (.nedf) files.
    
    Parameters:
    - fname: Path to the .nedf file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_neuralynx(fname: str, preload: bool = False) -> Raw:
    """
    Read Neuralynx format files.
    
    Parameters:
    - fname: Path to the Neuralynx file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_nicolet(fname: str, ch_type: str = 'eeg', eog: Union[List[str], str] = None,
                    misc: Union[List[str], str] = None, preload: bool = False) -> Raw:
    """
    Read Nicolet format (.data) files.
    
    Parameters:
    - fname: Path to the .data file
    - ch_type: Default channel type
    - eog: Names of EOG channels
    - misc: Names of miscellaneous channels
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_nihon(fname: str, preload: bool = False) -> Raw:
    """
    Read Nihon Kohden format (.eeg) files.
    
    Parameters:
    - fname: Path to the .eeg file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_nirx(fname: str, saturated: str = 'annotate', preload: bool = False) -> Raw:
    """
    Read NIRx NIRS format (.hdr) files.
    
    Parameters:
    - fname: Path to the .hdr file
    - saturated: How to handle saturated channels ('annotate', 'ignore')
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_nsx(fname: str, preload: bool = False) -> Raw:
    """
    Read Blackrock NSx format (.ns3) files.
    
    Parameters:
    - fname: Path to the .ns3 file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_persyst(fname: str, preload: bool = False) -> Raw:
    """
    Read Persyst format (.lay) files.
    
    Parameters:
    - fname: Path to the .lay file
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

def read_raw_snirf(fname: str, optode_frame: str = 'head', preload: bool = False) -> Raw:
    """
    Read SNIRF NIRS format (.snirf) files.
    
    Parameters:
    - fname: Path to the .snirf file
    - optode_frame: Coordinate frame for optodes
    - preload: Load data into memory immediately
    
    Returns:
    Raw object containing continuous data
    """

Epochs and Evoked Data Reading

Read preprocessed epoched data and averaged evoked responses from various formats.

def read_epochs(fname: str, proj: bool = True, preload: bool = True,
               verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
    """
    Read epochs from FIF file.
    
    Parameters:
    - fname: Path to epochs file
    - proj: Apply SSP projections
    - preload: Load data into memory
    - verbose: Verbosity level
    
    Returns:
    Epochs object
    """

def read_evokeds(fname: str, condition: Union[int, str, List] = None,
                baseline: Optional[Tuple[float, float]] = None,
                proj: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> Union[Evoked, List[Evoked]]:
    """
    Read evoked response(s) from FIF file.
    
    Parameters:
    - fname: Path to evoked file
    - condition: Which condition(s) to read
    - baseline: Baseline correction period
    - proj: Apply SSP projections
    - verbose: Verbosity level
    
    Returns:
    Evoked object or list of Evoked objects
    """

def read_epochs_eeglab(input_fname: str, events: Optional[ArrayLike] = None,
                      event_id: Optional[Dict] = None, eog: Union[str, List[str]] = (),
                      verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
    """
    Read EEGLAB epochs from .set file.
    
    Parameters:
    - input_fname: Path to .set file
    - events: Event array
    - event_id: Event ID mapping
    - eog: EOG channel names
    - verbose: Verbosity level
    
    Returns:
    Epochs object
    """

Array-Based Data Creation

Create MNE data objects directly from numpy arrays when importing from other analysis environments.

def RawArray(data: ArrayLike, info: Info, first_samp: int = 0,
            copy: str = 'auto', verbose: Optional[Union[bool, str, int]] = None) -> Raw:
    """
    Create Raw object from numpy array.
    
    Parameters:
    - data: Data array (n_channels, n_times)
    - info: Measurement info
    - first_samp: First sample index
    - copy: Whether to copy data
    - verbose: Verbosity level
    
    Returns:
    Raw object
    """

def EpochsArray(data: ArrayLike, info: Info, events: Optional[ArrayLike] = None,
               tmin: float = 0.0, event_id: Optional[Dict] = None,
               selection: Optional[ArrayLike] = None, drop_log: Optional[List] = None,
               verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
    """
    Create Epochs object from numpy array.
    
    Parameters:
    - data: Data array (n_epochs, n_channels, n_times)
    - info: Measurement info
    - events: Event array
    - tmin: Start time of epochs
    - event_id: Event ID mapping
    - selection: Subset of original event indices
    - drop_log: Drop log from original epochs
    - verbose: Verbosity level
    
    Returns:
    Epochs object
    """

def EvokedArray(data: ArrayLike, info: Info, tmin: float = 0.0,
               comment: str = '', nave: int = 1, kind: str = 'average',
               verbose: Optional[Union[bool, str, int]] = None) -> Evoked:
    """
    Create Evoked object from numpy array.
    
    Parameters:
    - data: Data array (n_channels, n_times)  
    - info: Measurement info
    - tmin: Start time
    - comment: Comment for evoked response
    - nave: Number of averaged epochs
    - kind: Type of data ('average' or 'standard_error')
    - verbose: Verbosity level
    
    Returns:
    Evoked object
    """

Measurement Info Creation and Manipulation

Create and modify measurement information containers that store channel details and acquisition parameters.

def create_info(ch_names: List[str], sfreq: float, ch_types: Union[str, List[str]] = 'eeg',
               verbose: Optional[Union[bool, str, int]] = None) -> Info:
    """
    Create measurement info structure.
    
    Parameters:
    - ch_names: Channel names
    - sfreq: Sampling frequency in Hz
    - ch_types: Channel types ('eeg', 'meg', 'stim', etc.)
    - verbose: Verbosity level
    
    Returns:
    Info object with measurement information
    """

def read_info(fname: str, verbose: Optional[Union[bool, str, int]] = None) -> Info:
    """
    Read measurement info from file.
    
    Parameters:
    - fname: Path to file containing info
    - verbose: Verbosity level
    
    Returns:
    Info object
    """

def anonymize_info(info: Info, daysback: int = None, keep_his: bool = False,
                  verbose: Optional[Union[bool, str, int]] = None) -> Info:
    """
    Remove subject information from Info object.
    
    Parameters:
    - info: Info object to anonymize
    - daysback: Days to subtract from measurement date
    - keep_his: Keep head isotrak digitization
    - verbose: Verbosity level
    
    Returns:
    Anonymized Info object
    """

Event Detection and Handling

Find and manipulate events in continuous data for epoch creation.

def find_events(raw: Raw, stim_channel: Optional[str] = None, output: str = 'onset',
               consecutive: Union[bool, str] = True, min_duration: float = 0,
               shortest_event: int = 2, mask: Optional[int] = None,
               uint_cast: bool = False, mask_type: str = 'and',
               initial_event: bool = False, verbose: Optional[Union[bool, str, int]] = None) -> ArrayLike:
    """
    Find events in raw data.
    
    Parameters:
    - raw: Raw data instance
    - stim_channel: Name of stimulus channel
    - output: Output format ('onset', 'offset', 'step')
    - consecutive: How to handle consecutive events
    - min_duration: Minimum event duration
    - shortest_event: Minimum number of samples
    - mask: Mask for event values
    - uint_cast: Cast to unsigned integer
    - mask_type: Mask operation type
    - initial_event: Include initial event
    - verbose: Verbosity level
    
    Returns:
    Events array (n_events, 3) with [sample, prev_id, id]
    """

def make_fixed_length_events(raw: Raw, id: int = 1, start: float = 0, stop: Optional[float] = None,
                            duration: float = 1.0, first_samp: bool = True,
                            overlap: float = 0.0) -> ArrayLike:
    """
    Make fixed length events for epoching.
    
    Parameters:
    - raw: Raw data instance
    - id: Event ID to use
    - start: Start time
    - stop: Stop time
    - duration: Event duration
    - first_samp: Include first sample
    - overlap: Overlap between events
    
    Returns:
    Events array
    """

Covariance Estimation

Compute noise covariance matrices for inverse modeling and source analysis.

def compute_covariance(epochs: Epochs, tmin: Optional[float] = None, tmax: Optional[float] = None,
                      method: Union[str, List[str]] = 'empirical', method_params: Optional[Dict] = None,
                      cv: int = 3, scalings: Optional[Dict] = None, n_jobs: int = 1,
                      return_estimators: bool = False, on_mismatch: str = 'raise',
                      rank: Optional[Union[str, int, Dict]] = None,
                      verbose: Optional[Union[bool, str, int]] = None) -> Covariance:
    """
    Compute covariance matrix from epochs.
    
    Parameters:
    - epochs: Epochs data
    - tmin: Start time for covariance estimation
    - tmax: End time for covariance estimation
    - method: Covariance estimation method
    - method_params: Method-specific parameters
    - cv: Cross-validation folds
    - scalings: Channel scaling factors
    - n_jobs: Number of parallel jobs
    - return_estimators: Return all estimators
    - on_mismatch: How to handle channel mismatches
    - rank: Data rank specification
    - verbose: Verbosity level
    
    Returns:
    Covariance object
    """

def read_cov(fname: str, verbose: Optional[Union[bool, str, int]] = None) -> Covariance:
    """
    Read covariance matrix from file.
    
    Parameters:
    - fname: Path to covariance file
    - verbose: Verbosity level
    
    Returns:
    Covariance object
    """

def write_cov(fname: str, cov: Covariance, overwrite: bool = False,
             verbose: Optional[Union[bool, str, int]] = None) -> None:
    """
    Write covariance matrix to file.
    
    Parameters:
    - fname: Output filename
    - cov: Covariance object to write
    - overwrite: Overwrite existing file
    - verbose: Verbosity level
    """

Data Concatenation and Combination

Combine multiple data objects into single containers for analysis across sessions or conditions.

def concatenate_raws(raws: List[Raw], preload: Optional[bool] = None,
                    events_list: Optional[List[ArrayLike]] = None) -> Raw:
    """
    Concatenate raw data objects.
    
    Parameters:
    - raws: List of Raw objects to concatenate  
    - preload: Load data into memory
    - events_list: List of events for each raw object
    
    Returns:
    Concatenated Raw object
    """

def concatenate_epochs(epochs_list: List[Epochs], add_offset: bool = True) -> Epochs:
    """
    Concatenate epochs objects.
    
    Parameters:
    - epochs_list: List of Epochs objects
    - add_offset: Add offset to event IDs to avoid conflicts
    
    Returns:
    Concatenated Epochs object
    """

def grand_average(all_inst: List[Union[Evoked, AverageTFR]], interpolate_bads: bool = True,
                 drop_bads: bool = True) -> Union[Evoked, AverageTFR]:
    """
    Compute grand average across subjects/sessions.
    
    Parameters:
    - all_inst: List of evoked responses or TFR objects
    - interpolate_bads: Interpolate bad channels
    - drop_bads: Drop bad channels
    
    Returns:
    Grand averaged object
    """

File Format Conversion and Export

Export MNE data objects to other analysis software formats and convert between different neuroimaging file formats.

def what(fname: str) -> str:
    """
    Determine file type from filename or header.
    
    Parameters:
    - fname: Path to file
    
    Returns:
    String describing file type
    """

def match_channel_orders(instances: List[Union[Raw, Epochs, Evoked]], copy: bool = True) -> List:
    """
    Match channel orders across multiple instances.
    
    Parameters:
    - instances: List of MNE objects
    - copy: Make copies of instances
    
    Returns:
    List of instances with matched channel orders  
    """

def show_fiff(fname: str, tag: Optional[int] = None, indent: str = '\t', 
             read_limit: Optional[int] = None, max_str: int = 30) -> None:
    """
    Show contents of FIF file.
    
    Parameters:
    - fname: Path to FIF file
    - tag: Tag to show (show all if None)
    - indent: String to use for indentation
    - read_limit: Maximum number of tags to read
    - max_str: Maximum string length to show
    """

def read_fiducials(fname: str) -> List[Dict]:
    """
    Read fiducial points from file.
    
    Parameters:
    - fname: Path to fiducials file
    
    Returns:
    List of fiducial point dictionaries
    """

def write_fiducials(fname: str, pts: List[Dict], coord_frame: int, overwrite: bool = False) -> None:
    """
    Write fiducial points to file.
    
    Parameters:
    - fname: Output filename
    - pts: List of fiducial points
    - coord_frame: Coordinate frame constant
    - overwrite: Overwrite existing file
    """

Usage Examples

Reading Different File Formats

import mne

# Read FIF format (native MNE format)
raw_fif = mne.io.read_raw_fif('sample_audvis_raw.fif', preload=True)

# Read EDF format
raw_edf = mne.io.read_raw_edf('sleep_recording.edf', preload=True)

# Read BrainVision format
raw_bv = mne.io.read_raw_brainvision('experiment.vhdr', preload=True)

# Read EEGLAB format  
raw_eeglab = mne.io.read_raw_eeglab('experiment.set', preload=True)

Creating Data from Arrays

import mne
import numpy as np

# Create synthetic data
sfreq = 1000  # Hz
times = np.arange(0, 10, 1/sfreq)
data = np.random.randn(64, len(times))

# Create channel names and info
ch_names = [f'EEG{i:03d}' for i in range(64)]
ch_types = ['eeg'] * 64
info = mne.create_info(ch_names, sfreq, ch_types)

# Create Raw object
raw = mne.io.RawArray(data, info)

# Create epochs data
n_epochs = 100
epochs_data = np.random.randn(n_epochs, 64, 1000)
events = np.column_stack([np.arange(n_epochs) * 1000, 
                         np.zeros(n_epochs, dtype=int),
                         np.ones(n_epochs, dtype=int)])

epochs = mne.EpochsArray(epochs_data, info, events, tmin=-0.5)

Concatenating Multiple Files

import mne

# Load multiple raw files
raw1 = mne.io.read_raw_fif('session1.fif', preload=True)
raw2 = mne.io.read_raw_fif('session2.fif', preload=True)
raw3 = mne.io.read_raw_fif('session3.fif', preload=True)

# Concatenate into single object
raw = mne.concatenate_raws([raw1, raw2, raw3])

# Load multiple epochs files  
epochs1 = mne.read_epochs('condition1-epo.fif')
epochs2 = mne.read_epochs('condition2-epo.fif')

# Concatenate epochs
all_epochs = mne.concatenate_epochs([epochs1, epochs2])

Event Detection and Covariance Estimation

import mne

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

# Find events in stimulus channel
events = mne.find_events(raw, stim_channel='STI 014')
print(f"Found {len(events)} events")

# Create epochs around events
epochs = mne.Epochs(raw, events, event_id={'auditory': 1, 'visual': 3}, 
                   tmin=-0.2, tmax=0.5, preload=True)

# Compute noise covariance from baseline period
noise_cov = mne.compute_covariance(epochs, tmin=-0.2, tmax=0.0, method='empirical')

# Save covariance for later use
mne.write_cov('sample-cov.fif', noise_cov)

# Load covariance from file
loaded_cov = mne.read_cov('sample-cov.fif')

# Create fixed-length events for resting state analysis
rest_events = mne.make_fixed_length_events(raw, duration=2.0, overlap=0.5)
rest_epochs = mne.Epochs(raw, rest_events, tmin=0, tmax=2.0, preload=True)

Types

class Info:
    """
    Measurement information container.
    
    Behaves like a dictionary containing all metadata for a recording,
    with keys restricted to FIF format specification.
    """
    ch_names: List[str]  # Channel names
    sfreq: float  # Sampling frequency in Hz
    bads: List[str]  # Bad channel names
    nchan: int  # Number of channels
    highpass: Optional[float]  # Highpass filter frequency
    lowpass: Optional[float]  # Lowpass filter frequency
    
    def copy(self) -> 'Info': ...
    def normalize_proj(self) -> 'Info': ...

class Covariance:
    """
    Data covariance matrix container.
    
    Stores covariance matrix with metadata for noise modeling and inverse solutions.
    """
    data: ArrayLike  # Covariance matrix (n_channels, n_channels)
    ch_names: List[str]  # Channel names
    nfree: int  # Degrees of freedom
    method: str  # Estimation method used
    
    def plot(self, info: Info, **kwargs) -> Figure: ...
    def save(self, fname: str) -> None: ...

ArrayLike = Union[np.ndarray, List, Tuple]

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