Hello,
I am trying to do source localization for EEG using MNE, but am running into some issues. Sorry in advance for the long read. For reference, I am on a Windows OS and I installed FreeSurfer and MNE on WSL, and I am running my actual program on Jupyter Notebook with MNE installed.
- MNE version (on Jupyter Notebook): 1.9.0
- operating system: Windows 11
- WSL version: 2.4.12.0
- FreeSurfer version: freesurfer-linux-centos7_x86_64-7.4.1-20230613-7eb8460
I started by producing BEM surfaces using the command line
mne watershed_bem --subject=sub-05-reconstruction --subjects-dir=/mnt/c/freesurfer/subjects/AazLab/SourceImging
in WSL, which produced a ‘bem’ folder containing 0 kb symlink .surf files (brain.surf, inner_skull.surf, outer_skin.surf, outer_skull.surf), a sub-05-reconstruction-head.fif file, and a ‘watershed’ folder containing target files with no format extension (sub-05-reconstruction_brain_surface, sub-05-reconstruction_inner_skull_surface, sub-05-reconstruction_outer_skin_surface, and sub-05-reconstruction_outer_skull_surface). The WSL commands
freeview -f /mnt/c/freesurfer/subjects/AazLab/SourceImging/sub-05-reconstruction/bem/inner_skull.surf
freeview -f /mnt/c/freesurfer/subjects/AazLab/SourceImging/sub-05-reconstruction/bem/watershed/sub-05-reconstruction_inner_skull_surface
both open the BEM surfaces in Freeview correctly, but the Jupyter code below produces an error:
subj_src_dir= 'C:\\freesurfer\\subjects\\AazLab\\SourceImging'
subj_src= 'sub-05-reconstruction'
surface = r'C:\freesurfer\subjects\AazLab\SourceImging\sub-05-reconstruction\bem\sub-05-reconstruction_inner_skull.surf'
vol_src = mne.setup_volume_source_space(
subj_src, subjects_dir=subj_src_dir, surface=surface, add_interpolator=True
)
mne.viz.plot_bem(src=vol_src, **plot_bem_kwargs)
OSError: [WinError 1920] The file cannot be accessed by the system: ‘C:\freesurfer\subjects\AazLab\SourceImging\sub-05-reconstruction\bem\inner_skull.surf’
I assumed this error occurred because Jupyter was unable to read the 0 kb symlink files (I already checked their permissions, which were ‘lrwxrwxrwx’, and I assume that if they were corrupted Freeview would have been unable to read them). I deleted the symlink files entirely, moved the target files to the ‘bem’ folder, and renamed them as new_brain.surf, new_inner_skull.surf, new_outer_skin.surf, and new_outer_skull.surf respectively. Following this change, the above Jupyter code worked normally. However, the following Jupyter code produced an error:
bem_surfaces = mne.read_bem_surfaces('C:\\freesurfer\\subjects\\AazLab\\SourceImging\\sub-05-reconstruction\\bem\\new_inner_skull.surf')
ValueError: file WindowsPath(‘C:/Users/aadhi/mne_data/MNE-sample-data/subjects/sample/bem/new_inner_skull.surf’) does not start with a file id tag
I read the BEM files with Notepad, and below are the first couple lines:
ÿÿþ
( P À‹Á™%¸BÍR–A£$j²iªB„tõB‡7ÁŸ‰3B„ÙjA”áhBD!»B…NüÂU¨øA›N6BxefÂbQÂ{Ý—Bx|ÁÂļoR¿7Ò)BqRÂ~°Ù?1VBI]|A²º&>ËËÁ´>B$Ö@œüqˆÎÁ´âÌ>’½N¿ÅCÎÁ¡ÒìÁ7S˜Áù†O?÷ì³B°,Áx^B3$B§(AXÞAŒ~tB´ÎºÂ¦cÂ/´ÚB¶êÛƒCìÁ¥DdB‹·
Initially I thought deleting the symlink file might have caused the issue, but trying to run the above code with the symlink files produced the ‘file cannot be accessed’ error (again, presumably because the files were 0 kb). I also thought the issue might have been caused by me renaming the target files to .surf format without formally converting them, but using the WSL command
mris_convert /mnt/c/freesurfer/subjects/AazLab/SourceImging/sub-05-reconstruction/bem/watershed/sub-05-reconstruction_inner_skull_surface /mnt/c/freesurfer/subjects/AazLab/SourceImging/sub-05-reconstruction/bem/new_inner_skull.surf
just created junk characters (Freeview still opened them normally, and mne.read_bem_surfaces()
still didn’t find the file id tag). When I checked the file contents using the following WSL command, I found that the file contained normal .surf information, including the info that should have been in the file id tag:
mris_info /mnt/c/freesurfer/subjects/AazLab/SourceImging/sub-05-reconstruction/bem/watershed/sub-05-reconstruction_inner_skull_surface
SURFACE INFO ========================================
type : MRIS_TRIANGULAR_SURFACE=MRIS_ICO_SURFACE
num vertices: 10242
num faces : 20480
num strips : 0
surface area: 74100.3
(etc.)
This, as well as the fact that mne.viz.plot_bem()
could read the files correctly leads me to believe that FreeSurfer is producing valid BEM files in .surf format. I also checked the ‘mne_data’ sample BEM files, and they appeared similar to my BEM files when opened in Notepad, were opened normally by Freeview, and produced the file id tag error when opened by mne.read_bem_surfaces()
. However, I haven’t been able to resolve the file id tag error. It may be because mne.read_bem_surfaces()
is unable to decrypt the BEM files, but I don’t see why mne.viz.plot_bem()
worked in that case. Maybe the symlink files issue is related, but I can’t be sure. Please help!