| Crates.io | fiff |
| lib.rs | fiff |
| version | 0.1.0 |
| created_at | 2025-10-22 22:58:23.560034+00 |
| updated_at | 2025-10-22 22:58:23.560034+00 |
| description | Pure Rust implementation of the FIFF (Functional Imaging File Format) parser for MEG/EEG data |
| homepage | |
| repository | https://github.com/sdraeger/DDALAB |
| max_upload_size | |
| id | 1896376 |
| size | 130,169 |
⚠️ MINIMAL IMPLEMENTATION - See limitations below.
Pure Rust implementation of the FIFF (Functional Imaging File Format) parser for MEG/EEG data.
FIFF is the native file format for Neuromag/Elekta MEG systems and is widely used in magnetoencephalography (MEG) and electroencephalography (EEG) research. It stores:
Add to your Cargo.toml:
[dependencies]
fiff = "0.1"
use fiff::{open_fiff, MeasInfo};
use std::path::Path;
fn main() -> std::io::Result<()> {
// Open the FIFF file
let path = Path::new("data.fif");
let (mut reader, tree) = open_fiff(path)?;
// Extract measurement metadata
let meas_info = MeasInfo::read(&mut reader, &tree)?;
// Print channel information
println!("Channels: {}", meas_info.nchan);
println!("Sampling rate: {} Hz", meas_info.sfreq);
for ch in &meas_info.channels {
println!("{}: {} (cal={}, range={})",
ch.ch_name, ch.type_name(), ch.cal, ch.range);
}
Ok(())
}
use fiff::{FIFFV_MEG_CH, FIFFV_STIM_CH};
// Get only MEG channels
let meg_channels: Vec<_> = meas_info.channels
.iter()
.filter(|ch| ch.kind == FIFFV_MEG_CH)
.collect();
// Exclude stimulus channels
let data_channels: Vec<_> = meas_info.channels
.iter()
.filter(|ch| ch.is_data_channel())
.collect();
// 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("MEG 0113") {
println!("Channel MEG 0113 is marked as bad");
}
// Get good channels for analysis
let good_channels: Vec<_> = meas_info.get_good_channels()
.iter()
.map(|&idx| &meas_info.channels[idx])
.collect();
// Filter information
if let Some(lowpass) = meas_info.lowpass {
println!("Lowpass filter: {} Hz", lowpass);
}
// Measurement date (Unix timestamp)
if let Some(date) = meas_info.meas_date {
println!("Recorded at: {}", date);
}
// Experiment information
if let Some(exp) = &meas_info.experimenter {
println!("Experimenter: {}", exp);
}
// Check for SSP projections (artifact removal)
println!("SSP Projections: {}", meas_info.projs.len());
for proj in &meas_info.projs {
println!("- {}: {} vectors ({})",
proj.desc,
proj.nvec,
if proj.active { "active" } else { "inactive" }
);
}
// Check CTF compensation (for CTF MEG systems)
println!("CTF Compensation: {}", meas_info.comps.len());
for comp in &meas_info.comps {
println!("- Grade {}: {} ({})",
comp.grade_name(),
comp.kind,
if comp.calibrated { "calibrated" } else { "uncalibrated" }
);
}
// Get device-to-head transformation
if let Some(trans) = meas_info.get_device_to_head_trans() {
println!("Device-to-head transform: {}", trans.description());
println!(" Rotation matrix: {:?}", trans.rot);
println!(" Translation: {:?}", trans.move_);
}
// Get head-to-MRI transformation
if let Some(trans) = meas_info.get_head_to_mri_trans() {
println!("Head-to-MRI transform: {}", trans.description());
}
// Check all available transformations
println!("Coordinate transforms: {}", meas_info.coord_trans.len());
for trans in &meas_info.coord_trans {
println!("- {}", trans.description());
}
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 navigationopen_fiff, MeasInfo, ChannelInfo)Based on the MNE-Python FIFF implementation, this crate is compatible with:
The parser is designed for efficiency:
byteorderThe crate includes comprehensive tests based on MNE-Python's test suite:
cargo test
Note: Integration tests require actual FIFF files (not included).
Licensed under either of:
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.
⚠️ This is a minimal implementation suitable for basic raw data reading.
We implement ~25% of MNE-Python's _fiff module:
See IMPLEMENTATION_STATUS.md for detailed comparison.
✅ Good for:
❌ Not suitable for:
For scientific MEG/EEG analysis, use MNE-Python. This crate is for Rust integration and basic data access.
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.