示例#1
0
    def test_set_cor_at_slice(self):
        m = CorTiltDataModel()
        m.add_point(None, 10, 5.0)
        m.add_point(None, 20, 6.0)
        m.add_point(None, 30, 7.0)
        m.add_point(None, 40, 8.0)

        m.set_cor_at_slice(30, 15)
        self.assertEqual(m.cors, [5.0, 6.0, 15.0, 8.0])
示例#2
0
    def test_get_data_idx_for_slice_idx(self):
        m = CorTiltDataModel()
        m.add_point(None, 10, 5.0)
        m.add_point(None, 20, 6.0)
        m.add_point(None, 30, 7.0)
        m.add_point(None, 40, 8.0)

        self.assertEqual(m._get_data_idx_from_slice_idx(10), 0)
        self.assertIsNone(m._get_data_idx_from_slice_idx(100))
示例#3
0
    def test_add_points_no_index(self):
        m = CorTiltDataModel()
        m.add_point(None)
        m.add_point(None, 20, 5.0)
        m.add_point(None, 60, 7.8)

        self.assertFalse(m.empty)
        self.assertEqual(m.num_points, 3)
        self.assertEqual(m.slices, [0, 20, 60])
        self.assertEqual(m.cors, [0.0, 5.0, 7.8])
示例#4
0
    def test_add_points(self):
        m = CorTiltDataModel()
        m.add_point(0)
        m.add_point(0, 20, 5.0)
        m.add_point(1, 60, 7.8)

        self.assertFalse(m.empty)
        self.assertEqual(m.num_points, 3)
        self.assertEqual(m.slices, [20, 60, 0])
        self.assertEqual(m.cors, [5.0, 7.8, 0.0])
示例#5
0
    def test_clear_points(self):
        m = CorTiltDataModel()
        m.add_point(0)
        m.add_point(0, 20, 5.0)
        m.add_point(1, 60, 7.8)
        m.clear_points()

        self.assertTrue(m.empty)
        self.assertEqual(m.num_points, 0)
        self.assertEqual(m.slices, [])
        self.assertEqual(m.cors, [])
示例#6
0
    def test_get_cor_for_slice_from_regression(self):
        m = CorTiltDataModel()
        m.add_point(None, 10, 5.0)
        m.add_point(None, 20, 6.0)
        m.add_point(None, 30, 7.0)
        m.add_point(None, 40, 8.0)

        m.linear_regression()

        self.assertEqual(m.get_cor_from_regression(0), 4.0)
        self.assertEqual(m.get_cor_from_regression(10), 5.0)
        self.assertEqual(m.get_cor_from_regression(50), 9.0)
示例#7
0
    def test_data_ordering(self):
        m = CorTiltDataModel()
        m.add_point(None, 30, 7.0)
        m.add_point(None, 10, 5.0)
        m.add_point(None, 40, 8.0)
        m.add_point(None, 20, 6.0)

        m.sort_points()

        # Expect data to be sorted as it is inserted
        self.assertEqual(m.slices, [10, 20, 30, 40])
        self.assertEqual(m.cors, [5.0, 6.0, 7.0, 8.0])

        m.linear_regression()

        self.assertTrue(m.has_results)
        self.assertAlmostEqual(m.gradient.value, 0.1)
        self.assertAlmostEqual(m.cor.value, 4.0)
示例#8
0
    def test_linear_regression(self):
        m = CorTiltDataModel()
        m.add_point(None, 0, 5.0)
        m.add_point(None, 10, 6.0)
        m.add_point(None, 20, 7.0)
        m.add_point(None, 30, 8.0)
        m.linear_regression()

        self.assertTrue(m.has_results)
        self.assertAlmostEqual(m.gradient.value, 0.1)
        self.assertAlmostEqual(m.cor.value, 5.0)
示例#9
0
    def test_clear_results(self):
        m = CorTiltDataModel()
        m.add_point(None, 0, 5.0)
        m.add_point(None, 10, 6.0)
        m.add_point(None, 20, 7.0)
        m.add_point(None, 30, 8.0)
        m.linear_regression()

        m.clear_results()

        self.assertFalse(m.has_results)
示例#10
0
    def test_stack_properties(self):
        m = CorTiltDataModel()
        m.add_point(None, 0, 5.0)
        m.add_point(None, 10, 6.0)
        m.add_point(None, 20, 7.0)
        m.add_point(None, 30, 8.0)
        m.linear_regression()

        d = m.stack_properties
        self.assertEqual(len(d), 5)

        self.assertEqual(d[const.COR_TILT_FITTED_GRADIENT], m.gradient.value)
        self.assertEqual(d[const.COR_TILT_ROTATION_CENTRE], m.cor.value)
        self.assertEqual(d[const.COR_TILT_SLICE_INDICES], m.slices)
        self.assertEqual(d[const.COR_TILT_ROTATION_CENTRES], m.cors)
        self.assertTrue(isinstance(d[const.COR_TILT_TILT_ANGLE_DEG], float))