Exemple #1
0
    def test_write_image_stream(self, image_size, bytes_per_voxel, is_signed, start_coords, num_voxels_to_write):
        file_factory = file_wrapper.FileHandleFactory()

        wrapper = file_wrapper.HugeFileWrapper('/test/test_write_image_stream.bin', file_factory, 'wb')
        file_streamer = HugeFileStreamer(wrapper, image_size, bytes_per_voxel,
                                         TestHugeFileStreamer.get_np_type(bytes_per_voxel, is_signed))
        start = start_coords[0] + start_coords[1]*image_size[0] + start_coords[2]*image_size[0]*image_size[1]
        # end = start + num_voxels_to_write
        to_write_voxels = [0] * num_voxels_to_write
        for index in range(0, num_voxels_to_write):
            to_write_voxels[index] = index + 12

        base_data_numpy = TestHugeFileStreamer.generate_array(image_size[0]*image_size[1]*image_size[2],
                                                              bytes_per_voxel, is_signed)
        expected = base_data_numpy.copy()
        to_write_numpy = np.asarray(to_write_voxels, dtype=TestHugeFileStreamer.get_np_type(bytes_per_voxel, is_signed))
        file_streamer.write_image_stream([0, 0, 0], base_data_numpy)
        file_streamer.write_image_stream(start_coords, to_write_numpy)
        file_streamer.close()
        read_file_contents = TestHugeFileStreamer.read_from_fake_file('/test/test_write_image_stream.bin',
                                                                      bytes_per_voxel, is_signed)
        for index in range(0, num_voxels_to_write):
            expected[index + start] = to_write_voxels[index]

        expected = np.asarray(expected, dtype=TestHugeFileStreamer.get_np_type(bytes_per_voxel, is_signed))
        self.assertTrue(np.array_equal(expected, read_file_contents))
Exemple #2
0
 def test_open_with(self, image_size, bytes_per_voxel, start_coords, num_voxels_to_read):
     fake_file = FakeFile(range(0, image_size[0]*image_size[1]*image_size[2]-1), bytes_per_voxel)
     fake_file_factory = FakeFileHandleFactory(fake_file)
     self.assertEqual(fake_file.closed, True)
     with file_wrapper.HugeFileWrapper("abc", fake_file_factory, 'rb') as wrapper:
         self.assertEqual(fake_file.closed, False)
     self.assertEqual(fake_file.closed, True)
Exemple #3
0
 def test_get_handle(self, image_size, bytes_per_voxel, start_coords, num_voxels_to_read):
     fake_file = FakeFile(range(0, image_size[0]*image_size[1]*image_size[2]-1), bytes_per_voxel)
     fake_file_factory = FakeFileHandleFactory(fake_file)
     wrapper = file_wrapper.HugeFileWrapper("abc", fake_file_factory, 'rb')
     self.assertEqual(fake_file.closed, True)
     self.assertEqual(wrapper.get_handle(), fake_file)
     self.assertEqual(fake_file.filename, "abc")
     self.assertEqual(fake_file.mode, "rb")
     self.assertEqual(fake_file.closed, False)
Exemple #4
0
    def test_read_image_stream(self, image_size, bytes_per_voxel, is_signed, start_coords, num_voxels_to_read):

        # Create a fake file of random data within the full range of this datatype
        base_data_numpy = TestHugeFileStreamer.generate_array(image_size[0]*image_size[1]*image_size[2],
                                                              bytes_per_voxel, is_signed)

        TestHugeFileStreamer.write_to_fake_file('/test/test_read_image_stream.bin', base_data_numpy, bytes_per_voxel,
                                                is_signed)
        file_factory = file_wrapper.FileHandleFactory()
        wrapper = file_wrapper.HugeFileWrapper('/test/test_read_image_stream.bin', file_factory, 'rb')
        file_streamer = HugeFileStreamer(wrapper, image_size, bytes_per_voxel,
                                         TestHugeFileStreamer.get_np_type(bytes_per_voxel, is_signed))
        start = start_coords[0] + start_coords[1]*image_size[0] + start_coords[2]*image_size[0]*image_size[1]
        end = start + num_voxels_to_read
        expected = base_data_numpy[start:end]
        read_file_contents = file_streamer.read_image_stream(start_coords, num_voxels_to_read)
        expected = np.asarray(expected, dtype=TestHugeFileStreamer.get_np_type(bytes_per_voxel, is_signed))
        self.assertTrue(np.array_equal(expected, read_file_contents))