Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Bugs

- Fix bug in :func:`mne.io.read_raw_ctf` on Windows where large files could not be read (:gh:`10866` by `Eric Larson`_)

- Fix bug in :func:`mne.io.read_raw_ctf` where invalid measurement dates were not handled properly (:gh:`10957` by `Jean-Remi King`_ and `Eric Larson`_)

- Rendering issues with recent MESA releases can be avoided by setting the new environment variable``MNE_3D_OPTION_MULTI_SAMPLES=1`` or using :func:`mne.viz.set_3d_options` (:gh:`10513` by `Eric Larson`_)

- Fix behavior for the ``pyvista`` 3D renderer's ``quiver3D`` function so that default arguments plot a glyph in ``arrow`` mode (:gh:`10493` by `Alex Rockhill`_)
Expand Down
6 changes: 6 additions & 0 deletions mne/io/ctf/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def _pick_isotrak_and_hpi_coils(res4, coils, t):

def _convert_time(date_str, time_str):
"""Convert date and time strings to float time."""
if date_str == time_str == '':
date_str = '01/01/1970'
time_str = '00:00:00'
logger.info('No date or time found, setting to the start of the '
'POSIX epoch (1970/01/01 midnight)')

for fmt in ("%d/%m/%Y", "%d-%b-%Y", "%a, %b %d, %Y", "%Y/%m/%d"):
try:
date = strptime(date_str.strip(), fmt)
Expand Down
17 changes: 17 additions & 0 deletions mne/io/ctf/tests/test_ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License: BSD-3-Clause

import copy
from datetime import datetime, timezone
import os
from os import path as op
import shutil
Expand All @@ -13,12 +14,14 @@
import pytest

import mne
import mne.io.ctf.info
from mne import (pick_types, read_annotations, create_info,
events_from_annotations, make_forward_solution)
from mne.transforms import apply_trans
from mne.io import read_raw_fif, read_raw_ctf, RawArray
from mne.io.compensator import get_current_comp
from mne.io.ctf.constants import CTF
from mne.io.ctf.info import _convert_time
from mne.io.tests.test_raw import _test_raw_reader
from mne.tests.test_annotations import _assert_annotations_equal
from mne.utils import (_clean_names, catch_logging, _stamp_to_dt,
Expand Down Expand Up @@ -439,3 +442,17 @@ def test_read_ctf_mag_bad_comp(tmp_path, monkeypatch):
monkeypatch.setattr(mne.io.ctf.ctf, '_read_res4', _bad_res4_grad_comp)
with pytest.raises(RuntimeError, match='inconsistent compensation grade'):
read_raw_ctf(path)


@testing.requires_testing_data
def test_invalid_meas_date(monkeypatch):
"""Test handling of invalid meas_date."""
def _convert_time_bad(date_str, time_str):
return _convert_time('', '')
monkeypatch.setattr(mne.io.ctf.info, '_convert_time', _convert_time_bad)

with catch_logging() as log:
raw = read_raw_ctf(ctf_dir / ctf_fname_continuous, verbose=True)
log = log.getvalue()
assert 'No date or time found' in log
assert raw.info['meas_date'] == datetime.fromtimestamp(0, tz=timezone.utc)