OHBA Software Library: Sign-Flipping Toolbox
Fast, reproducible sign-flipping for source-reconstructed M/EEG data.
🙋♂️ Please email SungJun Cho at sungjun.cho@ndcn.ox.ac.uk or simply raise GitHub Issues if you have any questions or concerns.
Table of Contents
- Overview
- Installation
- Quick Start
- Tutorial
- A Note on the Global Sign
- Reproducing the Paper
- Citation
- License
💡 Overview
Source reconstruction of MEG/EEG data with unconstrained or data-driven source orientations leaves each parcel
time course with an arbitrary sign that can differ between recording sessions. osl-signflip aligns these signs
to a common template session so that group-level analyses (averaging, functional connectivity, network models)
are not distorted.
It casts sign-flipping as a Z₂ synchronization problem (equivalent to finding the ground state of an Ising model) and solves it with:
| Method | method= |
Notes |
|---|---|---|
| Semidefinite programming relaxation | "sdp" (default) |
Recommended. Seeded and insensitive to the seed. |
| Spectral synchronization | "spectral" |
Deterministic. |
| Loopy belief propagation | "belief_propagation" |
Deterministic. |
| Random search | "random" |
The stochastic baseline used by existing pipelines. |
The first three are followed by greedy refinement of the exact objective and run roughly 160 to more than 2,000 times faster than random search while giving equally good or better solutions.
📌 Installation
osl-signflip requires Python 3.9 or later (tested on Python 3.9–3.13).
pip install osl-signflip # core (NumPy, tqdm, and joblib only)
pip install "osl-signflip[mne]" # + helpers for MNE-Python Raw/Epochs and .fif files
To install it from source instead (e.g., for development):
git clone https://github.com/OHBA-analysis/osl-signflip.git
cd osl-signflip
pip install -e ".[mne,dev]" # install osl-signflip in editable mode
pytest # run its test suite
⚡️ Quick Start
import osl_signflip as oslsf
flips, metrics, template, data_flipped = oslsf.align_signs(
data, n_embeddings=15, method="sdp", apply=True, n_jobs=8
)
# data: list of (n_samples, n_parcels) arrays, one per session
flips[s] is a vector of ±1 per parcel for session s, and metrics[s] tracks the correlation between the
session and template covariances (first entry: before flipping; last entry: after). The template is selected
automatically; to choose it yourself, pass template= (the index of a session in data, or the time series of
another session) or template_cov= (a precomputed template covariance). n_jobs sets the number of parallel
worker processes (-1 uses all CPU cores).
To work directly with covariances, e.g. when aligning new sessions to an existing template:
cov = oslsf.compute_covariance(x, n_embeddings=15)
flips, metrics = oslsf.find_flips(cov, template_cov, n_embeddings=15, method="sdp")
With parcellated .fif files (MNE-Python Raw/Epochs with parcel channels named parcel_X, as written by
osl-ephys), one call loads each file, finds the flips, and saves the sign-flipped data. Each worker handles one
file at a time, so only a few sessions are held in memory:
from osl_signflip import io
flips, metrics, template = io.sign_flip_files(
["sub-01_parc-raw.fif", "sub-02_parc-raw.fif", ...], # input files
["sub-01_sflip_parc-raw.fif", "sub-02_sflip_parc-raw.fif", ...], # output files
n_embeddings=15, method="sdp", n_jobs=16,
)
Here, template= can be the index of an input file or the path to any template file.
📚 Tutorial
The sign-flipping tutorial demonstrates the complete workflow using parcellated MEG data from the Wakeman–Henson dataset, which is downloaded automatically.
The tutorial covers:
- Sign flipping: Apply all four methods using
align_signs()andio.sign_flip_files(). - Performance evaluation: Compare alignment quality and agreement across methods.
- Runtime benchmarking: Evaluate the computational efficiency of each method.
🧭 A Note on the Global Sign
Sign-flipping uses covariances, which cannot distinguish a flip vector f from its global negation -f
(flipping every parcel of a session leaves its covariance unchanged). osl-signflip therefore fixes the global
sign by convention, ensuring that the output is reproducible.
📄 Reproducing the Paper
This repository also contains the scripts that reproduce the analyses and figures of the accompanying paper
(evaluated on the LEMON, Cam-CAN, and Wakeman-Henson datasets). See
scripts/README.md for the
requirements and instructions.
📝 Citation
If you use osl-signflip, please cite the accompanying paper (citation to be added). Citation metadata is also
available in CITATION.cff.
Metadata
Release files for osl-signflip 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| osl_signflip-0.1.0.tar.gz | 28.9 kB | With provenance | Details for osl_signflip-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| osl_signflip-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for osl_signflip-0.1.0-py3-none-any.whl |
Total release size: 59.8 kB
Release files / osl_signflip-0.1.0.tar.gz
| Download URL | osl_signflip-0.1.0.tar.gz |
|---|---|
| Size | 28.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e12dcbdf5a5501eb895124f43714b554887259f737fc304bc472675590e31eea
|
|
BLAKE2b-256 checksum How to use checksums |
f27f7685bc68de911b7d835ef675bfca1f254d24a37cd4e4c260bd3648df9095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / osl_signflip-0.1.0-py3-none-any.whl
| Download URL | osl_signflip-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a5bc9223fc6e5217274b0cb6bbb9724c4adcc189c02e7de1fb21e699ab76f7b
|
|
BLAKE2b-256 checksum How to use checksums |
c012e86e3e8447b87b9b04d23cbf543ea7051a397d5313ed4378f2b8e922d8fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for osl-signflip 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for osl_signflip-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.