From fbc79efb0e73004a071ebdb89ea88f1da4ebe26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Tue, 5 Mar 2024 12:53:30 +0100 Subject: [PATCH 1/4] Support variable time windows for epochs metadata creation --- docs/source/v1.7.md.inc | 8 ++++++-- mne_bids_pipeline/_config.py | 26 ++++++++++++++++++++------ pyproject.toml | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/docs/source/v1.7.md.inc b/docs/source/v1.7.md.inc index fb3be1914..5a4022b6b 100644 --- a/docs/source/v1.7.md.inc +++ b/docs/source/v1.7.md.inc @@ -1,6 +1,8 @@ ## v1.7.0 (unreleased) -[//]: # (### :new: New features & enhancements) +### :new: New features & enhancements + +- Epochs metadata creation now supports variable time windows by specifying the names of events via [`epochs_metadata_tmin`][mne_bids_pipeline._config.epochs_metadata_tmin] and [`epochs_metadata_tmax`][mne_bids_pipeline._config.epochs_metadata_tmax]. (#873 by @hoechenberger) [//]: # (- Whatever (#000 by @whoever)) @@ -8,7 +10,9 @@ [//]: # (- Whatever (#000 by @whoever)) -[//]: # (### :package: Requirements) +### :package: Requirements + +- The minimum required version of MNE-Python is now 1.7.0. [//]: # (- Whatever (#000 by @whoever)) diff --git a/mne_bids_pipeline/_config.py b/mne_bids_pipeline/_config.py index 1d5406410..7e63084be 100644 --- a/mne_bids_pipeline/_config.py +++ b/mne_bids_pipeline/_config.py @@ -931,15 +931,29 @@ April 1st, 2021. """ -epochs_metadata_tmin: Optional[float] = None +epochs_metadata_tmin: Optional[Union[float, str, list[str]]] = None """ -The beginning of the time window for metadata generation, in seconds, -relative to the time-locked event of the respective epoch. This may be less -than or larger than the epoch's first time point. If `None`, use the first -time point of the epoch. +The beginning of the time window used for epochs metadata generation. This setting +controls the `tmin` value passed to +[`mne.epochs.make_metadata`](https://mne.tools/stable/generated/mne.epochs.make_metadata.html). + +If a float, the time in seconds relative to the time-locked event of the respective +epoch. Negative indicate times before, positive values indicate times after the +time-locked event. + +If a string or a list of strings, the name(s) of events marking the start of time +window. + +If `None`, use the first time point of the epoch. + +???+ info + Note that `None` here behaves differently than `tmin=None` in + `mne.epochs.make_metadata`. To achieve the same behavior, pass the name(s) of the + time-locked events instead. + """ -epochs_metadata_tmax: Optional[float] = None +epochs_metadata_tmax: Optional[Union[float, str, list[str]]] = None """ Same as `epochs_metadata_tmin`, but specifying the **end** of the time window for metadata generation. diff --git a/pyproject.toml b/pyproject.toml index e2b222fa6..1ac81fc73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ dependencies = [ "pyvistaqt", "openpyxl", "autoreject", - "mne[hdf5] >=1.2", + "mne[hdf5] >=1.7", "mne-bids[full]", "filelock", ] From 7f8c5ac06370182cc8507c465bebcb151f077a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Fri, 29 Mar 2024 13:12:21 +0100 Subject: [PATCH 2/4] Update changelog --- docs/source/v1.9.md.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/v1.9.md.inc b/docs/source/v1.9.md.inc index 8d56bc9a5..41c54651d 100644 --- a/docs/source/v1.9.md.inc +++ b/docs/source/v1.9.md.inc @@ -5,6 +5,9 @@ - Added number of subject to `sub-average` report (#902 by @SophieHerbst) - The type annotations in the default configuration file are now easier to read: We replaced `Union[X, Y]` with `X | Y` and `Optional[X]` with `X | None`. (#908 by @hoechenberger) +- Epochs metadata creation now supports variable time windows by specifying the names of events via + [`epochs_metadata_tmin`][mne_bids_pipeline._config.epochs_metadata_tmin] and + [`epochs_metadata_tmax`][mne_bids_pipeline._config.epochs_metadata_tmax]. (#873 by @hoechenberger) [//]: # (- Whatever (#000 by @whoever)) @@ -15,6 +18,7 @@ ### :package: Requirements - We dropped support for Python 3.9. You now need Python 3.10 or newer. +- The minimum required version of MNE-Python is now 1.7.0. [//]: # (- Whatever (#000 by @whoever)) From 55b5fe37e3116f4ecddee8accffae749f4c750f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Fri, 29 Mar 2024 13:12:52 +0100 Subject: [PATCH 3/4] Apply suggestions from code review --- docs/source/v1.7.md.inc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/source/v1.7.md.inc b/docs/source/v1.7.md.inc index 1dcff0e92..3db0f1dfd 100644 --- a/docs/source/v1.7.md.inc +++ b/docs/source/v1.7.md.inc @@ -2,7 +2,6 @@ ### :new: New features & enhancements -- Epochs metadata creation now supports variable time windows by specifying the names of events via [`epochs_metadata_tmin`][mne_bids_pipeline._config.epochs_metadata_tmin] and [`epochs_metadata_tmax`][mne_bids_pipeline._config.epochs_metadata_tmax]. (#873 by @hoechenberger) - Improved logging message during cache invalidation: We now print the selected [`memory_file_method`][mne_bids_pipeline._config.memory_file_method] ("hash" or "mtime"). Previously, we'd always print "hash". (#876 by @hoechenberger) @@ -13,9 +12,7 @@ [//]: # (- Whatever (#000 by @whoever)) -### :package: Requirements - -- The minimum required version of MNE-Python is now 1.7.0. +[//]: # (### :package: Requirements) [//]: # (- Whatever (#000 by @whoever)) From 059460f906d64d0e3713d2381f4cf820dd2dde1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Sat, 20 Apr 2024 12:20:17 +0200 Subject: [PATCH 4/4] Add test case --- mne_bids_pipeline/tests/configs/config_ds000246.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mne_bids_pipeline/tests/configs/config_ds000246.py b/mne_bids_pipeline/tests/configs/config_ds000246.py index d1a9610d4..1aa58f244 100644 --- a/mne_bids_pipeline/tests/configs/config_ds000246.py +++ b/mne_bids_pipeline/tests/configs/config_ds000246.py @@ -17,6 +17,7 @@ ch_types = ["meg"] reject = dict(mag=4e-12, eog=250e-6) conditions = ["standard", "deviant", "button"] +epochs_metadata_tmin = ["standard", "deviant"] # for testing only contrasts = [("deviant", "standard")] decode = True decoding_time_generalization = True