Skip to content

Should PSD plots in the report contain bad channels by default? #12137

Closed

Description

@hoechenberger

Since we switched from plot_psd() to compute_psd().plot(), PSD plots in the Report contain bad channels. Is this a default we want to keep? I was using MNE-BIDS-Pipeline and triple-checked my data until I realized what's going on. (I thought something was wrong with my BIDS conversion)
So even if we keep this behavior for Report, we should reconsider it for MNE-BIDS-Pipeline (and transfer this issue if needed)

Activity

  1. hoechenberger commented on Oct 25, 2023

    @hoechenberger
    MemberAuthor

    One argument for excluding bads is that the PSDs are added as sub-sections for the corresponding Raw and Epochs instances, where the data traces are currently not corresponding to the PSD since the former do not contain bads ... sorry about the phrasing, I'm a bit in a rush right now 🥵

  2. drammock commented on Oct 25, 2023

    @drammock
    Member

    Since we switched from plot_psd() to compute_psd().plot(), PSD plots in the Report contain bad channels

    actually the change was here: #11680 and the motivation was a dev-meeting discussion where I think @agramfort made the point that PSDs are often used for data quality checks and thus showing bads is a useful default to have.

    Is this a default we want to keep?

    I think so. And after #12006 it should now be possible to specify exclude="bads" either when creating the spectrum or when plotting.

  3. hoechenberger commented on Oct 26, 2023

    @hoechenberger
    MemberAuthor

    Yes, I'm using the PSD plots myself for data quality checks and I can see that for interactive use, showing the bads by default can make sense.

    But for the reports, the data has usually already been inspected or processed by the time it gets added to the report. Now the issue is that the bad channels are not visually distinct from the non-bads, and since the PSD plot in the report is not interactive, there is no way to figure out (post-hoc, when looking at the report) whether a channel with an odd PSD has actually been marked as bad or not.

    This is especially problematic when using MNE-BIDS-Pipeline, where one cannot be sure which channels actually entered analysis…

    The PSD plots in Report I'm talking about are auto-generated when callingReport.add_raw(..., psd=True) and Report.add_epochs(..., psd=True); that is, they are generated automatically and added below raw.plot() and epochs.plot_image() – both of which ignore bads by default, which makes sense. Now, the PSD plots don't correspond to those figures anymore, because a different set of channels is included.

    Proposals:

    • in Report, don't show bads in PSD by default for add_raw() and add_epochs(), or
    • at least in MNE-BIDS-Pipeline reports, don't show bads in PSD by default or
    • plot PSD traces of bad channels in a different color so they're easy to spot
  4. drammock commented on Oct 26, 2023

    @drammock
    Member
    • in Report, don't show bads in PSD by default for add_raw() and add_epochs()

    This is the approach I would take. Sorry, I think I misunderstood your earlier post as suggesting to change the method default, not just the default within report contexts

  5. added this to the 1.6 milestone on Oct 26, 2023
  6. larsoner commented on Oct 26, 2023

    @larsoner
    Member

    Changing the report.add_raw/epochs(..., psd=True) behavior sounds reasonable to me. But I think really some variant of this would be the best solution:

    plot PSD traces of bad channels in a different color so they're easy to spot

    Given that we use spatial_colors (and that this is useful) I'm not totally sure what would work. One option would be to use middle gray since it would stand out as the only saturation=0 color. (And in cases where spatial colors are not used then we can use red as usual, which I think is what evoked.plot(spatial_colors=False) does for example.) Maybe we should look to see how this looks with evoked.plot() butterfly for example where spatial_colors=True. I don't actually know what we do for a bad color there (?) but gray might be easy enough to spot as bad in the middle of the channel rainbow.

  7. hoechenberger commented on Oct 26, 2023

    @hoechenberger
    MemberAuthor

    @larsoner
    If finding a suitable color turns out to be a problem, we could consider selecting a different line style (dashed?) maybe?

  8. larsoner commented on Oct 26, 2023

    @larsoner
    Member

    I thought about this but it can be really hard to follow dotted or dashed lines when the lines are squiggly, and evoked/psd lines can be quite squiggly

  9. hoechenberger commented on Oct 26, 2023

    @hoechenberger
    MemberAuthor

    In that case – maybe a very red red? :) I don't think we use that as a spatial color, do we?

  10. larsoner commented on Oct 26, 2023

    @larsoner
    Member

    In that case – maybe a very red red? :)

    We use a whole bunch of colors, including red. :( I think it would be hard to find a high-saturation color that stands out, hence the idea to use a color with saturation zero.

    I quickly modified mne/viz/evoked.py to try middle gray. Looks like we might already be setting the line style in evoked.plot to be an acceptable dashing, too (I didn't set it), but I think the middle gray also helps distinguish it further:

    Patch
    diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py
    index 6abcbcc0d1..1c6712a6be 100644
    --- a/mne/viz/evoked.py
    +++ b/mne/viz/evoked.py
    @@ -679,15 +679,17 @@ def _plot_lines(
                         _handle_spatial_colors(
                             colors, info, idx, this_type, psd, ax, sphere
                         )
    +                    bad_color = (0.5, 0.5, 0.5)
                     else:
                         if isinstance(_spat_col, (tuple, str)):
                             col = [_spat_col]
                         else:
                             col = ["k"]
    +                    bad_color = "r"
                         colors = col * len(idx)
    -                    for i in bad_ch_idx:
    -                        if i in idx:
    -                            colors[idx.index(i)] = "r"
    +                for i in bad_ch_idx:
    +                    if i in idx:
    +                        colors[idx.index(i)] = bad_color
     
                     if zorder == "std":
                         # find the channels with the least activity
    
    
    import mne
    evoked = mne.read_evokeds(mne.datasets.sample.data_path() / "MEG" / "sample" / "sample_audvis-ave.fif", baseline=(None, 0))[0]
    evoked.pick("eeg", exclude=())
    evoked.plot(spatial_colors=True, exclude=())
    

    Screenshot from 2023-10-26 09-26-04

    Zoomed:

    Screenshot from 2023-10-26 09-27-57

    And here is spatial_colors=False:

    Screenshot from 2023-10-26 09-24-36

  11. hoechenberger commented on Oct 26, 2023

    @hoechenberger
    MemberAuthor

    I think it would be hard to find a high-saturation color that stands out, hence the idea to use a color with saturation zero.

    Thinking about it again, it doesn't need to stand out – because figuring "oh, that's the channel I already marked as bad!" only becomes relevant if that channel has an odd (very high or low power) spectrum which clearly separates it from the other traces anyway

    Otherwise you wouldn't really care, I suppose

  12. larsoner commented on Oct 26, 2023

    @larsoner
    Member

    Sorry I mean "stands out" as in "is easy to tell that it's different/separate from the good, spatial-color-mapped channels", not "pops out as prominent". Just that we need them to be differentiable in some way

  13. hoechenberger commented on Oct 26, 2023

    @hoechenberger
    MemberAuthor

    Sorry I mean "stands out" as in "is easy to tell that it's different/separate from the good, spatial-color-mapped channels", not "pops out as prominent". Just that we need them to be differentiable in some way

    Yes, that's how I understood it :) I meant to say, maybe gray is a good choice after all, even if it's not easily discoverable if the traces for all channels are close together. Because then, the bad channel won't raise any eyebrows. Currently, it does raise eyebrows in my analysis because the trace is spatially displaced from the other traces, and it has the regular spatial color, so it's not immediately obvious that it's bad. If it were gray, it would already help

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