def test_loading(self): """Test various loading schemes.""" # load demo images CBCT.from_demo_images() # load from folder directly folder = osp.join(varian_test_file_dir, 'Pelvis') CBCT(folder) # load from zip file zfile = osp.join(varian_test_file_dir, 'Pelvis.zip') CBCT.from_zip_file(zfile)
class Test_General(unittest.TestCase): """Test general things when using cbct module.""" def setUp(self): self.cbct = CBCT() def test_demo(self): """Run the demo to make sure it works.""" self.cbct.run_demo(show=False) def test_images_not_loaded(self): """Raise error if trying to analyze when images aren't loaded yet.""" self.assertRaises(AttributeError, self.cbct.analyze) def test_bad_files(self): """Test bad file inputs.""" not_a_folder = "notafolder" self.assertRaises(NotADirectoryError, self.cbct.load_folder, not_a_folder) not_a_zip = "notazip.zip" self.assertRaises(FileExistsError, self.cbct.load_zip_file, not_a_zip) not_image_folder = osp.join(osp.dirname(__file__), 'core') self.assertRaises(FileNotFoundError, self.cbct.load_folder, not_image_folder) def test_too_few_images_loaded(self): """Test when too few images are given to be loaded.""" pass def test_phan_center(self): """Test locations of the phantom center.""" self.cbct.load_demo_images() known_phan_center = Point(257, 255) self.cbct._construct_HU() self.assertAlmostEqual(self.cbct.HU.phan_center.x, known_phan_center.x, delta=0.7) self.assertAlmostEqual(self.cbct.HU.phan_center.y, known_phan_center.y, delta=0.7) # test a shifted image set shifted_phan_center = Point(287, 255) self.cbct.settings.images = np.roll(self.cbct.settings.images, 30, axis=1) self.cbct._construct_HU() self.assertAlmostEqual(self.cbct.HU.phan_center.x, shifted_phan_center.x, delta=0.7) self.assertAlmostEqual(self.cbct.HU.phan_center.y, shifted_phan_center.y, delta=0.7)
def setUp(self): self.cbct = CBCT()
def setUpClass(cls): cls.cbct = CBCT.from_demo_images()
class Test_General(unittest.TestCase): """Test general things when using cbct module.""" def setUp(self): self.cbct = CBCT() def test_demo(self): """Run the demo to make sure it works.""" self.cbct.run_demo() def test_loading(self): """Test various loading schemes.""" # load demo images CBCT.from_demo_images() # load from folder directly folder = osp.join(varian_test_file_dir, 'Pelvis') CBCT(folder) # load from zip file zfile = osp.join(varian_test_file_dir, 'Pelvis.zip') CBCT.from_zip_file(zfile) def test_images_not_loaded(self): """Raise error if trying to analyze when images aren't loaded yet.""" self.assertRaises(AttributeError, self.cbct.analyze) def test_bad_files(self): """Test bad file inputs.""" not_a_folder = "notafolder" self.assertRaises(NotADirectoryError, self.cbct.load_folder, not_a_folder) not_a_zip = "notazip.zip" self.assertRaises(FileExistsError, self.cbct.load_zip_file, not_a_zip) not_image_folder = osp.join(osp.dirname(__file__), 'core') self.assertRaises(FileNotFoundError, self.cbct.load_folder, not_image_folder) no_CT_images_zip = osp.join(varian_test_file_dir, 'dummy.zip') self.assertRaises(FileNotFoundError, self.cbct.load_zip_file, no_CT_images_zip) def test_images_not_from_same_study(self): """Loading images from different studies should raise and error.""" mixed_zip = osp.join(varian_test_file_dir, 'mixed_studies.zip') with self.assertRaises(InvalidDicomError): self.cbct.load_zip_file(mixed_zip) def test_phan_center(self): """Test locations of the phantom center.""" self.cbct.load_demo_images() known_phan_center = Point(257, 255) self.cbct._construct_HU() self.assertAlmostEqual(self.cbct.HU.phan_center.x, known_phan_center.x, delta=0.7) self.assertAlmostEqual(self.cbct.HU.phan_center.y, known_phan_center.y, delta=0.7) # test a shifted image set shifted_phan_center = Point(287, 255) self.cbct.settings.images = np.roll(self.cbct.settings.images, 30, axis=1) self.cbct._construct_HU() self.assertAlmostEqual(self.cbct.HU.phan_center.x, shifted_phan_center.x, delta=0.7) self.assertAlmostEqual(self.cbct.HU.phan_center.y, shifted_phan_center.y, delta=0.7) @unittest.skip def test_finding_HU_slice(self): """Test the robustness of the algorithm to find the HU linearity slice.""" self.cbct.load_demo_images() self.assertEqual(self.cbct.settings.hu_slice_num, 32) # roll the phantom data by 4 slices np.roll(self.cbct.settings.images, 4, axis=2) def test_save_image(self): """Test that saving an image does something.""" filename = 'saved_img.jpg' self.cbct.load_demo_images() self.cbct.analyze(hu_tolerance=10, scaling_tolerance=0.01) for method in ['save_analyzed_image', 'save_analyzed_subimage']: methodcall = getattr(self.cbct, method) methodcall(filename) time.sleep(0.1) # sleep just to let OS work self.assertTrue(osp.isfile(filename), "Save file did not successfully save the image") # cleanup os.remove(filename) self.assertFalse(osp.isfile(filename), "Save file test did not clean up saved image") def test_plot_images(self): """Test the various plotting functions.""" self.cbct.load_demo_images() self.cbct.analyze() self.cbct.plot_analyzed_image() for item in ['hu', 'unif', 'mtf', 'sr']: self.cbct.plot_analyzed_subimage(item) with self.assertRaises(ValueError): self.cbct.plot_analyzed_subimage('srunif')
def setUpClass(cls): if cls.zip: cls.cbct = CBCT.from_zip_file(cls.location) else: cls.cbct = CBCT(cls.location)
class GeneralTests(unittest.TestCase): """Test general things when using cbct module.""" def setUp(self): self.cbct = CBCT() def test_demo(self): """Run the demo to make sure it works.""" self.cbct.run_demo() def test_helpers(self): """Test the various helper methods.""" self.cbct.load_demo_images() self.cbct.analyze() self.cbct._return_results() def test_loading(self): """Test various loading schemes.""" # load demo images CBCT.from_demo_images() # load from folder directly folder = osp.join(varian_test_file_dir, 'Pelvis') CBCT(folder) # load from zip file zfile = osp.join(varian_test_file_dir, 'Pelvis.zip') CBCT.from_zip_file(zfile) def test_images_not_loaded(self): """Raise error if trying to analyze when images aren't loaded yet.""" self.assertRaises(AttributeError, self.cbct.analyze) def test_bad_files(self): """Test bad file inputs.""" not_a_folder = "notafolder" self.assertRaises(NotADirectoryError, self.cbct.load_folder, not_a_folder) not_a_zip = "notazip.zip" self.assertRaises(FileExistsError, self.cbct.load_zip_file, not_a_zip) not_image_folder = osp.join(osp.dirname(__file__), 'core') self.assertRaises(FileNotFoundError, self.cbct.load_folder, not_image_folder) no_CT_images_zip = osp.join(varian_test_file_dir, 'dummy.zip') self.assertRaises(FileNotFoundError, self.cbct.load_zip_file, no_CT_images_zip) @unittest.expectedFailure def test_images_not_from_same_study(self): """Loading images from different studies should raise and error.""" mixed_zip = osp.join(varian_test_file_dir, 'mixed_studies.zip') with self.assertRaises(ValueError): self.cbct.load_zip_file(mixed_zip) def test_phan_center(self): """Test locations of the phantom center.""" self.cbct.load_demo_images() known_phan_center = Point(257, 255) self.cbct.analyze() self.assertAlmostEqual(self.cbct.hu.phan_center.x, known_phan_center.x, delta=0.7) self.assertAlmostEqual(self.cbct.hu.phan_center.y, known_phan_center.y, delta=0.7) @unittest.skip def test_finding_HU_slice(self): """Test the robustness of the algorithm to find the HU linearity slice.""" self.cbct.load_demo_images() self.assertEqual(self.cbct.settings.hu_slice_num, 32) # roll the phantom data by 4 slices np.roll(self.cbct.settings.images, 4, axis=2) def test_save_image(self): """Test that saving an image does something.""" self.cbct.load_demo_images() self.cbct.analyze(hu_tolerance=10, scaling_tolerance=0.01) for method in ['save_analyzed_image', 'save_analyzed_subimage']: methodcall = getattr(self.cbct, method) save_file(methodcall) def test_plot_images(self): """Test the various plotting functions.""" self.cbct.load_demo_images() self.cbct.analyze() self.cbct.plot_analyzed_image() for item in ['hu', 'un', 'mtf', 'sp', 'prof', 'lin', 'lc']: self.cbct.plot_analyzed_subimage(item) self.cbct.plot_analyzed_subimage('lin', delta=False) with self.assertRaises(ValueError): self.cbct.plot_analyzed_subimage('sr')
def setUpClass(cls): if cls.zip: cls.cbct = CBCT.from_zip_file(cls.location) else: cls.cbct = CBCT(cls.location) cls.cbct.analyze(cls.hu_tolerance, cls.scaling_tolerance)
def setUpClass(cls): cls.cbct = CBCT.from_demo_images() cls.cbct.analyze()
def setUpClass(cls): cls.cbct = CBCT.from_zip_file(cls.thorax_zip)
def setUpClass(cls): cls.cbct = CBCT.from_zip_file(cls.pelvis_zip)