Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Reader and Writer for Philips' MFF file format.

Project description


Build Status

mffpy is a lean reader for EGI's MFF file format. These files are directories containing several files of mostly xml files, but also binary files.

The main entry point into the library is class Reader that accesses a selection of functions in the .mff directory to return signal data and its meta information.


$ conda create -n mffpy python=3.6 pip
$ conda activate mffpy
$ pip install -r requirements.txt
$ python install
$ # and to run the test
$ make test


Definitely run:

$ pip install pre-commit
$ pre-commit install

Test Coverage

Name                                Stmts   Miss  Cover
mffpy/                       2      0   100%
mffpy/                     40      8    80%
mffpy/                    47      7    85%
mffpy/                       10      0   100%
mffpy/                      31      3    90%
mffpy/                         23      5    78%
mffpy/                  49      1    98%
mffpy/                        92     18    80%
mffpy/                 95      0   100%
mffpy/                        57      2    96%
mffpy/tests/                 0      0   100%
mffpy/tests/            12      0   100%
mffpy/tests/           15      0   100%
mffpy/tests/       37      0   100%
mffpy/tests/             30      0   100%
mffpy/tests/      33      0   100%
mffpy/tests/             26      0   100%
mffpy/tests/             50      2    96%
mffpy/tests/         130      1    99%
mffpy/tests/            34      0   100%
mffpy/                        51      2    96%
mffpy/                    325      8    98%
mffpy/                       45      0   100%
TOTAL                                1234     57    95%

View the Docs

All documentation and API guidance are generated from the python doc-strings and this README file using pydoc-markdown. To view the docs:

  • install pydoc-markdown: pip install pydoc-markdown
  • build and run: pydocmd build; pydocmd serve
  • Navigate to the docs

Example Code

Example 1: Basic Information

import mffpy
fo = mffpy.Reader("./examples/example_1.mff")
print("time and date of the start of recording:", fo.startdatetime)
print("number of channels:", fo.num_channels)
print("sampling rates:", fo.sampling_rates, "(in Hz)")
print("durations:", fo.durations, "(in sec.)")
print("Here's the epoch information")
for i, e in enumerate(fo.epochs):
    print("Epoch number", i)

Example 2: Reading Samples

from mffpy import Reader
fo = Reader("./examples/example_1.mff")
fo.set_unit('EEG', 'uV')
eeg_in_mV, t0_EEG = fo.get_physical_samples_from_epoch(fo.epochs[0], dt=0.1)['EEG']
fo.set_unit('EEG', 'V')
eeg_in_V, t0_EEG = fo.get_physical_samples_from_epoch(fo.epochs[0], dt=0.1)['EEG']
print('data in mV:', eeg_in_mV[0])
print('data in V :', eeg_in_V[0])

Example 3: Reading .mff xml files

from mffpy import XML
categories = XML.from_file("./examples/example_1.mff/categories.xml")

Example 4: Writing random numbers into an .mff file

from os.path import join
from datetime import datetime
import numpy as np
from mffpy import Reader
from mffpy.writer import *

# write 256 channels of 10 data points at a sampling rate of 128 Hz
B = BinWriter(sampling_rate=128)
B.add_block(np.random.randn(256, 10).astype(np.float32))
W = Writer(join('examples', 'my_new_file.mff'))
startdatetime = datetime.strptime('1984-02-18T14:00:10.000000+0100',
W.addxml('fileInfo', recordTime=startdatetime)
W.add_coordinates_and_sensor_layout(device='HydroCel GSN 256 1.0')

License and Copyright

Copyright 2019 Brain Electrophysiology Laboratory Company LLC

Licensed under the ApacheLicense, Version 2.0(the "License"); you may not use this module except in compliance with the License. You may obtain a copy of the License at:

http: // / licenses / LICENSE - 2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mffpy, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size mffpy-0.3.0-py3-none-any.whl (132.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size mffpy-0.3.0.tar.gz (108.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page