def runICA(subjectID): jumpAmplitudes = dict(grad=400e-12, mag=6e-12) subject = 'dh{:#02d}a'.format(subjectID) subjectPath = data_path + '/MEG_mc_hp004/' + subject + '/block' for block in ['1', '2']: outfilename = subjectPath + block + '_ica.fif' raw_fname = subjectPath + block + '.fif' if os.path.exists(raw_fname): raw = Raw(raw_fname, preload=True) raw.info['bads'] = badChanLibrary[subjectID][int(block)] MEG_channels = mne.fiff.pick_types(raw.info, meg=True, eeg=False, eog=False, stim=False) ica = ICA(n_components=0.99, n_pca_components=64, max_pca_components=100, noise_cov=None, random_state=17259) # decompose sources for raw data ica.fit(raw, picks=MEG_channels, reject=jumpAmplitudes, tstep=1.0) # Save ICA results for diagnosis and reconstruction ica.save(outfilename) else: print(raw_fname + ' does not exist. Skipping ICA.')