-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Description of the problem
Hello,
When creating an Epochs object with the argument preloaded set to True, the get_data method does not work as expected when passing a unit that is not volts. It will work well the first time, but subsequent calls will each time return data that is multiplied by the unit factor. Please note that this only happens when the preload argument is passed as True due to the if statement of line 1670 of epochs.py.
Steps to reproduce
# Create fake EEG Epochs: All channels are a constant value of 1uV.
eeg = np.ones((8, 2500)) * 1e-6
info = mne.create_info(ch_names=[str(i) for i in range(1,9)], sfreq=250, ch_types="eeg")
raw = mne.io.RawArray(eeg, info)
epochs = mne.make_fixed_length_epochs(raw, duration=0.5, overlap=0, preload=True)
# Get the data for the first time: Works well
data = epochs.get_data(units="uV")
print(data[0,0,0]) # This will correctly print the first sample of the first channel of the first epoch in uV (1 uV)
# Get the data for the second time: Unexpected result
data = epochs.get_data(units="uV")
print(data[0,0,0]) # This will return the value from before, but multiplied by 1e6, which is unexpected (100000 uV)Link to data
No response
Expected results
Subsequent calls to epochs.get_data(units="uV") should always return the same value, since the underlying data is not supposed to be modified. In the previous code, this value should be 1uV.
Actual results
After the first call to epochs.get_data(units="uV") the underlying data is multiplied by 10^6 (if the unit is uV) each time that get_data is called, therefore giving different results each time.
Additional information
Platform macOS-10.16-x86_64-i386-64bit
Python 3.8.13 (default, Mar 28 2022, 06:16:26) [Clang 12.0.0 ]
Executable /Users/pmainar/miniconda3/envs/xdf/bin/python
CPU i386 (8 cores)
Memory 16.0 GB
Core
├☑ mne 1.5.0
├☑ numpy 1.22.4 (OpenBLAS 0.3.18 with 4 threads)
├☑ scipy 1.9.0
├☑ matplotlib 3.7.0 (backend=module://ipympl.backend_nbagg)
├☑ pooch 1.6.0
└☑ jinja2 3.1.2
Numerical (optional)
├☑ sklearn 1.0.2
├☑ numba 0.57.1
├☑ pandas 1.4.2
└☐ unavailable nibabel, nilearn, dipy, openmeeg, cupy
Visualization (optional)
├☑ qtpy 2.2.0 (None=None)
├☑ ipympl 0.9.3
└☐ unavailable pyvista, pyvistaqt, ipyvtklink, vtk, pyqtgraph, mne-qt-browser
Ecosystem (optional)
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline