Пример #1
0
 def __next__(self):
     """
     Return in each iteration the data from a single file
     """
     if self.__curr_index < len(channel_files):
         newfp = np.memmap(channel_files[self.__curr_index],
                           dtype='float64', mode='r', shape=(self.num_steps,))
         curr_data = newfp[:]
         i = self.__curr_index
         self.__curr_index += 1
         del newfp
         return DataChunk(data=curr_data,
                          selection=np.s_[:, i])
     else:
         raise StopIteration
Пример #2
0
 def __next__(self):
     """
     Return in each iteration a fully occupied data chunk of self.chunk_shape values at a random
     location within the matrix. Chunks are non-overlapping. REMEMBER: h5py does not support all
     fancy indexing that numpy does so we need to make sure our selection can be
     handled by the backend.
     """
     if self.__chunks_created < self.num_chunks:
         data = np.random.rand(np.prod(self.chunk_shape)).reshape(self.chunk_shape)
         xmin = np.random.randint(0, int(self.shape[0] / self.chunk_shape[0]), 1)[0] * self.chunk_shape[0]
         xmax = xmin + self.chunk_shape[0]
         ymin = np.random.randint(0, int(self.shape[1] / self.chunk_shape[1]), 1)[0] * self.chunk_shape[1]
         ymax = ymin + self.chunk_shape[1]
         self.__chunks_created += 1
         return DataChunk(data=data,
                          selection=np.s_[xmin:xmax, ymin:ymax])
     else:
         raise StopIteration
Пример #3
0
 def test_len_operator_with_data(self):
     temp = DataChunk(np.arange(10).reshape(5, 2))
     self.assertEqual(len(temp), 5)
Пример #4
0
 def test_len_operator_no_data(self):
     temp = DataChunk()
     self.assertEqual(len(temp), 0)