Skip to content

Pipeline Functions API Reference

This page documents the core functions of the AutoClean pipeline.

Data Import Functions

step_import_raw

def step_import_raw(autoclean_dict: dict, preload: bool = True) -> mne.io.Raw

Import and configure raw EEG data.

Parameters:

  • autoclean_dict (dict): Dictionary containing pipeline configuration including:
  • unprocessed_file: Path to raw EEG data file
  • eeg_system: Name of the EEG system montage
  • preload (bool): If True, data will be loaded into memory at initialization

Returns:

  • mne.io.Raw: Imported and configured raw EEG data with appropriate montage set

step_convert_to_bids

def step_convert_to_bids(
    raw,
    output_dir,
    task="rest",
    participant_id=None,
    line_freq=60.0,
    overwrite=False,
    events=None,
    event_id=None,
    study_name="EEG Study"
)

Converts a single EEG data file into BIDS format with default/dummy metadata.

Parameters:

  • raw (mne.io.Raw): Raw EEG data
  • output_dir (str or Path): Directory for BIDS dataset
  • task (str): Task name
  • participant_id (str): Participant ID
  • line_freq (float): Power line frequency in Hz
  • overwrite (bool): Whether to overwrite existing files
  • events (array): Events array
  • event_id (dict): Event ID dictionary
  • study_name (str): Name of the study

Preprocessing Functions

step_clean_bad_channels

def step_clean_bad_channels(raw, autoclean_dict)

Detect and interpolate bad channels using PyPrep.

Parameters:

  • raw (mne.io.Raw): Raw EEG data
  • autoclean_dict (dict): Configuration dictionary

step_resample_data

def step_resample_data(raw, resample_freq)

Resample data using frequency from config.

Parameters:

  • raw (mne.io.Raw): Raw EEG data
  • resample_freq (float): Target sampling frequency

Artifact Rejection Functions

step_run_pylossless

def step_run_pylossless(autoclean_dict)

Run the PyLossless pipeline for artifact rejection.

Parameters:

  • autoclean_dict (dict): Configuration dictionary

detect_muscle_beta_focus_robust

def detect_muscle_beta_focus_robust(
    epochs,
    pipeline,
    autoclean_dict,
    freq_band=(20, 30),
    scale_factor=3.0
)

Detect muscle artifacts using a robust measure focusing on beta band.

Parameters:

  • epochs (mne.Epochs): Epoched data
  • pipeline: Pipeline object
  • autoclean_dict (dict): Configuration dictionary
  • freq_band (tuple): Frequency band for detection
  • scale_factor (float): Scale factor for threshold

Quality Control Functions

step_psd_topo_figure

def step_psd_topo_figure(
    raw_original,
    raw_cleaned,
    pipeline,
    autoclean_dict,
    bands=None,
    metadata=None
)

Generate PSD and topographical plots for quality control.

Parameters:

  • raw_original (mne.io.Raw): Original raw data
  • raw_cleaned (mne.io.Raw): Cleaned data
  • pipeline: Pipeline object
  • autoclean_dict (dict): Configuration dictionary
  • bands (list): Frequency bands
  • metadata (dict): Additional metadata

generate_ica_reports

def generate_ica_reports(
    pipeline,
    cleaned_raw,
    autoclean_dict,
    duration=60
)

Generate comprehensive ICA component reports.

Parameters:

  • pipeline: Pipeline object
  • cleaned_raw (mne.io.Raw): Cleaned raw data
  • autoclean_dict (dict): Configuration dictionary
  • duration (int): Duration in seconds for plots

Database Management Functions

manage_database

def manage_database(
    operation: str = 'connect',
    run_record: dict = None,
    update_record: dict = None
)

Manage the pipeline's database operations.

Parameters:

  • operation (str): Database operation type
  • run_record (dict): Record to insert
  • update_record (dict): Record to update