mne-tools / mne-tools/mne-python

Montage in MRI space converted to head when saving to epoch.fif

Open
#10,946 6 comments 0 reactions 1 assignee View on GitHub

@wmvanvliet is already working on this.

Since Aug 23, 2022.

BUG
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Describe the bug

Montage in MRI space gets transformed to head space when saving to an epochs .fif file. The issue seems to be due to the saving and not the loading, but not 100% clear. See here

Steps to reproduce
import mne
import numpy as np
from numpy.random import normal
import tempfile
import os


# Create random montage:
montage = mne.channels.make_dig_montage(ch_pos={"ch_1": np.array([1, 2, 3]), "ch_2": np.array([4, 5, 6]),
                                                "ch_3": np.array([7, 8, 9])}, coord_frame="mri")

# Create random data:
info = mne.create_info(ch_names=['ch_1', 'ch_2', 'ch_3'],
                       ch_types=['ecog'] * 3,
                       sfreq=100)
data = np.array([[normal(loc=0, scale=2, size=100), normal(loc=0, scale=2, size=100),
                  normal(loc=0, scale=2, size=100)],
                 [normal(loc=0, scale=2, size=100), normal(loc=0, scale=2, size=100),
                  normal(loc=0, scale=2, size=100)]])
epochs = mne.EpochsArray(data, info, tmin=-0.2, verbose="ERROR")
epochs.set_montage(montage, verbose="ERROR")

# Printing the epochs montage info:
print("Coordinate frames before saving:")
print(epochs.get_montage().dig[0]["coord_frame"])

# Creating a temporary directory
temp_dir = tempfile.mkdtemp()
# Generate a file name
fname = temp_dir + os.sep + "-epo.fif"
epochs.save(fname)

loaded_epochs = mne.read_epochs(fname, verbose="ERROR")
print("Coordinate frames after saving:")
print(loaded_epochs.get_montage().dig[0]["coord_frame"])
Expected results

Coordinate frames before saving:
5 (FIFFV_COORD_MRI)
5 (FIFFV_COORD_MRI)

Actual results

Coordinate frames before saving:
5 (FIFFV_COORD_MRI)
4 (FIFFV_COORD_HEAD)

Additional information

Platform: Windows-10-10.0.19044-SP0
Python: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:15:42) [MSC v.1916 64 bit (AMD64)]
Executable: C:\Users\alexander.lepauvre\Anaconda3\envs\mne_24\python.exe
CPU: Intel64 Family 6 Model 142 Stepping 10, GenuineIntel: 8 cores
Memory: 15.9 GB
mne: 0.24.0
numpy: 1.21.4 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy: 1.7.2
matplotlib: 3.4.3 {backend=Qt5Agg}
sklearn: 1.0.1
numba: 0.53.1
nibabel: 3.2.1
nilearn: 0.8.1
dipy: 1.4.1
cupy: Not found
pandas: 1.3.4
mayavi: 4.7.2
pyvista: 0.32.1 {OpenGL 4.5.0 - Build 26.20.100.6860 via Intel(R) UHD Graphics 620}
pyvistaqt: 0.5.0
ipyvtklink: Not found
vtk: 9.0.3
PyQt5: 5.12.3
ipympl: Not found
mne_qt_browser: Not found

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.