示例#1
0
def test_partition_init_raise():
    # Check different error scenarios
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    grid = odl.TensorGrid(vec1, vec2)
    begin = [2, -5]
    end = [10, 4]

    beg_toolarge = (2, -3.5)
    end_toosmall = (7, 1)
    beg_badshape = (-1, 2, 0)
    end_badshape = (2, )

    with pytest.raises(ValueError):
        odl.RectPartition(odl.IntervalProd(beg_toolarge, end), grid)

    with pytest.raises(ValueError):
        odl.RectPartition(odl.IntervalProd(begin, end_toosmall), grid)

    with pytest.raises(ValueError):
        odl.RectPartition(odl.IntervalProd(beg_badshape, end_badshape), grid)

    with pytest.raises(TypeError):
        odl.RectPartition(None, grid)

    with pytest.raises(TypeError):
        odl.RectPartition(odl.IntervalProd(beg_toolarge, end), None)
示例#2
0
def test_partition_insert():
    vec11 = [2, 4, 5, 7]
    vec12 = [-4, -3, 0, 1, 4]
    min_pt1 = [1, -4]
    max_pt1 = [7, 5]
    grid1 = odl.RectGrid(vec11, vec12)
    intv1 = odl.IntervalProd(min_pt1, max_pt1)
    part1 = odl.RectPartition(intv1, grid1)

    vec21 = [-2, 0, 3]
    vec22 = [0]
    min_pt2 = [-2, -2]
    max_pt2 = [4, 0]
    grid2 = odl.RectGrid(vec21, vec22)
    intv2 = odl.IntervalProd(min_pt2, max_pt2)
    part2 = odl.RectPartition(intv2, grid2)

    part = part1.insert(0, part2)
    assert all_equal(part.min_pt, [-2, -2, 1, -4])
    assert all_equal(part.max_pt, [4, 0, 7, 5])
    assert all_equal(part.grid.min_pt, [-2, 0, 2, -4])
    assert all_equal(part.grid.max_pt, [3, 0, 7, 4])

    part = part1.insert(1, part2)
    assert all_equal(part.min_pt, [1, -2, -2, -4])
    assert all_equal(part.max_pt, [7, 4, 0, 5])
    assert all_equal(part.grid.min_pt, [2, -2, 0, -4])
    assert all_equal(part.grid.max_pt, [7, 3, 0, 4])
示例#3
0
def test_partition_insert():
    vec11 = [2, 4, 5, 7]
    vec12 = [-4, -3, 0, 1, 4]
    begin1 = [1, -4]
    end1 = [7, 5]
    grid1 = odl.TensorGrid(vec11, vec12)
    intv1 = odl.IntervalProd(begin1, end1)
    part1 = odl.RectPartition(intv1, grid1)

    vec21 = [-2, 0, 3]
    vec22 = [0]
    begin2 = [-2, -2]
    end2 = [4, 0]
    grid2 = odl.TensorGrid(vec21, vec22)
    intv2 = odl.IntervalProd(begin2, end2)
    part2 = odl.RectPartition(intv2, grid2)

    part = part1.insert(0, part2)
    assert all_equal(part.begin, [-2, -2, 1, -4])
    assert all_equal(part.end, [4, 0, 7, 5])
    assert all_equal(part.grid.min_pt, [-2, 0, 2, -4])
    assert all_equal(part.grid.max_pt, [3, 0, 7, 4])

    part = part1.insert(1, part2)
    assert all_equal(part.begin, [1, -2, -2, -4])
    assert all_equal(part.end, [7, 4, 0, 5])
    assert all_equal(part.grid.min_pt, [2, -2, 0, -4])
    assert all_equal(part.grid.max_pt, [7, 3, 0, 4])
