How to create simple Topoplot image file from BrainVision files and (vaguely) related questions

  • MNE version: 0.24.1
  • operating system: currently Windows 11 for evaluation/development - if evaluation is successful, will move to a dedicated Docker container

In the context of a research project I was tasked to research how to visualize a snapshot of EEG data as a topomap and thus discovered the MNE library which at first glance appears to be a good fit.

Being primarily a developer of Windows desktop software by profession, I am unfortunately not (yet) fluent in the domain language required here nor do I have any significant experience with Python graphics libraries or MatLab or the likes so please forgive me if I use weird words (or use the right words in weird ways) in the following descriptions and feel free to correct me... Also, as this is just a very small part of the overall project and mainly intended for use in a demo prototype, I am also trying to keep the effort as low as possible, so I might have missed obvious information or documentation. In that case I'd obviously be grateful for links to the relevant documents.

So what I get as input is a set of .vhdr/.vmrk/.eeg files and the number of seconds into the recording that Iā€™m supposed to take the snapshot of (though that info might also already be embedded as an annotation - Iā€™m not yet sure how to read this). The output should be a single PNG file.

Edging towards a solution by trial and error, I started out with this test code:

import os
import mne

raw_file = os.path.join('.', 'RawData', 'vp_1232.vhdr')
raw = mne.io.read_raw_brainvision(raw_file)
events, event_id = mne.events_from_annotations(raw)
epochs = mne.Epochs(raw, events, event_id = event_id)
projs = mne.compute_proj_epochs(epochs)
epochs.add_proj(projs)

This produces the following output:
Ā“Ā“Ā“
Extracting parameters from .\RawData\vp_1232.vhdrā€¦
Setting channel info structureā€¦
Backend TkAgg is interactive backend. Turning interactive mode on.
Used Annotations descriptions: [ā€˜New Segment/ā€™, ā€˜Stimulus/S 1ā€™, ā€˜Stimulus/S 2ā€™, ā€˜Stimulus/S 4ā€™, ā€˜Stimulus/S 8ā€™, ā€˜Stimulus/S 32ā€™, ā€˜Stimulus/S 64ā€™, ā€˜Stimulus/S128ā€™, ā€˜Stimulus/S160ā€™]
Not setting metadata
Not setting metadata
4211 matching events found
Setting baseline interval to [-0.2, 0.0] sec
Applying baseline correction (mode: mean)
0 projection items activated
No gradiometers found. Forcing n_grad to 0
No magnetometers found. Forcing n_mag to 0
Adding projection: eeg-Multiple-eventsā€“0.200-0.500-PCA-01
Adding projection: eeg-Multiple-eventsā€“0.200-0.500-PCA-02
2 projection items deactivated
WARNING:root:Did not find any electrode locations (in the info object), will attempt to use digitization points instead. However, if digitization points do not correspond to the EEG electrodes, this will lead to bad results. Please verify that the sensor locations in the plot are accurate.
Ā“Ā“Ā“

This already looks like something is not yet right and indeed, when I then try to call epochs.plot_projs_topomap() I get this error (beginning of stacktrace containing references to VS Code Extensions truncated for brevity):

Traceback (most recent call last):
...
  File "c:\Dev\Att\att-topmaps\test1.py", line 10, in <module>
    epochs.plot_projs_topomap()
  File "C:\Python38\lib\site-packages\mne\io\proj.py", line 292, in plot_projs_topomap
    fig = plot_projs_topomap(self.info['projs'], self.info, cmap=cmap,
  File "C:\Python38\lib\site-packages\mne\viz\topomap.py", line 336, in plot_projs_topomap
    clip_origin = _prepare_topomap_plot(
  File "C:\Python38\lib\site-packages\mne\viz\topomap.py", line 82, in _prepare_topomap_plot
    layout = find_layout(info)
  File "C:\Python38\lib\site-packages\mne\channels\layout.py", line 428, in find_layout
    return make_eeg_layout(info, exclude=exclude)
  File "C:\Python38\lib\site-packages\mne\channels\layout.py", line 262, in make_eeg_layout
    loc2d = _find_topomap_coords(info, picks)
  File "C:\Python38\lib\site-packages\mne\channels\layout.py", line 627, in _find_topomap_coords
    pos = _auto_topomap_coords(
  File "C:\Python38\lib\site-packages\mne\channels\layout.py", line 692, in _auto_topomap_coords
    raise RuntimeError('No digitization points found.')
RuntimeError: No digitization points found.

Could anyone give me a hint on how to proceed from here? Sounds to me like either the information about the sensorsā€™ locations in 3D space and/or the information about how to project that information into the 2D space is missing. Where can I get that and how would I then make it known to MNE? Would it help if I knew the model of ā€œEEG capā€ that was used (I already know that our project partners use at least two different devices)? Are there maybe any default projections that I could access somehow? As I wrote initially, accuracy is not yet essential at this stage - the main point at the moment is to showcase that per-patient data can be visualised at all - getting accurate locations and projections would be ā€œfinetuningā€ that will happen in the next step. Or is that the wrong way to go about this?
Also, Iā€™m not yet sure how to tell MNE what point in time to plotā€¦ That is clearly still missing from code. I was hoping the code above would maybe already produce a sequence of plots for each event or something like thatā€¦ As I wrote, Iā€™m taking this one trial-and-error step at a timeā€¦

Or is MNE maybe not the right/best tool for this task after all? (Iā€™m sure it can do what I want but maybe it is overkill and there is something more lightweight and more directly tailored to my specific use case out there?)

Thanks in advance for any pointers you could provide!

Regards,

Oliver

Have you seen https://mne.tools/dev/auto_tutorials/intro/40_sensor_locations.html ? It should hopefully cover this stuff