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

MAINT: Compat with MNE 1.8 birthday date #1278

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ repos:
- id: ruff
name: ruff mne_bids/
files: ^mne_bids/
args: ["--fix"]
- id: ruff
name: ruff examples/
# D103: missing docstring in public function
Expand Down
5 changes: 3 additions & 2 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following authors contributed for the first time. Thank you so much! 🤩
The following authors had contributed before. Thank you for sticking around! 🤘

* `Daniel McCloy`_
* `Eric Larson`_
* `Stefan Appelhoff`_

Detailed list of changes
Expand All @@ -45,12 +46,12 @@ Detailed list of changes
🪲 Bug fixes
^^^^^^^^^^^^

- When anonymizing the date of a recording, MNE-BIDS will no longer error during `~mne_bids.write_raw_bids` if passing a `~mne.io.Raw` instance to ``empty_room``. By `Daniel McCloy`_ (:gh:`1270`)
- When anonymizing the date of a recording, MNE-BIDS will no longer error during `~mne_bids.write_raw_bids` if passing a `~mne.io.Raw` instance to ``empty_room``, by `Daniel McCloy`_ (:gh:`1270`)

⚕️ Code health
^^^^^^^^^^^^^^

- nothing yet
- Keep MNE-BIDS up to date with recent changes on participant birthday date handling in MNE-Python, by `Eric Larson`_ (gh:1278:)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

Expand Down
9 changes: 9 additions & 0 deletions mne_bids/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ def pytest_configure(config):
config.addinivalue_line("usefixtures", "monkeypatch_mne")


@pytest.fixture(autouse=True)
def close_all():
"""Close all figures after each test."""
yield
import matplotlib.pyplot as plt

plt.close("all")


@pytest.fixture(scope="session")
def monkeypatch_mne():
"""Monkeypatch MNE to ensure we have download=False everywhere in tests."""
Expand Down
3 changes: 2 additions & 1 deletion mne_bids/tests/data/tiny_bids/code/make_tiny_bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# %%
import json
from datetime import date
from pathlib import Path

import mne
Expand Down Expand Up @@ -45,7 +46,7 @@
"last_name": "Musterperson",
"first_name": "Maxi",
"middle_name": "Luka",
"birthday": (1970, 10, 20),
"birthday": date(1970, 10, 20),
"sex": 2,
"hand": 3,
}
Expand Down
5 changes: 1 addition & 4 deletions mne_bids/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,9 @@ def test_handle_chpi_reading(tmp_path):

with (
pytest.warns(RuntimeWarning, match="Defaulting to .* mne.Raw object"),
pytest.warns(
RuntimeWarning, match="This file contains raw Internal Active Shielding"
),
pytest.warns(RuntimeWarning, match="The unit for channel"),
):
raw_read = read_raw_bids(bids_path)
raw_read = read_raw_bids(bids_path, extra_params=dict(allow_maxshield="yes"))

# cHPI "off" according to sidecar, but present in the data
meg_json_data_chpi_mismatch = meg_json_data.copy()
Expand Down
14 changes: 11 additions & 3 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import shutil as sh
import sys
import warnings
from datetime import datetime, timedelta, timezone
from datetime import date, datetime, timedelta, timezone
from glob import glob
from pathlib import Path

Expand Down Expand Up @@ -102,6 +102,8 @@

def _wrap_read_raw(read_raw):
def fn(fname, *args, **kwargs):
if str(fname).endswith(".mff") and check_version("mne", "1.8"):
kwargs["events_as_annotations"] = True
raw = read_raw(fname, *args, **kwargs)
raw.info["line_freq"] = 60
return raw
Expand Down Expand Up @@ -222,9 +224,12 @@ def test_write_participants(_bids_validate, tmp_path):

# add fake participants data
raw.set_meas_date(datetime(year=1994, month=1, day=26, tzinfo=timezone.utc))
birthday = (1993, 1, 26)
if check_version("mne", "1.8"):
birthday = date(*birthday)
raw.info["subject_info"] = {
"his_id": subject_id2,
"birthday": (1993, 1, 26),
"birthday": birthday,
"sex": 1,
"hand": 2,
}
Expand Down Expand Up @@ -707,9 +712,12 @@ def test_fif(_bids_validate, tmp_path):
# data
# change the gender but don't force overwrite.
raw = _read_raw_fif(raw_fname)
birthday = (1994, 1, 26)
if check_version("mne", "1.8"):
birthday = date(*birthday)
raw.info["subject_info"] = {
"his_id": subject_id2,
"birthday": (1994, 1, 26),
"birthday": birthday,
"sex": 2,
"hand": 1,
}
Expand Down
6 changes: 4 additions & 2 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import warnings
from collections import OrderedDict, defaultdict
from datetime import datetime, timedelta, timezone
from datetime import date, datetime, timedelta, timezone
from pathlib import Path

import mne
Expand Down Expand Up @@ -456,12 +456,14 @@ def _participants_tsv(raw, subject_id, fname, overwrite=False):

# determine the age of the participant
age = subject_info.get("birthday", None)
if isinstance(age, tuple): # can be removed once MNE >= 1.8 is required
age = date(*age)
meas_date = raw.info.get("meas_date", None)
if isinstance(meas_date, (tuple, list, np.ndarray)):
meas_date = meas_date[0]

if meas_date is not None and age is not None:
bday = datetime(age[0], age[1], age[2], tzinfo=timezone.utc)
bday = datetime(age.year, age.month, age.day, tzinfo=timezone.utc)
if isinstance(meas_date, datetime):
meas_datetime = meas_date
else:
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ full = [
]

# Dependencies for running the test infrastructure
test = ["mne_bids[full]", "pytest", "pytest-cov", "pytest-sugar", "ruff"]
test = ["mne_bids[full]", "pytest >= 8", "pytest-cov", "pytest-sugar", "ruff"]

# Dependencies for building the documentation
doc = [
Expand Down Expand Up @@ -148,4 +148,6 @@ filterwarnings = [
# old MNE _fake_click
"ignore:The .*_event function was deprecated in Matplotlib.*:",
"ignore:datetime\\.datetime\\.utcfromtimestamp.* is deprecated and scheduled for removal in a future version.*:DeprecationWarning",
# matplotlib
"ignore:Figure.*is non-interactive.*cannot be shown:UserWarning",
]
Loading