示例#4
0
def test_empty_partition():
    """Check if empty partitions behave as expected and all methods work."""
    part = odl.RectPartition(odl.IntervalProd([], []),
                             odl.uniform_grid([], [], ()))

    assert part.cell_boundary_vecs == ()
    assert part.nodes_on_bdry is True
    assert part.nodes_on_bdry_byaxis == ()
    assert part.has_isotropic_cells
    assert part.boundary_cell_fractions == ()
    assert part.cell_sizes_vecs == ()
    assert np.array_equal(part.cell_sides, [])
    assert part.cell_volume == 0

    same = odl.RectPartition(odl.IntervalProd([], []),
                             odl.uniform_grid([], [], ()))
    assert part == same
    assert hash(part) == hash(same)
    other = odl.uniform_partition(0, 1, 4)
    assert part != other

    assert part[[]] == part
    assert part.insert(0, other) == other
    assert other.insert(0, part) == other
    assert other.insert(1, part) == other
    assert part.squeeze() == part
    assert part.index([]) == ()
    part.byaxis
    assert part == odl.uniform_partition([], [], ())
    repr(part)
示例#5
0
def test_partition_init_raise():
    # Check different error scenarios
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    grid = odl.RectGrid(vec1, vec2)
    min_pt = [2, -5]
    max_pt = [10, 4]

    min_pt_toolarge = (2, -3.5)
    max_pt_toosmall = (7, 1)
    min_pt_badshape = (-1, 2, 0)
    max_pt_badshape = (2, )

    with pytest.raises(ValueError):
        odl.RectPartition(odl.IntervalProd(min_pt_toolarge, max_pt), grid)

    with pytest.raises(ValueError):
        odl.RectPartition(odl.IntervalProd(min_pt, max_pt_toosmall), grid)

    with pytest.raises(ValueError):
        odl.RectPartition(odl.IntervalProd(min_pt_badshape, max_pt_badshape),
                          grid)

    with pytest.raises(TypeError):
        odl.RectPartition(None, grid)

    with pytest.raises(TypeError):
        odl.RectPartition(odl.IntervalProd(min_pt_toolarge, max_pt), None)
示例#6
0
def test_partition_init():
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    begin = [2, -5]
    end = [10, 4]

    # Simply test if code runs
    odl.RectPartition(odl.Rectangle(begin, end), odl.TensorGrid(vec1, vec2))
    odl.RectPartition(odl.Interval(begin[0], end[0]), odl.TensorGrid(vec1))

    # Degenerate dimensions should work, too
    vec2 = np.array([1.0])
    odl.RectPartition(odl.Rectangle(begin, end), odl.TensorGrid(vec1, vec2))
示例#7
0
def test_partition_init():
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    min_pt = [2, -5]
    max_pt = [10, 4]

    # Simply test if code runs
    odl.RectPartition(odl.IntervalProd(min_pt, max_pt),
                      odl.RectGrid(vec1, vec2))
    odl.RectPartition(odl.IntervalProd(min_pt[0], max_pt[0]),
                      odl.RectGrid(vec1))

    # Degenerate dimensions should work, too
    vec2 = np.array([1.0])
    odl.RectPartition(odl.IntervalProd(min_pt, max_pt),
                      odl.RectGrid(vec1, vec2))
