Skip to main content

Introduction

Github Actions

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.

Installation

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

Contribute

Definitely run:

$ pre-commit install

Test Coverage

============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-7.0.1, pluggy-1.0.0
rootdir: /home/runner/work/mffpy/mffpy
plugins: cov-4.0.0
collected 124 items

mffpy/tests/test_cached_property.py ..                                   [  1%]
mffpy/tests/test_devices.py ..............                               [ 12%]
mffpy/tests/test_dict2xml.py .                                           [ 13%]
mffpy/tests/test_header_block.py ..                                      [ 15%]
mffpy/tests/test_mffdir.py ....                                          [ 18%]
mffpy/tests/test_raw_bin_files.py ..................                     [ 33%]
mffpy/tests/test_reader.py ......................                        [ 50%]
mffpy/tests/test_writer.py ...........                                   [ 59%]
mffpy/tests/test_xml_files.py .......................................... [ 93%]
...                                                                      [ 95%]
mffpy/tests/test_zipfile.py .....                                        [100%]

----------- coverage: platform linux, python 3.6.7-final-0 -----------
Name                                          Stmts   Miss  Cover
-----------------------------------------------------------------
mffpy/__init__.py                                 4      0   100%
mffpy/bin_files.py                               40      2    95%
mffpy/bin_writer.py                              71      0   100%
mffpy/cached_property.py                         25      1    96%
mffpy/devices.py                                 10      0   100%
mffpy/dict2xml.py                                31      3    90%
mffpy/epoch.py                                   24      3    88%
mffpy/header_block/__init__.py                    1      0   100%
mffpy/header_block/header_block.py               48      2    96%
mffpy/header_block/helpers.py                    15      0   100%
mffpy/header_block/optional_header_block.py      32      1    97%
mffpy/mffdir.py                                  92      7    92%
mffpy/raw_bin_files.py                          113      0   100%
mffpy/reader.py                                 110      2    98%
mffpy/tests/__init__.py                           0      0   100%
mffpy/tests/conftest.py                          15      0   100%
mffpy/tests/test_cached_property.py              33      0   100%
mffpy/tests/test_devices.py                      12      0   100%
mffpy/tests/test_dict2xml.py                     16      0   100%
mffpy/tests/test_header_block.py                 33      0   100%
mffpy/tests/test_mffdir.py                       30      0   100%
mffpy/tests/test_raw_bin_files.py                63      0   100%
mffpy/tests/test_reader.py                       96      0   100%
mffpy/tests/test_writer.py                      212      0   100%
mffpy/tests/test_xml_files.py                   214      1    99%
mffpy/tests/test_zipfile.py                      34      0   100%
mffpy/version.py                                  1      0   100%
mffpy/writer.py                                  71      0   100%
mffpy/xml_files.py                              607     22    96%
mffpy/zipfile.py                                 47      0   100%
-----------------------------------------------------------------
TOTAL                                          2100     44    98%


============================= 122 passed in 7.19s ==============================

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)
    print(e)

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")
print(categories['ULRN'])

Example 4: Writing random numbers into an .mff file

from os.path import join
from datetime import datetime
import numpy as np
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('.cache', 'example_4_output.mff'))
startdatetime = datetime.strptime('1984-02-18T14:00:10.000000+0100',
        "%Y-%m-%dT%H:%M:%S.%f%z")
W.addxml('fileInfo', recordTime=startdatetime)
W.add_coordinates_and_sensor_layout(device='HydroCel GSN 256 1.0')
W.addbin(B)
W.write()

Example 5: Exporting MFF content to a .json file

from mffpy import Reader, Writer

# Read data from an MFF file
reader = Reader("./examples/example_2.mff")
data = reader.get_mff_content()

# Write data to a JSON file
writer = Writer(".cache/example_5_output.json")
writer.export_to_json(data)

Note: for now, the JSON exporting feature only works for segmented mffs files.

Specification of the .mff File Format

.XML Files

Xml-type files are specified in "/schemata/" using XML Schema Definition. Any .xml file can be checked for compliance with the command-line tool xmllint. One can validate your xml files by: xmllint --schema schemata/categories.xsd /path/to/my/file.xml --noout. We are using the following version of xmllint:

$ xmllint --version
xmllint: using libxml version 20909
compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP
HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X
Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma

Currently we describe the following .xml file types:

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: // www.apache.org / 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.

Release files for mffpy 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mffpy 0.11.0
File Size Uploaded
mffpy-0.11.0.tar.gz 152.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mffpy 0.11.0
File Interpreter ABI Platform
mffpy-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 331.0 kB

Release files / mffpy-0.11.0.tar.gz

Download URL mffpy-0.11.0.tar.gz
Size 152.7 kB
Tags Source
SHA-256 checksum
How to use checksums
daaf3d018e7bb4a6827e4bb32d7877a3cc78e1bc97c2b0f3d1027e7ae1724eef
BLAKE2b-256 checksum
How to use checksums
7b419e0fc4b7bd68e8a79c654d3918a517bc5a5f55654961ec76b341548237c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / mffpy-0.11.0-py3-none-any.whl

Download URL mffpy-0.11.0-py3-none-any.whl
Size 178.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84a0f869febd1feb89db62bb85bcfb576420fefaaad667ec37f82ec398a2982f
BLAKE2b-256 checksum
How to use checksums
09c98099ff994fbbb201efdb3c19181bef37a2894cb7bfb4ba7fb87e959298a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.4

2 release files

0.7.3

3 release files

0.7.2

2 release files

0.7.1

3 release files

0.7.0

3 release files

0.6.3

2 release files

0.6.2

3 release files

0.6.0

3 release files

0.5.9

3 release files

0.5.8

3 release files

0.5.7

3 release files

0.5.6

3 release files

0.5.5

4 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.1

3 release files

0.5.0

2 release files

0.4.2

1 release file

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page