def test_temporaldataset_convert_to_dataset(self): measurements = np.zeros((10, 5, 15)) des = {'session': 0, 'subj': 0} obs_des = {'conds': np.array([0, 0, 1, 1, 2, 2, 2, 3, 4, 5])} chn_des = {'rois': np.array(['V1', 'V1', 'IT', 'IT', 'V4'])} tim_des = { 'time': np.linspace(0, 1000, 15), 'time_formatted': ['%0.0f ms' % (x) for x in np.linspace(0, 1000, 15)] } data_temporal = rsd.TemporalDataset(measurements=measurements, descriptors=des, obs_descriptors=obs_des, channel_descriptors=chn_des, time_descriptors=tim_des) data = data_temporal.convert_to_dataset('time') self.assertEqual(data.n_obs, 150) self.assertEqual(data.n_channel, 5) self.assertEqual(len(data.obs_descriptors['time']), 150) self.assertEqual(data.obs_descriptors['time'][0], tim_des['time'][0]) self.assertEqual(data.obs_descriptors['time'][10], tim_des['time'][1]) self.assertEqual(data.obs_descriptors['time_formatted'][10], tim_des['time_formatted'][1]) self.assertEqual(data.obs_descriptors['conds'][0], obs_des['conds'][0]) self.assertEqual(data.obs_descriptors['conds'][1], obs_des['conds'][1])
def test_temporaldataset_subset_time(self): measurements = np.zeros((10, 5, 15)) des = {'session': 0, 'subj': 0} obs_des = {'conds': np.array([0, 0, 1, 1, 2, 2, 2, 3, 4, 5])} chn_des = {'rois': np.array(['V1', 'V1', 'IT', 'IT', 'V4'])} tim_des = {'time': np.linspace(0, 1000, 15)} data = rsd.TemporalDataset(measurements=measurements, descriptors=des, obs_descriptors=obs_des, channel_descriptors=chn_des, time_descriptors=tim_des) subset = data.subset_time(by='time', t_from=tim_des['time'][3], t_to=tim_des['time'][3]) self.assertEqual(subset.n_obs, 10) self.assertEqual(subset.n_channel, 5) self.assertEqual(subset.n_time, 1) self.assertEqual(subset.time_descriptors['time'][0], tim_des['time'][3]) subset = data.subset_time(by='time', t_from=tim_des['time'][3], t_to=tim_des['time'][5]) self.assertEqual(subset.n_obs, 10) self.assertEqual(subset.n_channel, 5) self.assertEqual(subset.n_time, 3) self.assertEqual(subset.time_descriptors['time'][0], tim_des['time'][3]) self.assertEqual(subset.time_descriptors['time'][-1], tim_des['time'][5])
def test_temporaldataset_simple_init(self): measurements = np.zeros((10, 5, 15)) data = rsd.TemporalDataset(measurements) self.assertEqual(data.n_obs, 10) self.assertEqual(data.n_channel, 5) self.assertEqual(data.n_time, 15) self.assertEqual(len(data.time_descriptors['time']), 15) self.assertEqual(data.time_descriptors['time'][0], 0)
def test_temporaldataset_bin_time(self): measurements = np.random.randn(10, 5, 15) des = {'session': 0, 'subj': 0} obs_des = {'conds': np.array([0, 0, 1, 1, 2, 2, 2, 3, 4, 5])} chn_des = {'rois': np.array(['V1', 'V1', 'IT', 'IT', 'V4'])} tim_des = {'time': np.linspace(0, 1000, 15)} data = rsd.TemporalDataset(measurements=measurements, descriptors=des, obs_descriptors=obs_des, channel_descriptors=chn_des, time_descriptors=tim_des) bins = np.reshape(tim_des['time'], [5, 3]) binned_data = data.bin_time('time', bins) self.assertEqual(binned_data.n_obs, 10) self.assertEqual(binned_data.n_channel, 5) self.assertEqual(binned_data.n_time, 5) self.assertEqual(binned_data.time_descriptors['time'][0], np.mean(bins[0])) self.assertEqual(binned_data.measurements[0, 0, 0], np.mean(measurements[0, 0, :3]))
def test_temporaldataset_split_obs(self): measurements = np.zeros((10, 5, 15)) des = {'session': 0, 'subj': 0} obs_des = {'conds': np.array([0, 0, 1, 1, 2, 2, 2, 3, 4, 5])} chn_des = {'rois': np.array(['V1', 'V1', 'IT', 'IT', 'V4'])} tim_des = {'time': np.linspace(0, 1000, 15)} data = rsd.TemporalDataset(measurements=measurements, descriptors=des, obs_descriptors=obs_des, channel_descriptors=chn_des, time_descriptors=tim_des) splited_list = data.split_obs('conds') self.assertEqual(len(splited_list), 6) self.assertEqual(splited_list[0].n_obs, 2) self.assertEqual(splited_list[2].n_obs, 3) self.assertEqual(splited_list[0].n_channel, 5) self.assertEqual(splited_list[2].n_channel, 5) self.assertEqual(splited_list[0].n_time, 15) self.assertEqual(splited_list[2].n_time, 15) self.assertEqual(splited_list[2].obs_descriptors['conds'][0], 2)
def test_temporaldataset_full_init(self): measurements = np.zeros((10, 5, 15)) des = {'session': 0, 'subj': 0} obs_des = { 'conds': np.array(['cond_' + str(x) for x in np.arange(10)]) } chn_des = {'rois': np.array(['roi_' + str(x) for x in np.arange(5)])} tim_des = {'time': np.linspace(0, 1000, 15)} data = rsd.TemporalDataset(measurements=measurements, descriptors=des, obs_descriptors=obs_des, channel_descriptors=chn_des, time_descriptors=tim_des) self.assertEqual(data.n_obs, 10) self.assertEqual(data.n_channel, 5) self.assertEqual(data.n_time, 15) self.assertEqual(data.descriptors, des) self.assertEqual(data.obs_descriptors, obs_des) self.assertEqual(data.channel_descriptors, chn_des) self.assertEqual(data.time_descriptors, tim_des)