bids-standard / pybv

A lightweight I/O utility for the BrainVision data format, written in Python.

Home Page:https://pybv.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading .vmrk as mne.Annotations: Combine events of individual channels

sappelhoff opened this issue · comments

A .vmrk file may look like this:

Brain Vision Data Exchange Marker File, Version 1.0
;Exported using pybv 0.7.0.dev0

[Common Infos]
Codepage=UTF-8
DataFile=mne_export.vhdr.eeg

[Marker Infos]
; Each entry: Mk<Marker number>=<Type>,<Description>,<Position in data points>,
;             <Size in data points>, <Channel number (0 = marker is related to all channels)>
;             <Date (YYYYMMDDhhmmssuuuuuu)>
; Fields are delimited by commas, some fields might be omitted (empty).
; Commas in type or description text are coded as "\1".
Mk1=Stimulus,S  1,751,250,0
Mk2=Comment,2.50,3251,250,0
Mk3=Response,R101,7501,125,0
Mk4=Comment,Look at this,17501,62,1
Mk5=Comment,And at this,22501,2250,1
Mk6=Comment,And at this,22501,2250,2
  • Note Mk1 up to Mk3: These events are specified for "all channels" (the trailing zero)
  • Note Mk4: This event is specified for the channel with index 1 (1-based indexing)
  • Note Mk5 and Mk6: This is actually one event, but it pertains to several channels (1-based indices 1 and 2) --> We can see this because all information is identical except the trailing "channel number"

Writing the data this way is supported and fine with the BrainVision format.

In MNE-Python however, we may represent Mk5 and Mk6 as a single entry in mne.Annotations, because there, ch_names may be a tuple of channels, for example, the following is the same event information from above but in MNE-Python format:

    annots = mne.Annotations(
        onset=[3, 13, 30, 70, 90],  # seconds
        duration=[1, 1, 0.5, 0.25, 9],  # seconds
        description=[
            "Stimulus/S  1",
            "Stimulus/S2.50",
            "Response/R101",
            "Look at this",
            "Comment/And at this",
        ],
        ch_names=[(), (), (), ("Fp1",), ("Fp1", "Fp2")],
    )

the MNE-Python BV reader should be extended to combine Mk5 and Mk6 from the example above.