Skip to content

compute_spectra: a detrend argument, and a home without matplotlib #689

Done

Description

@neuromechanist

At edf694c, compute_spectra (functions/sigprocfunc/spectopo.py) calls scipy's welch with detrend=False, as EEGLAB's spectopo does, and has no argument to change that. A caller that needs Welch's method with each window detrended by its own mean (scipy's detrend="constant") cannot get it from eegprep. NEMAR's nemar-spectrum plugin needs exactly that, because its spectrum view specifies a mean detrend and leaves out the 0 Hz row (nemarOrg/nemar-process#91, epic nemarOrg/nemar-cli#2324). For now the plugin cuts the Welch windows itself, removes each window's mean, and passes each window to compute_spectra as one epoch of a 3-D call. The result matches scipy's welch(detrend="constant") within 1e-9 dB, but the caller is repeating work that welch already does.

Requests:

  1. Add a detrend argument to compute_spectra and pass it through to welch (and to spectopo if that is convenient). Keep the default at False so EEGLAB parity is unchanged.
  2. Move compute_spectra, or the numeric core it calls, out of spectopo.py into a module that does not import matplotlib. spectopo.py imports matplotlib.pyplot at module level, so a headless pipeline that only wants the numbers also loads a plotting library. The current import path could stay as a re-export.

Once a commit includes the argument, nemar-process will re-pin eegprep and drop its own window cutting; a strict xfail there turns green on that day.


Agentic AI tools were used. Workflows follow the Research Skills (doi:10.5281/zenodo.20696515). The author assumes full responsibility for this content and associated changes.

Activity

  1. claude commented on Nov 25, 2026

    @claude
    Contributor

    🤖 Plan:

  2. added a commit that references this issue on Nov 25, 2026
  3. added a commit that references this issue on Nov 25, 2026
    2d72ca5
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions