concatenate_raws reported raws[1].info['dev_head_t'] differs

when I tried to concatenate 12 runs:

run_con = mne.io.concatenate_raws(raws = run_list)

it reported error:

ValueError: raws[1].info['dev_head_t'] differs. The instances probably come from different runs, and are therefore associated with different head positions. Manually change info['dev_head_t'] to avoid this message but beware that this means the MEG sensors will not be properly spatially aligned. See mne.preprocessing.maxwell_filter to realign the runs to a common head position.

but i checked that all these run’s info[‘dev_head_t’] are the same:

i = 0 
while i<=11:
    print(run_list[i].info['dev_head_t'])
    i = i+1
<Transform | MEG device->head>
[[        nan         nan         nan -0.00328767]
 [        nan         nan         nan  0.00677107]
 [ 0.01876122  0.0254103   0.99950105  0.05687291]
 [ 0.          0.          0.          1.        ]]
<Transform | MEG device->head>
[[        nan         nan         nan -0.00328767]
 [        nan         nan         nan  0.00677107]
 [ 0.01876122  0.0254103   0.99950105  0.05687291]
 [ 0.          0.          0.          1.        ]]

omit several outputs

maybe it’s because you have NaNs?

Alex

That would imply our test for equality is not “nan-aware”, which would probably be a bug…

I can reproduce:

import numpy as np
from mne import concatenate_raws
from mne.datasets import sample
from mne.io import read_raw_fif


raw = read_raw_fif(sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif")
raw.crop(0, 10).load_data()
raw.info["dev_head_t"]["trans"][0, 0] = np.nan
raw2 = raw.copy()
raw = concatenate_raws([raw, raw2])

EDIT: PR to fix the bug here.

Mathieu

2 Likes

@ling how did you get files with np.nan in the dev_head_t? Did you process with MNE-Python and get this, or did they come from MEGIN/Elekta MaxFilter?

From MaxFilter ,ELEKTA.
In general, the experimenters in our school’s MEG lab, after recording the raw MEG data using ELEKTA, would preprocess the raw data using MaxFilter. One of the steps involves aligning the data from different runs to the average head position across all runs.

and it seems that if dev_head_t has NaN values , the data processed with this matrix turns into NaN values entirely, indicating a problem likely occurred during MaxFilter preprocessing. This matrix should not contain any NaN values.