示例#8
0
def test_partition_getitem():
    vec1 = [2, 4, 5, 7]
    vec2 = [-4, -3, 0, 1, 4]
    vec3 = [-2, 0, 3]
    vec4 = [0]
    vecs = [vec1, vec2, vec3, vec4]
    min_pt = [1, -4, -2, -2]
    max_pt = [7, 5, 4, 0]
    grid = odl.RectGrid(*vecs)
    intv = odl.IntervalProd(min_pt, max_pt)
    part = odl.RectPartition(intv, grid)

    # Test a couple of slices
    slc = (1, -2, 2, 0)
    slc_vecs = [v[i] for i, v in zip(slc, vecs)]
    slc_part = part[slc]
    assert slc_part.grid == odl.RectGrid(*slc_vecs)
    slc_min_pt = [3, 0.5, 1.5, -2]
    slc_max_pt = [4.5, 2.5, 4, 0]
    assert slc_part.set == odl.IntervalProd(slc_min_pt, slc_max_pt)

    slc = (slice(None), slice(None, None, 2), slice(None, 2), 0)
    slc_vecs = [v[i] for i, v in zip(slc, vecs)]
    slc_part = part[slc]
    assert slc_part.grid == odl.RectGrid(*slc_vecs)
    slc_min_pt = [1, -4, -2, -2]
    slc_max_pt = [7, 5, 1.5, 0]
    assert slc_part.set == odl.IntervalProd(slc_min_pt, slc_max_pt)

    # Fewer indices
    assert part[1] == part[1, :, :, :] == part[1, ...]
    assert part[1, 2:] == part[1, 2:, :, :] == part[1, 2:, ...]
    assert part[1, 2:, ::2] == part[1, 2:, ::2, :] == part[1, 2:, ::2, ...]

    # Index list using indices 0 and 2
    lst_min_pt = [1, -4, -2, -2]
    lst_max_pt = [6, 5, 4, 0]
    lst_intv = odl.IntervalProd(lst_min_pt, lst_max_pt)
    lst_vec1 = [2, 5]
    lst_grid = odl.RectGrid(lst_vec1, vec2, vec3, vec4)
    lst_part = odl.RectPartition(lst_intv, lst_grid)
    assert part[[0, 2]] == lst_part
示例#9
0
def test_astra_projection_geometry():
    """Create ASTRA projection geometry from geometry objects."""

    with pytest.raises(TypeError):
        odl.tomo.astra_projection_geometry(None)

    apart = odl.uniform_partition(0, 2 * np.pi, 5)
    dpart = odl.uniform_partition(-40, 40, 10)

    # motion sampling grid, detector sampling grid but not uniform
    dpart_0 = odl.RectPartition(odl.IntervalProd(0, 3), odl.RectGrid([0, 1,
                                                                      3]))
    geom_p2d = odl.tomo.Parallel2dGeometry(apart, dpart=dpart_0)
    with pytest.raises(ValueError):
        odl.tomo.astra_projection_geometry(geom_p2d)

    # detector sampling grid, motion sampling grid
    geom_p2d = odl.tomo.Parallel2dGeometry(apart, dpart)
    odl.tomo.astra_projection_geometry(geom_p2d)

    # Parallel 2D geometry
    geom_p2d = odl.tomo.Parallel2dGeometry(apart, dpart)
    astra_geom = odl.tomo.astra_projection_geometry(geom_p2d)
    assert astra_geom['type'] == 'parallel'

    # Fan flat
    src_rad = 10
    det_rad = 5
    geom_ff = odl.tomo.FanFlatGeometry(apart, dpart, src_rad, det_rad)
    astra_geom = odl.tomo.astra_projection_geometry(geom_ff)
    assert astra_geom['type'] == 'fanflat_vec'

    dpart = odl.uniform_partition([-40, -3], [40, 3], (10, 5))

    # Parallel 3D geometry
    geom_p3d = odl.tomo.Parallel3dAxisGeometry(apart, dpart)
    odl.tomo.astra_projection_geometry(geom_p3d)
    astra_geom = odl.tomo.astra_projection_geometry(geom_p3d)
    assert astra_geom['type'] == 'parallel3d_vec'

    # Circular conebeam flat
    geom_ccf = odl.tomo.ConeFlatGeometry(apart, dpart, src_rad, det_rad)
    astra_geom = odl.tomo.astra_projection_geometry(geom_ccf)
    assert astra_geom['type'] == 'cone_vec'

    # Helical conebeam flat
    pitch = 1
    geom_hcf = odl.tomo.ConeFlatGeometry(apart,
                                         dpart,
                                         src_rad,
                                         det_rad,
                                         pitch=pitch)
    astra_geom = odl.tomo.astra_projection_geometry(geom_hcf)
    assert astra_geom['type'] == 'cone_vec'
