mne-tools / mne-bids

MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python.
https://mne.tools/mne-bids/
BSD 3-Clause "New" or "Revised" License
132 stars 87 forks source link

get_head_mri_trans will not work with 4D data because headshape is not read (and hs_file contains fiducials) #1319

Open nugenta opened 2 weeks ago

nugenta commented 2 weeks ago

Description of the problem

Running mne_bids.get_head_mri_trans() with a BIDSpath pointing to a BTi dataset will not work because the hs_file is not read. mne_bids.get_head_mri_trans() calls read_raw_bids(), which in turn calls _read_raw() with hsp=None. In the case of 4D/BTi data, this calls mne.io.read_raw_bti() with head_shape_fname = None. In 4D/BTi data, the fiducial coordinates are saved in the file hs_file in the data directory. Thus, mne.io.read_raw_bti() defaults to head_shape_fname=hs_file. When you call mne.io.read_raw_bti() with head_shape_fname=None, there are no fiducial coordinates loaded with the raw dataset, and the get_head_mri_trans() function will necessarily fail.

Steps to reproduce

There is no straightforward way of replicating this with the sample data because it's not in BIDS format. In fact, you can't even convert it to BIDS format, because when mne_bids.write_raw_bids() checks the extension using mne_bids.path._parse_ext, it only allows 4D/BTi files with the format 'c,rf', and the sample data has the format 'e,rf', which I guess is another bug but not one I'm concerned about here.

Expected results

Here is the raw.info file if you open a dataset using default parameters in mne.io.read_raw_bti() and default parameters

<Info | 11 non-empty values bads: [] ch_names: MEG 001, MEG 002, MEG 003, MEG 004, MEG 005, MEG 006, MEG 007, ... chs: 150 Magnetometers, 2 Stimulus, 11 Reference Magnetometers, 32 misc ctf_head_t: CTF/4D/KIT head -> head transform custom_ref_applied: False dev_ctf_t: CTF MEG device -> CTF/4D/KIT head transform dev_head_t: MEG device -> head transform dig: 6211 items (3 Cardinal, 6208 Extra) highpass: 1.0 Hz lowpass: 254.3 Hz meas_date: 2023-12-18 04:22:20 UTC nchan: 195 projs: [] sfreq: 508.6 Hz

Actual results

Here's what you get if you open the same dataset using mne_bids.read._read_raw() - note that dig is missing

<Info | 11 non-empty values bads: [] ch_names: MEG 001, MEG 002, MEG 003, MEG 004, MEG 005, MEG 006, MEG 007, ... chs: 150 Magnetometers, 2 Stimulus, 11 Reference Magnetometers, 32 misc custom_ref_applied: False description: Anonymized using a time shift to preserve age at acquisition dev_ctf_t: CTF MEG device -> CTF/4D/KIT head transform experimenter: mne_anonymize highpass: 1.0 Hz lowpass: 254.3 Hz meas_date: 2023-12-18 04:22:20 UTC nchan: 195 projs: [] sfreq: 508.6 Hz subject_info: 3 items (dict)

Additional information

mne.sys_info() Platform Linux-4.18.0-425.19.2.el8_7.x86_64-x86_64-with-glibc2.28 Python 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0] Executable /vf/users/MEGmodules/modules/enigma_meg0.6/bin/python3.11 CPU x86_64 (72 cores) Memory 1511.1 GB

Core ├☑ mne 1.5.0 ├☑ numpy 1.26.3 (OpenBLAS 0.3.26 with 1 thread) ├☑ scipy 1.12.0 ├☑ matplotlib 3.8.2 (backend=module://matplotlib_inline.backend_inline) ├☑ pooch 1.8.0 └☑ jinja2 3.1.3

Numerical (optional) ├☑ sklearn 1.4.0 ├☑ numba 0.58.1 ├☑ nibabel 5.2.0 ├☑ nilearn 0.10.2 ├☑ dipy 1.7.0 ├☑ openmeeg 2.5.7 ├☑ pandas 2.2.0 └☐ unavailable cupy

Visualization (optional) ├☑ pyvista 0.43.2 (OpenGL 3.3 (Core Profile) Mesa 18.0.0 via softpipe) ├☑ pyvistaqt 0.11.0 ├☑ ipyvtklink 0.2.2 ├☑ vtk 9.2.6 ├☑ qtpy 2.4.1 (PyQt5=5.15.8) ├☑ pyqtgraph 0.13.3 ├☑ mne-qt-browser 0.6.1 └☐ unavailable ipympl

Ecosystem (optional) ├☑ mne-bids 0.14 └☐ unavailable mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline

agramfort commented 2 weeks ago

can you share a dataset or point to a public one eg in openneuro? thx

Message ID: @.***>

sappelhoff commented 1 week ago

Thanks for the report. If you have a suggestion for a fix, that'd also be welcome.

with the format 'c,rf', and the sample data has the format 'e,rf', which I guess is another bug but not one I'm concerned about here.

just because you are working with BTI data and we are always keen on input from the people who actually work with the data: What is the difference between those two formats (c vs e) and do you think e,rf should be supported?