FIFF - Functional Imaging File Format Parser
⚠️ MINIMAL IMPLEMENTATION - See limitations below.
Pure Rust implementation of the FIFF (Functional Imaging File Format) parser for MEG/EEG data.
Features
- ✅ Pure Rust - No C dependencies, fully memory-safe
- ✅ Zero-copy parsing where possible for performance
- ✅ Channel calibration - Automatic conversion to physical units
- ✅ Sequential reading - Handles files with and without directory pointers
- ✅ Complete metadata - Channel names, types, positions, sampling rates
- ✅ Bad channel detection - Automatically filter out defective sensors
- ✅ Filter information - Lowpass/highpass filter settings preserved
- ✅ Experiment metadata - Recording date, experimenter, project info
- ✅ SSP Projectors - Signal space projection metadata for artifact removal
- ✅ CTF Compensation - CTF MEG compensation grades and matrices
- ✅ Coordinate Transformations - Device-to-head, head-to-MRI transforms
- ✅ Well-documented - Based on MNE-Python's battle-tested implementation
What is FIFF?
FIFF is the native file format for Neuromag/Elekta MEG systems and is widely used in magnetoencephalography (MEG) and electroencephalography (EEG) research. It stores:
- Raw sensor data (MEG, EEG, EOG, ECG, etc.)
- Channel metadata (names, types, calibration coefficients, sensor positions)
- Measurement metadata (sampling rate, recording time, coordinate frames)
- Processing history and annotations
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Reading a FIFF file
use ;
use Path;
Filtering channels by type
use ;
// Get only MEG channels
let meg_channels: = meas_info.channels
.iter
.filter
.collect;
// Exclude stimulus channels
let data_channels: = meas_info.channels
.iter
.filter
.collect;
Working with bad channels
// Get indices of good (non-bad) channels
let good_indices = meas_info.get_good_channels;
// Check if a specific channel is bad
if meas_info.is_bad_channel
// Get good channels for analysis
let good_channels: = meas_info.get_good_channels
.iter
.map
.collect;
Accessing metadata
// Filter information
if let Some = meas_info.lowpass
// Measurement date (Unix timestamp)
if let Some = meas_info.meas_date
// Experiment information
if let Some = &meas_info.experimenter
Working with SSP projections and CTF compensation
// Check for SSP projections (artifact removal)
println!;
for proj in &meas_info.projs
// Check CTF compensation (for CTF MEG systems)
println!;
for comp in &meas_info.comps
Working with coordinate transformations
// Get device-to-head transformation
if let Some = meas_info.get_device_to_head_trans
// Get head-to-MRI transformation
if let Some = meas_info.get_head_to_mri_trans
// Check all available transformations
println!;
for trans in &meas_info.coord_trans
Architecture
The crate is organized into focused modules:
constants- FIFF format constants (block types, tag kinds, channel types)tag- Binary tag reading and parsingtree- Directory tree structure navigation- Main module - High-level API (
open_fiff,MeasInfo,ChannelInfo)
Supported Features
- File opening and validation
- Tag-based file structure parsing
- Sequential tag reading (no directory required)
- Directory-based random access
- Measurement info extraction
- Channel info parsing (96-byte structures)
- Channel calibration coefficients
- Channel type detection
- Bad channel detection and filtering
- Filter information (lowpass/highpass)
- Measurement date and timing
- Experiment metadata (experimenter, project, description)
- Raw data buffer reading
- Coordinate transformations (device-to-head, head-to-MRI)
- SSP projectors (metadata parsing)
- Compensation matrices (metadata parsing)
- Event parsing
- Annotations
Compatibility
Based on the MNE-Python FIFF implementation, this crate is compatible with:
- Neuromag/Elekta MEG systems
- Vectorview systems
- Modern MEGIN systems
- Files created by MNE-Python
- Files from OpenNeuro NEMAR datasets
Performance
The parser is designed for efficiency:
- Big-endian binary parsing with
byteorder - Minimal allocations during parsing
- Lazy loading of data buffers
- Streaming-friendly API
Testing
The crate includes comprehensive tests based on MNE-Python's test suite:
Note: Integration tests require actual FIFF files (not included).
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Limitations
⚠️ This is a minimal implementation suitable for basic raw data reading.
What This Crate DOES
- ✅ Read raw MEG/EEG sensor data from Neuromag/Elekta systems
- ✅ Parse channel metadata (names, types, calibration)
- ✅ Apply calibration coefficients (cal × range)
- ✅ Extract sampling rate and basic info
- ✅ Filter channels by type
What This Crate DOES NOT Do
- ⚠️ Matrix application - SSP/CTF matrices stored but not applied (no ndarray dependency)
- ❌ Digitization data - No HPI/fiducial/head shape points
- ❌ Events/annotations - No stimulus timing
- ❌ File writing - Read-only
Comparison to MNE-Python
We implement ~25% of MNE-Python's _fiff module:
- 5 of 17 files implemented (constants, tag, tree, meas_info, coord_trans)
- 86 of 350+ constants defined
- 15 of 25+ metadata tags parsed
See IMPLEMENTATION_STATUS.md for detailed comparison.
When to Use This Crate
✅ Good for:
- Quick data extraction from Neuromag FIF files
- Integrating MEG data into Rust pipelines
- Educational/learning purposes
- Prototyping
❌ Not suitable for:
- CTF MEG data (without implementing compensation)
- Advanced MEG analysis requiring full metadata
- Source localization
- Publication-quality analysis (use MNE-Python)
Recommendation
For scientific MEG/EEG analysis, use MNE-Python. This crate is for Rust integration and basic data access.
Acknowledgments
This implementation is based on MNE-Python's FIFF parser. We thank the MNE community for their excellent work and documentation of the FIFF format.
See Also
- MNE-Python - The Python library for MEG/EEG analysis
- edfio - EDF/EDF+ file parser in Rust
- neurokit - Neuroscience data processing toolkit