示例#10
0
def test_equals():
    """Test partition equality checks and hash."""
    vec1 = np.array([2, 3, 4, 5])
    vec2 = np.array([-4, -2, 0, 2, 4])

    part1 = odl.RectPartition(odl.IntervalProd(1, 6), odl.RectGrid(vec1))
    part2 = odl.RectPartition(odl.IntervalProd([1, -5], [6, 5]),
                              odl.RectGrid(vec1, vec2))
    part2_again = odl.RectPartition(odl.IntervalProd([1, -5], [6, 5]),
                                    odl.RectGrid(vec1, vec2))
    part2_rev = odl.RectPartition(odl.IntervalProd([-5, 1], [5, 6]),
                                  odl.RectGrid(vec2, vec1))

    _test_eq(part1, part1)
    _test_eq(part2, part2)
    _test_eq(part2, part2_again)

    _test_neq(part1, part2)
    _test_neq(part2, part2_rev)
    assert part2 != (vec1, vec2)
示例#11
0
def test_partition_set():
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    grid = odl.RectGrid(vec1, vec2)

    min_pt = [1, -4]
    max_pt = [10, 5]
    intv = odl.IntervalProd(min_pt, max_pt)

    part = odl.RectPartition(intv, grid)
    assert part.set == odl.IntervalProd(min_pt, max_pt)
    assert all_equal(part.min_pt, min_pt)
    assert all_equal(part.min(), min_pt)
    assert all_equal(part.max_pt, max_pt)
    assert all_equal(part.max(), max_pt)
示例#12
0
def test_partition_set():
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    grid = odl.TensorGrid(vec1, vec2)

    begin = [1, -4]
    end = [10, 5]
    intv = odl.IntervalProd(begin, end)

    part = odl.RectPartition(intv, grid)
    assert part.set == odl.IntervalProd(begin, end)
    assert all_equal(part.begin, begin)
    assert all_equal(part.min(), begin)
    assert all_equal(part.end, end)
    assert all_equal(part.max(), end)
示例#13
0
def test_partition_cell_boundary_vecs():
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    grid = odl.RectGrid(vec1, vec2)

    midpts1 = [3, 4.5, 6]
    midpts2 = [-3.5, -1.5, 0.5, 2.5]

    min_pt = [2, -6]
    max_pt = [10, 4]
    intv = odl.IntervalProd(min_pt, max_pt)

    true_bvec1 = [2] + midpts1 + [10]
    true_bvec2 = [-6] + midpts2 + [4]

    part = odl.RectPartition(intv, grid)
    assert all_equal(part.cell_boundary_vecs, (true_bvec1, true_bvec2))
示例#14
0
def test_partition_cell_sizes_vecs():
    vec1 = np.array([2, 4, 5, 7])
    vec2 = np.array([-4, -3, 0, 1, 4])
    grid = odl.TensorGrid(vec1, vec2)

    midpts1 = [3, 4.5, 6]
    midpts2 = [-3.5, -1.5, 0.5, 2.5]

    begin = [2, -6]
    end = [10, 4]
    intv = odl.IntervalProd(begin, end)

    bvec1 = np.array([2] + midpts1 + [10])
    bvec2 = np.array([-6] + midpts2 + [4])
    true_csizes1 = bvec1[1:] - bvec1[:-1]
    true_csizes2 = bvec2[1:] - bvec2[:-1]

    part = odl.RectPartition(intv, grid)
    assert all_equal(part.cell_sizes_vecs, (true_csizes1, true_csizes2))
