Repository navigation
Description
Description of the problem
For raw instances loaded from CTF data, head position computations produce inconsistent results when performed on the raw instance before vs. after saving and reloading. The issue only occurs if head position is first calculated prior to saving the raw instance.
I think saving and reloading the raw instance must affect the record of the digitisation points in raw.info, because the computation of the CHPI locations themselves are unaffected by the bug.
Thank you in advance for any help.
Steps to reproduce
import os
import tempfile
import mne
import numpy as np
sample_dir = mne.datasets.brainstorm.bst_auditory.data_path()
sample_raw = os.path.join(sample_dir, 'MEG', 'bst_auditory',
'S01_AEF_20131218_01.ds')
raw0 = mne.io.read_raw_ctf(sample_raw)
raw0.crop(tmax=60)
raw0.load_data()
chpiLocs = mne.chpi.extract_chpi_locs_ctf(raw0)
headPos = mne.chpi.compute_head_pos(raw0.info, chpiLocs, verbose='error')
# Error only occurs if compute_head_pos is called on raw0 prior to saving
with tempfile.TemporaryDirectory() as tmp_dir:
temp_file_1 = os.path.join(tmp_dir, 'save1-raw.fif')
raw0.save(temp_file_1)
raw1 = mne.io.read_raw_fif(temp_file_1)
chpiLocs0 = mne.chpi.extract_chpi_locs_ctf(raw0)
headPos0 = mne.chpi.compute_head_pos(raw0.info, chpiLocs0, verbose='error')
chpiLocs1 = mne.chpi.extract_chpi_locs_ctf(raw1)
headPos1 = mne.chpi.compute_head_pos(raw1.info, chpiLocs1, verbose='error')
assert np.allclose(chpiLocs0['rrs'], chpiLocs1['rrs']), 'CHPI locs diff'
assert np.allclose(headPos0[0], headPos1[0], atol=1e-04), 'Head pos diff'Link to data
No response
Expected results
No assertion errors. Computed head position should not depend on whether the raw instance was previously saved or not.
Actual results
Computed head position differs depending on whether the raw instance has been saved and reloaded, or not.
Additional information
Platform: Windows-10
Python: 3.10.9 | packaged by conda-forge
CPU: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel: 8 cores
Memory: 15.8 GB
mne: 1.3.1
numpy: 1.23.5 {MKL 2022.1-Product with 4 threads}
scipy: 1.10.1
matplotlib: 3.7.1 {backend=QtAgg}
sklearn: 1.2.1
numba: 0.56.4
nibabel: 5.0.1
nilearn: 0.10.0
dipy: 1.6.0
openmeeg: 2.5.5
cupy: Not found
pandas: 1.5.3
pyvista: 0.38.3 {OpenGL 4.5.0 - Build 30.0.101.1692 via Intel(R) UHD Graphics 620}
pyvistaqt: 0.9.1
ipyvtklink: 0.2.2
vtk: 9.2.6
qtpy: 2.3.0 {PyQt5=5.15.6}
ipympl: Not found
pyqtgraph: 0.13.2
pooch: v1.7.0
mne_bids: Not found
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: 0.4.0
mne_connectivity: Not found
mne_icalabel: Not found
Activity