mne-tools / mne-tools/mne-python

add phase plot to plot_psd()

Open
#14,309 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ENH
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Describe the new feature or enhancement

I confronted this PSD plot from an eeg recording, which I don't know where this 25 Hz artifact is coming from, any idea on it?
So, I was thinking of adding phase spectrum next to the PSD plot, but AI suggests that adding raw phase spectrum is uniformly random for stochastic signals, so it is not interpretable, instead adding:

  • "Inter-segment / inter-epoch phase consistency": which is similar to compute_tfr(output="itc")
  • "Cross-channel relative phase": relative to a ref channel or to the common mode. A common-mode artifact gives ≈0 rad on all channels, so it could be best viewed with plot_topomap
Describe your proposed implementation

MNE already has compute_psd(output="complex") which returns per-segment Fourier coefficients but for all plotting functions it passes through _prepare_data_for_plot and silently discards phase information. I would suggest adding 2 new methods to BaseSpectrum so the existing plotting methods can be reused.

spec = raw.compute_psd(method="welch", output="complex", average=False)
pc = spec.phase_consistency()
rp = spec.relative_phase(ref="...")

pc.plot_topomap(...) 
rp.plot_topomap(...) 
Image
Describe possible alternatives

None.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with BaseSpectrum and _prepare_data_for_plot, tracing how compute_psd(output="complex", average=False) currently loses phase data. Clarify the phase-consistency and relative-phase entry points and how existing plotting methods, including plot_topomap, should render them; done when the agreed behavior no longer silently discards the relevant phase information.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.