def testIteratorAccess2(self): reader = FeatureReader([self.trajfile, self.trajfile], self.topfile) reader.chunksize = 100 frames = 0 data = [] for i, X in reader: frames += X.shape[0] data.append(X) self.assertEqual(frames, reader.trajectory_lengths()[0] * 2) # restore shape of input data = np.array( data[0:reader.trajectory_lengths()[0] / reader.chunksize]).reshape(self.xyz.shape) self.assertTrue(np.allclose(data, self.xyz))
def testIteratorAccess2(self): reader = FeatureReader([self.trajfile, self.trajfile], self.topfile) reader.chunksize = 100 frames = 0 data = [] for i, X in reader: frames += X.shape[0] data.append(X) self.assertEqual(frames, reader.trajectory_lengths()[0] * 2) # restore shape of input data = np.array(data[0:reader.trajectory_lengths()[0] / reader.chunksize]).reshape(self.xyz.shape) self.assertTrue(np.allclose(data, self.xyz))
def testTimeLaggedIterator(self): lag = 10 reader = FeatureReader(self.trajfile, self.topfile) frames = 0 data = [] lagged = [] for _, X, Y in reader.iterator(lag=lag): frames += X.shape[0] data.append(X) lagged.append(Y) assert len(data) == len(lagged) # .reshape(self.xyz.shape) merged_lagged = np.concatenate(lagged, axis=0) # reproduce outcome xyz_s = self.xyz.shape fake_lagged = self.xyz.reshape((xyz_s[0], -1))[lag:] self.assertTrue(np.allclose(merged_lagged, fake_lagged)) # restore shape of input data = np.vstack(data).reshape(self.xyz[lag:].shape) self.assertEqual(frames, reader.trajectory_lengths()[0] - lag) self.assertTrue(np.allclose(data, self.xyz[:len(self.xyz) - lag]))
def testTimeLaggedIterator(self): lag = 10 reader = FeatureReader(self.trajfile, self.topfile) frames = 0 data = [] lagged = [] for _, X, Y in reader.iterator(lag=lag): frames += X.shape[0] data.append(X) lagged.append(Y) assert len(data) == len(lagged) merged_lagged = np.concatenate(lagged, axis=0) # .reshape(self.xyz.shape) # reproduce outcome xyz_s = self.xyz.shape fake_lagged = np.empty((xyz_s[0]-lag, xyz_s[1]*xyz_s[2])) fake_lagged = self.xyz.reshape((xyz_s[0], -1))[lag:] self.assertTrue(np.allclose(merged_lagged, fake_lagged)) # restore shape of input data = np.array(data).reshape(self.xyz.shape) self.assertEqual(frames, reader.trajectory_lengths()[0]) self.assertTrue(np.allclose(data, self.xyz))