diff options
-rwxr-xr-x | Wrappers/Python/ccpi/framework/TestData.py | 6 | ||||
-rw-r--r-- | Wrappers/Python/setup.py | 2 | ||||
-rwxr-xr-x | Wrappers/Python/test/test_TestData.py | 111 |
3 files changed, 107 insertions, 12 deletions
diff --git a/Wrappers/Python/ccpi/framework/TestData.py b/Wrappers/Python/ccpi/framework/TestData.py index b512e81..eda14ab 100755 --- a/Wrappers/Python/ccpi/framework/TestData.py +++ b/Wrappers/Python/ccpi/framework/TestData.py @@ -36,9 +36,9 @@ class TestData(object): if which == TestData.SIMPLE_PHANTOM_2D:
N = size[0]
M = size[1]
- sdata = numpy.zeros((N,M))
- sdata[round(N/4):round(3*N/4),round(N/4):round(3*N/4)] = 0.5
- sdata[round(M/8):round(7*M/8),round(3*M/8):round(5*M/8)] = 1
+ sdata = numpy.zeros((N, M))
+ sdata[int(round(N/4)):int(round(3*N/4)), int(round(N/4)):int(round(3*N/4))] = 0.5
+ sdata[int(round(M/8)):int(round(7*M/8)), int(round(3*M/8)):int(round(5*M/8))] = 1
ig = ImageGeometry(voxel_num_x = N, voxel_num_y = M, dimension_labels=[ImageGeometry.HORIZONTAL_X, ImageGeometry.HORIZONTAL_Y])
data = ig.allocate()
data.fill(sdata)
diff --git a/Wrappers/Python/setup.py b/Wrappers/Python/setup.py index 8bd33a6..9e9b1f5 100644 --- a/Wrappers/Python/setup.py +++ b/Wrappers/Python/setup.py @@ -41,7 +41,7 @@ setup( 'ccpi.contrib.optimisation.algorithms'], data_files = [('share/ccpi', ['data/boat.tiff', 'data/peppers.tiff', 'data/camera.png', - 'data/resolution_chart.tiff'])], + 'data/resolution_chart.tiff', 'data/shapes.png'])], # Project uses reStructuredText, so ensure that the docutils get # installed or upgraded on the target machine diff --git a/Wrappers/Python/test/test_TestData.py b/Wrappers/Python/test/test_TestData.py index 3b26612..fa0b98f 100755 --- a/Wrappers/Python/test/test_TestData.py +++ b/Wrappers/Python/test/test_TestData.py @@ -1,19 +1,114 @@ - import numpy from ccpi.framework import TestData import os, sys -sys.path.append( os.path.dirname( os.path.abspath(__file__) ) ) +sys.path.append(os.path.dirname(os.path.abspath(__file__))) from testclass import CCPiTestClass - +import unittest class TestTestData(CCPiTestClass): def test_random_noise(self): - #loader = TestData(data_dir=os.path.join(sys.prefix, 'share','ccpi')) - #data_dir=os.path.join(os.path.dirname(__file__),'..', 'data') + # loader = TestData(data_dir=os.path.join(sys.prefix, 'share','ccpi')) + # data_dir=os.path.join(os.path.dirname(__file__),'..', 'data') loader = TestData() - camera = loader.load(TestData.CAMERA) - noisy_camera = TestData.random_noise(camera, seed=1) - norm = (camera-noisy_camera).norm() + norm = (camera - noisy_camera).norm() self.assertAlmostEqual(norm, 48.881268, places=4) + + def test_load_CAMERA(self): + + loader = TestData() + res = False + try: + image = loader.load(TestData.CAMERA) + if (image.shape[0] == 512) and (image.shape[1] == 512): + res = True + else: + print("Image dimension mismatch") + except FileNotFoundError: + print("File not found") + except: + print("Failed to load file") + + self.assertTrue(res) + + + def test_load_BOAT(self): + loader = TestData() + res = False + try: + image = loader.load(TestData.BOAT) + if (image.shape[0] == 512) and (image.shape[1] == 512): + res = True + else: + print("Image dimension mismatch") + except FileNotFoundError: + print("File not found") + except: + print("Failed to load file") + + self.assertTrue(res) + + def test_load_PEPPERS(self): + loader = TestData() + res = False + try: + image = loader.load(TestData.PEPPERS) + if (image.shape[0] == 512) and (image.shape[1] == 512) and (image.shape[2] == 3): + res = True + else: + print("Image dimension mismatch") + except FileNotFoundError: + print("File not found") + except: + print("Failed to load file") + + self.assertTrue(res) + + def test_load_RESOLUTION_CHART(self): + loader = TestData() + res = False + try: + image = loader.load(TestData.RESOLUTION_CHART) + if (image.shape[0] == 512) and (image.shape[1] == 512): + res = True + else: + print("Image dimension mismatch") + except FileNotFoundError: + print("File not found") + except: + print("Failed to load file") + + self.assertTrue(res) + + def test_load_SIMPLE_PHANTOM_2D(self): + loader = TestData() + res = False + try: + image = loader.load(TestData.SIMPLE_PHANTOM_2D) + if (image.shape[0] == 512) and (image.shape[1] == 512): + res = True + else: + print("Image dimension mismatch") + except FileNotFoundError: + print("File not found") + except: + print("Failed to load file") + + self.assertTrue(res) + + def test_load_SHAPES(self): + loader = TestData() + res = False + try: + image = loader.load(TestData.SHAPES) + if (image.shape[0] == 200) and (image.shape[1] == 300): + res = True + else: + print("Image dimension mismatch") + except FileNotFoundError: + print("File not found") + except: + print("Failed to load file") + + self.assertTrue(res) |