1010import mne
1111import pandas as pd
1212from mne .preprocessing import read_ica
13- from mne .report import Report
1413from mne_bids import BIDSPath
1514
1615from ..._config_utils import (
2120from ..._import_data import _get_run_rest_noise_path , _import_data_kwargs
2221from ..._logging import gen_log_kwargs , logger
2322from ..._parallel import get_parallel_backend , parallel_func
24- from ..._report import _add_raw , _agg_backend , _open_report
23+ from ..._report import _add_raw , _open_report
2524from ..._run import _prep_out_files , _update_for_splits , failsafe_run , save_logs
2625
2726
@@ -116,12 +115,8 @@ def apply_ica_epochs(
116115 session : str | None ,
117116 in_files : dict ,
118117) -> dict :
119- bids_basename = in_files ["ica" ].copy ().update (processing = None )
120118 out_files = dict ()
121119 out_files ["epochs" ] = in_files ["epochs" ].copy ().update (processing = "ica" , split = None )
122- out_files ["report" ] = bids_basename .copy ().update (
123- processing = "ica" , suffix = "report" , extension = ".html"
124- )
125120
126121 title = f"ICA artifact removal – sub-{ subject } "
127122 if session is not None :
@@ -156,32 +151,6 @@ def apply_ica_epochs(
156151 split_size = cfg ._epochs_split_size ,
157152 )
158153 _update_for_splits (out_files , "epochs" )
159-
160- # Compare ERP/ERF before and after ICA artifact rejection. The evoked
161- # response is calculated across ALL epochs, just like ICA was run on
162- # all epochs, regardless of their respective experimental condition.
163- #
164- # We apply baseline correction here to (hopefully!) make the effects of
165- # ICA easier to see. Otherwise, individual channels might just have
166- # arbitrary DC shifts, and we wouldn't be able to easily decipher what's
167- # going on!
168- report = Report (out_files ["report" ], title = title , verbose = False )
169- picks = ica .exclude if ica .exclude else None
170- with _agg_backend ():
171- report .add_ica (
172- ica = ica ,
173- title = "Effects of ICA cleaning" ,
174- inst = epochs .copy ().apply_baseline (cfg .baseline ),
175- picks = picks ,
176- replace = True ,
177- n_jobs = 1 , # avoid automatic parallelization
178- )
179- report .save (
180- out_files ["report" ],
181- overwrite = True ,
182- open_browser = exec_params .interactive ,
183- )
184-
185154 assert len (in_files ) == 0 , in_files .keys ()
186155
187156 # Report
@@ -198,18 +167,18 @@ def apply_ica_epochs(
198167 exec_params = exec_params ,
199168 subject = subject ,
200169 session = session ,
201- name = "ICA.apply report" ,
202170 ) as report :
203171 report .add_ica (
204172 ica = ica ,
205- title = "ICA" ,
173+ title = "ICA: removals " ,
206174 inst = epochs ,
207175 picks = ica .exclude ,
208176 # TODO upstream
209177 # captions=f'Evoked response (across all epochs) '
210178 # f'before and after ICA '
211179 # f'({len(ica.exclude)} ICs removed)'
212180 replace = True ,
181+ n_jobs = 1 , # avoid automatic parallelization
213182 )
214183
215184 return _prep_out_files (exec_params = exec_params , out_files = out_files )
0 commit comments