Skip to content

Spurious values when using plot_topomap #5315

Closed

Description

@cbrnr

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)

figure_1

This is likely an interpolation artifact, with possibly serious consequences when interpreting scalp maps. Or maybe it is specific to the biosemi montages.

Activity

  1. changed the title [-]Wrong values when using plot_topomap[/-] [+]Spurious values when using plot_topomap[/+] on Jul 3, 2018
  2. agramfort commented on Jul 3, 2018

    @agramfort
    SponsorMember
  3. jasmainak commented on Jul 3, 2018

    @jasmainak
    Member

    one could use monotonic interpolation like pchip ...

  4. agramfort commented on Jul 3, 2018

    @agramfort
    SponsorMember
  5. cbrnr commented on Jul 4, 2018

    @cbrnr
    ContributorAuthor

    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:

    skirt

  6. agramfort commented on Jul 4, 2018

    @agramfort
    SponsorMember
  7. larsoner commented on Jul 4, 2018

    @larsoner
    Member
  8. cbrnr commented on Jul 4, 2018

    @cbrnr
    ContributorAuthor

    Alright, I assume you mean #5085 - I've added an item to the list.

  9. cbrnr commented on Aug 6, 2018

    @cbrnr
    ContributorAuthor

    Moved to #5085.

  10. larsoner commented on Aug 25, 2018

    @larsoner
    Member

    Reopening so I don't forget to add this since I closed the currently linked PR

  11. added this to the 0.17 milestone on Aug 25, 2018
  12. modified the milestones: 0.17, 0.18 on Oct 4, 2018
  13. 12 remaining items

  14. cbrnr commented on Nov 28, 2018

    @cbrnr
    ContributorAuthor

    https://github.com/scot-dev/scot includes a topoplot function that uses a grid (I think). With the data above, I get this image:

    figure_1

    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).

  15. mmagnuski commented on Nov 28, 2018

    @mmagnuski
    Member

    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):
    topo_conv_hull
    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.

  16. mmagnuski commented on Nov 28, 2018

    @mmagnuski
    Member

    It is a bit better if I add more external points (red dots) where the distance between them is too high:
    topo_conv_hull

  17. jsosulski commented on Nov 28, 2018

    @jsosulski
    Contributor

    @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)

  18. cbrnr commented on Nov 28, 2018

    @cbrnr
    ContributorAuthor

    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.

  19. mmagnuski commented on Nov 28, 2018

    @mmagnuski
    Member

    Yes, the values are higher around the edges:
    image

  20. mmagnuski commented on Nov 28, 2018

    @mmagnuski
    Member

    @cbrnr I didn't know about visbrain, thanks!

  21. larsoner commented on Nov 28, 2018

    @larsoner
    Member

    @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.

  22. mmagnuski commented on Nov 28, 2018

    @mmagnuski
    Member

    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)).

  23. larsoner commented on Nov 28, 2018

    @larsoner
    Member

    By average distance do you mean some function of distance between the channels (like the median you previously mentioned)?

    Yes

    it was quicker to just divide the lines that were too long.

    Yeah it worked to demonstrate that it looks better if the lines are not too long

    I can try to hack some code into mne this evening just to open a PR where we can discuss this further

    Great. Hopefully with your changes and #5472 (and someday #5471) everyone will finally be happy with the topomap plotting :)

  24. larsoner commented on Nov 28, 2018

    @larsoner
    Member

    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.

  25. mmagnuski commented on Nov 28, 2018

    @mmagnuski
    Member

    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.

  26. mmagnuski commented on Dec 19, 2018

    @mmagnuski
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions