mne-bids write_raw_bids crash with maxfiltered data

mne.__version__
'1.3.1'

mne_bids.__version__
'0.12'

After using Maxfilter with the following command:

maxfilter -ctc ./sss_config/ct_sparse.fif -cal ./sss_config/sss_cal.dat -st 2000 -corr 0.98 -f rest1_anon.fif -o rest1_anon_tsss.fif

Trying to simply import this dataset in a BIDS folder:

raw_tsss = mne.io.read_raw_fif('rest1_anon_tsss.fif')

bp = BIDSPath(subject='01',
                  session="ses",
                  task="task",
                  processing="tsss",
                  root="REST",
                  datatype='meg',
                  suffix='meg',
                  extension='.fif')
raw.info['line_freq'] = 50
    
write_raw_bids(raw_tsss, bp, overwrite=True, allow_preload=True, format='FIF')

raises this error:

File :12, in write_raw_bids(raw, bids_path, events, event_id, anonymize, format, symlink, empty_room, allow_preload, montage, acpc_aligned, overwrite, events_data, verbose)

File /DATA_FAST/software/anaconda3/envs/mne/lib/python3.10/site-packages/mne_bids/write.py:1860, in write_raw_bids(***failed resolving arguments***)
   1854 # make dataset description and add template data if it does not
   1855 # already exist. Always set overwrite to False here. If users
   1856 # want to edit their dataset_description, they can directly call
   1857 # this function.
   1858 make_dataset_description(path=bids_path.root, name=" ", overwrite=False)
-> 1860 _sidecar_json(raw, task=bids_path.task, manufacturer=manufacturer,
   1861               fname=sidecar_path.fpath, datatype=bids_path.datatype,
   1862               emptyroom_fname=associated_er_path, overwrite=overwrite)
   1863 _channels_tsv(raw, channels_path.fpath, overwrite)
   1865 # create parent directories if needed
...
   1425 chpi_ts = raw[chpi_info[1]][0].astype(int)
-> 1426 chpi_active = (chpi_ts & chpi_info[2][:, np.newaxis]).astype(bool)
   1427 return chpi_active.sum(axis=0)

ValueError: operands could not be broadcast together with shapes (380,601000) (4,1)

I tested this with the original raw.fif file

raw = mne.io.read_raw_fif('rest1_anon.fif', allow_maxshield=True)

bp = BIDSPath(subject='01',
                  session="ses",
                  task="task",
                  root="REST",
                  datatype='meg',
                  suffix='meg',
                  extension='.fif')
raw.info['line_freq'] = 50
    
write_raw_bids(raw, bp, overwrite=True)

Works fine.

With mne.maxwell_filtered version:


raw_tsss = mne.preprocessing.maxwell_filter(raw, st_duration=10)
bp = BIDSPath(subject='01',
                  session="ses",
                  task="task",
                  processing="mnemaxwell",
                  root="REST",
                  datatype='meg',
                  suffix='meg',
                  extension='.fif')
write_raw_bids(raw_tsss, bp, overwrite=True, allow_preload=True, format='FIF')

    

Works fine too.

image

Any idea how I could fix that? We have a lot of datasets still being processed with Maxfilter.

Hi! I have the same error after using Maxfilter and I don’t know how to proceed. Could you finally solve it?

Hi,
No solution on my side. I can only import raw or mne.maxwell fitered files. I’ll be looking forward to a solution.

1 Like

I’ve opened a bug report upstream:

3 Likes

This should be closed on the next release of MNE-Python

1 Like