コード例 #1
0
def runica(x, fs, channels, mode='ica'):
    from PyQt5.QtWidgets import QApplication
    from pynfb.protocols.ssd.topomap_selector_ica import ICADialog
    a = QApplication([])
    ica = ICADialog(x, channels, fs, mode=mode)
    ica.exec_()
    a.exit()
    return ica.spatial, ica.topography
コード例 #2
0
def run_ica_and_select_band(data, channels, fs):
    app = QApplication([])
    ica = ICADialog(data, channels, fs)
    ica.exec_()
    band = select_band(data.dot(ica.spatial), fs)
    results = {
        'spatial_filter': ica.spatial,
        'spatial_filter_ind': ica.table.get_checked_rows()[0],
        'filters': ica.decomposition.filters,
        'topographies': ica.decomposition.topographies,
        'band': band
    }
    return results
コード例 #3
0
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
コード例 #4
0
ファイル: csp3.py プロジェクト: keenieayla/nfb-1
    dir_ = 'D:\\vnd_spbu\\pilot\\mu5days'
    experiment = 'pilot5days_Rakhmankulov_Day3_03-01_12-51-41'
    with h5py.File('{}\\{}\\{}'.format(dir_, experiment,
                                       'experiment_data.h5')) as f:
        ica = f['protocol1/signals_stats/left/rejections/rejection1'][:]

        x_filters = dc_blocker(np.dot(f['protocol1/raw_data'][:], ica))
        x_rotation = dc_blocker(np.dot(f['protocol2/raw_data'][:], ica))
        x_dict = {
            'closed': x_filters[:x_filters.shape[0] // 2],
            'opened': x_filters[x_filters.shape[0] // 2:],
            'rotate': x_rotation
        }
        drop_channels = ['AUX', 'A1', 'A2']
        labels, fs = get_lsl_info_from_xml(f['stream_info.xml'][0])
        print('fs: {}\nall labels {}: {}'.format(fs, len(labels), labels))
        channels = [label for label in labels if label not in drop_channels]

        scores, unmixing_matrix, topographies = csp3(x_dict,
                                                     250, (9, 14),
                                                     lambda_=0.5,
                                                     regularization_coef=0.01)
        app = QtWidgets.QApplication([])
        selector = ICADialog(np.vstack((x_filters, x_rotation)),
                             channels,
                             fs,
                             unmixing_matrix=unmixing_matrix,
                             mode='csp',
                             scores=scores)
        selector.exec_()
コード例 #5
0
ファイル: ica_gui.py プロジェクト: keenieayla/nfb-1
    return df.loc[good_samples_mask].values, good_samples_mask


N_EEG_CHANNELS = 30

raw = mne.io.read_raw_fif('/media/kolai/prispasobo/Kondrashin_raw.fif')
channels = raw.info['ch_names'][:N_EEG_CHANNELS]
fs = int(raw.info['sfreq'])

data = raw.load_data().notch_filter([50, 100]).filter(
    0.5, 40.).get_data()[:N_EEG_CHANNELS].T

# plt.plot(data[:fs*100])

ica_data, good_samples_mask = remove_bad_samples(data[:fs * 60 * 10],
                                                 window_size=fs * 5,
                                                 threshold=2000)

ica = ICADialog(ica_data, channels, fs)
ica.exec_()
# ica.table.get_checked_rows()

plt.plot(data[:, :] + np.arange(30) * 2000, 'r')
plt.plot(ica.rejection.apply(data)[:, :] + np.arange(30) * 2000, 'k')
plt.fill_between(np.arange(data.shape[0]),
                 (~good_samples_mask).astype(int) * 30 * 2000,
                 color='r',
                 alpha=0.4)
plt.gca().set_yticks(np.arange(30) * 2000)
plt.gca().set_yticklabels(channels)
plt.xlim(0, fs * 30)