def test_only_npy(self): reader = NumPyFileReader(self.npy_files) from_files = [np.load(f) for f in self.npy_files] concatenated = np.vstack(from_files) output = reader.get_output() self.assertEqual(reader.number_of_trajectories(), len(self.npy_files)) self.assertEqual(reader.n_frames_total(), concatenated.shape[0]) for x, y in zip(output, from_files): np.testing.assert_array_almost_equal(x, y)
def test_npz(self): reader = NumPyFileReader(self.npz) all_data = reader.get_output() fh = np.load(self.npz) data = [x[1] for x in fh.items()] fh.close() self.assertEqual(reader.number_of_trajectories(), len(data)) for outp, inp in zip(all_data, data): np.testing.assert_equal(outp, inp)
def test_npz(self): reader = NumPyFileReader(self.npz) all_data = reader.get_output() fh = np.load(self.npz) data = [x[1] for x in list(fh.items())] fh.close() self.assertEqual(reader.number_of_trajectories(), len(data)) for outp, inp in zip(all_data, data): np.testing.assert_equal(outp, inp)
def test_only_npy(self): reader = NumPyFileReader(self.npy_files) from_files = [np.load(f) for f in self.npy_files] concatenated = np.vstack(from_files) output = reader.get_output() self.assertEqual(reader.number_of_trajectories(), len(self.npy_files)) self.assertEqual(reader.n_frames_total(), concatenated.shape[0]) for x, y in zip(output, from_files): np.testing.assert_array_almost_equal(x, y)
def test_lagged_stridden_access_multiple_files(self): reader = NumPyFileReader(self.files2d) strides = [2, 3, 5, 7, 15] lags = [1, 3, 7, 10, 30] for stride in strides: for lag in lags: chunks = { i: [] for i in range(reader.number_of_trajectories()) } for itraj, _, Y in reader.iterator(stride, lag): chunks[itraj].append(Y) for i, k in enumerate(chunks.values()): stack = np.vstack(k) d = np.load(self.files2d[i]) np.testing.assert_equal( stack, d[lag::stride], "not equal for stride=%i" " and lag=%i" % (stride, lag))