Skip to content

Conversation

@nordme
Copy link
Contributor

@nordme nordme commented Sep 28, 2023

Fixes #11985.

What does this implement/fix?

source_induced_power and source_band_induced_power currently only allow one label to be passed for power and plv calculation. It should be able to do this over multiple labels.

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.

Great! Next (before adding anything else) I would add a test that return_plv actually makes the pow, itc tuple get returned. Don't actually need to check the values but you could for example make sure that their data shapes are the same

@nordme
Copy link
Contributor Author

nordme commented Oct 10, 2023

Let's check in about how we want to handle output for single labels and any other main feedback points about restricting K and then averaging power over labels. After we've got that shored up, then I will need to do work on the tests.

@nordme
Copy link
Contributor Author

nordme commented Oct 10, 2023

The most recent commit proposes performing kernel restriction to labels within the _prepare_source_params function, but if we do that, then we need to handle the _compute_source_psd_epochs function as well. So, at this point, let's touch base on a conceptual level about if we want to move multi-label restriction into _source_induced_power so that we avoid changes to psd functions or if we want to look at multi-label functionality for the psd epochs function too.

If we want to continue on with _prepare_source_params then I need to finish the alterations to that function and clean it up (e.g. excessive comments), but I don't want to move ahead until we've weighed the overall strategy.

@nordme nordme requested a review from larsoner October 10, 2023 21:18
@larsoner
Copy link
Member

if we do that, then we need to handle the _compute_source_psd_epochs function as well.

The current public API of https://mne.tools/stable/generated/mne.minimum_norm.compute_source_psd_epochs.html says it only supports a single label. So the easy way out is to still only allow that behavior in that function, but add in a code comment somewhere # TODO: Now that multiple labels are supported in _prepare_source_params, it should be easy to add multi-label support here and someone else can implement it later if they want. Then your job now is just to add this comment and catch in compute_source_psd_epochs (e.g., with _validate_type(label, (None, Label), label)) that only a single label is passed. Then the simple/equivalent-to-main code path of _prepare_source_params will be triggered so the output and behavior of compute_source_psd_epochs remains unchanged.

... or if you want to go into bonus territory, yes you make compute_source_psd_epochs also support multiple labels, with the same tutorial and testing updates to make sure things are still working there. Depends on how strong your motivation (and how open your time) is to work on this :)

@nordme
Copy link
Contributor Author

nordme commented Oct 11, 2023

Thanks, @larsoner! About single label behavior: do you think the _source_induced_power should continue to output power as (n_vertices, n_freqs, n_samples) if there's only a single label so that old scripts using this function are not broken? It would be kinda weird, but it would not break people's existing pipelines?

@larsoner
Copy link
Member

do you think the _source_induced_power should continue to output power as (n_vertices, n_freqs, n_samples) if there's only a single label so that old scripts using this function are not broken? It would be kinda weird, but it would not break people's existing pipelines?

Yes exactly. We keep backward compat that way. And to me it's okay (even though it's a bit awkward) that label=label will give (n_vertices, n_freqs, n_samples) whereas label=[label] will give (1, n_freqs, n_samples). To me it's two different modes of operation, the first giving all vertices within a label (single-label input) and the second giving label-meaned/aggregated data (list of labels).

@nordme
Copy link
Contributor Author

nordme commented Oct 17, 2023

@larsoner Looks like pre-commit hooks fixed a whitespace issue that's now causing CircleCi to fail (unregistered user issue). Can I fix this or does it need to be you?

@larsoner
Copy link
Member

You can fix it and push a commit

@nordme
Copy link
Contributor Author

nordme commented Oct 17, 2023

@larsoner There's nothing to fix in terms of the code, so am I pushing an empty commit to get CircleCI to restart?

@larsoner
Copy link
Member

@nordme
Copy link
Contributor Author

nordme commented Oct 17, 2023

@larsoner I'm puzzled about the 4 failed CircleCi tests. It looks to me like they're failing on code that a) I didn't touch, b) doesn't call code that I touched, and c) passes pytest on my machine locally. Do you have thoughts on what's happening?

