Skip to content

By-pass set_annotations when plotting ICA sources - #11763

Closed
mscheltienne wants to merge 6 commits into
mne-tools:mainfrom
mscheltienne:fix-ica-viz
Closed

mscheltienne wants to merge 6 commits into
mne-tools:mainfrom
mscheltienne:fix-ica-viz

Conversation

@mscheltienne

@mscheltienne mscheltienne commented Jun 29, 2023 •

Copy link
Copy Markdown
Member

Fixes #11762
Tested in the following scenario:

  • raw.first_samp set to 0, with and without measurement date
  • raw.first_samp different from 0, with and without measurement date

I'll try to add some tests when able.

@mscheltienne

Copy link
Copy Markdown
Member Author

That should do it, test are failing or main and passing in this PR because in ica.plot_sources(raw) the annotation ends up being outside of the raw range (raw of 1s, annotation shifted to 43.1s due to first_samp and lack of meas_date).
So we don't even enter in the part which checks that the region location is indeed (0.2, 0.3).. but that's a bonus 😄

Comment thread mne/viz/tests/test_ica.py
assert len(fig.mne.ax_hscroll.collections) == 1
else:
assert len(fig.mne.regions) == 1
assert np.allclose(fig.mne.regions[0].getRegion(), (0.2, 0.3))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do not use assert np.allclose in tests but rather assert_allclose -- it has a sane default atol=0 and also more informative message on failure

Suggested change
assert np.allclose(fig.mne.regions[0].getRegion(), (0.2, 0.3))
assert_allclose(fig.mne.regions[0].getRegion(), (0.2, 0.3))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the tip, I'll look into numpy.testing, looks useful :)

Comment thread mne/viz/tests/test_ica.py
assert len(fig.mne.ax_hscroll.collections) == 1
else:
assert len(fig.mne.regions) == 1
assert np.allclose(fig.mne.regions[0].getRegion(), (0.2, 0.3))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here. Then you'll need to import at the top.

I tried to push the change but GitHub wouldn't let me for some reason

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can't either.. well that's interesting.

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.

Annotation displayed on ICA sources when meas_date is None and first_samp is not 0 are wrong

2 participants