Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICA get_sources() can't deal with a concatenated raw object #13057

Open
BeiGeJin opened this issue Jan 13, 2025 · 3 comments · May be fixed by #13068
Open

ICA get_sources() can't deal with a concatenated raw object #13057

BeiGeJin opened this issue Jan 13, 2025 · 3 comments · May be fixed by #13068
Labels

Comments

@BeiGeJin
Copy link

Description of the problem

I think there might be a bug in the _source_as_raw function, here it assigns [self.last_samp] to self._last_samps, however self.last_samp is a property function and it seems that if its wrapped in a list, it won't actually call this function until used later.

Steps to reproduce

import mne

# load data
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = sample_data_folder / "MEG" / "sample" / "sample_audvis_filt-0-40_raw.fif"
raw = mne.io.read_raw_fif(sample_data_raw_file).crop(0, 60).load_data()  # raw has 60 seconds of data
# concatenate
raw_concat = mne.concatenate_raws([raw.copy(), raw.copy()])  # raw_concat has 120 seconds of data
# do ICA
ica = mne.preprocessing.ICA(n_components=20)
ica.fit(raw_concat)
# get sources
raw_sources = ica.get_sources(raw_concat)  # but this will only have 60 seconds of data
print(raw_concat)
print(raw_sources)

Link to data

No response

Expected results

raw_concat and raw_sources should have the same length of data.

Actual results

But raw_sources only have the length of data corresponding to the first object in the list that we concatenate.

Additional information

Platform Linux-3.10.0-957.1.3.el7.x86_64-x86_64-with-glibc2.17
Python 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]
Executable /home/jerryjin/miniconda3/envs/meg/bin/python
CPU x86_64 (16 cores)
Memory 46.9 GB

Core
├☒ mne 1.8.0 (outdated, release 1.9.0 is available!)
├☑ numpy 1.26.4 (MKL 2023.2-Product with 16 threads)
├☑ scipy 1.14.1
└☑ matplotlib 3.9.2 (backend=module://matplotlib_inline.backend_inline)

Numerical (optional)
├☑ sklearn 1.5.1
├☑ numba 0.60.0
├☑ pandas 2.2.2
├☑ h5py 3.11.0
└☐ unavailable nibabel, nilearn, dipy, openmeeg, cupy, h5io

Visualization (optional)
├☑ qtpy 2.4.1 (None=None)
├☑ pyqtgraph 0.13.7
├☑ mne-qt-browser 0.6.3
├☑ ipywidgets 8.1.5
└☐ unavailable pyvista, pyvistaqt, vtk, ipympl, trame_client, trame_server, trame_vtk, trame_vuetify

Ecosystem (optional)
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv

@BeiGeJin BeiGeJin added the BUG label Jan 13, 2025
Copy link

welcome bot commented Jan 13, 2025

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@BeiGeJin
Copy link
Author

As a workaround, I change the code

out._first_samps = [out.first_samp]
out._last_samps = [out.last_samp]

to below

a = out.first_samp
b = out.last_samp
out._first_samps = [a]
out._last_samps = [b]

And it seems to solve my problem.

@larsoner
Copy link
Member

@BeiGeJin would you be up for making a quick PR to fix the issue? I would start by using TDD (test-driven development) to add a minimal new test to mne/preprocessing/tests/test_ica.py that causes the error you see at the top, then add your fix and see that the test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants