Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_raw_bids cannot find emptyroom when anonymize=True #1269

Closed
drammock opened this issue Jul 11, 2024 · 0 comments · Fixed by #1270
Closed

write_raw_bids cannot find emptyroom when anonymize=True #1269

drammock opened this issue Jul 11, 2024 · 0 comments · Fixed by #1270
Labels

Comments

@drammock
Copy link
Member

Description of the problem

calling write_raw_bids(..., anonymize=dict(daysback=<some_positive_integer>), empty_room=<some_Raw_object>) fails, because the ERM will be written at sub-emptyroom/ses-<some_date_far_in_the_past>, but the subsequent call to actually write the Raw data file will try to find the empty room based on the value of the ERM's BidsPath before anonymization.

I think the culprit is basically this line:

associated_er_path = er_bids_path.fpath

Steps to reproduce

In [1]: import mne
In [2]: from mne_bids import write_raw_bids, BIDSPath
In [3]: fdir = mne.datasets.sample.data_path()
In [4]: fpath = (fdir / 'MEG' / 'sample' / 'sample_audvis_raw.fif')
In [5]: raw = mne.io.read_raw(fpath, preload=False, verbose=False)
In [6]: erm = raw.copy()  # fake ERM just for demo purposes
In [7]: bp = BIDSPath(subject="sample", root=".", task="foo")
In [8]: write_raw_bids(raw=raw, empty_room=erm, bids_path=bp, anonymize=dict(daysback=23456))

Expected results

writing succeeds

Actual results

Here's the output and traceback

<ipython-input-8-84bb36779bc7>:1: RuntimeWarning: `daysback` is too small; the measurement date is after 1925, which is not recommended by BIDS.The minimum `daysback` value for changing the measurement date of this data to before this date is 28461
  write_raw_bids(raw=raw, empty_room=erm, bids_path=bp, anonymize=dict(daysback=23456))
Writing './README'...
Writing './participants.tsv'...
Writing 'participants.json'...
Writing of electrodes.tsv is not supported for data type "meg". Skipping ...
Writing './dataset_description.json'...
Writing 'sub-emptyroom/ses-19380914/meg/sub-emptyroom_ses-19380914_task-noise_meg.json'...
Writing 'sub-emptyroom/ses-19380914/meg/sub-emptyroom_ses-19380914_task-noise_channels.tsv'...
Copying data files to sub-emptyroom_ses-19380914_task-noise_meg.fif
Reserving possible split file sub-emptyroom_ses-19380914_task-noise_split-01_meg.fif
Writing /home/drmccloy/sub-emptyroom/ses-19380914/meg/sub-emptyroom_ses-19380914_task-noise_meg.fif
Closing /home/drmccloy/sub-emptyroom/ses-19380914/meg/sub-emptyroom_ses-19380914_task-noise_meg.fif
[done]
Writing 'sub-emptyroom/ses-19380914/sub-emptyroom_ses-19380914_scans.tsv'...
Wrote sub-emptyroom/ses-19380914/sub-emptyroom_ses-19380914_scans.tsv entry with meg/sub-emptyroom_ses-19380914_task-noise_meg.fif.
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[8], line 1
----> 1 write_raw_bids(raw=raw, empty_room=erm, bids_path=bp, anonymize=dict(daysback=23456))

File <decorator-gen-447>: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 /opt/mne/bids/mne_bids/write.py:1854, in write_raw_bids(raw, bids_path, events, event_id, anonymize, format, symlink, empty_room, allow_preload, montage, acpc_aligned, overwrite, events_data, verbose)
   1852 if associated_er_path is not None:
   1853     if not associated_er_path.exists():
-> 1854         raise FileNotFoundError(
   1855             f"Empty-room data file not found: " f"{associated_er_path}"
   1856         )
   1858     # Turn it into a path relative to the BIDS root
   1859     associated_er_path = Path(
   1860         str(associated_er_path).replace(str(bids_path.root), "")
   1861     )

FileNotFoundError: Empty-room data file not found: sub-emptyroom/ses-20021203/meg/sub-emptyroom_ses-20021203_task-noise_meg.fif

Additional information

$ mne sys_info
Platform             Linux-5.15.0-58-generic-x86_64-with-glibc2.35
Python               3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0]
Executable           /opt/mambaforge/envs/mnedev/bin/python3.11
CPU                  x86_64 (16 cores)
Memory               125.7 GB

Core
├☒ mne               1.7.0.dev76+g52a905928 (outdated, release 1.7.1 is available!)
├☑ numpy             1.26.4 (OpenBLAS 0.3.23.dev with 16 threads)
├☑ scipy             1.11.4
└☑ matplotlib        3.8.2 (backend=QtAgg)

Numerical (optional)
├☑ sklearn           1.3.2
├☑ numba             0.58.1
├☑ nibabel           5.2.0
├☑ nilearn           0.10.2
├☑ dipy              1.9.0
├☑ openmeeg          2.5.7
├☑ cupy              13.0.0
├☑ pandas            2.1.4
├☑ h5io              0.2.1
└☑ h5py              3.10.0

Visualization (optional)
├☑ pyvista           0.43.2 (OpenGL 4.5.0 NVIDIA 545.23.08 via NVIDIA GeForce RTX 2060/PCIe/SSE2)
├☑ pyvistaqt         0.11.0
├☑ vtk               9.3.0
├☑ qtpy              2.4.1 (PyQt6=6.6.0)
├☑ ipympl            0.9.3
├☑ pyqtgraph         0.13.3
├☑ mne-qt-browser    0.7.0.dev9+g547b976
├☑ ipywidgets        8.1.1
├☑ trame_client      2.14.2
├☑ trame_server      2.15.0
├☑ trame_vtk         2.7.0
└☑ trame_vuetify     2.3.1

Ecosystem (optional)
├☑ mne-bids          0.15.0.dev24+g05b8e6b8
├☑ mne-nirs          0.7.0.dev0
├☑ mne-connectivity  0.7.0.dev0
├☑ mne-bids-pipeline 1.6.0.dev8+g9055e9c
├☑ neo               0.13.0
├☑ eeglabio          0.0.2-4
├☑ edfio             0.4.0
├☑ mffpy             0.8.0
├☑ pybv              0.7.5
└☐ unavailable       mne-features, mne-icalabel

To update to the latest supported release version to get bugfixes and improvements, visit https://mne.tools/stable/install/updating.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant