Issue when saving raw files loaded with mne_bids.read_raw_bids

Hi,

I’m encountering an issue saving raw files loaded with mne_bids.read_raw_bids().

When I use this function and I want to save my raw file like that :

bids_path = BIDSPath(subject=subject, session='01', task='task', run='01', split='01', root='path/to/bids')
raw = read_raw_bids(bids_path=bids_path, verbose=True)
raw.crop(tmin=0, tmax=10) 
raw.save('example_raw.fif', overwrite=True, verbose=True)

I get this error:

ValueError                                Traceback (most recent call last)
Cell In[39], line 9
      7 raw = read_raw_bids(bids_path=bids_path, verbose=True)
      8 raw.crop(tmin=0, tmax=10) 
----> 9 raw.save('example_raw.fif', overwrite=True, verbose=True)

File <decorator-gen-197>:10, in save(self, fname, picks, tmin, tmax, buffer_size_sec, drop_small_buffer, proj, fmt, overwrite, split_size, split_naming, verbose)

File ~/path/to/.venv/lib/python3.10/site-packages/mne/io/base.py:1836, in BaseRaw.save(self, fname, picks, tmin, tmax, buffer_size_sec, drop_small_buffer, proj, fmt, overwrite, split_size, split_naming, verbose)
   1834 cfg = _RawFidWriterCfg(buffer_size, split_size, drop_small_buffer, fmt)
   1835 raw_fid_writer = _RawFidWriter(self, info, picks, projector, start, stop, cfg)
-> 1836 filenames = _write_raw(raw_fid_writer, fname, split_naming, overwrite)
   1837 return filenames

File ~/path/to/.venv/lib/python3.10/site-packages/mne/io/base.py:2777, in _write_raw(raw_fid_writer, fpath, split_naming, overwrite)
   2775 logger.info(f"Writing {use_fpath}")
   2776 with start_and_end_file(use_fpath) as fid, reserved_ctx:
-> 2777     is_next_split = raw_fid_writer.write(fid, part_idx, prev_fname, next_fname)
   2778     logger.info(f"Closing {use_fpath}")
   2779 if bids_special_behavior and is_next_split:

File ~/path/to/.venv/lib/python3.10/site-packages/mne/io/base.py:2850, in _RawFidWriter.write(self, fid, part_idx, prev_fname, next_fname)
   2848 self._check_start_stop_within_bounds()
   2849 start_block(fid, FIFF.FIFFB_MEAS)
...
    999         or dt.tzinfo is not timezone.utc
   1000     ):
-> 1001         raise ValueError(f"Date must be datetime object in UTC: {repr(dt)}")

ValueError: Date must be datetime object in UTC: None

Manually setting info["meas_date"] to an arbitrary date before saving does not change the error, which makes me think this is an issue unrelated to meas_date, but something else?

raw.set_meas_date(datetime.now(timezone.utc))
print("MEAS DATE:", raw.info['meas_date'])
print(raw.info['meas_date'].tzinfo is timezone.utc)

MEAS DATE: 2025-07-07 09:06:09.673433+00:00
True

And if I load the info from the file and set it to the raw before saving, it solves the problem :

info = mne.io.read_info('path/to/bids_file_meg.fif')
raw.info = info
raw.save('example_raw.fif', overwrite=True, verbose=True)

I could apply this fix, but it prevents me from using the MNE-BIDS-Pipeline for preprocessing, where the same issue occurs.

The data has been acquired using a MEGIN Triux Neo machine.

  • MNE version: 1.9.0
  • MNE-BIDS version: 0.16.0
  • MNE-BIDS-pipeline version : dev
  • operating system: macOS 15.5

Fixed it by swapping to dev versions for MNE (1.10) and MNE-BIDS (0.17) after seeing this : [BUG] Saving anonymized helium info still produces error · Issue #13055 · mne-tools/mne-python · GitHub!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.