示例#15
0
def test_resizing_op_raise():

    # domain not a uniformely discretized Lp
    with pytest.raises(TypeError):
        odl.ResizingOperator(odl.rn(5), ran_shp=(10, ))

    grid = odl.RectGrid([0, 2, 3])
    part = odl.RectPartition(odl.IntervalProd(0, 3), grid)
    fspace = odl.FunctionSpace(odl.IntervalProd(0, 3))
    dspace = odl.rn(3)
    space = odl.DiscreteLp(fspace, part, dspace)
    with pytest.raises(ValueError):
        odl.ResizingOperator(space, ran_shp=(10, ))

    # different cell sides in domain and range
    space = odl.uniform_discr(0, 1, 10)
    res_space = odl.uniform_discr(0, 1, 15)
    with pytest.raises(ValueError):
        odl.ResizingOperator(space, res_space)

    # non-integer multiple of cell sides used as shift (grid of the
    # resized space shifted)
    space = odl.uniform_discr(0, 1, 5)
    res_space = odl.uniform_discr(-0.5, 1.5, 10)
    with pytest.raises(ValueError):
        odl.ResizingOperator(space, res_space)

    # need either range or ran_shp
    with pytest.raises(ValueError):
        odl.ResizingOperator(space)

    # offset cannot be combined with range
    space = odl.uniform_discr([0, -1], [1, 1], (10, 5))
    res_space = odl.uniform_discr([0, -3], [2, 3], (20, 15))
    with pytest.raises(ValueError):
        odl.ResizingOperator(space, res_space, offset=(0, 0))

    # bad pad_mode
    with pytest.raises(ValueError):
        odl.ResizingOperator(space, res_space, pad_mode='something')
示例#16
0
def test_norm_rectangle_boundary(impl, exponent):
    # Check the constant function 1 in different situations regarding the
    # placement of the outermost grid points.

    if exponent == float('inf'):
        pytest.xfail('inf-norm not implemented in CUDA')

    rect = odl.Rectangle([-1, -2], [1, 2])

    # Standard case
    discr = odl.uniform_discr_fromspace(odl.FunctionSpace(rect), (4, 8),
                                        impl=impl, exponent=exponent)
    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert almost_equal(discr.one().norm(),
                            (rect.volume) ** (1 / exponent))

    # Nodes on the boundary (everywhere)
    discr = odl.uniform_discr_fromspace(
        odl.FunctionSpace(rect), (4, 8), exponent=exponent,
        impl=impl, nodes_on_bdry=True)

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert almost_equal(discr.one().norm(),
                            (rect.volume) ** (1 / exponent))

    # Nodes on the boundary (selective)
    discr = odl.uniform_discr_fromspace(
        odl.FunctionSpace(rect), (4, 8), exponent=exponent,
        impl=impl, nodes_on_bdry=((False, True), False))

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert almost_equal(discr.one().norm(),
                            (rect.volume) ** (1 / exponent))

    discr = odl.uniform_discr_fromspace(
        odl.FunctionSpace(rect), (4, 8), exponent=exponent,
        impl=impl, nodes_on_bdry=(False, (True, False)))

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert almost_equal(discr.one().norm(),
                            (rect.volume) ** (1 / exponent))

    # Completely arbitrary boundary
    grid = odl.RegularGrid([0, 0], [1, 1], (4, 4))
    part = odl.RectPartition(rect, grid)
    weight = 1.0 if exponent == float('inf') else part.cell_volume
    dspace = odl.Rn(part.size, exponent=exponent, weight=weight)
    discr = DiscreteLp(odl.FunctionSpace(rect), part, dspace,
                       impl=impl, exponent=exponent)

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert almost_equal(discr.one().norm(),
                            (rect.volume) ** (1 / exponent))
