Basic Usage Examples
This guide provides practical examples of using the AutoClean pipeline for common EEG processing tasks.
Simple Resting State Processing
Here's a basic example of processing resting-state EEG data:
- Create a configuration file
config.yml:
task: resting_eyesopen
eeg_system: biosemi64
input_file: /path/to/your/data.bdf
line_freq: 60.0
resample_freq: 250
ref_type: average
- Set up environment variables:
- Run the pipeline:
from autoclean_preprocessing import autoclean_pipeline_v2 as autoclean
# Process resting state data
autoclean.process_resting_eyesopen({
'task': 'resting_eyesopen',
'eeg_system': 'biosemi64',
'input_file': '/path/to/your/data.bdf'
})
Processing Multiple Files
Here's how to process multiple EEG files:
import glob
from pathlib import Path
from autoclean_preprocessing import autoclean_pipeline_v2 as autoclean
# Get all BDF files in a directory
files = glob.glob('/path/to/data/*.bdf')
# Process each file
for file in files:
config = {
'task': 'resting_eyesopen',
'eeg_system': 'biosemi64',
'input_file': str(Path(file).absolute())
}
autoclean.process_resting_eyesopen(config)
Custom Preprocessing Settings
Example with custom preprocessing settings:
config = {
'task': 'resting_eyesopen',
'eeg_system': 'biosemi64',
'input_file': '/path/to/data.bdf',
# Custom preprocessing settings
'resample_freq': 500, # Higher sampling rate
'ref_type': 'average',
'crop_start': 10, # Start at 10 seconds
'crop_end': 310, # End at 310 seconds
# Custom artifact rejection settings
'bad_channel_criteria': {
'deviation_threshold': 4.0,
'correlation_threshold': 0.6,
'line_noise_threshold': 5.0
},
# ICA settings
'ica_settings': {
'n_components': 30,
'random_state': 42,
'method': 'fastica'
}
}
autoclean.process_resting_eyesopen(config)
Accessing Processing Results
Example of accessing and analyzing processing results:
from autoclean_preprocessing import autoclean_pipeline_v2 as autoclean
# Get the run record
run_id = "your_run_id"
run_record = autoclean.get_run_record(run_id)
# Access processing metadata
metadata = run_record['metadata']
# Print processing statistics
print(f"Bad channels detected: {metadata['bad_channels']}")
print(f"ICA components removed: {metadata['ica_components_removed']}")
print(f"Processing duration: {metadata['processing_duration']} seconds")
Error Handling
Example with proper error handling:
from autoclean_preprocessing import autoclean_pipeline_v2 as autoclean
try:
config = {
'task': 'resting_eyesopen',
'eeg_system': 'biosemi64',
'input_file': '/path/to/data.bdf'
}
autoclean.process_resting_eyesopen(config)
except FileNotFoundError:
print("Input file not found. Please check the file path.")
except ValueError as e:
print(f"Configuration error: {str(e)}")
except Exception as e:
print(f"An unexpected error occurred: {str(e)}")
Customizing Output Reports
Example of generating custom reports:
from autoclean_preprocessing import autoclean_pipeline_v2 as autoclean
# Process the data
config = {
'task': 'resting_eyesopen',
'eeg_system': 'biosemi64',
'input_file': '/path/to/data.bdf',
# Custom report settings
'report_settings': {
'generate_pdf': True,
'include_psd': True,
'include_ica': True,
'include_topomaps': True
}
}
autoclean.process_resting_eyesopen(config)