Python API¶
MEEGFlow can also be used programmatically, which is useful for scripting, notebooks, or integrating the pipeline into larger workflows.
Basic usage¶
import yaml
from meegflow import MEEGFlowPipeline
from meegflow.readers import BIDSReader
# Load config
with open("configs/config_example.yaml") as f:
config = yaml.safe_load(f)
# Create a reader
reader = BIDSReader("/data/my_study")
# Build and run the pipeline
pipeline = MEEGFlowPipeline(reader=reader, config=config)
pipeline.run_pipeline(subjects=["01", "02"], tasks=["rest"])
Using a GlobReader¶
For datasets that don't follow strict BIDS naming you can use GlobReader with a glob pattern that contains {subject}, {session}, {task}, etc. placeholders:
from meegflow.readers import GlobReader
reader = GlobReader(
root="/data/my_study",
pattern="sub-{subject}/ses-{session}/eeg/sub-{subject}_ses-{session}_task-{task}_eeg.vhdr",
)
pipeline = MEEGFlowPipeline(reader=reader, config=config)
pipeline.run_pipeline()
Custom steps¶
Place a Python file anywhere and pass its directory to the pipeline. The file must contain functions with the signature (data, step_config) -> data: