示例#1
0
    def test_get_source_positions(self):
        pg1 = ts.cone(source_distance=1).to_vector()
        pg2 = ts.cone(source_distance=2).to_vector()

        source_diff = pg1.get_source_positions(
        ) * 2 - pg2.get_source_positions()
        self.assertTrue(np.all(abs(source_diff) < ts.epsilon))
示例#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_volume_from_projection(self):
        """Test volume_from_projection_geometry

        This method checks that astra projections of a volume obtained
        by volume_from_projection_geometry satisfy some
        conditions. Notably,

        1) when inside=True, the backprojection of a detector
           should hit all volume voxels. This should actually hold for
           each angle individually, but this is too expensive to test.
        2) when inside=False, the forward projection of the volume
           should hit each detector pixel. Again, this should hold for
           each angle individually.

        NOTE: When the source intersects the volume, astra does not
        always do a correct forward projection. Hence, a correctly
        sized volume might fail the test.

        """

        num_angles = 119
        interactive = False
        proj_angles = np.linspace(0, 2 * np.pi, num_angles, False)

        pg = ts.cone()

        vg = ts.volume_from_projection_geometry(pg)
 def test_get_item(self):
     pg = ts.cone(angles=10, shape=20)
     self.assertEqual(pg[1].get_num_angles(), 1)
     self.assertEqual(pg[:1].get_num_angles(), 1)
     self.assertEqual(pg[:2].get_num_angles(), 2)
     self.assertEqual(pg[:].get_num_angles(), 10)
     self.assertEqual(pg[10].get_num_angles(), 0)
    def test_display_geometry(self):
        """Test something."""
        interactive = False
        pg = ts.cone(angles=100, source_distance=10, detector_distance=5)
        vg = ts.volume_from_projection_geometry(pg, inside=False)

        if interactive:
            ts.display_geometry(pg, vg)
示例#6
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))
示例#7
0
 def test_get_size(self):
     size = (1, 1)
     pg = ts.cone(angles=5, size=size).to_vector()
     self.assertTrue(abs(size - pg.get_size()).sum() < ts.epsilon)
     for _ in range(10):
         new_shape = np.random.uniform(1, 100, size=2).astype(np.int)
         # Change the number of detector pixels and test if the
         # change in size is proportional
         pg2 = pg.reshape(new_shape)
         self.assertTrue(
             abs(size * new_shape - pg2.get_size()).sum() < ts.epsilon)
    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)
示例#9
0
    def test_project_point_detector_spacing(self):
        """Test project_point with detector spacing

        Test whether projection_point works with non-uniform detector spacing.
        """
        angles = np.zeros(1)
        shape = (10, 40)
        size = (30, 80)

        pg = ts.cone(1, size, shape, source_distance=10).to_vector()
        self.assertAlmostEqual(np.abs(pg.project_point((0, 0, 0))).sum(), 0)

        self.assertAlmostEqual(
            np.abs(pg.project_point((3.0, 0, 0)) - [1.0, 0.0]).sum(), 0)
        self.assertAlmostEqual(
            np.abs(pg.project_point((0, 0, 2.0)) - [0.0, 1.0]).sum(), 0)

        shape = (100, 400)
        pg = ts.cone(1, size, shape, source_distance=10).to_vector()
        self.assertAlmostEqual(np.abs(pg.project_point((0, 0, 0))).sum(), 0)
        self.assertAlmostEqual(
            np.abs(pg.project_point((0.3, 0, 0)) - [1.0, 0.0]).sum(), 0)
        self.assertAlmostEqual(
            np.abs(pg.project_point((0, 0, 0.2)) - [0.0, 1.0]).sum(), 0)
示例#10
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
示例#11
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)
    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()
示例#13
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))
示例#14
0
    def test_get_corners(self):
        # TODO: This test deserves better..
        size = (1, 1)
        pg1 = ts.cone(angles=5, size=size).to_vector()

        self.assertEqual(pg1.get_corners().shape, (4, 5, 3))
 def test_cone(self):
     self.assertEqual(ts.ConeGeometry(), ts.cone())
示例#16
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())
 def test_get_size(self):
     size = (1, 2)
     pg = ts.cone(size=size)
     self.assertTrue(abs(size - pg.get_size()).sum() < ts.epsilon)