Description of the problem
In the developed version 1.7, after saving the RawTFR object whose output was set as 'phase' with 'save()' method as a h5 file, it cannot be loaded correctly with 'mne.time_frequency.read_tfrs()'.
The error is 'ValueError: too many values to unpack (expected 3)'
I found the most possible reason, in Line 4225 of https://github.com/mne-tools/mne-python/blob/main/mne/time_frequency/tfr.py, the data with 4 dimensions were assigned as EpochTFR. But according to https://mne.tools/dev/generated/mne.time_frequency.tfr_array_multitaper.html#mne.time_frequency.tfr_array_multitaper, it says:
if output in ('complex',' 'phase'), array of shape (n_epochs, n_chans, n_tapers, n_freqs, n_times)\
Steps to reproduce
import mne
import numpy as np
# Since my data were also SEEG which were loaded as Raw objects, here I used the SEEG sample for reproduction
misc_path = mne.datasets.misc.data_path()
sample_path = mne.datasets.sample.data_path()
subjects_dir = sample_path / "subjects"
raw = mne.io.read_raw(misc_path / "seeg" / "sample_seeg_ieeg.fif")
# Generate the TFR with output as phase and save the object in the h5 file
spec_session_phase = raw.compute_tfr(method='multitaper', freqs=np.arange(4, 200, 4), output='phase', n_cycles=10, time_bandwidth=4)
spec_session_phase.save("spec_phase.h5", overwrite=True)
# Load the TFR object from the h5 file
spec_session_phase_load = mne.time_frequency.read_tfrs("spec_phase.h5")
Link to data
No response
Expected results
'spec_session_phase_load' should be a RawTFR object as same as spec_session_phase.
Actual results
ValueError Traceback (most recent call last)
Cell In[10], line 1
----> 1 spec_session_phase_load = mne.time_frequency.read_tfrs("spec_phase.h5")
File :12, in read_tfrs(fname, condition, verbose)
File /userdata/yhan/myenv/lib/python3.10/site-packages/mne/time_frequency/tfr.py:4231, in read_tfrs(fname, condition, verbose)
4229 else:
4230 Klass = RawTFR
-> 4231 out = Klass(inst=hdf5_dict)
4232 if getattr(out, "metadata", None) is not None:
4233 out.metadata = _prepare_read_metadata(out.metadata)
File /userdata/yhan/myenv/lib/python3.10/site-packages/mne/time_frequency/tfr.py:3213, in EpochsTFR.init(self, info, data, times, freqs, inst, method, comment, tmin, tmax, picks, proj, decim, events, event_id, selection, drop_log, metadata, n_jobs, verbose, **method_kw)
3207 # end TODO ↑↑↑↑↑↑
3208
3209 # dict is allowed for setstate compatibility
3210 _validate_type(
3211 inst, (BaseEpochs, dict), "object passed to EpochsTFR constructor", "Epochs"
3212 )
-> 3213 super().init(
3214 inst,
3215 method,
3216 freqs,
...
-> 1513 n_chan, n_freq, n_time = self._data.shape[self._dims.index("channel") :]
1514 if n_chan_info != n_chan:
1515 msg = msg.format("Channel", n_chan, "info", n_chan_info)
ValueError: too many values to unpack (expected 3)
Additional information
Platform Linux-5.4.0-173-generic-x86_64-with-glibc2.31
Python 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0]
Executable /userdata/yhan/myenv/bin/python
CPU x86_64 (48 cores)
Memory 1005.5 GB
Core
├☑ mne 1.7.0.dev163+geee8e6fe5 (devel, latest release is 1.6.1)
├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 48 threads)
├☑ scipy 1.12.0
└☑ matplotlib 3.8.3 (backend=module://matplotlib_inline.backend_inline)
Numerical (optional)
├☑ sklearn 1.4.1.post1
├☑ nibabel 5.2.1
├☑ pandas 2.2.0
├☑ h5io 0.2.2
├☑ h5py 3.10.0
└☐ unavailable numba, nilearn, dipy, openmeeg, cupy
Visualization (optional)
├☑ pyvista 0.43.3 (OpenGL unavailable)
├☑ pyvistaqt 0.11.0
├☑ vtk 9.3.0
├☑ qtpy 2.4.1 (None=None)
...
Ecosystem (optional)
├☑ mne-bids 0.14
└☐ unavailable mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo
Description of the problem
In the developed version 1.7, after saving the RawTFR object whose output was set as 'phase' with 'save()' method as a h5 file, it cannot be loaded correctly with 'mne.time_frequency.read_tfrs()'.
The error is 'ValueError: too many values to unpack (expected 3)'
I found the most possible reason, in Line 4225 of https://github.com/mne-tools/mne-python/blob/main/mne/time_frequency/tfr.py, the data with 4 dimensions were assigned as EpochTFR. But according to https://mne.tools/dev/generated/mne.time_frequency.tfr_array_multitaper.html#mne.time_frequency.tfr_array_multitaper, it says:
if output in ('complex',' 'phase'), array of shape (n_epochs, n_chans, n_tapers, n_freqs, n_times)\
Steps to reproduce
Link to data
No response
Expected results
'spec_session_phase_load' should be a RawTFR object as same as spec_session_phase.
Actual results
ValueError Traceback (most recent call last)
Cell In[10], line 1
----> 1 spec_session_phase_load = mne.time_frequency.read_tfrs("spec_phase.h5")
File :12, in read_tfrs(fname, condition, verbose)
File /userdata/yhan/myenv/lib/python3.10/site-packages/mne/time_frequency/tfr.py:4231, in read_tfrs(fname, condition, verbose)
4229 else:
4230 Klass = RawTFR
-> 4231 out = Klass(inst=hdf5_dict)
4232 if getattr(out, "metadata", None) is not None:
4233 out.metadata = _prepare_read_metadata(out.metadata)
File /userdata/yhan/myenv/lib/python3.10/site-packages/mne/time_frequency/tfr.py:3213, in EpochsTFR.init(self, info, data, times, freqs, inst, method, comment, tmin, tmax, picks, proj, decim, events, event_id, selection, drop_log, metadata, n_jobs, verbose, **method_kw)
3207 # end TODO ↑↑↑↑↑↑
3208
3209 # dict is allowed for setstate compatibility
3210 _validate_type(
3211 inst, (BaseEpochs, dict), "object passed to EpochsTFR constructor", "Epochs"
3212 )
-> 3213 super().init(
3214 inst,
3215 method,
3216 freqs,
...
-> 1513 n_chan, n_freq, n_time = self._data.shape[self._dims.index("channel") :]
1514 if n_chan_info != n_chan:
1515 msg = msg.format("Channel", n_chan, "info", n_chan_info)
ValueError: too many values to unpack (expected 3)
Additional information
Platform Linux-5.4.0-173-generic-x86_64-with-glibc2.31
Python 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0]
Executable /userdata/yhan/myenv/bin/python
CPU x86_64 (48 cores)
Memory 1005.5 GB
Core
├☑ mne 1.7.0.dev163+geee8e6fe5 (devel, latest release is 1.6.1)
├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 48 threads)
├☑ scipy 1.12.0
└☑ matplotlib 3.8.3 (backend=module://matplotlib_inline.backend_inline)
Numerical (optional)
├☑ sklearn 1.4.1.post1
├☑ nibabel 5.2.1
├☑ pandas 2.2.0
├☑ h5io 0.2.2
├☑ h5py 3.10.0
└☐ unavailable numba, nilearn, dipy, openmeeg, cupy
Visualization (optional)
├☑ pyvista 0.43.3 (OpenGL unavailable)
├☑ pyvistaqt 0.11.0
├☑ vtk 9.3.0
├☑ qtpy 2.4.1 (None=None)
...
Ecosystem (optional)
├☑ mne-bids 0.14
└☐ unavailable mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo