|
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 |
@@ -3455,6 +3455,42 @@ def test_convert_eeg_formats(dir_name, fmt, fname, reader, tmp_path): |
3455 | 3455 | assert_array_almost_equal(raw.get_data(), raw2.get_data()[:, :orig_len], decimal=6) |
3456 | 3456 |
|
3457 | 3457 |
|
| 3458 | +def test_anonymize_and_convert_to_edf(tmp_path): |
| 3459 | + """Test anonymization if converting to EDF (different codepath than EDF → EDF).""" |
| 3460 | + bids_root = tmp_path / "EDF" |
| 3461 | + raw_fname = data_path / "NihonKohden" / "MB0400FU.EEG" |
| 3462 | + bids_path = _bids_path.copy().update(root=bids_root, datatype="eeg") |
| 3463 | + raw = _read_raw_nihon(raw_fname) |
| 3464 | + |
| 3465 | + with ( |
| 3466 | + pytest.warns(RuntimeWarning, match="limits `startdate` to dates after 1985"), |
| 3467 | + pytest.warns(RuntimeWarning, match="Converting data files to EDF format"), |
| 3468 | + ): |
| 3469 | + bids_output_path = write_raw_bids( |
| 3470 | + raw=raw, |
| 3471 | + format="EDF", |
| 3472 | + bids_path=bids_path, |
| 3473 | + overwrite=True, |
| 3474 | + verbose=False, |
| 3475 | + anonymize=dict(daysback=41234), |
| 3476 | + ) |
| 3477 | + # make sure the written EDF file is valid |
| 3478 | + direct_read = read_raw_edf(bids_output_path.fpath) |
| 3479 | + assert direct_read.info["meas_date"] == datetime(1985, 1, 1, tzinfo=timezone.utc) |
| 3480 | + # make sure MNE-BIDS replaced the 1985-1-1 date with the date from scans.tsv |
| 3481 | + bids_read = read_raw_bids(bids_output_path) |
| 3482 | + bids_output_path.update( |
| 3483 | + suffix="scans", |
| 3484 | + extension=".tsv", |
| 3485 | + task=None, |
| 3486 | + acquisition=None, |
| 3487 | + run=None, |
| 3488 | + datatype=None, |
| 3489 | + ) |
| 3490 | + scans = _from_tsv(bids_output_path.fpath) |
| 3491 | + assert bids_read.info["meas_date"] == datetime.fromisoformat(scans["acq_time"][0]) |
| 3492 | + |
| 3493 | + |
3458 | 3494 | @pytest.mark.parametrize("dir_name, fmt, fname, reader", test_converteeg_data) |
3459 | 3495 | @pytest.mark.filterwarnings( |
3460 | 3496 | warning_str["channel_unit_changed"], |
|
0 commit comments