mnetonix
index
/Users/achilleas/code/pilsen-workshop/DataConversionToNIX/mnetonix.py

mnetonix.py
 
Usage:
  python mnetonix.py [--split-data] [--split-stimuli] <datafile> <montage>
 
Arguments:
  datafile   Either an EDF file or a BrainVision header file (vhdr).
  montage    Any format montage file supported by MNE.
 
Flags:
  --split-data      If specified, each channel of raw data is stored in its own
                    separate DataArray.
 
  --split-stimuli   If specified, each stimulus type (identified by its label)
                    is stored in a separate MultiTag (one MultiTag per
                    stimulus type).
 
 
(Requires Python 3)
 
Command line script for reading EDF and BrainVision files using MNE
(mne-python) and storing the data and metadata into a NIX file.  Supports
reading montage files for recording channel locations.
 
To include in a script, call the 'write_raw_mne()' and provide a NIX filename
and MNE Raw structure as arguments.
 
NIX Format layout
=================
 
Data
----
Raw Data are stored in either a single 2-dimensional DataArray or a collection
of DataArrays (one per recording channel).  The latter makes tagging easier
since MultiTag positions and extents don't need to specify every channel they
reference.  However, creating multiple DataArrays makes file sizes much
bigger.
 
Stimuli
-------
MNE provides stimulus information through the Raw.annotations dictionary.
Onsets correspond to the 'positions' array and durations correspond to the
'extents' array of the "Stimuli" MultiTag.  If stimulus information is split
by label, each MultiTag uses the label as its name.
 
Metadata
--------
MNE collects metadata into a (nested) dictionary (Raw.info).  All non-empty
keys are converted into Properties in NIX.  The nested structure of the
dictionary is replicated in NIX by creating child Sections, starting with one
root section with name "Info".
 
Some extra metadata is kept in the '_raw_extras' private member when loading
from EDF files.  This seems to be missing from the 'Info' dictionary in order
to keep it anonymous (missing keys are 'subject_info', 'meas_date', 'file_id',
and 'meas_id').  The '_raw_extras' are also stored in the NIX file in a
separate Section with name "Extras".

 
Modules
       
mne
nixio
numpy
os
matplotlib.pyplot
sys

 
Functions
       
create_md_tree(section, values, block)
create_stimulus_multi_tag(stimtuples, block, mneraw, mtagname='Stimuli')
main()
plot_channel(data_array, index)
separate_stimulus_types(stimuli)
write_multi_da(mneraw, block)
write_raw_mne(nfname, mneraw, split_data_channels=False, split_stimuli=False)
Writes the provided Raw MNE structure to a NIX file with the given name.
 
:param nfname: Name for the NIX file to write to. Existing file will be
overwritten.
:param mneraw: An MNE Raw structure (any mne.io.BaseRaw subclass).
:param split_data_channels: If True, each raw data channel will be stored
in a separate DataArray.
:param split_stimuli: If True, stimuli will be split into separate
MultiTags based on the stimulus type (label).
:rtype: None
write_single_da(mneraw, block)
write_stim_tags(mneraw, block, split)

 
Data
        DATA_BLOCK_NAME = 'EEG Data Block'
DATA_BLOCK_TYPE = 'Recording'
RAW_DATA_GROUP_NAME = 'Raw Data Group'
RAW_DATA_GROUP_TYPE = 'EEG Channels'
RAW_DATA_TYPE = 'Raw Data'