You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I plot negative values using mne.viz.plot_topomap, I get spurious positive values near the boundary:
import numpy as np
import mne
m = mne.channels.read_montage("biosemi64")
info = mne.create_info(m.ch_names[:-3], sfreq=512, ch_types="eeg", montage=m)
np.random.seed(1)
values = np.random.randint(-100, 0, 64)
mne.viz.plot_topomap(values, info)
This is likely an interpolation artifact, with possibly serious consequences when interpreting scalp maps. Or maybe it is specific to the biosemi montages.
yes it's an interpolation issue. I don't really see a way out here.
Interpolation is bad outside the data domain...
does eeglab or fieldtrip have the same pb?
Would it be possible to plot the image only within the outermost electrodes, that is, without extrapolation? Would that solve the problem? Basically if some kind of skirt can be defined (yellow lines), don't draw the map outside:
Please add this to the list of things for the open issue about topomap
deficiencies (there might even be a WIP PR by me on it? In any case the
issue should already be assigned to me if that helps you find it). This
problem should be probably be tackled at the same time, keeping in mind the
related considerations.
So obviously this extrapolates to positive values on the head border. I think what we really need is an option to specify the value on the head border (by default this value could be 0).
I have tested the approach with adding zero points based on extended convex hull vertices, but it is not ideal (I'd have to play with convhull parameters to get more points):
Red dots are based on covex hull and moved slightly outwards. I've used griddata with cubic interpolation above so it is not identical to what mne uses.
@mmagnuski Does your example data have higher positive values on the outer electrodes on the left/right and back or is this again an interpolation artefact? (due to the smoothness requirement)
Visbrain also has a topoplot object. I tried to plot the random data from above, but didn't succeed (the resulting plot looked rather strange). In addition, I got a message saying that VisPy is not yet compatible with Matplotlib 2.2+, whatever that means. Anyway, maybe we can still have a look what they do. There is also the R package eegUtils, which also includes a topoplot function.
@mmagnuski I like your second example. We just need to think about how to generalize it. Maybe take the convex hull and subdivide each edge by the (rounded) number of "average distance"s it is? I think it would produce something a lot like you have but be pretty general.
By average distance do you mean some function of distance between the channels (like the median you previously mentioned)? If so - I was thinking about something like that, but it was quicker to just divide the lines that were too long. I can try to hack some code into mne this evening just to open a PR where we can discuss this further. @cbrnr - let me know if you get some insight from how the other libs you've checked do topos, we can implement multiple options and compare (some may be better visually and some in terms of performance - and that makes a difference when plotting tens of topos like during inspection of ICA components(it is usually too slow for me)).
we can implement multiple options and compare (some may be better visually and some in terms of performance - and that makes a difference when plotting tens of topos like during inspection of ICA components(it is usually too slow for me)).
We need to profile the calls to see what is actually slow. I did some work a while ago and IIRC the limitation was matplotlib / the number of effective points used in pcolormesh or some similar call.
Great. Hopefully with your changes and #5472 (and someday #5471) everyone will finally be happy with the topomap plotting :)
Sure, I even imagine a future where one could change the nose of the topo head with a kwarg (with the current option being named 'pinokio' ;) ).
We need to profile the calls to see what is actually slow. I did some work a while ago and IIRC the limitation was matplotlib / the number of effective points used in pcolormesh or some similar call.
Right, compared to plotting time all the interpolation steps might not matter much. Do you know if matplotlib is seriously considering using openGL? As far as I know Bokeh has it on one of their priorities now.
I'm going to close this one as fixed with #5754. We can open another issue concerning possible differences stemming from the interpolation method used.
Activity
[-]Wrong values when using plot_topomap[/-][+]Spurious values when using plot_topomap[/+]agramfort commentedon Jul 3, 2018
jasmainak commentedon Jul 3, 2018
one could use monotonic interpolation like pchip ...
agramfort commentedon Jul 3, 2018
cbrnr commentedon Jul 4, 2018
EEGLAB produces a very similar output.
Would it be possible to plot the image only within the outermost electrodes, that is, without extrapolation? Would that solve the problem? Basically if some kind of skirt can be defined (yellow lines), don't draw the map outside:
agramfort commentedon Jul 4, 2018
larsoner commentedon Jul 4, 2018
cbrnr commentedon Jul 4, 2018
Alright, I assume you mean #5085 - I've added an item to the list.
cbrnr commentedon Aug 6, 2018
Moved to #5085.
larsoner commentedon Aug 25, 2018
Reopening so I don't forget to add this since I closed the currently linked PR
12 remaining items
cbrnr commentedon Nov 28, 2018
https://github.com/scot-dev/scot includes a topoplot function that uses a grid (I think). With the data above, I get this image:
So obviously this extrapolates to positive values on the head border. I think what we really need is an option to specify the value on the head border (by default this value could be 0).
mmagnuski commentedon Nov 28, 2018
I have tested the approach with adding zero points based on extended convex hull vertices, but it is not ideal (I'd have to play with convhull parameters to get more points):

Red dots are based on covex hull and moved slightly outwards. I've used
griddatawith cubic interpolation above so it is not identical to what mne uses.mmagnuski commentedon Nov 28, 2018
It is a bit better if I add more external points (red dots) where the distance between them is too high:

jsosulski commentedon Nov 28, 2018
@mmagnuski Does your example data have higher positive values on the outer electrodes on the left/right and back or is this again an interpolation artefact? (due to the smoothness requirement)
cbrnr commentedon Nov 28, 2018
Visbrain also has a topoplot object. I tried to plot the random data from above, but didn't succeed (the resulting plot looked rather strange). In addition, I got a message saying that VisPy is not yet compatible with Matplotlib 2.2+, whatever that means. Anyway, maybe we can still have a look what they do. There is also the R package eegUtils, which also includes a topoplot function.
mmagnuski commentedon Nov 28, 2018
Yes, the values are higher around the edges:

mmagnuski commentedon Nov 28, 2018
@cbrnr I didn't know about visbrain, thanks!
larsoner commentedon Nov 28, 2018
@mmagnuski I like your second example. We just need to think about how to generalize it. Maybe take the convex hull and subdivide each edge by the (rounded) number of "average distance"s it is? I think it would produce something a lot like you have but be pretty general.
mmagnuski commentedon Nov 28, 2018
By average distance do you mean some function of distance between the channels (like the median you previously mentioned)? If so - I was thinking about something like that, but it was quicker to just divide the lines that were too long. I can try to hack some code into mne this evening just to open a PR where we can discuss this further. @cbrnr - let me know if you get some insight from how the other libs you've checked do topos, we can implement multiple options and compare (some may be better visually and some in terms of performance - and that makes a difference when plotting tens of topos like during inspection of ICA components(it is usually too slow for me)).
larsoner commentedon Nov 28, 2018
Yes
Yeah it worked to demonstrate that it looks better if the lines are not too long
Great. Hopefully with your changes and #5472 (and someday #5471) everyone will finally be happy with the
topomapplotting :)larsoner commentedon Nov 28, 2018
We need to profile the calls to see what is actually slow. I did some work a while ago and IIRC the limitation was matplotlib / the number of effective points used in
pcolormeshor some similar call.mmagnuski commentedon Nov 28, 2018
Sure, I even imagine a future where one could change the nose of the topo head with a kwarg (with the current option being named 'pinokio' ;) ).
Right, compared to plotting time all the interpolation steps might not matter much. Do you know if matplotlib is seriously considering using openGL? As far as I know Bokeh has it on one of their priorities now.
mmagnuski commentedon Dec 19, 2018
I'm going to close this one as fixed with #5754. We can open another issue concerning possible differences stemming from the interpolation method used.