a = QApplication([]) ica = ICADialog(x, channels, fs, mode=mode) ica.exec_() a.exit() return ica.spatial, ica.topography def runica2(x, fs, channels, names=('Right', 'Left'), mode='ica'): from PyQt5.QtWidgets import QApplication from pynfb.protocols.ssd.topomap_selector_ica import ICADialog a = QApplication([]) res = [] decomposition = None for n in names: print('*** Select component for condition: ' + n) ica = ICADialog(x, channels, fs, decomposition=decomposition, mode=mode) ica.exec_() res.append(np.array((ica.spatial, ica.topography))) decomposition = ica.decomposition a.exit() return res if __name__ == '__main__': from mne.viz import plot_topomap from pynfb.inlets.montage import Montage from pynfb.generators import ch_names32 montage = Montage(ch_names32) spatial, topo = runica(np.random.normal(size=(100000, 32)), 1000, montage.get_names(), mode='csp') plot_topomap(spatial, montage.get_pos()) plot_topomap(topo, montage.get_pos())
# estimate snr freq, pxx = sg.welch(df.query('block_name=="Baseline0"')['P4'], FS, nperseg=FS * 2) band = subj_bands[dataset] sig = pxx[(freq >= band[0]) & (freq <= band[1])].mean() noise = pxx[((freq >= band[0] - FLANKER_WIDTH) & (freq <= band[0])) | ((freq >= band[1]) & (freq <= band[1] + FLANKER_WIDTH))].mean() snr = sig / noise # exclude subjects with snr < 1 if snr < 1: continue montage = Montage(channels[:-1]) csp = CSPDecomposition(montage.get_names(), FS, subj_bands[dataset].tolist()) b_numbers = df.query('block_name=="FB"')['block_number'].unique() x = np.concatenate([ df.query('block_number=={}'.format(b))[channels[:-1]].values for b in b_numbers[1:] ]) y = np.concatenate([ np.zeros(sum(df['block_number'] == b)) + int(b < b_numbers[8]) for b in b_numbers[1:] ]) csp.fit(x, y) #plt.figure() plt.plot(x.dot(csp.filters[:, 1]))
from PyQt5.QtWidgets import QApplication from pynfb.protocols.ssd.topomap_selector_ica import ICADialog a = QApplication([]) res = [] decomposition = None for n in names: print('*** Select component for condition: ' + n) ica = ICADialog(x, channels, fs, decomposition=decomposition, mode=mode) ica.exec_() res.append(np.array((ica.spatial, ica.topography))) decomposition = ica.decomposition a.exit() return res if __name__ == '__main__': from mne.viz import plot_topomap from pynfb.inlets.montage import Montage from pynfb.generators import ch_names32 montage = Montage(ch_names32) spatial, topo = runica(np.random.normal(size=(100000, 32)), 1000, montage.get_names(), mode='csp') plot_topomap(spatial, montage.get_pos()) plot_topomap(topo, montage.get_pos())