@drammock
Copy link
Member

  • pip pre errors are related to numpy API changes it looks like
  • ubuntu minimal error is in test_tfr_multi_label which looks related?: `E FileNotFoundError: fname does not exist: "/home/runner/work/mne-python/mne-python/MEG/sample/sample_audvis_trunc_raw.fif"

@nordme
Copy link
Contributor Author

nordme commented Oct 17, 2023

@drammock Thanks, Dan. About the multi-label one, my raw instantiation call is the same as the one above it in test_tfr_with_inverse_operator(method). Do I need the decorator @testing.requires_testing_data above my multi-label test function to make it work? Is that an issue that would normally pass pytest on my machine but break CircleCI checks?

@drammock
Copy link
Member

@drammock Thanks, Dan. About the multi-label one, my call is the same as the one above it in test_tfr_with_inverse_operator(method). Do I need the decorator @testing.requires_testing_data above my multi-label test function to make it work? Is that an issue that would normally pass pytest on my machine but break CircleCI checks?

yes indeed. Look at the step in which the failure occurs: https://github.com/mne-tools/mne-python/actions/runs/6551626097/job/17793283214?pr=12026

it's title is "Run tests with no testing data". adding the decorator would cause the test to get skipped on that CI job.

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.

One major suggestion for refactoring/restructuring. If it's not clear let me know and I'm happy to chat about it, or if you want I can push a commit to try it

@nordme
Copy link
Contributor Author

nordme commented Oct 23, 2023

One major suggestion for refactoring/restructuring. If it's not clear let me know and I'm happy to chat about it, or if you want I can push a commit to try it

@larsoner Sounds good, exploiting the power of dicts more here is a good idea. I'll work on it and push, probably tomorrow!

@nordme nordme requested a review from dengemann as a code owner October 24, 2023 20:35
@nordme
Copy link
Contributor Author

nordme commented Oct 30, 2023

@drammock @larsoner I think this PR is pretty much ready, but do either of you have last comments?

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.

Just some tiny stuff and one remaining choice, then I think we can merge!

@nordme
Copy link
Contributor Author

nordme commented Oct 31, 2023

@larsoner Looks like nibabel errors are causing the CircleCi failures?

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.

Pushed a tiny commit to make CIs happy (failures are unrelated but might as well get them fixed now!) and marking for merge-when-green, thanks @nordme !

@larsoner larsoner enabled auto-merge (squash) October 31, 2023 22:23
@larsoner larsoner merged commit e4a6eba into mne-tools:main Nov 1, 2023
larsoner added a commit to larsoner/mne-python that referenced this pull request Nov 3, 2023
* upstream/main: (35 commits)
  [DOC] Add documentation for setting montage order (mne-tools#12160)
  Fix inferring fiducials from EEGLAB (mne-tools#12165)
  Try to fix ICA Report (mne-tools#12167)
  BUG: Fix bug with Report.add_ica component number (mne-tools#12156)
  MAINT: Add rstcheck to CIs and pre-commit (mne-tools#12163)
  DOC: fix sphinx style typos (mne-tools#12161)
  MAINT: Fix linkcheck (mne-tools#12162)
  ENH: Add multiple label support to source_band_induced_power, source_induced_power (mne-tools#12026)
  Allow automated metadata generation to be bounded by "row events" instead of explicit time windows (mne-tools#12118)
  ENH: Collapse only in doc gen (mne-tools#12145)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12155)
  BUG: Fix bug with interior points not showing (mne-tools#12148)
  ENH: Warn about versions in sys_info (mne-tools#12146)
  Fix in conftest.py (mne-tools#12150)
  ENH: set color for bad channel with spatial_colors=True (mne-tools#12142)
  DOC: Better documentation of realign_raw (mne-tools#12135)
  Add mne-icalabel wildcard (mne-tools#12143)
  Remove LGTM.com configuration file (mne-tools#12139)
  DOC: Fix typo found by codespell (mne-tools#12140)
  DOC: Document governance updates (mne-tools#12133)
  ...
larsoner added a commit to JD-Zhu/mne-python that referenced this pull request Nov 3, 2023
* upstream/main: (26 commits)
  FIX: Fix bug with coreg scalars (mne-tools#12164)
  Changed casting rule in np.clip to allow reading of raw GDF files (mne-tools#12168)
  [DOC] Add documentation for setting montage order (mne-tools#12160)
  Fix inferring fiducials from EEGLAB (mne-tools#12165)
  Try to fix ICA Report (mne-tools#12167)
  BUG: Fix bug with Report.add_ica component number (mne-tools#12156)
  MAINT: Add rstcheck to CIs and pre-commit (mne-tools#12163)
  DOC: fix sphinx style typos (mne-tools#12161)
  MAINT: Fix linkcheck (mne-tools#12162)
  ENH: Add multiple label support to source_band_induced_power, source_induced_power (mne-tools#12026)
  Allow automated metadata generation to be bounded by "row events" instead of explicit time windows (mne-tools#12118)
  ENH: Collapse only in doc gen (mne-tools#12145)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12155)
  BUG: Fix bug with interior points not showing (mne-tools#12148)
  ENH: Warn about versions in sys_info (mne-tools#12146)
  Fix in conftest.py (mne-tools#12150)
  ENH: set color for bad channel with spatial_colors=True (mne-tools#12142)
  DOC: Better documentation of realign_raw (mne-tools#12135)
  Add mne-icalabel wildcard (mne-tools#12143)
  Remove LGTM.com configuration file (mne-tools#12139)
  ...
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
…induced_power (mne-tools#12026)

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
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.

ENH: Allow list-of-label in source_band_induced_power

3 participants