def test_append_cnt_swapaxes(self): """append_cnt must work with nonstandard timeaxis.""" dat = append_cnt(swapaxes(self.dat, 0, 1), swapaxes(self.dat, 0, 1), timeaxis=1) dat = swapaxes(dat, 0, 1) dat2 = append_cnt(self.dat, self.dat) self.assertEqual(dat, dat2)
def test_append_cnt_with_extra(self): """append_cnt with extra must work with list and ndarrays.""" self.dat.a = range(10) self.dat.b = np.arange(10) dat = append_cnt(self.dat, self.dat, extra=['a', 'b']) self.assertEqual(dat.a, range(10) + range(10)) np.testing.assert_array_equal(dat.b, np.concatenate([np.arange(10), np.arange(10)])) self.assertEqual(dat.markers, 2 * self.dat.markers)
def test_append_cnt(self): """append_cnt.""" dat = append_cnt(self.dat, self.dat) self.assertEqual(dat.data.shape[0], 2*self.dat.data.shape[0]) self.assertEqual(len(dat.axes[0]), 2*len(self.dat.axes[0])) np.testing.assert_array_equal(dat.data, np.concatenate([self.dat.data, self.dat.data], axis=0)) np.testing.assert_array_equal(dat.axes[0], np.concatenate([self.dat.axes[0], self.dat.axes[0]])) self.assertEqual(dat.markers, 2 * self.dat.markers)
def test_append_cnt_with_extra(self): """append_cnt with extra must work with list and ndarrays.""" self.dat.a = list(range(10)) self.dat.b = np.arange(10) dat = append_cnt(self.dat, self.dat, extra=['a', 'b']) self.assertEqual(dat.a, list(range(10)) + list(range(10))) np.testing.assert_array_equal(dat.b, np.concatenate([np.arange(10), np.arange(10)])) self.assertEqual(dat.markers, self.dat.markers + [[x[0] + 3000, x[1]] for x in self.dat.markers])
def test_append_cnt(self): """append_cnt.""" dat = append_cnt(self.dat, self.dat) self.assertEqual(dat.data.shape[0], 2*self.dat.data.shape[0]) self.assertEqual(len(dat.axes[0]), 2*len(self.dat.axes[0])) np.testing.assert_array_equal(dat.data, np.concatenate([self.dat.data, self.dat.data], axis=0)) np.testing.assert_array_equal(dat.axes[0], np.linspace(0, 6000, 60, endpoint=False)) self.assertEqual(dat.markers, self.dat.markers + [[x[0] + 3000, x[1]] for x in self.dat.markers])
def test_append_cnt_with_extra(self): """append_cnt with extra must work with list and ndarrays.""" self.dat.a = list(range(10)) self.dat.b = np.arange(10) dat = append_cnt(self.dat, self.dat, extra=['a', 'b']) self.assertEqual(dat.a, list(range(10)) + list(range(10))) np.testing.assert_array_equal( dat.b, np.concatenate([np.arange(10), np.arange(10)])) self.assertEqual( dat.markers, self.dat.markers + [[x[0] + 3000, x[1]] for x in self.dat.markers])
def test_append_cnt(self): """append_cnt.""" dat = append_cnt(self.dat, self.dat) self.assertEqual(dat.data.shape[0], 2 * self.dat.data.shape[0]) self.assertEqual(len(dat.axes[0]), 2 * len(self.dat.axes[0])) np.testing.assert_array_equal( dat.data, np.concatenate([self.dat.data, self.dat.data], axis=0)) np.testing.assert_array_equal(dat.axes[0], np.linspace(0, 6000, 60, endpoint=False)) self.assertEqual( dat.markers, self.dat.markers + [[x[0] + 3000, x[1]] for x in self.dat.markers])
def load(self): cnt = self.set_loaders[0].load() for loader in self.set_loaders[1:]: next_cnt = loader.load() # always sample down to lowest common denominator if next_cnt.fs > cnt.fs: log.warn("Next set has larger sampling rate ({:d}) " "than before ({:d}), resampling next set".format( next_cnt.fs, cnt.fs)) next_cnt = resample_cnt(next_cnt, cnt.fs) if next_cnt.fs < cnt.fs: log.warn("Next set has smaller sampling rate ({:d}) " "than before ({:d}), resampling set so far".format( next_cnt.fs, cnt.fs)) cnt = resample_cnt(cnt, next_cnt.fs) cnt = append_cnt(cnt, next_cnt) return cnt
def append(self, dat): """Append data to the Block Buffer. This method accumulates the incoming data. Parameters ---------- dat : Data continuous Data object """ if self.dat is None: self.dat = dat.copy() elif not dat: pass else: self.dat = append_cnt(self.dat, dat)
def init_training_vars(self): assert self.n_folds is None, "Cannot use folds on train test split" assert self.restricted_n_trials is None, "Not implemented yet" self.filterbands = generate_filterbank(min_freq=self.min_freq, max_freq=self.max_freq, last_low_freq=self.last_low_freq, low_width=self.low_width, low_overlap=self.low_overlap, high_width=self.high_width, high_overlap=self.high_overlap, low_bound=self.low_bound) assert filterbank_is_stable(self.filterbands, self.filt_order, self.cnt.fs), ( "Expect filter bank to be stable given filter order.") self.class_pairs = list(itertools.combinations([0,1,2,3],2)) train_fold = range(len(self.cnt.markers)) test_fold = np.arange(len(self.test_cnt.markers)) + len(train_fold) self.folds = [{'train': train_fold, 'test': test_fold}] assert np.intersect1d(self.folds[0]['test'], self.folds[0]['train']).size == 0 # merge cnts!! self.cnt = append_cnt(self.cnt, self.test_cnt)
def init_training_vars(self): assert self.n_folds is None, "Cannot use folds on train test split" assert self.restricted_n_trials is None, "Not implemented yet" self.filterbands = generate_filterbank( min_freq=self.min_freq, max_freq=self.max_freq, last_low_freq=self.last_low_freq, low_width=self.low_width, low_overlap=self.low_overlap, high_width=self.high_width, high_overlap=self.high_overlap, low_bound=self.low_bound) assert filterbank_is_stable( self.filterbands, self.filt_order, self.cnt.fs), ( "Expect filter bank to be stable given filter order.") # check if number of selected features is not too large if self.n_selected_features is not None: n_spatial_filters = self.n_top_bottom_csp_filters if n_spatial_filters is None: n_spatial_filters = len(self.sensor_names) n_max_features = len(self.filterbands) * n_spatial_filters assert n_max_features >= self.n_selected_features, ( "Cannot select more features than will be originally created " "Originally: {:d}, requested: {:d}".format( n_max_features, self.n_selected_features)) n_classes = len(self.marker_def) self.class_pairs = list(itertools.combinations(range(n_classes), 2)) # check that markers are all for trials for _, mrk_code in self.cnt.markers + self.test_cnt.markers: assert mrk_code in list(itertools.chain(*self.marker_def.values())) train_fold = range(len(self.cnt.markers)) test_fold = np.arange(len(self.test_cnt.markers)) + len(train_fold) self.folds = [{'train': train_fold, 'test': test_fold}] assert np.intersect1d(self.folds[0]['test'], self.folds[0]['train']).size == 0 # merge cnts!! self.cnt = append_cnt(self.cnt, self.test_cnt)
def test_append_cnt_copy(self): """append_cnt means must not modify argument.""" cpy = self.dat.copy() append_cnt(self.dat, self.dat) self.assertEqual(self.dat, cpy)