@@ -2018,6 +2018,22 @@ def _add_ica_components(self, *, ica, picks, image_format, section, tags, replac
20182018 replace = replace ,
20192019 )
20202020
2021+ def _add_ica_sources (
2022+ self , * , ica , inst , picks , image_format , section , tags , replace
2023+ ):
2024+ with use_browser_backend ("matplotlib" ):
2025+ fig = ica .plot_sources (inst = inst , picks = picks , show = False )
2026+ self ._add_figure (
2027+ fig = fig ,
2028+ title = "Sources" ,
2029+ caption = None ,
2030+ image_format = image_format ,
2031+ tags = tags ,
2032+ section = section ,
2033+ replace = replace ,
2034+ own_figure = True ,
2035+ )
2036+
20212037 def _add_ica (
20222038 self ,
20232039 * ,
@@ -2034,6 +2050,7 @@ def _add_ica(
20342050 tags ,
20352051 n_jobs ,
20362052 replace ,
2053+ plot_sources = False ,
20372054 ):
20382055 if _path_like (ica ):
20392056 ica = read_ica (ica )
@@ -2164,6 +2181,26 @@ def _add_ica(
21642181 replace = replace ,
21652182 )
21662183
2184+ # Sources plot
2185+ if plot_sources :
2186+ if inst is None :
2187+ raise ValueError (
2188+ "Cannot plot ICA sources because inst=None. "
2189+ "Please pass a Raw, Epochs, or Evoked instance to "
2190+ "add_ica() to enable source plotting, or pass "
2191+ "plot_sources=False."
2192+ )
2193+
2194+ self ._add_ica_sources (
2195+ ica = ica ,
2196+ inst = inst ,
2197+ picks = picks ,
2198+ image_format = image_format ,
2199+ section = section ,
2200+ tags = tags ,
2201+ replace = replace ,
2202+ )
2203+
21672204 @fill_doc
21682205 def add_ica (
21692206 self ,
@@ -2179,6 +2216,7 @@ def add_ica(
21792216 n_jobs = None ,
21802217 tags = ("ica" ,),
21812218 replace = False ,
2219+ plot_sources = False ,
21822220 ):
21832221 """Add (a fitted) `~mne.preprocessing.ICA` to the report.
21842222
@@ -2205,6 +2243,12 @@ def add_ica(
22052243 %(n_jobs)s
22062244 %(tags_report)s
22072245 %(replace_report)s
2246+ plot_sources : bool
2247+ Whether to add a plot of the ICA source time-courses using
2248+ :meth:`mne.preprocessing.ICA.plot_sources`. Requires ``inst``
2249+ to be provided. Defaults to ``False``.
2250+
2251+ .. versionadded:: 1.12
22082252
22092253 Notes
22102254 -----
@@ -2225,6 +2269,7 @@ def add_ica(
22252269 section = title ,
22262270 n_jobs = n_jobs ,
22272271 replace = replace ,
2272+ plot_sources = plot_sources ,
22282273 )
22292274
22302275 def remove (self , * , title = None , tags = None , remove_all = False ):
0 commit comments