-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[BUG, MRG] Replace image_interp with interpolation in topomap plot arguments #10617
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
Conversation
|
My suggestion in the issue that seemed more or less accepted was not to change the argument name, but just make image_interp do what people would expect... |
Hmmm I should have read more closely, sorry I was concentrating more on what it said under option 4... This took a bit longer than I thought but a lot of it can be reverted quickly. Now that it's done and should pass all the tests, what do you think about doing it this slightly more painful but in the end less-of-a-misnomer way? I will do the followup to remove |
|
Yes let’s avoid unnecessary deprecation |
|
I prefer changes this way, but the consesus seems to be toward repurposing I have also one question regarding the voronoi plotting behavior that can be seen below: |
|
I agree with you both @larsoner and @agramfort, I just should have written it that way in the first place! Should be good to go now. |
mne/viz/topomap.py
Outdated
| self.border = border | ||
| self.tri = tri | ||
| self.interp = {'cubic': CloughTocher2DInterpolator, | ||
| 'nearest': CloughTocher2DInterpolator, # hack not used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is not used then I'd remove it. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to do with using the fill polygon method for the Voronoi diagrams but you still need an underlying image to have a consistent return type...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand - the _GridData object shouldn't be used when image_interp='nearest'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need the extent which is in the _setup_interp method, which is not easy to untangle
|
Btw, since we've changed the behavior of |
|
To answer your question @mmagnuski, they shouldn't invade other channels' space but the extrapolation near the edges is a bit different, it is still the nearest channel though, that's just what you need to do to fill that space outside the edges. It would be really nice to add an informative error, but unfortunately, |
mne/viz/topomap.py
Outdated
| # find mask limits | ||
| extent, Xi, Yi, interp = _setup_interp( | ||
| pos, res, extrapolate, sphere, outlines, border) | ||
| pos, res, image_interp, extrapolate, sphere, outlines, border) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the lines below (set_values and set_locations) should be done only for linear and cubic interpolation. Voronoi does not use the interpolated grid Zi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to get the extent though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zi is used for the contours too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, the contours... but in such case iI don't think it makes much sense to plot cubic-interpolated contours, and nearest interpolated topomap. One option is to turn off the contours for nearest interpolation - at least for now.
| yi = np.linspace(ymin, ymax, res) | ||
| Xi, Yi = np.meshgrid(xi, yi) | ||
| interp = _GridData(pos, extrapolate, clip_origin, clip_radius, border) | ||
| interp = _GridData(pos, image_interp, extrapolate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only when image_interp is cubic or linear, otherwise could be None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other functions depend on this return
|
@alexrockhill |
|
None of the examples use |
|
Ok so my best solution this round is to plot the nearest interpolation as an image and then add Voronoi on top but only for non-animated topomaps, for animated topomaps, there is no Voronoi overlay. The issue is that the interp object is returned and the |
|
@alexrockhill |
The i.e. it's already taken from the nearest not the cubic interpolation. |
|
Ok. How does these contours look like now then? The figure you pasted here before shows the nearest interpolated image, but without the contours, and the figure I pasted looks like having cubic interpolated contours - thats why I was confused. I'll try to pull and test this PR locally tomorrow and have a look myself! :) Thanks @alexrockhill for all the work and sorry for the complications that stem from my insistence to do things the other way. :) |
|
I think compromising made this a lot better, it's nice to have the contours look reasonable. Here they are: They are slightly offset from the Voronoi diagram which looks nice actually, having them be right on the lines would be a bit confusing. The one downside is that they look a bit jagged but I think that's the best we can do. |
Agreed it already looks okay/usable. We can always make it look better in future PRs if it's not perfect |
|
Sounds good, okay to merge? |
agramfort
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmagnuski merge if happy.
thx @alexrockhill
|
LGTM too, merging then! Thanks @alexrockhill! 🚀 |
* upstream/main: (24 commits) Use less memory when loading EDF file (mne-tools#10638) BUG: fix ipython console accessibility after MNEQtBrowser in Spyder (mne-tools#10637) WIP: Fix mne.time_frequency.multitaper Nyquist adjustment slightly incorrect (mne-tools#10541) BUG: Fix bug with fNIRS reordering (mne-tools#10630) MNT: PyQt6 for pip pre 3.10 (mne-tools#10636) CI: Fix conda (mne-tools#10628) MRG: Update installer links to point to 1.0.3_0 (mne-tools#10622) [BUG, MRG] fix info write access (mne-tools#10626) [MRG] Fixed group_by titles in evoked_plot. (mne-tools#10618) [BUG, MRG] Replace image_interp with interpolation in topomap plot arguments (mne-tools#10617) MAINT: Fix timeout (mne-tools#10624) Simplify mne-tools#10619 (mne-tools#10620) Drop EEG rejection thresholds when replacing EEG with CSD channels (mne-tools#10619) Add get_montage support for fNIRS (mne-tools#10611) ENH: Improve make_head_surface options (mne-tools#10592) [ENH, MRG] Add citation for intracranial JOSS paper (mne-tools#10616) [ENH] Add sys info for mne-icalabel (mne-tools#10615) MRG: Add "highlight" parameter to Evoked.plot() to conveniently highlight time periods (mne-tools#10614) MRG: Allow to pass array of "average" values to plot_evoked_topomap() (mne-tools#10610) fix: snirf length units (mne-tools#10613) ...



Fixes #10579.