def load_graz(filename): # load the training data_mat = scio.loadmat('dataset_BCIcomp1.mat') data = data_mat['x_train'].astype('double') #print data.shape data = data.swapaxes(-3, -2) data = data.swapaxes(-1, -3) labels = data_mat['y_train'].astype('int').ravel() #print data.shape # convert into wyrm Data axes = [np.arange(i) for i in data.shape] axes[0] = labels axes[2] = [str(i) for i in range(data.shape[2])] names = ['Class', 'Time', 'Channel'] units = ['#', 'ms', '#'] dat_train = Data(data=data, axes=axes, names=names, units=units) dat_train.fs = 128 dat_train.class_names = ['left', 'right'] # load the test data #test_data_mat = loadmat(test_file) data = data_mat['x_test'].astype('double') data = data.swapaxes(-3, -2) data = data.swapaxes(-1, -3) # convert into wyrm Data axes = [np.arange(i) for i in data.shape] axes[2] = [str(i) for i in range(data.shape[2])] names = ['Class','Time', 'Channel'] units = ['#','ms', '#'] dat_test = Data(data=data, axes=axes, names=names, units=units) dat_test.fs = 128 # map labels 2 -> 0 dat_test.axes[0][dat_test.axes[0] == 2] = 0 dat_train.axes[0][dat_train.axes[0] == 2] = 0 return dat_train, dat_test
def load_bcicomp3_ds1(dirname): """Load the BCI Competition III Data Set 1. This method loads the data set and converts it into Wyrm's ``Data`` format. Before you use it, you have to download the training- and test data in Matlab format and unpack it into a directory. .. note:: If you need the true labels of the test sets, you'll have to download them separately from http://bbci.de/competition/iii/results/index.html#labels Parameters ---------- dirname : str the directory where the ``Competition_train.mat`` and ``Competition_test.mat`` are located Returns ------- epo_train, epo_test : epoched ``Data`` objects Examples -------- >>> epo_test, epo_train = load_bcicomp3_ds1('/home/foo/bcicomp3_dataset1/') """ # construct the filenames from the dirname training_file = path.sep.join([dirname, 'Competition_train.mat']) test_file = path.sep.join([dirname, 'Competition_test.mat']) # load the training data training_data_mat = loadmat(training_file) data = training_data_mat['X'].astype('double') data = data.swapaxes(-1, -2) labels = training_data_mat['Y'].astype('int').ravel() # convert into wyrm Data axes = [np.arange(i) for i in data.shape] axes[0] = labels axes[2] = [str(i) for i in range(data.shape[2])] names = ['Class', 'Time', 'Channel'] units = ['#', 'ms', '#'] dat_train = Data(data=data, axes=axes, names=names, units=units) dat_train.fs = 1000 dat_train.class_names = ['pinky', 'tongue'] # load the test data test_data_mat = loadmat(test_file) data = test_data_mat['X'].astype('double') data = data.swapaxes(-1, -2) # convert into wyrm Data axes = [np.arange(i) for i in data.shape] axes[2] = [str(i) for i in range(data.shape[2])] names = ['Epoch', 'Time', 'Channel'] units = ['#', 'ms', '#'] dat_test = Data(data=data, axes=axes, names=names, units=units) dat_test.fs = 1000 # map labels -1 -> 0 dat_test.axes[0][dat_test.axes[0] == -1] = 0 dat_train.axes[0][dat_train.axes[0] == -1] = 0 return dat_train, dat_test
train_labels = np.array(train_labels, dtype=np.int8) test_labels = np.array(test_labels, dtype=np.int8) #sorted_by_labels = [[], [], []] #for i, label in enumerate(train_labels): # sorted_by_labels[int(label[0])].append(train_instances[i]) #pdb.set_trace() #shape = (2, len(sorted_by_labels[1][0]), len(sorted_by_labels[1][0])) #csp_training_data = np.ndarray(sorted_by_labels[1:2]) # only want positive classes in our CSP training data train_data = Data( np_train_instances, [train_labels, range(0, np_train_instances.shape[1]), range(1, 26)], ["class", "time", "channel"], ["#", "1s/250", "#"]) train_data.fs = 250 train_data.class_names = ["none", "left", "right"] test_data = Data( np_test_instances, [test_labels, range(0, np_test_instances.shape[1]), range(1, 26)], ["class", "time", "channel"], ["#", "1s/250", "#"]) test_data.fs = 250 #dat_train, dat_test = load_bcicomp3_ds1(DATA_DIR) dat_train = train_data dat_test = test_data #pdb.set_trace() # TODO: FILTER OUT LABELS OF NaN INSTANCES # load true labels