def main(): mne.utils.set_log_level('ERROR') layout = load_layout(MEG) print "Reading and processing data from files.." filenames = sys.argv[1:] new_components = [] for idx, fname in enumerate(filenames): print "Handling " + str(idx+1) + ". subject" raw = mne.io.read_raw_fif(fname, preload=True) picks = mne.pick_types(raw.info, eeg=True, meg=True) raw.drop_channels([ch_name for ix, ch_name in enumerate(raw.info['ch_names']) if ix not in picks]) raw.drop_channels(raw.info['bads']) fica = FourierICA(wsize=WSIZE, n_components=COMPONENTS, maxiter=7000, sfreq=raw.info['sfreq'], hpass=BAND[0], lpass=BAND[1]) fica.fit(raw._data) components = get_components(fica, raw.info, len(raw.times), layout) handle = plot_components(components, layout) input_ = int(raw_input("Which component to use: ")) if input_ == -1: continue new_components.append(components[input_ - 1]) import pdb; pdb.set_trace() print "kissa"
# find triggers try: triggers = [event[0] for event in mne.find_events(raw) if event[1] == 0] except: print "No triggers found" triggers = [] # drop bad and non-data channels picks = mne.pick_types(raw.info, eeg=True, meg=True) raw.drop_channels([name for idx, name in enumerate(raw.info['ch_names']) if idx not in picks]) raw.drop_channels(raw.info['bads']) # calculate fourier-ica fica = FourierICA(wsize=wsize, n_components=n_components, sfreq=raw.info['sfreq'], hpass=5, lpass=30, maxiter=7000) fica.fit(raw._data[:, raw.first_samp:raw.last_samp]) source_stft = fica.source_stft freqs = fica.freqs # plot components in sensor space on head topographies fig_ = plt.figure() for i in range(source_stft.shape[0]): sensor_component = np.abs(fica.component_in_sensor_space(i)) tfr_ = mne.time_frequency.AverageTFR(raw.info, sensor_component, range(sensor_component.shape[2]), freqs, 1) axes = fig_.add_subplot(source_stft.shape[0], 1, i+1) mne.viz.plot_tfr_topomap(tfr_, layout=layout, axes=axes, show=False)
raw.drop_channels(raw.info['bads']) raw = mne.concatenate_raws(raws) layout = load_layout(MEG=True) wsize = 4096 sfreq = raw.info['sfreq'] states = [] events = mne.find_events(raw) # calculate fourier-ica fica = FourierICA(wsize=wsize, n_components=N_COMPONENTS, sfreq=sfreq, hpass=4, lpass=30, maxiter=7000) fica.fit(raw._data) source_stft = fica.source_stft freqs = fica.freqs # plot components in sensor space on head topographies fig_ = plt.figure() for i in range(source_stft.shape[0]): sensor_component = np.abs(fica.component_in_sensor_space(i)) tfr_ = mne.time_frequency.AverageTFR(raw.info, sensor_component, range(sensor_component.shape[2]), freqs, 1) axes = fig_.add_subplot(source_stft.shape[0], 1, i+1) mne.viz.plot_tfr_topomap(tfr_, layout=layout, axes=axes, show=False)