mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

Allow `Spectrum` objects to support complex coefficients #12728

Closed tsbinns closed 2 months ago

tsbinns commented 3 months ago

Describe the new feature or enhancement

Discussed briefly with @larsoner.

We are considering changes in MNE-Connectivity where the spectral coefficients can be passed directly to the connectivity estimation functions in the form of EpochsSpectrum and EpochsTFR objects, as returned from Epochs.compute_psd/tfr(output="complex").

While the complex output is supported for TFR objects, Spectrum objects do not allow complex outputs from the various PSD functions: https://github.com/mne-tools/mne-python/blob/6ad28a461fe29d96e5d822e2de6c4c9d1b7c2537/mne/time_frequency/spectrum.py#L319-L323

Describe your proposed implementation

Remove the ValueError for output="complex" from Spectrum classes.

There are a couple places where tweaks would be required, e.g. in _check_values() and handling PSD func outputs in _compute_spectra(), but similar solutions are already present in the TFR classes.

Same situation for the plotting methods, but again TFR classes also have solutions for this already which could be followed: https://github.com/mne-tools/mne-python/blob/0c369e0eaa1327e612137ba0e4a54ad776ea6e48/mne/time_frequency/tfr.py#L4326-L4328

One thing that would need to be added is storage for weights in the Spectrum class when complex output is requested from the multitaper mode, which as I understand is not the case for the TFR multitaper.

Describe possible alternatives

N/A

Additional context

No response

tsbinns commented 2 months ago

Addressed in #12747