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

Problems with conversion of BTI datasets #1155

Closed nugenta closed 1 year ago

nugenta commented 1 year ago

Description of the problem

There are two problems with the conversion of BTI/4D data to BIDS format. The first is that if there is no headshape data, mne_bids.write_raw_bids will fail (in function copyfile_bti_mod).

The second issue is both an MNE bids and an MNE issue - not sure if I should replicate this issue there? When reading in a 4D dataset, raw.__init_kwargs is correctly populated with the full path for the dataset, i.e.

raw._init_kwargs['pdf_fname'] = '/path_to_file/4D/c,rfDC'

but the field for the config file

raw._init_kwargs['config_fname'] = 'config'

Without the full path to the config file, copyfile_bti_mod will fail.

Steps to reproduce

#requires definition of the 'meg_fname' filepath and 'topdir' filepath

raw=mne.io.read_raw_bti(meg_fname, head_shape_fname=None, convert=False)
bids_path = BIDSPath(subject=subjid, session='1', task='rest',
                    run='01', root=topdir, suffix='meg')
write_raw_bids(raw, bids_path, overwrite=True)

Expected results

I expect it to copy the files to the BIDS directory rather than erroring out

Actual results

Error because full path for config file is not specified:

Traceback (most recent call last):

Cell In[7], line 48 write_raw_bids(raw, bids_path, overwrite=True)

File :12 in write_raw_bids

File ~/mambaforge/envs/enigma_meg/lib/python3.11/site-packages/mne_bids/write.py:1979 in write_raw_bids copyfile_bti(raw_orig, raw_dir)

File ~/mambaforge/envs/enigma_meg/lib/python3.11/site-packages/mne_bids/copyfiles.py:600 in copyfile_bti sh.copyfile(raw._init_kwargs['config_fname'],

File ~/mambaforge/envs/enigma_meg/lib/python3.11/shutil.py:256 in copyfile with open(src, 'rb') as fsrc:

FileNotFoundError: [Errno 2] No such file or directory: 'config'

Additional information

Using mne version 1.4.2 and mne-bids 0.12

welcome[bot] commented 1 year ago

Hello! πŸ‘‹ Thanks for opening your first issue here! ❀️ We will try to get back to you soon. πŸš΄πŸ½β€β™‚οΈ

sappelhoff commented 1 year ago

Hi, thanks for the report!

The second issue is both an MNE bids and an MNE issue - not sure if I should replicate this issue there? When reading in a 4D dataset, raw.__init_kwargs is correctly populated with the full path for the dataset, i.e.

please open an MNE-Python issue on the MNE-Python repository πŸ‘

The first is that if there is no headshape data, mne_bids.write_raw_bids will fail (in function copyfile_bti_mod).

why do you not have a headshape file for your data? Have you had a look at the mne-bids codebase to identify the potential problem?

nugenta commented 1 year ago

This is HCP data that I'm trying to get into a format resembling BIDS. Since the HCP did not distribute the data with the headshape or the locations of the fiducial points, I'm limited to organizing the data more-or-less in BIDS format with the -trans.fif file for coregistration. It will make it easier for me to modify software designed to work on BIDS format data if I have the HCP data in something close to BIDS.

nugenta commented 1 year ago

Oh - and in response to the suggestion of identifying the source of the problem in the mne-bids codebase, it's just that copyfile_bti fails on line 602 of copyfiles.py:

sh.copyfile(raw._init_kwargs['head_shape_fname'],
                    op.join(dest, 'hs_file'))

It returns an error that sh.copyfile cannot accept an argument of type None.