Skip to content

Commit

Permalink
Implement core functionality for PyMoBI library including configurati…
Browse files Browse the repository at this point in the history
…on, data handling, and preprocessing pipeline
  • Loading branch information
snesmaeili committed Nov 18, 2024
1 parent ab7db54 commit 6208530
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

from .core.config import PyMoBIConfig
from .core.data import PyMoBIData
from .preprocessing.basic import create_mobile_pipeline

__all__ = ['PyMoBIConfig', 'PyMoBIData', 'create_mobile_pipeline']
12 changes: 12 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# pymobi/core/config.py

from dataclasses import dataclass
from typing import Dict, Any

@dataclass
class PyMoBIConfig:
"""Configuration management for mobile EEG processing."""
mne_preprocessing: Dict[str, Any]
motion_preprocessing: Dict[str, Any]
custom_processing: Dict[str, Any]
visualization: Dict[str, Any]
25 changes: 25 additions & 0 deletions core/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# pymobi/core/data.py

import mne

class PyMoBIData:
"""Data container for EEG and motion data."""

def __init__(self, raw_mne: mne.io.Raw, motion_data=None):
self.mne_raw = raw_mne # MNE Raw object for EEG data.
self.motion_data = motion_data # Optional motion data.
self.processing_history = [] # Track all processing steps.

def add_processing_step(self, step_name: str, params: dict):
"""Record a processing step."""
self.processing_history.append({"step": step_name, "params": params})

def to_mne(self):
"""Return the MNE Raw object."""
return self.mne_raw

def sync_motion_events(self):
"""Synchronize motion events with EEG data."""
if self.motion_data:
# Implement synchronization logic here.
pass
26 changes: 26 additions & 0 deletions core/pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# pymobi/core/pipeline.py

from abc import ABC, abstractmethod

class ProcessingStep(ABC):
"""Abstract base class for all processing steps."""

@abstractmethod
def run(self, data, config):
pass

class PreprocessingPipeline:
"""Pipeline to manage and run preprocessing steps."""

def __init__(self):
self.steps = []

def add_step(self, step: ProcessingStep):
"""Add a processing step to the pipeline."""
self.steps.append(step)

def run(self, data, config):
"""Run all steps in the pipeline."""
for step in self.steps:
data = step.run(data, config)
return data
31 changes: 31 additions & 0 deletions examples/basic_preprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# examples/basic_preprocessing.py

import mne
from pymobi.core.config import PyMoBIConfig
from pymobi.core.data import PyMoBIData
from pymobi.preprocessing.basic import create_mobile_pipeline

def main():
# Load sample EEG data using MNE.
raw = mne.io.read_raw_fif('sample_data.fif')

# Create PyMoBIData container.
eeg_data = PyMoBIData(raw)

# Define configuration for preprocessing.
config = PyMoBIConfig(
mne_preprocessing={'l_freq': 1.0, 'h_freq': 40.0},
motion_preprocessing={},
custom_processing={},
visualization={}
)

# Create and run the preprocessing pipeline.
pipeline = create_mobile_pipeline(config)
processed_data = pipeline.run(eeg_data)

# Save or visualize the processed data.
processed_data.to_mne().save('processed_eeg.fif')

if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions preprocessing/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# pymobi/preprocessing/basic.py

import mne

class BasicPreprocessing:
"""Basic EEG preprocessing using MNE functions."""

def __init__(self, l_freq=1.0, h_freq=40.0):
self.l_freq = l_freq # Low frequency cut-off.
self.h_freq = h_freq # High frequency cut-off.

def run(self, data, config):
"""Run basic preprocessing (filtering)."""
data.mne_raw.filter(l_freq=self.l_freq, h_freq=self.h_freq)
return data


def create_mobile_pipeline(config):
"""Create a mobile EEG preprocessing pipeline."""
pipeline = PreprocessingPipeline()

# Add basic preprocessing step.
pipeline.add_step(BasicPreprocessing(
l_freq=config.mne_preprocessing['l_freq'],
h_freq=config.mne_preprocessing['h_freq']
))

return pipeline
9 changes: 9 additions & 0 deletions preprocessing/pyamica.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pymobi/preprocessing/pyamica.py

class PyAMICA:
"""Python implementation of AMICA (Adaptive Mixture ICA)."""

def run(self, data, config):
"""Run AMICA for ICA decomposition."""
# Implement AMICA logic here.
return data
9 changes: 9 additions & 0 deletions preprocessing/pyasr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pymobi/preprocessing/pyasr.py

class PyASR:
"""Python implementation of Artifact Subspace Reconstruction (ASR)."""

def run(self, data, config):
"""Run ASR to clean EEG artifacts."""
# Implement ASR logic here.
return data
9 changes: 9 additions & 0 deletions preprocessing/pyzapline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pymobi/preprocessing/pyzapline.py

class PyZaplinePlus:
"""Python implementation of the Zapline+ algorithm."""

def run(self, data, config):
"""Run Zapline+ on the EEG data to remove line noise."""
# Implement Zapline+ logic here.
return data
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from setuptools import setup, find_packages

setup(
name='PyMoBI',
version='0.1.0',
author='Your Name',
author_email='[email protected]',
description='A Python library for mobile EEG data analysis',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/yourusername/PyMoBI',
packages=find_packages(),
install_requires=[
'mne>=0.23.0',
'numpy>=1.19.0',
'scipy>=1.5.0',
'matplotlib>=3.2.0',
'pandas>=1.0.0'
],
classifiers=[
'Programming Language :: Python :: 3',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Information Analysis',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
python_requires='>=3.8',
)

0 comments on commit 6208530

Please sign in to comment.