示例#17
0
@author: Rob Tovey
'''
from os.path import join
RECORD = join('store', 'DogBones_small')
RECORD = None
if RECORD is not None:
    import matplotlib
    matplotlib.use('Agg')
import odl
from numpy import sqrt, loadtxt, asarray, pi, ascontiguousarray
from PIL import Image

# Import data:
angles = loadtxt(join('DogBones', 'Sample_A2_Tilt_Series_tiltcorr_cut.rawtlt'))
angles = odl.RectPartition(odl.IntervalProd(-pi / 2, pi / 2),
                           odl.RectGrid((pi / 180) * angles))
# angles = odl.uniform_partition(-(pi / 180) * 69, (pi / 180) * 73, 71)
data = Image.open(join('DogBones', 'Sample A2 Tilt Series_tiltcorr_cut.tif'))
data = [asarray(data).T for i in range(data.n_frames) if data.seek(i) is None]
# First dimension is angle, second is width, third is slice
data = asarray(data)
# import matplotlib
# matplotlib.use('Agg')
from matplotlib import pyplot as plt, animation as mv
# writer = mv.writers['ffmpeg'](fps=5, metadata={'title': 'DogBones'})
fig = plt.figure()
# writer.setup(fig, 'DogBones' + '.mp4', dpi=100)
for i in range(data.shape[0]):
    plt.gca().clear()
    plt.imshow(data[i, :, 500:564].T)
    plt.pause(0.1)
示例#18
0
def test_norm_rectangle_boundary(odl_tspace_impl, exponent):
    # Check the constant function 1 in different situations regarding the
    # placement of the outermost grid points.
    impl = odl_tspace_impl

    dtype = 'float32'
    rect = odl.IntervalProd([-1, -2], [1, 2])
    fspace = odl.FunctionSpace(rect, out_dtype=dtype)

    # Standard case
    discr = odl.uniform_discr_fromspace(fspace, (4, 8),
                                        impl=impl,
                                        exponent=exponent)
    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert (discr.one().norm() == pytest.approx(rect.volume**(1 /
                                                                  exponent)))

    # Nodes on the boundary (everywhere)
    discr = odl.uniform_discr_fromspace(fspace, (4, 8),
                                        exponent=exponent,
                                        impl=impl,
                                        nodes_on_bdry=True)

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert (discr.one().norm() == pytest.approx(rect.volume**(1 /
                                                                  exponent)))

    # Nodes on the boundary (selective)
    discr = odl.uniform_discr_fromspace(fspace, (4, 8),
                                        exponent=exponent,
                                        impl=impl,
                                        nodes_on_bdry=((False, True), False))

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert (discr.one().norm() == pytest.approx(rect.volume**(1 /
                                                                  exponent)))

    discr = odl.uniform_discr_fromspace(fspace, (4, 8),
                                        exponent=exponent,
                                        impl=impl,
                                        nodes_on_bdry=(False, (True, False)))

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert (discr.one().norm() == pytest.approx(rect.volume**(1 /
                                                                  exponent)))

    # Completely arbitrary boundary
    grid = odl.uniform_grid([0, 0], [1, 1], (4, 4))
    part = odl.RectPartition(rect, grid)
    weight = 1.0 if exponent == float('inf') else part.cell_volume
    tspace = odl.rn(part.shape,
                    dtype=dtype,
                    impl=impl,
                    exponent=exponent,
                    weighting=weight)
    discr = DiscreteLp(fspace, part, tspace)

    if exponent == float('inf'):
        assert discr.one().norm() == 1
    else:
        assert (discr.one().norm() == pytest.approx(rect.volume**(1 /
                                                                  exponent)))
示例#19
0
def projector(request):

    n_angles = 200

    geom, impl, angle = request.param.split()

    if angle == 'uniform':
        apart = odl.uniform_partition(0, 2 * np.pi, n_angles)
    elif angle == 'random':
        # Linearly spaced with random noise
        min_pt = 2 * (2.0 * np.pi) / n_angles
        max_pt = (2.0 * np.pi) - 2 * (2.0 * np.pi) / n_angles
        points = np.linspace(min_pt, max_pt, n_angles)
        points += np.random.rand(n_angles) * (max_pt - min_pt) / (5 * n_angles)
        agrid = odl.TensorGrid(points)
        apart = odl.RectPartition(odl.Interval(0, 2 * np.pi), agrid)
    elif angle == 'nonuniform':
        # Angles spaced quadratically
        min_pt = 2 * (2.0 * np.pi) / n_angles
        max_pt = (2.0 * np.pi) - 2 * (2.0 * np.pi) / n_angles
        points = np.linspace(min_pt**0.5, max_pt**0.5, n_angles)**2
        agrid = odl.TensorGrid(points)
        apart = odl.RectPartition(odl.Interval(0, 2 * np.pi), agrid)
    else:
        raise ValueError('angle not valid')

    if geom == 'par2d':
        # Discrete reconstruction space
        discr_reco_space = odl.uniform_discr([-20, -20], [20, 20], [100, 100],
                                             dtype='float32')

        # Geometry
        dpart = odl.uniform_partition(-30, 30, 200)
        geom = tomo.Parallel2dGeometry(apart, dpart)

        # Ray transform
        return tomo.RayTransform(discr_reco_space, geom, impl=impl)

    elif geom == 'par3d':
        # Discrete reconstruction space
        discr_reco_space = odl.uniform_discr([-20, -20, -20], [20, 20, 20],
                                             [100, 100, 100],
                                             dtype='float32')

        # Geometry
        dpart = odl.uniform_partition([-30, -30], [30, 30], [200, 200])
        geom = tomo.Parallel3dAxisGeometry(apart, dpart, axis=[1, 0, 0])

        # Ray transform
        return tomo.RayTransform(discr_reco_space, geom, impl=impl)

    elif geom == 'cone2d':
        # Discrete reconstruction space
        discr_reco_space = odl.uniform_discr([-20, -20], [20, 20], [100, 100],
                                             dtype='float32')

        # Geometry
        dpart = odl.uniform_partition(-30, 30, 200)
        geom = tomo.FanFlatGeometry(apart,
                                    dpart,
                                    src_radius=200,
                                    det_radius=100)

        # Ray transform
        return tomo.RayTransform(discr_reco_space, geom, impl=impl)

    elif geom == 'cone3d':
        # Discrete reconstruction space
        discr_reco_space = odl.uniform_discr([-20, -20, -20], [20, 20, 20],
                                             [100, 100, 100],
                                             dtype='float32')

        # Geometry
        dpart = odl.uniform_partition([-30, -30], [30, 30], [200, 200])
        geom = tomo.CircularConeFlatGeometry(apart,
                                             dpart,
                                             src_radius=200,
                                             det_radius=100,
                                             axis=[1, 0, 0])

        # Ray transform
        return tomo.RayTransform(discr_reco_space, geom, impl=impl)

    elif geom == 'helical':
        # Discrete reconstruction space
        discr_reco_space = odl.uniform_discr([-20, -20, 0], [20, 20, 40],
                                             [100, 100, 100],
                                             dtype='float32')

        # Geometry
        # TODO: angles
        n_angle = 700
        apart = odl.uniform_partition(0, 8 * 2 * np.pi, n_angle)
        dpart = odl.uniform_partition([-30, -3], [30, 3], [200, 20])
        geom = tomo.HelicalConeFlatGeometry(apart,
                                            dpart,
                                            pitch=5.0,
                                            src_radius=200,
                                            det_radius=100)

        # Ray transform
        return tomo.RayTransform(discr_reco_space, geom, impl=impl)
    else:
        raise ValueError('param not valid')
示例#20
0
def test_partition_cell_volume():
    grid = odl.uniform_grid([0, 1], [2, 4], (5, 3))
    intv = odl.IntervalProd([0, 1], [2, 4])
    part = odl.RectPartition(intv, grid)
    true_volume = 0.5 * 1.5
    assert part.cell_volume == true_volume
示例#21
0
def test_partition_cell_sides():
    grid = odl.uniform_grid([0, 1], [2, 4], (5, 3))
    intv = odl.IntervalProd([0, 1], [2, 4])
    part = odl.RectPartition(intv, grid)
    true_sides = [0.5, 1.5]
    assert all_equal(part.cell_sides, true_sides)