def test_ill_coodinates(self): with self.assertRaisesRegexp(IndexError, ""): coords = rand_spatial_coordinates(subject_id=1, img_sizes={ 'image': (42, 42, 1, 1, 1), 'label': (42, 42, 1, 1, 1) }, win_sizes={ 'image': (23, 23), 'label': (40, 32) }, n_samples=10) with self.assertRaisesRegexp(TypeError, ""): coords = rand_spatial_coordinates(subject_id=1, img_sizes={ 'image': (42, 42, 1, 1, 1), 'label': (42, 42, 1, 1, 1) }, win_sizes={ 'image': (23, 23, 1), 'label': (40, 32, 1) }, n_samples='test') with self.assertRaisesRegexp(AssertionError, ""): coords = rand_spatial_coordinates( subject_id=1, img_sizes={'label': (42, 1, 1, 1)}, win_sizes={'image': (23, 23, 1)}, n_samples=0)
def test_ill_coordinates(self): with self.assertRaisesRegexp(IndexError, ""): coords = rand_spatial_coordinates( subject_id=1, data={}, img_sizes={'image': (42, 42, 1, 1, 1), 'label': (42, 42, 1, 1, 1)}, win_sizes={'image': (23, 23), 'label': (40, 32)}, n_samples=10) with self.assertRaisesRegexp(TypeError, ""): coords = rand_spatial_coordinates( subject_id=1, data={}, img_sizes={'image': (42, 42, 1, 1, 1), 'label': (42, 42, 1, 1, 1)}, win_sizes={'image': (23, 23, 1), 'label': (40, 32, 1)}, n_samples='test') with self.assertRaisesRegexp(AssertionError, ""): coords = rand_spatial_coordinates( subject_id=1, data={}, img_sizes={'label': (42, 1, 1, 1)}, win_sizes={'image': (23, 23, 1)}, n_samples=0)
def test_2d_coordinates(self): cropped_map = np.zeros((256, 512, 1)) img_size = [8, 9, 1] win_size = [8, 8, 1] coords = rand_spatial_coordinates(64, img_size, win_size, None) self.assertAllEqual(coords.shape, (64, N_SPATIAL)) self.assertCoordinatesAreValid(coords, img_size, win_size)
def test_3d_coordinates(self): img_size = [8, 9, 10] win_size = [7, 9, 4] coords = rand_spatial_coordinates( 32, img_size, win_size, None) self.assertAllEqual(coords.shape, (32, N_SPATIAL)) self.assertCoordinatesAreValid(coords, img_size, win_size)
def test_1d_coordinates(self): cropped_map = np.zeros((1, 1, 1)) img_size = [4, 1, 1] win_size = [2, 1, 1] coords = rand_spatial_coordinates(20, img_size, win_size, None) print(coords) self.assertAllEqual(coords.shape, (20, N_SPATIAL)) self.assertCoordinatesAreValid(coords, img_size, win_size)
def test_2d_coordinates(self): cropped_map=np.zeros((256, 512, 1)) img_size = [8, 9, 1] win_size = [8, 8, 1] coords = rand_spatial_coordinates( 64, img_size, win_size, None) self.assertAllEqual(coords.shape, (64, N_SPATIAL)) self.assertCoordinatesAreValid(coords, img_size, win_size)
def test_1d_coordinates(self): cropped_map=np.zeros((1, 1, 1)) img_size = [4, 1, 1] win_size = [2, 1, 1] coords = rand_spatial_coordinates( 20, img_size, win_size, None) print(coords) self.assertAllEqual(coords.shape, (20, N_SPATIAL)) self.assertCoordinatesAreValid(coords, img_size, win_size)
def test_2D_coordinates(self): coords = rand_spatial_coordinates( subject_id=1, data={}, img_sizes={'image': (42, 42, 1, 1, 1), 'label': (42, 42, 1, 1, 1)}, win_sizes={'image': (23, 23, 1), 'label': (40, 32, 1)}, n_samples=10) self.assertEquals(np.all(coords['image'][:0] == 1), True) self.assertEquals(coords['image'].shape, (10, 7)) self.assertEquals(coords['label'].shape, (10, 7)) self.assertAllClose( (coords['image'][:, 4] + coords['image'][:, 1]), (coords['label'][:, 4] + coords['label'][:, 1]), atol=1.0) self.assertAllClose( (coords['image'][:, 5] + coords['image'][:, 2]), (coords['label'][:, 5] + coords['label'][:, 2]), atol=1.0) self.assertAllClose( (coords['image'][:, 6] + coords['image'][:, 3]), (coords['label'][:, 6] + coords['label'][:, 3]), atol=1.0)
def test_2D_coodinates(self): coords = rand_spatial_coordinates(subject_id=1, img_sizes={ 'image': (42, 42, 1, 1, 1), 'label': (42, 42, 1, 1, 1) }, win_sizes={ 'image': (23, 23, 1), 'label': (40, 32, 1) }, n_samples=10) self.assertEquals(np.all(coords['image'][:0] == 1), True) self.assertEquals(coords['image'].shape, (10, 7)) self.assertEquals(coords['label'].shape, (10, 7)) self.assertAllClose((coords['image'][:, 4] + coords['image'][:, 1]), (coords['label'][:, 4] + coords['label'][:, 1]), atol=1.0) self.assertAllClose((coords['image'][:, 5] + coords['image'][:, 2]), (coords['label'][:, 5] + coords['label'][:, 2]), atol=1.0) self.assertAllClose((coords['image'][:, 6] + coords['image'][:, 3]), (coords['label'][:, 6] + coords['label'][:, 3]), atol=1.0)
def test_3d_coordinates(self): img_size = [8, 9, 10] win_size = [7, 9, 4] coords = rand_spatial_coordinates(32, img_size, win_size, None) self.assertAllEqual(coords.shape, (32, N_SPATIAL)) self.assertCoordinatesAreValid(coords, img_size, win_size)