problems with report.add_ica visualization

Hi, I have a question regarding the mne.Report function, specifically with mne.Report.add_ica.

  • MNE version: 1.11.0
  • operating system: e.g. macOS Tahoe 26.2

My problem is the following: I am preprocessing a dataset on continuous EEG data and I am applying ICA to the data with automatic artifactual IC selection with ICLabel. During the execution of my script, I see a popup image showing the visualization of the effects of ICA cleaning, with the expected differences between the data on which I fitted the ICA and a copy of the data used for comparison. However, when I save the report, I do not get the same image.

Here’s the code I used:

# filter data
raw_filt = raw.copy().filter(l_freq=0.3, h_freq=40)
raw_filt_ica = raw.copy().filter(l_freq=1, h_freq=40)

# [...]

# fit ica
ica = ICA(n_components=None, method="infomax",
          fit_params=dict(extended=True),
          max_iter=500, random_state=1999)
ica.fit(raw_filt_ica, picks="eeg")

# IClabel to automatically label ICs
ic_labels = label_components(raw_filt_ica, ica, method="iclabel")

# exclude eye blink and heart beat
labels = ic_labels["labels"]
exclude_idx = [idx for idx, label in enumerate(labels) if label not in ["brain", 
                                                                        "other",
                                                                        "muscle
                                                                     artifact"]]

# apply ica weights
reconst_raw = raw_filt.copy() # copying not to overright raw_filt which we need later without ica applied to it
ica.apply(reconst_raw, exclude=exclude_idx)

# plot overlay of the original signal against the reconstructed signal
fig_comparison = ica.plot_overlay(raw_filt, exclude=exclude_idx)

report.add_ica(ica=ica,
               title="Independent Component Analysis",
               picks=exclude_idx,
               inst=raw_filt, # copy of the data I fitted the ICA on
               n_jobs=None)

And here a demonstration of what I was referring to:

Hope that’s enough and thanks to anyone who could help me.

Hello @riccardoventurini and welcome to the forum!

The picks parameter in Report.add_ica() is not for specifying which components to exclude. It’s for selecting sensors to plot in the topography and properties plots.

What you’ll want to do is attach the excludes to the ICA instance before calling Report.add_ica(). Something along the lines of:

ica.exclude = exclude_idx
report.add_ica(ica, title="ICA", inst=raw_filt)

Best wishes,

Richard

Everything works as intended now.

Thank you very much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.