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

Add warning if the ICA decomposition provided to ICLabel is not using an extended infomax #42

Merged
merged 18 commits into from
May 11, 2022

Conversation

mscheltienne
Copy link
Member

As pointed out by @jacobf18 in #40 (comment)
I added a warning if the ICA provided is not using an extended infomax + test for this warning and the 2 previously added warnings if the raw|epochs instance was not filtered between [1, 100] Hz or referenced to a common average.

Comment on lines 38 to 43
ica = ICA(n_components=3, method="infomax", fit_params=dict(extended=True))
ica.fit(raw)
with pytest.warns(RuntimeWarning, match="common average reference"), pytest.warns(
RuntimeWarning, match="not filtered between 1 and 100 Hz"
):
iclabel_label_components(raw, ica)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this part isn't firing a warning. Not sure why tho...

error msg from CI

with pytest.warns(RuntimeWarning, match="common average reference"), pytest.warns(
[69](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:69)
            RuntimeWarning, match="not filtered between 1 and 100 Hz"
[70](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:70)
        ):
[71](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:71)
>           iclabel_label_components(raw, ica)
[72](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:72)
E           Failed: DID NOT WARN. No warnings of type (<class 'RuntimeWarning'>,) were emitted. The list of emitted warnings is: [].
[73](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:73)

[74](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:74)
data       = array([[4, 9, 2, ..., 1, 2, 5],
[75](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:75)
       [6, 4, 6, ..., 1, 2, 7],
[76](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:76)
       [1, 9, 2, ..., 3, 9, 7]])
[77](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:77)
ica        = <ICA | raw data decomposition, method: infomax (fit in 500 iterations on 5000 samples), 3 ICA components explaining 100.0 % of variance (3 PCA components available), channel types: eeg, no sources marked for exclusion>
[78](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:78)
raw        = <RawArray | 3 x 5000 (10.0 s), ~128 kB, data loaded>
[79](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:79)

[80](https://github.com/mne-tools/mne-icalabel/runs/6342837668?check_suite_focus=true#step:9:80)
mne_icalabel/iclabel/tests/test_label_components.py:43: Failed

Copy link
Member Author

Choose a reason for hiding this comment

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

It is firing, it's just not getting caught by pytest for some reason.. not sure why either..

Copy link
Member

Choose a reason for hiding this comment

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

Is it working locally? / are the other warnings firing?

Copy link
Member Author

@mscheltienne mscheltienne May 10, 2022

Choose a reason for hiding this comment

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

The warnings are firing locally, but pytest doesn't catch them either locally or on the CI.

Copy link
Member

Choose a reason for hiding this comment

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

@larsoner any chance you know where this might be coming from? My understanding is that mne.utils.warn should fire by default.

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 pushed a fix, but I don't know why the syntax:

with pytest.warns(RuntimeWarning, match=...), pytest.warns(RuntimeWarning, match=...):
    function()

does not work.

Copy link
Member Author

@mscheltienne mscheltienne May 11, 2022

Choose a reason for hiding this comment

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

I'm still interesting to figure out why this syntax was failing, if anyone as any idea...
I wonder if parenthesis were necessary, e.g.

with (pytest.warns(RuntimeWarning, match=...), pytest.warns(RuntimeWarning, match=...)):
    function()

Copy link
Member

Choose a reason for hiding this comment

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

I have not looked at the error, but the syntax seems fine, but I wouldn't expect it to work since each instance will try to caputure/swallow all warnings without allowing them to propagate (I think), but only one of them will be able to do so (the other one will get no warnings because they've been "taken" by the other one)

Copy link
Member Author

Choose a reason for hiding this comment

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

And you are probably right, now that I look again, it looks like it's the second pytest.warns that was complaining because the list of warnings was empty.
Although, I did try to set logger.propagate to True.

@codecov
Copy link

codecov bot commented May 11, 2022

Codecov Report

Merging #42 (7a66bad) into main (68a7d19) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   97.57%   97.60%   +0.02%     
==========================================
  Files          12       12              
  Lines         495      501       +6     
==========================================
+ Hits          483      489       +6     
  Misses         12       12              
Impacted Files Coverage Δ
mne_icalabel/iclabel/features.py 98.06% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68a7d19...7a66bad. Read the comment docs.

@adam2392
Copy link
Member

adam2392 commented May 11, 2022

Can you add a changelog entry in what's_new.rst file? You can link it to the current PR with a

:gh:`42`

doc/whats_new.rst Outdated Show resolved Hide resolved
doc/whats_new.rst Outdated Show resolved Hide resolved
doc/whats_new.rst Outdated Show resolved Hide resolved
Copy link
Member

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

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

Kay if CIs pass, then this is good to merge.

@mscheltienne mscheltienne merged commit dde09c0 into mne-tools:main May 11, 2022
@mscheltienne mscheltienne deleted the warning branch May 11, 2022 16:35
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