Exemple #1
0
    def test_init(self):
        """Test data creation."""
        pg = ts.cone(angles=10, shape=20)
        vg = ts.VolumeGeometry().reshape(10)
        pd = ts.Data(pg, 0)

        proj_shape = pd.get().shape

        # Should warn when data is silently converted to float32.
        with self.assertWarns(UserWarning):
            ts.Data(pg, np.ones(proj_shape, dtype=np.float64))
        with self.assertWarns(UserWarning):
            ts.Data(vg, np.ones(vg.shape, dtype=np.float64))

        # Should warn when data is made contiguous.
        with self.assertWarns(UserWarning):
            p_data = np.ones(
                (pg.shape[0] * 2, pg.get_num_angles(), pg.shape[1]),
                dtype=np.float32)
            ts.Data(pg, p_data[::2, ...])
        with self.assertWarns(UserWarning):
            v_data = np.ones((vg.shape[0] * 2, *vg.shape[1:]),
                             dtype=np.float32)
            ts.Data(vg, v_data[::2, ...])

        ts.Data(pg, np.ones(proj_shape, dtype=np.float32))
        ts.Data(vg, np.ones(vg.shape, dtype=np.float32))
Exemple #2
0
 def test_contains(self):
     vg = ts.VolumeGeometry()
     self.assertFalse(vg in vg.translate(1))
     self.assertFalse(vg in vg.scale(0.5))
     self.assertTrue(vg in vg.scale(2))
     self.assertTrue(vg.translate(5) in vg.translate(5).scale(2))
     self.assertTrue(vg in vg)
Exemple #3
0
    def test_reshape(self):
        vg = ts.VolumeGeometry()

        vg1 = vg.reshape(100)
        vg2 = vg.reshape((100, ) * 3)

        self.assertEqual(vg1, vg2)
Exemple #4
0
    def test_scale(self):
        vg = ts.VolumeGeometry()

        self.assertEqual(vg, vg.scale((1, 1, 1)))
        self.assertEqual(vg, vg.scale(1))
        for _ in range(10):
            t = abs(np.random.normal(size=3)) + 0.01
            self.assertAlmostEqual(vg, vg.scale(t).scale(1 / t), places=5)
Exemple #5
0
    def test_translate(self):
        vg = ts.VolumeGeometry()

        self.assertEqual(vg, vg.translate((0, 0, 0)))
        self.assertEqual(vg, vg.translate(0))
        self.assertEqual(vg, vg.untranslate((0, 0, 0)))
        self.assertEqual(vg, vg.untranslate(0))
        for _ in range(10):
            t = np.random.normal(size=3)
            self.assertAlmostEqual(vg, vg.translate(t).untranslate(t))
    def test_init(self):
        """Test ReconstructionGeometry init."""

        pd = ts.Data(ts.cone())
        vd = ts.Data(ts.VolumeGeometry())

        r = ts.ReconstructionGeometry(pd, vd)

        r = ts.ReconstructionGeometry(pd,
                                      vd,
                                      detector_supersampling=2,
                                      voxel_supersampling=2)
Exemple #7
0
    def test_with(self):
        """Test that data in a with statement gets cleaned up

        Also, that using the with statement works.
        """
        seg_fault = False
        pg = ts.cone()
        vg = ts.VolumeGeometry()

        with ts.Data(pg, 0) as pd, ts.Data(vg, 0) as vd:
            proj = pd.get()
            vol = vd.get()

        # No test to check that the code below segfaults, but it does :)
        # You can run the code..
        if seg_fault:
            proj[:] = 0
            vol[:] = 0
Exemple #8
0
    def test_intersection(self):

        vg = ts.VolumeGeometry()

        for _ in range(100):
            t = np.random.normal(size=3)
            r = np.random.normal(size=3)
            r = abs(r) + 0.01

            vg2 = vg.translate(t).scale(r)

            intersection = vg.intersect(vg2)

            if intersection is not None:
                self.assertTrue(intersection in vg)
                self.assertTrue(intersection in vg2)
            else:
                self.assertFalse(vg in vg2)
                self.assertFalse(vg2 in vg)

            self.assertAlmostEqual(vg2, vg2.intersect(vg2))
    def test_forward_backward(self):
        pd = ts.Data(ts.cone().reshape(10))
        vd = ts.Data(ts.VolumeGeometry().reshape(10))

        rs = [
            ts.ReconstructionGeometry(pd, vd),
            ts.ReconstructionGeometry(pd,
                                      vd,
                                      detector_supersampling=2,
                                      voxel_supersampling=2),
            ts.ReconstructionGeometry(pd,
                                      vd,
                                      detector_supersampling=1,
                                      voxel_supersampling=2),
            ts.ReconstructionGeometry(pd,
                                      vd,
                                      detector_supersampling=2,
                                      voxel_supersampling=1),
        ]

        for r in rs:
            r.forward()
            r.backward()
Exemple #10
0
 def test_is_volume_projection(self):
     self.assertTrue(ts.Data(ts.cone()).is_projection())
     self.assertFalse(ts.Data(ts.cone()).is_volume())
     self.assertTrue(ts.Data(ts.VolumeGeometry()).is_volume())
     self.assertFalse(ts.Data(ts.VolumeGeometry()).is_projection())
Exemple #11
0
    def test_astra(self):
        vg = ts.VolumeGeometry()
        vg = vg.scale((1, 2, 3)).translate((10, 20, 30))
        vg1 = ts.VolumeGeometry.from_astra(vg.to_astra())

        self.assertEqual(vg, vg1)
Exemple #12
0
 def test_volume(self):
     self.assertEqual(ts.volume(), ts.VolumeGeometry())
     shapes = [2, (1, 4, 5), (10, 10, 10)]
     for s in shapes:
         self.assertEqual(ts.volume(s), ts.VolumeGeometry().reshape(s))
Exemple #13
0
 def test_init(self):
     """Test init."""
     vg = ts.VolumeGeometry()
Exemple #14
0
 def test_is_volume_geometry(self):
     self.assertTrue(ts.is_volume_geometry(ts.VolumeGeometry()))
     self.assertFalse(ts.is_volume_geometry(ts.cone()))
     self.assertFalse(ts.is_volume_geometry(None))