Exemplo n.º 1
0
def get_data():
    import os
    os.sys.path.append('/home/schirrmr/braindecode/code/braindecode/')
    from braindecode.datautil.trial_segment import create_signal_target_from_raw_mne
    from braindecode.datasets.bbci import BBCIDataset
    from braindecode.mne_ext.signalproc import mne_apply, resample_cnt
    from braindecode.datautil.signalproc import exponential_running_standardize
    subject_id = 4  # 1-14
    loader = BBCIDataset(
        '/data/schirrmr/schirrmr/HGD-public/reduced/train/{:d}.mat'.format(
            subject_id),
        load_sensor_names=['C3'])
    cnt = loader.load()
    cnt = cnt.drop_channels(['STI 014'])
    from collections import OrderedDict
    marker_def = OrderedDict([('Right Hand', [1]), (
        'Left Hand',
        [2],
    ), ('Rest', [3]), ('Feet', [4])])
    # Here you can choose a larger sampling rate later
    # Right now chosen very small to allow fast initial experiments
    cnt = resample_cnt(cnt, new_fs=500)
    cnt = mne_apply(
        lambda a: exponential_running_standardize(
            a.T, factor_new=1e-3, init_block_size=1000, eps=1e-4).T, cnt)
    ival = [0, 2000]  # ms to cut trial
    dataset = create_signal_target_from_raw_mne(cnt, marker_def, ival)
    return dataset.X, dataset.y
def load_bbci_data(filename, low_cut_hz):
	load_sensor_names = None
	loader = BBCIDataset(filename, load_sensor_names=load_sensor_names)


	log.info("Loading data...")
	cnt = loader.load()

	# Cleaning: First find all trials that have absolute microvolt values
	# larger than +- 800 inside them and remember them for removal later
	log.info("Cutting trials...")

	marker_def = OrderedDict([('Right Hand', [1]), ('Left Hand', [2],),
							  ('Rest', [3]), ('Feet', [4])])
	clean_ival = [0, 4000]

	set_for_cleaning = create_signal_target_from_raw_mne(cnt, marker_def,
												  clean_ival)

	clean_trial_mask = np.max(np.abs(set_for_cleaning.X), axis=(1, 2)) < 800

	log.info("Clean trials: {:3d}  of {:3d} ({:5.1f}%)".format(
		np.sum(clean_trial_mask),
		len(set_for_cleaning.X),
		np.mean(clean_trial_mask) * 100))

	# now pick only sensors with C in their name
	# as they cover motor cortex
	C_sensors = ['FC5', 'FC1', 'FC2', 'FC6', 'C3', 'C4', 'CP5',
				 'CP1', 'CP2', 'CP6', 'FC3', 'FCz', 'FC4', 'C5', 'C1', 'C2',
				 'C6',
				 'CP3', 'CPz', 'CP4', 'FFC5h', 'FFC3h', 'FFC4h', 'FFC6h',
				 'FCC5h',
				 'FCC3h', 'FCC4h', 'FCC6h', 'CCP5h', 'CCP3h', 'CCP4h', 'CCP6h',
				 'CPP5h',
				 'CPP3h', 'CPP4h', 'CPP6h', 'FFC1h', 'FFC2h', 'FCC1h', 'FCC2h',
				 'CCP1h',
				 'CCP2h', 'CPP1h', 'CPP2h']

	cnt = cnt.pick_channels(C_sensors)

	# Further preprocessings
	log.info("Resampling...")
	cnt = resample_cnt(cnt, 250.0)

	print("REREFERENCING")

	log.info("Highpassing...")
	cnt = mne_apply(lambda a: highpass_cnt(a, low_cut_hz, cnt.info['sfreq'], filt_order=3, axis=1),cnt)
	log.info("Standardizing...")
	cnt = mne_apply(lambda a: exponential_running_standardize(a.T, factor_new=1e-3,init_block_size=1000,eps=1e-4).T,cnt)

	# Trial interval, start at -500 already, since improved decoding for networks
	ival = [-500, 4000]

	dataset = create_signal_target_from_raw_mne(cnt, marker_def, ival)

	dataset.X = dataset.X[clean_trial_mask]
	dataset.y = dataset.y[clean_trial_mask]
	return dataset.X, dataset.y
Exemplo n.º 3
0
def load_cnt(file_path, channel_names, clean_on_all_channels=True):
    # if we have to run the cleaning procedure on all channels, putting
    # load_sensor_names to None will assure us the BBCIDataset class will
    # load all possible sensors
    if clean_on_all_channels is True:
        channel_names = None

    # create the loader object for BBCI standard
    loader = BBCIDataset(file_path, load_sensor_names=channel_names)

    # load data
    return loader.load()
Exemplo n.º 4
0
def load_bbci_data(filename, low_cut_hz, debug=False):
    load_sensor_names = None
    if debug:
        load_sensor_names = ['C3', 'C4', 'C2']
    loader = BBCIDataset(filename, load_sensor_names=load_sensor_names)

    log.info("Loading data...")
    cnt = loader.load()

    log.info("Cutting trials...")

    marker_def = OrderedDict([('Right Hand', [1]), (
        'Left Hand',
        [2],
    ), ('Rest', [3]), ('Feet', [4])])
    clean_ival = [0, 4000]

    set_for_cleaning = create_signal_target_from_raw_mne(
        cnt, marker_def, clean_ival)

    clean_trial_mask = np.max(np.abs(set_for_cleaning.X), axis=(1, 2)) < 800

    log.info("Clean trials: {:3d}  of {:3d} ({:5.1f}%)".format(
        np.sum(clean_trial_mask), len(set_for_cleaning.X),
        np.mean(clean_trial_mask) * 100))

    # lets convert to millivolt for numerical stability of next operations
    C_sensors = [
        'FC5', 'FC1', 'FC2', 'FC6', 'C3', 'C4', 'CP5', 'CP1', 'CP2', 'CP6',
        'FC3', 'FCz', 'FC4', 'C5', 'C1', 'C2', 'C6', 'CP3', 'CPz', 'CP4',
        'FFC5h', 'FFC3h', 'FFC4h', 'FFC6h', 'FCC5h', 'FCC3h', 'FCC4h', 'FCC6h',
        'CCP5h', 'CCP3h', 'CCP4h', 'CCP6h', 'CPP5h', 'CPP3h', 'CPP4h', 'CPP6h',
        'FFC1h', 'FFC2h', 'FCC1h', 'FCC2h', 'CCP1h', 'CCP2h', 'CPP1h', 'CPP2h'
    ]
    if debug:
        C_sensors = load_sensor_names
    cnt = cnt.pick_channels(C_sensors)
    cnt = mne_apply(lambda a: a * 1e6, cnt)
    log.info("Resampling...")
    cnt = resample_cnt(cnt, 250.0)
    log.info("Highpassing...")
    cnt = mne_apply(
        lambda a: highpass_cnt(
            a, low_cut_hz, cnt.info['sfreq'], filt_order=3, axis=1), cnt)
    log.info("Standardizing...")
    cnt = mne_apply(
        lambda a: exponential_running_standardize(
            a.T, factor_new=1e-3, init_block_size=1000, eps=1e-4).T, cnt)

    ival = [-500, 4000]

    dataset = create_signal_target_from_raw_mne(cnt, marker_def, ival)
    return dataset