def test_skip(self): for skip in [0, 3, 13]: r1 = NumPyFileReader(self.npy_files[0]) out_with_skip = r1.get_output(skip=skip)[0] r2 = NumPyFileReader(self.npy_files[0]) out = r2.get_output()[0] np.testing.assert_almost_equal( out_with_skip, out[skip::], err_msg="The first %s rows were skipped, but that did not " "match the rows with skip=0 and sliced by [%s::]" % (skip, skip))
def test_skip_input_list(self): for skip in [0, 3, 13]: r1 = NumPyFileReader(self.npy_files) out_with_skip = r1.get_output(skip=skip) r2 = NumPyFileReader(self.npy_files) out = r2.get_output() for i in range(0, len(self.npy_files)): np.testing.assert_almost_equal( out_with_skip[i], out[i][skip::], err_msg= "The first %s rows of the %s'th file were skipped, but that did not " "match the rows with skip=0 and sliced by [%s::]" % (skip, i, skip))
def test_stridden_access(self): reader = NumPyFileReader(self.f1) reader.chunksize = 10 wanted = np.load(self.f1) for stride in [2, 3, 5, 7, 15]: first_traj = reader.get_output(stride=stride)[0] np.testing.assert_equal(first_traj, wanted[::stride], "did not match for stride %i" % stride)
def test_stridden_access(self): reader = NumPyFileReader(self.f1) reader.chunksize = 10 wanted = np.load(self.f1) for stride in [2, 3, 5, 7, 15]: first_traj = reader.get_output(stride=stride)[0] np.testing.assert_equal(first_traj, wanted[::stride], "did not match for stride %i" % stride)
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 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_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_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 load_from_files(cls, files): """ construct this by loading all files into memory Parameters ---------- files: str or list of str filenames to read from """ # import here to avoid cyclic import from pyemma.coordinates.data.numpy_filereader import NumPyFileReader reader = NumPyFileReader(files) data = reader.get_output() return cls(data)
def load_from_files(cls, files): """ construct this by loading all files into memory Parameters ---------- files: str or list of str filenames to read from """ # import here to avoid cyclic import from pyemma.coordinates.data.numpy_filereader import NumPyFileReader reader = NumPyFileReader(files) data = reader.get_output() return cls(data)