Epochs.compute_tfr()
fails for complex and phase outputs in the multitaper method
#12831
Labels
Epochs.compute_tfr()
fails for complex and phase outputs in the multitaper method
#12831
Description of the problem
When calling
![image](https://private-user-images.githubusercontent.com/56922019/365164834-aec2e202-6179-4395-974b-a0902d64dae4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MjA3NDcsIm5iZiI6MTczOTUyMDQ0NywicGF0aCI6Ii81NjkyMjAxOS8zNjUxNjQ4MzQtYWVjMmUyMDItNjE3OS00Mzk1LTk3NGItYTA5MDJkNjRkYWU0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA4MDcyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYzMDExNGJkN2FiNGI0YTMyZGI3Mjk2NDgxODhiZWMwMzY3NzllMzgzZTY0NTA0MjU2ODIxMDUwYzc2OGQ5YjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.p0KA38rPtJXZFWTHqSMBM5nZTR_dgtK2XNN3kC2qZ6g)
Epochs.compute_tfr()
withmethod="multitaper"
andoutput="complex"/"phase"
, there is anAssertionError
that the actual shape of the results does not match the expected shape (self._shape
):The expected shape is incorrect due to the tapers dimension of the multitaper complex/phase outputs not being properly indexed in the epoched data.
There are no errors when TFR is computed from epoched data without a tapers dimension (e.g., multitaper mode with power output; Morlet mode with any output), or from raw data with a tapers dimension (multitaper mode with complex or phase outputs).
self._shape
is generated here:mne-python/mne/time_frequency/tfr.py
Lines 1527 to 1537 in 013d6c9
TFR results with tapers have shape
([epochs, ]channels, tapers, freqs, times)
. When tapers are present, they are added toexpected_shape
in L1536 withself._data.shape[1]
, however this only corresponds to the tapers dimension in non-epoched data. If the data is epoched, it corresponds to the number of channels, soself._shape
becomes(epochs, channels, channels, freqs, times)
. This causes the mismatch between the actual and expected shapes of the results.This could be fixed with something like:
Inserting the number of tapers into
expected_shape
in position 1 is fine for both epoched and non-epoched data, since the number of epochs gets added later:mne-python/mne/time_frequency/tfr.py
Line 3155 in 013d6c9
Happy to open a PR for this.
Steps to reproduce
Link to data
No response
Expected results
No
AssertionError
should be raised for any of the outputs.Actual results
An
AssertionError
is raised for"complex"
and"phase"
outputs, but not"power"
:Additional information
Platform Windows-11-10.0.22631-SP0
Python 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:24:51) [MSC v.1940 64 bit (AMD64)]
Executable c:\Users\tsbin\anaconda3\envs\mne\python.exe
CPU Intel64 Family 6 Model 154 Stepping 3, GenuineIntel (16 cores)
Memory 31.7 GB
Core
├☑ mne 1.9.0.dev20+g013d6c9f6 (devel, latest release is 1.8.0)
├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 16 threads)
├☑ scipy 1.14.1
└☑ matplotlib 3.9.2 (backend=qtagg)
The text was updated successfully, but these errors were encountered: