def test_flatness(self): """Test flatness values""" img = BeamImage() img.load_demo_image() self.assertAlmostEqual(img.flatness("x"), 1.91, delta=0.03) self.assertAlmostEqual(img.flatness("in"), 1.60, delta=0.03) self.assertAlmostEqual(img.flatness("x", method="elekta"), 103.9, delta=0.1) self.assertAlmostEqual(img.flatness("both")[0], 1.91, delta=0.03) self.assertAlmostEqual(img.flatness("both")[1], 1.60, delta=0.03) self.assertRaises(ValueError, img.flatness, method="varen")
def test_flatness(self): """Test flatness values""" img = BeamImage() img.load_demo_image() self.assertAlmostEqual(img.flatness('x'), 1.91, delta=0.03) self.assertAlmostEqual(img.flatness('in'), 1.60, delta=0.03) self.assertAlmostEqual(img.flatness('x', method='elekta'), 103.9, delta=0.1) self.assertAlmostEqual(img.flatness('both')[0], 1.91, delta=0.03) self.assertAlmostEqual(img.flatness('both')[1], 1.60, delta=0.03) self.assertRaises(ValueError, img.flatness, method='varen')
def AnalyseImage(self): Img=BeamImage(self.CurFile) self.CurFlatX=abs(Img.flatness(plane='both')[0]) self.CurFlatY=abs(Img.flatness(plane='both')[1]) self.CurSymX=abs(Img.symmetry(plane='both')[0]) self.CurSymY=abs(Img.symmetry(plane='both')[1]) self.CurOutput=1.0 self.ColorResults()
class UnitTests(unittest.TestCase): def setUp(self): self.img = BeamImage() self.img.load_demo_image() def test_get_symmetry(self): prof = self.img._get_profile('x', 'auto') # varian for method in ('varian', 'point difference'): symmetry, lt_edge, rt_edge, max_idx = self.img._get_symmetry( prof, method) self.assertAlmostEqual(symmetry, 3.08, delta=0.01) self.assertAlmostEqual(lt_edge, 393, delta=3) self.assertAlmostEqual(rt_edge, 681, delta=3) self.assertAlmostEqual(max_idx, 429, delta=3) # elekta for method in ('elekta', 'pdq-iec'): symmetry, lt_edge, rt_edge, max_idx = self.img._get_symmetry( prof, method) self.assertAlmostEqual(symmetry, 103.11, delta=0.05) def test_convert_position(self): input_pos = 'auto' out_pos = self.img._convert_position(input_pos, 'both') self.assertEqual(out_pos[0], 366) self.assertEqual(out_pos[1], 537) out_pos = self.img._convert_position(input_pos, 'x') self.assertEqual(out_pos[0], 366) input_pos = (300, 0.6) out_pos = self.img._convert_position(input_pos, 'both') self.assertEqual(out_pos[0], 300) self.assertEqual(out_pos[1], 614) input_pos = 0.6 out_pos = self.img._convert_position(input_pos, 'y') self.assertEqual(out_pos[0], 614) self.assertRaises(ValueError, self.img._convert_position, (300, 400, 0.5), 'both') self.assertRaises(ValueError, self.img._convert_position, (300, 400), 'x') self.assertRaises(ValueError, self.img._convert_position, (300, 400), 'notaplane') def test_parse_position(self): position = 30 int_input = self.img._parse_position(position, 'x') self.assertEqual(int_input, position) float_pos = 0.4 fl_input = self.img._parse_position(float_pos, 'i') self.assertAlmostEqual(fl_input, float_pos * self.img.image.shape[1], delta=1) fl_input = self.img._parse_position(float_pos, 'x') self.assertAlmostEqual(fl_input, float_pos * self.img.image.shape[0], delta=1) self.assertRaises(ValueError, self.img._parse_position, position, 'both') # self.assertRaises(ValueError, self.img._parse_position, 1.1, 'x') def test_get_profile(self): """Test various inputs for _get_profile().""" b = BeamImage() self.assertRaises(AttributeError, b._get_profile, 'x', 'auto') # test output type self.assertIsInstance(self.img._get_profile('x', 'auto'), SingleProfile) # test axes for axis in ('crossplane', 'cross', 'x', 'inplane', 'in'): self.img._get_profile(axis, 'auto') # self.assertRaises(ValueError, self.img._get_profile, 'notaplane', 'auto') # make sure extraction is along correct axis size_xplane = 1024 prof = self.img._get_profile('x', 'auto') self.assertEqual(prof.values.size, size_xplane) size_yplane = 768 prof = self.img._get_profile('in', 'auto') self.assertEqual(prof.values.size, size_yplane) def test_check_position_bounds(self): # test positions for pos in (100, 500, 0.5): self.img._check_position_inbounds(pos, 'x') self.assertRaises(IndexError, self.img._check_position_inbounds, 1100, 'x') self.assertRaises(IndexError, self.img._check_position_inbounds, 800, 'i') def test_get_flatness(self): prof = self.img._get_profile('x', 'auto') # varian for method in ('varian', 'VoM80', 'siemens'): flatness, dmax, dmin, lt_edge, rt_edge = self.img._get_flatness( prof, method) self.assertAlmostEqual(flatness, 1.91, delta=0.01) self.assertAlmostEqual(dmax, 58533, delta=20) self.assertAlmostEqual(dmin, 56335, delta=20) self.assertAlmostEqual(lt_edge, 393, delta=3) self.assertAlmostEqual(rt_edge, 681, delta=3) # elekta for method in ('elekta', 'IEC'): flatness, dmax, dmin, lt_edge, rt_edge = self.img._get_flatness( prof, method) self.assertAlmostEqual(flatness, 103.9, delta=0.05) def test_plot_annotation(self): fig, ax = plt.subplots() # axis = self.img._plot_annotation(ax, ) def test_plot_title(self): planes = ('x', 'in') prefixs = ('Crossplane', 'Inplane') flatsym = ('flat', 'sym') suffixs = (' Flatness', ' Symmetry') for plane, prefix in zip(planes, prefixs): for fs, suffix in zip(flatsym, suffixs): fig, ax = plt.subplots() title = prefix + suffix axis = self.img._plot_title(ax, plane, fs) self.assertEqual(title, axis.get_title()) def test_determine_center(self): """Test the determined center is correct""" y, x = self.img._determine_center('both') self.assertAlmostEqual(y, 366, delta=4) self.assertAlmostEqual(x, 537, delta=4) def test_check_inversion(self): """Test that inverting the image doesn't change the flat/sym values.""" sym = self.img.symmetry('x') flat = self.img.flatness('in') self.img.image.invert() i_sym = self.img.symmetry('x') i_flat = self.img.flatness('in') self.assertAlmostEqual(sym, i_sym, delta=0.01) self.assertAlmostEqual(flat, i_flat, delta=0.01) def test_img_is_loaded(self): """Test image is loaded property.""" b = BeamImage() self.assertFalse(b._img_is_loaded) b.load_demo_image() self.assertTrue(b._img_is_loaded)
class UnitTests(unittest.TestCase): def setUp(self): self.img = BeamImage() self.img.load_demo_image() def test_get_symmetry(self): prof = self.img._get_profile("x", "auto") # varian for method in ("varian", "point difference"): symmetry, lt_edge, rt_edge, max_idx = self.img._get_symmetry(prof, method) self.assertAlmostEqual(symmetry, 3.08, delta=0.01) self.assertAlmostEqual(lt_edge, 393, delta=3) self.assertAlmostEqual(rt_edge, 681, delta=3) self.assertAlmostEqual(max_idx, 429, delta=3) # elekta for method in ("elekta", "pdq-iec"): symmetry, lt_edge, rt_edge, max_idx = self.img._get_symmetry(prof, method) self.assertAlmostEqual(symmetry, 103.11, delta=0.05) def test_convert_position(self): input_pos = "auto" out_pos = self.img._convert_position(input_pos, "both") self.assertEqual(out_pos[0], 366) self.assertEqual(out_pos[1], 537) out_pos = self.img._convert_position(input_pos, "x") self.assertEqual(out_pos[0], 366) input_pos = (300, 0.6) out_pos = self.img._convert_position(input_pos, "both") self.assertEqual(out_pos[0], 300) self.assertEqual(out_pos[1], 614) input_pos = 0.6 out_pos = self.img._convert_position(input_pos, "y") self.assertEqual(out_pos[0], 614) self.assertRaises(ValueError, self.img._convert_position, (300, 400, 0.5), "both") self.assertRaises(ValueError, self.img._convert_position, (300, 400), "x") self.assertRaises(ValueError, self.img._convert_position, (300, 400), "notaplane") def test_parse_position(self): position = 30 int_input = self.img._parse_position(position, "x") self.assertEqual(int_input, position) float_pos = 0.4 fl_input = self.img._parse_position(float_pos, "i") self.assertAlmostEqual(fl_input, float_pos * self.img.image.shape[1], delta=1) fl_input = self.img._parse_position(float_pos, "x") self.assertAlmostEqual(fl_input, float_pos * self.img.image.shape[0], delta=1) self.assertRaises(ValueError, self.img._parse_position, position, "both") # self.assertRaises(ValueError, self.img._parse_position, 1.1, 'x') def test_get_profile(self): """Test various inputs for _get_profile().""" b = BeamImage() self.assertRaises(AttributeError, b._get_profile, "x", "auto") # test output type self.assertIsInstance(self.img._get_profile("x", "auto"), SingleProfile) # test axes for axis in ("crossplane", "cross", "x", "inplane", "in"): self.img._get_profile(axis, "auto") # self.assertRaises(ValueError, self.img._get_profile, 'notaplane', 'auto') # make sure extraction is along correct axis size_xplane = 1024 prof = self.img._get_profile("x", "auto") self.assertEqual(prof.values.size, size_xplane) size_yplane = 768 prof = self.img._get_profile("in", "auto") self.assertEqual(prof.values.size, size_yplane) def test_check_position_bounds(self): # test positions for pos in (100, 500, 0.5): self.img._check_position_inbounds(pos, "x") self.assertRaises(IndexError, self.img._check_position_inbounds, 1100, "x") self.assertRaises(IndexError, self.img._check_position_inbounds, 800, "i") def test_get_flatness(self): prof = self.img._get_profile("x", "auto") # varian for method in ("varian", "VoM80", "siemens"): flatness, dmax, dmin, lt_edge, rt_edge = self.img._get_flatness(prof, method) self.assertAlmostEqual(flatness, 1.91, delta=0.01) self.assertAlmostEqual(dmax, 58533, delta=20) self.assertAlmostEqual(dmin, 56335, delta=20) self.assertAlmostEqual(lt_edge, 393, delta=3) self.assertAlmostEqual(rt_edge, 681, delta=3) # elekta for method in ("elekta", "IEC"): flatness, dmax, dmin, lt_edge, rt_edge = self.img._get_flatness(prof, method) self.assertAlmostEqual(flatness, 103.9, delta=0.05) def test_plot_annotation(self): fig, ax = plt.subplots() # axis = self.img._plot_annotation(ax, ) def test_plot_title(self): planes = ("x", "in") prefixs = ("Crossplane", "Inplane") flatsym = ("flat", "sym") suffixs = (" Flatness", " Symmetry") for plane, prefix in zip(planes, prefixs): for fs, suffix in zip(flatsym, suffixs): fig, ax = plt.subplots() title = prefix + suffix axis = self.img._plot_title(ax, plane, fs) self.assertEqual(title, axis.get_title()) def test_determine_center(self): """Test the determined center is correct""" y, x = self.img._determine_center("both") self.assertAlmostEqual(y, 366, delta=4) self.assertAlmostEqual(x, 537, delta=4) def test_check_inversion(self): """Test that inverting the image doesn't change the flat/sym values.""" sym = self.img.symmetry("x") flat = self.img.flatness("in") self.img.image.invert() i_sym = self.img.symmetry("x") i_flat = self.img.flatness("in") self.assertAlmostEqual(sym, i_sym, delta=0.01) self.assertAlmostEqual(flat, i_flat, delta=0.01) def test_img_is_loaded(self): """Test image is loaded property.""" b = BeamImage() self.assertFalse(b._img_is_loaded) b.load_demo_image() self.assertTrue(b._img_is_loaded)