|
15 | 15 | import time |
16 | 16 | import warnings |
17 | 17 | from concurrent.futures import ProcessPoolExecutor |
18 | | -from datetime import date, datetime, timedelta, timezone |
| 18 | +from datetime import UTC, date, datetime, timedelta |
19 | 19 | from glob import glob |
20 | 20 | from pathlib import Path |
21 | 21 |
|
|
24 | 24 | import pandas as pd |
25 | 25 | import pytest |
26 | 26 | from mne.datasets import testing |
27 | | -from mne.io import anonymize_info |
| 27 | +from mne.io import anonymize_info, read_raw_edf |
28 | 28 | from mne.io.constants import FIFF |
29 | 29 | from mne.io.kit.kit import get_kit_info |
30 | 30 | from mne.utils import check_version |
@@ -115,7 +115,7 @@ def _make_parallel_raw(subject, *, seed=None): |
115 | 115 | info = mne.create_info(["MEG0113"], 100, ch_types="mag") |
116 | 116 | data = rng.standard_normal((1, 100)) * 1e-12 |
117 | 117 | raw = mne.io.RawArray(data, info, verbose=False) |
118 | | - raw.set_meas_date(datetime(2020, 1, 1, tzinfo=timezone.utc)) |
| 118 | + raw.set_meas_date(datetime(2020, 1, 1, tzinfo=UTC)) |
119 | 119 | raw.info["line_freq"] = 60 |
120 | 120 | raw.info["subject_info"] = { |
121 | 121 | "his_id": subject, |
@@ -267,7 +267,7 @@ def test_write_participants(_bids_validate, tmp_path): |
267 | 267 | raw = _read_raw_fif(raw_fname) |
268 | 268 |
|
269 | 269 | # add fake participants data |
270 | | - raw.set_meas_date(datetime(year=1994, month=1, day=26, tzinfo=timezone.utc)) |
| 270 | + raw.set_meas_date(datetime(year=1994, month=1, day=26, tzinfo=UTC)) |
271 | 271 | birthday = (1993, 1, 26) |
272 | 272 | birthday = date(*birthday) |
273 | 273 | raw.info["subject_info"] = { |
@@ -478,10 +478,10 @@ def test_stamp_to_dt(): |
478 | 478 | """Test conversions of meas_date to datetime objects.""" |
479 | 479 | meas_date = (1346981585, 835782) |
480 | 480 | meas_datetime = _stamp_to_dt(meas_date) |
481 | | - assert meas_datetime == datetime(2012, 9, 7, 1, 33, 5, 835782, tzinfo=timezone.utc) |
| 481 | + assert meas_datetime == datetime(2012, 9, 7, 1, 33, 5, 835782, tzinfo=UTC) |
482 | 482 | meas_date = (1346981585,) |
483 | 483 | meas_datetime = _stamp_to_dt(meas_date) |
484 | | - assert meas_datetime == datetime(2012, 9, 7, 1, 33, 5, 0, tzinfo=timezone.utc) |
| 484 | + assert meas_datetime == datetime(2012, 9, 7, 1, 33, 5, 0, tzinfo=UTC) |
485 | 485 |
|
486 | 486 |
|
487 | 487 | @testing.requires_testing_data |
@@ -688,7 +688,7 @@ def test_fif(_bids_validate, tmp_path): |
688 | 688 | raw = _read_raw_fif(raw_fname) |
689 | 689 | meas_date = raw.info["meas_date"] |
690 | 690 | if not isinstance(meas_date, datetime): |
691 | | - meas_date = datetime.fromtimestamp(meas_date[0], tz=timezone.utc) |
| 691 | + meas_date = datetime.fromtimestamp(meas_date[0], tz=UTC) |
692 | 692 | er_date = meas_date.strftime("%Y%m%d") |
693 | 693 | er_bids_path = BIDSPath( |
694 | 694 | subject="emptyroom", session=er_date, task="noise", root=bids_root |
@@ -3457,6 +3457,43 @@ def test_convert_eeg_formats(dir_name, fmt, fname, reader, tmp_path): |
3457 | 3457 | assert_array_almost_equal(raw.get_data(), raw2.get_data()[:, :orig_len], decimal=6) |
3458 | 3458 |
|
3459 | 3459 |
|
| 3460 | +@testing.requires_testing_data |
| 3461 | +def test_anonymize_and_convert_to_edf(tmp_path): |
| 3462 | + """Test anonymization if converting to EDF (different codepath than EDF → EDF).""" |
| 3463 | + bids_root = tmp_path / "EDF" |
| 3464 | + raw_fname = data_path / "NihonKohden" / "MB0400FU.EEG" |
| 3465 | + bids_path = _bids_path.copy().update(root=bids_root, datatype="eeg") |
| 3466 | + raw = _read_raw_nihon(raw_fname) |
| 3467 | + |
| 3468 | + with ( |
| 3469 | + pytest.warns(RuntimeWarning, match="limits `startdate` to dates after 1985"), |
| 3470 | + pytest.warns(RuntimeWarning, match="Converting data files to EDF format"), |
| 3471 | + ): |
| 3472 | + bids_output_path = write_raw_bids( |
| 3473 | + raw=raw, |
| 3474 | + format="EDF", |
| 3475 | + bids_path=bids_path, |
| 3476 | + overwrite=True, |
| 3477 | + verbose=False, |
| 3478 | + anonymize=dict(daysback=41234), |
| 3479 | + ) |
| 3480 | + # make sure the written EDF file is valid |
| 3481 | + direct_read = read_raw_edf(bids_output_path.fpath) |
| 3482 | + assert direct_read.info["meas_date"] == datetime(1985, 1, 1, tzinfo=UTC) |
| 3483 | + # make sure MNE-BIDS replaced the 1985-1-1 date with the date from scans.tsv |
| 3484 | + bids_read = read_raw_bids(bids_output_path) |
| 3485 | + bids_output_path.update( |
| 3486 | + suffix="scans", |
| 3487 | + extension=".tsv", |
| 3488 | + task=None, |
| 3489 | + acquisition=None, |
| 3490 | + run=None, |
| 3491 | + datatype=None, |
| 3492 | + ) |
| 3493 | + scans = _from_tsv(bids_output_path.fpath) |
| 3494 | + assert bids_read.info["meas_date"] == datetime.fromisoformat(scans["acq_time"][0]) |
| 3495 | + |
| 3496 | + |
3460 | 3497 | @pytest.mark.parametrize("dir_name, fmt, fname, reader", test_converteeg_data) |
3461 | 3498 | @pytest.mark.filterwarnings( |
3462 | 3499 | warning_str["channel_unit_changed"], |
@@ -3699,7 +3736,7 @@ def test_write_associated_emptyroom(_bids_validate, tmp_path, empty_room_dtype): |
3699 | 3736 | bids_root = tmp_path / "bids1" |
3700 | 3737 | raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" |
3701 | 3738 | raw = _read_raw_fif(raw_fname) |
3702 | | - meas_date = datetime(year=2020, month=1, day=10, tzinfo=timezone.utc) |
| 3739 | + meas_date = datetime(year=2020, month=1, day=10, tzinfo=UTC) |
3703 | 3740 |
|
3704 | 3741 | if empty_room_dtype == "BIDSPath": |
3705 | 3742 | # First write "empty-room" data |
|
0 commit comments