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

fix ignoring sessions that have no data #1035

Merged
merged 13 commits into from
Jan 24, 2025

Conversation

drammock
Copy link
Member

@drammock drammock commented Jan 7, 2025

The addition of allow_missing_sessions in #1000 had some problems:

  1. it was storing [None] in the subjs_sessions dict in cases where a subject had no valid sessions; this was not behaving as expected
  2. the use of mne_bids.get_entity_vals was not working as expected, because even if a subject had no data for a session for a given task, the presence of coordsystem.json or scans.tsv sidecars was causing it to report that the subject had some files for that session.

Item (2) was fixed in mne-tools/mne-bids#1362; item (1) is fixed here. Works on my data, but will self-review to add some questions about implementation/testing.

Before merging …

  • Changelog has been updated (docs/source/dev.md.inc)

Copy link
Member Author

@drammock drammock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding testing, @larsoner and I came up with the plan to use a small dataset we have from UW (after BIDSifying it and uploading to OSF). It could make sense to add that in this PR, or a separate one

@@ -159,9 +172,9 @@ def get_subjects_sessions(config: SimpleNamespace) -> dict[str, list[str] | list
f"{tuple(sorted(missing_sessions))}, and "
"`config.allow_missing_sessions` is False"
)
subj_sessions[subject] = sorted(set(cfg_sessions) & set(valid_sessions_subj))
if subj_sessions[subject] == []:
subj_sessions[subject] = [None]
Copy link
Member Author

@drammock drammock Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't doing what was intended. We want [None] (or (None,)) for datasets where sessions aren't tracked (ie there's just one session). But for datasets where sessions are tracked, we should omit an entry from this subj_sessions dict if there aren't any sessions found for that subj.

Comment on lines 164 to 165
ignore_acquisitions=("calibration", "crosstalk"),
ignore_suffixes=("scans", "coordsystem"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are the important bit, for getting MNE-BIDS to only tell us if data files are present.
This ignore_suffixes line requires upstream mne-tools/mne-bids@41ce36a to work, so we'll need to pin MNE-BIDS to that commit, or wait for the next MNE-BIDS release before merging here.

I'm also not really sure if coordsystems.json and scans.tsv are the only possible sidecars that could have the undesirous effect (of having get_entity_vals return a false positive when no data files are actually present for the requested session --- cf. discussion at mne-tools/mne-bids#1351). If you can think of other sidecar suffixes to exclude, speak now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we'll need to pin MNE-BIDS to that commit, or wait for the next MNE-BIDS release before merging here.

This is a tough req since MNE-BIDS does not release super frequently. And in the meantime anyone doing pip install -ve . will have a valid usable (sufficiently up-to-date) editable install overwritten by the pinned install etc.

Since this is a bit of a niche bug (right?), could we instead use inspect to see if the right kwarg is present and pass it if so? Then once MNE-BIDS releases we bump our min req to the one that actually has it and remove the kwarg thing here. If we wait to release MNE-BIDS-Pipeline until MNE-BIDS releases then users are in good shape, and in the meantime devs are also in (sufficiently) good shape. We'd "just" need to make CIs install the dev version of MNE-BIDS, which they might already be doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... i.e., we don't have to wait to merge this PR and we also don't have to explicitly pin below in pyproject.toml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but if someone sets allow_missing_sessions (and actually is missing some sessions) and they don't have a new enough mne_bids, then mne_bids will report that they have data for a given subj+session that they don't actually have data for, and then the pipeline will bomb later.

Maybe I should use inspect here, but also check it during config import, to make sure that if they want to allow_missing_sessions, that they also have a sufficiently capable version of mne_bids?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would work, if they have it set and the kwarg doesn't exist then raise an error, or at least emit a warning.

Should be a transient problem anyway since hopefully we'll release after MNE-BIDS, and then pin in pyproject.toml to >= a released version

@drammock drammock marked this pull request as ready for review January 10, 2025 16:00
mne_bids_pipeline/_download.py Outdated Show resolved Hide resolved
mne_bids_pipeline/tests/configs/config_funloc.py Outdated Show resolved Hide resolved
mne_bids_pipeline/tests/test_run.py Outdated Show resolved Hide resolved
@drammock
Copy link
Member Author

@larsoner @hoechenberger this one is all green and ready for review

@drammock
Copy link
Member Author

well, we know the check works at least:

FAILED mne_bids_pipeline/tests/test_run.py::test_missing_sessions[True] - mne_bids_pipeline._config_import.ConfigError: You've requested to `allow_missing_sessions`, but this functionality requires a newer version of `mne_bids` than you have available. Please update MNE-BIDS (or if on the latest version, install the dev version).

@larsoner
Copy link
Member

Accidental TDD is the best kind of TDD

@drammock
Copy link
Member Author

Accidental TDD is the best kind of TDD

not when you pay for your CIs 😅

@drammock
Copy link
Member Author

ok all green again 🙂

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging, thanks @drammock !

@larsoner larsoner merged commit 284a905 into mne-tools:main Jan 24, 2025
53 checks passed
@drammock drammock deleted the fix-allow-missing branch February 3, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants