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)
예제 #2
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))
예제 #3
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
예제 #4
0
    def test_display_data(self):
        interactive = False
        p = ts.Data(ts.cone(angles=100).reshape(100))
        v = ts.Data(
            ts.volume_from_projection_geometry(p.geometry).reshape(100))

        # Fill the projection data with random noise:
        proj = p.get()
        proj[:] = np.random.normal(size=proj.shape)
        proj[:] = abs(proj)

        r = ts.ReconstructionGeometry(p, v)

        if interactive:
            ts.display_data(p)
        r.backward()
        if interactive:
            ts.display_data(v)
예제 #5
0
    def test_get_set(self):
        """Test data.set() and data.get()
        """

        pg = ts.cone().reshape(10)
        data = ts.Data(pg, 0)

        self.assertTrue(np.all(abs(data.get()) < ts.epsilon))
        data.set(1)
        self.assertTrue(np.all(abs(data.get() - 1) < ts.epsilon))
    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()
예제 #7
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())