From 4800bb1280713da858b65e2282c93b4586fce65d Mon Sep 17 00:00:00 2001 From: Gemma Fardell Date: Fri, 21 Jun 2019 11:40:39 +0100 Subject: added shapes.png to setup.py --- Wrappers/Python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/setup.py b/Wrappers/Python/setup.py index 8bd33a6..84462ea 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 -- cgit v1.2.3 From ab4035cc0d8e0ad3faf83396bf8bc097c8b99c05 Mon Sep 17 00:00:00 2001 From: Gemma Fardell Date: Fri, 21 Jun 2019 11:56:51 +0100 Subject: added shapes.png to setup.py --- Wrappers/Python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/setup.py b/Wrappers/Python/setup.py index 84462ea..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/shapes.png])], + 'data/resolution_chart.tiff', 'data/shapes.png'])], # Project uses reStructuredText, so ensure that the docutils get # installed or upgraded on the target machine -- cgit v1.2.3 From b83fdeb39c1eb7a5e05fb7326a543079cb6b7d27 Mon Sep 17 00:00:00 2001 From: Gemma Fardell Date: Fri, 21 Jun 2019 16:53:45 +0100 Subject: Added unittests for test data --- Wrappers/Python/test/test_TestData.py | 78 +++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 7 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/test/test_TestData.py b/Wrappers/Python/test/test_TestData.py index 3b26612..c4a0a70 100755 --- a/Wrappers/Python/test/test_TestData.py +++ b/Wrappers/Python/test/test_TestData.py @@ -1,19 +1,83 @@ - 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 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() + image = loader.load(TestData.CAMERA) + + if image: + res = True + else: + res = False + + self.assertTrue(res) + + def test_load_BOAT(self): + loader = TestData() + image = loader.load(TestData.BOAT) + + if image: + res = True + else: + res = False + + self.assertTrue(res) + + def test_load_PEPPERS(self): + loader = TestData() + image = loader.load(TestData.PEPPERS) + + if image: + res = True + else: + res = False + + self.assertTrue(res) + + def test_load_RESOLUTION_CHART(self): + loader = TestData() + image = loader.load(TestData.RESOLUTION_CHART) + + if image: + res = True + else: + res = False + + self.assertTrue(res) + + def test_load_SIMPLE_PHANTOM_2D(self): + loader = TestData() + image = loader.load(TestData.SIMPLE_PHANTOM_2D) + + if image: + res = True + else: + res = False + + self.assertTrue(res) + + def test_load_SHAPES(self): + loader = TestData() + image = loader.load(TestData.SHAPES) + + if image: + res = True + else: + res = False + + self.assertTrue(res) -- cgit v1.2.3 From b49e77382db690ccacde93b7b947753b930f5458 Mon Sep 17 00:00:00 2001 From: Gemma Fardell Date: Mon, 24 Jun 2019 10:50:17 +0100 Subject: bug fix on generating test data --- Wrappers/Python/ccpi/framework/TestData.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Wrappers') 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) -- cgit v1.2.3 From 4235e71a4de64130228097907134f78bd9e22798 Mon Sep 17 00:00:00 2001 From: Gemma Fardell Date: Mon, 24 Jun 2019 14:44:06 +0100 Subject: Unit tests on test image loading and image size --- Wrappers/Python/test/test_TestData.py | 107 ++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 38 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/test/test_TestData.py b/Wrappers/Python/test/test_TestData.py index c4a0a70..fa0b98f 100755 --- a/Wrappers/Python/test/test_TestData.py +++ b/Wrappers/Python/test/test_TestData.py @@ -1,10 +1,9 @@ import numpy from ccpi.framework import TestData import os, sys - sys.path.append(os.path.dirname(os.path.abspath(__file__))) from testclass import CCPiTestClass - +import unittest class TestTestData(CCPiTestClass): def test_random_noise(self): @@ -17,67 +16,99 @@ class TestTestData(CCPiTestClass): self.assertAlmostEqual(norm, 48.881268, places=4) def test_load_CAMERA(self): - loader = TestData() - image = loader.load(TestData.CAMERA) - if image: - res = True - else: - res = False + 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() - image = loader.load(TestData.BOAT) - - if image: - res = True - else: - res = False + 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() - image = loader.load(TestData.PEPPERS) - - if image: - res = True - else: - res = False + 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() - image = loader.load(TestData.RESOLUTION_CHART) - - if image: - res = True - else: - res = False + 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() - image = loader.load(TestData.SIMPLE_PHANTOM_2D) - - if image: - res = True - else: - res = False + 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() - image = loader.load(TestData.SHAPES) - - if image: - res = True - else: - res = False + 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) -- cgit v1.2.3