Skip to content

raw.compute_psd("multitaper", ...) on a raw with "bad_xxx" annotations yields all np.nan #12519

Closed

Description

@mscheltienne

Description of the problem

Reported on our site today, it looks like raw.compute_psd() does not handle correctly annotated bad segments.
Both on 1.6 and on main.
@drammock Maybe you have an idea from the top of your head?

Steps to reproduce

import numpy as np
from mne import Annotations, create_info
from mne.io import RawArray

data = np.random.randn(3, 10000)
info = create_info(ch_names=["A", "B", "C"], sfreq=1000, ch_types="eeg")
raw = RawArray(data, info)
spectrum = raw.compute_psd(
    method="multitaper", fmin=0, fmax=40, picks="eeg", exclude="bads"
)
assert spectrum.get_data().shape[0] == len(raw.ch_names)
assert not np.all(np.isnan(spectrum.get_data()))

# with a bad segment
annotation = Annotations(onset=1, duration=1, description="bad_segment")
raw.set_annotations(annotation)
spectrum = raw.compute_psd(
    method="multitaper", fmin=0, fmax=40, picks="eeg", exclude="bads"
)
assert spectrum.get_data().shape[0] == len(raw.ch_names)
assert np.all(np.isnan(spectrum.get_data()))

Activity

  1. larsoner commented on Mar 27, 2024

    @larsoner
    Member

    Tangentially related #11413 could maybe be tackled at the same time

  2. self-assigned this
    on Mar 28, 2024
  3. added this to the 1.7 milestone on Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions