Пример #1
0
def test_angle_offset():
    """
    Tests if things are still correct when there is a 2PI offset in the angles.
    """
    sino, angles = create_test_sino_2d()
    parameters = get_test_parameter_set(2)
    # reference
    r1 = []
    for p in parameters:
        f1 = odtbrain.backpropagate_2d(sino, angles, weight_angles=False, **p)
        r1.append(f1)
    # with offset
    angles[::2] += 2*np.pi*np.arange(angles[::2].shape[0])
    r2 = []
    for p in parameters:
        f2 = odtbrain.backpropagate_2d(sino, angles, weight_angles=False, **p)
        r2.append(f2)
    # with offset and weights
    r3 = []
    for p in parameters:
        f3 = odtbrain.backpropagate_2d(sino, angles, weight_angles=True, **p)
        r3.append(f3)
    assert np.allclose(np.array(r1).flatten().view(float),
                       np.array(r2).flatten().view(float))
    assert np.allclose(np.array(r2).flatten().view(float),
                       np.array(r3).flatten().view(float))
Пример #2
0
def test_angle_swap():
    """
    Test if everything still works, when angles are swapped.
    """
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_2d()
    # remove elements so that we can see that weighting works
    angles = angles[:-2]
    sino = sino[:-2,:]
    parameters = get_test_parameter_set(2)
    # reference
    r1 = []
    for p in parameters:
        f1 = odtbrain._Back_2D.backpropagate_2d(sino, angles, weight_angles=True, **p)
        r1.append(f1)
    # change order of angles
    order = np.argsort(angles % .5) 
    angles = angles[order]
    sino = sino[order,:]
    r2 = []
    for p in parameters:
        f2 = odtbrain._Back_2D.backpropagate_2d(sino, angles, weight_angles=True, **p)    
        r2.append(f2)
    assert np.allclose(np.array(r1).flatten().view(float),
                       np.array(r2).flatten().view(float))
Пример #3
0
def test_angle_offset():
    """
    Tests if things are still correct when there is a 2PI offset in the angles.
    """
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_2d()
    parameters = get_test_parameter_set(2)
    # reference
    r1 = []
    for p in parameters:
        f1 = odtbrain._Back_2D.backpropagate_2d(sino, angles, weight_angles=False, **p)
        r1.append(f1)
    # with offset
    angles[::2] += 2*np.pi*np.arange(angles[::2].shape[0])
    r2 = []
    for p in parameters:
        f2 = odtbrain._Back_2D.backpropagate_2d(sino, angles, weight_angles=False, **p)    
        r2.append(f2)
    # with offset and weights
    r3 = []
    for p in parameters:
        f3 = odtbrain._Back_2D.backpropagate_2d(sino, angles, weight_angles=True, **p)    
        r3.append(f3)
    assert np.allclose(np.array(r1).flatten().view(float),
                       np.array(r2).flatten().view(float))
    assert np.allclose(np.array(r2).flatten().view(float),
                       np.array(r3).flatten().view(float))
Пример #4
0
def test_2d_fmap():
    myframe = sys._getframe()
    sino, angles = create_test_sino_2d()
    parameters = get_test_parameter_set(1)
    r = []
    for p in parameters:
        f = odtbrain.fourier_map_2d(sino, angles, **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    assert np.allclose(np.array(r).flatten().view(float), get_results(myframe))
Пример #5
0
def test_fmp_2d():
    sino, angles = create_test_sino_2d(N=10)
    p = get_test_parameter_set(1)[0]
    # complex
    jmc = mp.Value("i", 0)
    jmm = mp.Value("i", 0)

    odtbrain.fourier_map_2d(sino, angles, count=jmc, max_count=jmm, **p)

    assert jmc.value == jmm.value
    assert jmc.value != 0
Пример #6
0
def test_2d_backprop_full():
    myframe = sys._getframe()
    sino, angles = create_test_sino_2d(ampl_range=(0.9, 1.1))
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_2d(sino, angles, **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    assert np.allclose(np.array(r).flatten().view(float), get_results(myframe))
Пример #7
0
def test_2d_backprop_full():
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_2d(ampl_range=(0.9,1.1))
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain._Back_2D.backpropagate_2d(sino, angles, **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    assert np.allclose(np.array(r).flatten().view(float), get_results(myframe))
Пример #8
0
def test_bpp_2d():
    sino, angles = create_test_sino_2d(N=10)
    p = get_test_parameter_set(1)[0]
    # complex
    jmc = mp.Value("i", 0)
    jmm = mp.Value("i", 0)

    odtbrain.backpropagate_2d(sino,
                              angles,
                              padval=0,
                              count=jmc,
                              max_count=jmm,
                              **p)
    assert jmc.value == jmm.value
    assert jmc.value != 0
Пример #9
0
def test_back2d():
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_2d(N=10)
    p = get_test_parameter_set(1)[0]
    # complex
    jmc = mp.Value("i", 0)
    jmm = mp.Value("i", 0)

    f = odtbrain._Back_2D.backpropagate_2d(sino, angles, padval=0,
                                           jmc=jmc,
                                           jmm=jmm,
                                           **p)
    assert jmc.value == jmm.value
    assert jmc.value != 0
Пример #10
0
def test_2d_backprop_real():
    """
    Check if the real reconstruction matches the real part
    of the complex reconstruction.
    """
    sino, angles = create_test_sino_2d()
    parameters = get_test_parameter_set(2)
    # complex
    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_2d(sino, angles, padval=0, **p)
        r.append(f)
    # real
    r2 = list()
    for p in parameters:
        f = odtbrain.backpropagate_2d(sino,
                                      angles,
                                      padval=0,
                                      onlyreal=True,
                                      **p)
        r2.append(f)
    assert np.allclose(np.array(r).real, np.array(r2))
Пример #11
0
def test_2d_backprop_real():
    """
    Check if the real reconstruction matches the real part
    of the complex reconstruction.
    """
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_2d()
    parameters = get_test_parameter_set(2)
    # complex
    r = list()
    for p in parameters:
        f = odtbrain._Back_2D.backpropagate_2d(sino, angles, padval=0,
                                               **p)
        r.append(f)
    # real
    r2 = list()
    for p in parameters:
        f = odtbrain._Back_2D.backpropagate_2d(sino, angles, padval=0,
                                               onlyreal=True, **p)
        r2.append(f)
    assert np.allclose(np.array(r).real, np.array(r2))
Пример #12
0
def test_angle_swap():
    """
    Test if everything still works, when angles are swapped.
    """
    sino, angles = create_test_sino_2d()
    # remove elements so that we can see that weighting works
    angles = angles[:-2]
    sino = sino[:-2, :]
    parameters = get_test_parameter_set(2)
    # reference
    r1 = []
    for p in parameters:
        f1 = odtbrain.backpropagate_2d(sino, angles, weight_angles=True, **p)
        r1.append(f1)
    # change order of angles
    order = np.argsort(angles % .5)
    angles = angles[order]
    sino = sino[order, :]
    r2 = []
    for p in parameters:
        f2 = odtbrain.backpropagate_2d(sino, angles, weight_angles=True, **p)
        r2.append(f2)
    assert np.allclose(np.array(r1).flatten().view(float),
                       np.array(r2).flatten().view(float))