Example #1
0
def test_resolution_type():
    """
    Compresion defines a default resolution, check that the types are integers.
    """
    compression = Compression(mCT())
    assert isinstance(compression.num_non_arccor_bins, int)
    assert isinstance(compression.num_of_views, int)
Example #2
0
def test_domain():
    from odlpet.stir.space import space_from_stir_domain
    s = mCT()
    c = Compression(s)
    domain = c.get_stir_domain()
    space = space_from_stir_domain(domain)
    shape = space.shape
    smin, smax = space.min_pt, space.max_pt

    domain_z = c.get_stir_domain(zoom=2.)
    space_z = space_from_stir_domain(domain_z)
    assert pytest.approx(space_z.min_pt) == smin
    # assert pytest.approx(space_z.max_pt) == smax
    assert space_z.shape[0] == shape[0]
    for i in [1, 2]:
        assert space_z.shape[i] // 2 == shape[i] - 1

    new_shape = (2, 3, 4)
    domain_s = c.get_stir_domain(sizes=new_shape)
    space_s = space_from_stir_domain(domain_s)
    assert space_s.shape == new_shape

    offset = [10., 30., 20.]
    domain_o = c.get_stir_domain(offset=offset)
    space_o = space_from_stir_domain(domain_o)
    assert space_o.shape == shape
    assert pytest.approx(space_o.min_pt - smin) == offset
    assert pytest.approx(space_o.max_pt - smax) == offset
Example #3
0
def test_sinogram_resolution():
    """
    Possible to specify a sinogram resolution.
    """
    c = Compression(mCT())
    nb_tans = np.random.randint(1, 10)
    c.num_non_arccor_bins = nb_tans
    nb_views = np.random.randint(1, 10)
    c.num_of_views = nb_views
    proj = c.get_projector()
    resolution = proj.range.shape[-2:]
    assert resolution == (nb_views, nb_tans)
Example #4
0
def test_sinogram():
    """
    Make sure that the sinogram offsets are correct.
    """
    scanner = mCT()
    compression, proj, projections = get_projections(scanner)

    sinfo = compression._get_sinogram_info()

    seg_ind = np.random.randint(len(sinfo))
    segment = sinfo[seg_ind][0]
    ax_ind = np.random.randint(sinfo[seg_ind][1])

    offset = compression.get_offset(segment, ax_ind)
    computed = projections[offset].asarray()
    expected = stirextra.to_numpy(proj.proj_data.get_sinogram(ax_ind, segment))
    assert pytest.approx(computed) == expected
Example #5
0
def test_wrong_sinogram():
    """
    Bound controls for sinograms (wrong segment or wrong axial coordinate)
    """
    scanner = mCT()
    compression, proj, projections = get_projections(scanner)
    sinfo = compression._get_sinogram_info()
    segments = [si[0] for si in sinfo]
    maxax = [si[1] for si in sinfo]
    min_seg = np.min(segments)
    max_seg = np.max(segments)
    with pytest.raises(ValueError):
        compression.get_offset(min_seg - 1, 0)
    with pytest.raises(ValueError):
        compression.get_offset(max_seg + 1, 0)
    for s, a in sinfo:
        with pytest.raises(ValueError):
            compression.get_offset(s, a + 1)