Esempio n. 1
0
def test_correct_reproduce():
    myframe = sys._getframe()
    sino, angles = create_test_sino_3d(Nx=10, Ny=10)
    p = get_test_parameter_set(1)[0]
    sryt = odtbrain.sinogram_as_rytov(uSin=sino, u0=1, align=False)
    f = odtbrain.backpropagate_3d(sryt,
                                  angles,
                                  padval=0,
                                  dtype=np.float64,
                                  copy=False,
                                  **p)
    fc = odtbrain.apple.correct(f=f,
                                res=p["res"],
                                nm=p["nm"],
                                enforce_envelope=.95,
                                max_iter=100,
                                min_diff=0.01)
    fo = cutout(fc)
    fo = np.array(fo, dtype=np.complex128)

    if WRITE_RES:
        write_results(myframe, fo)

    data = fo.flatten().view(float)
    assert np.allclose(data, get_results(myframe))
Esempio n. 2
0
def test_3d_backprop_phase_real():
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    # reference
    rref = list()
    for p in parameters:
        fref = odtbrain.backpropagate_3d(sino, angles, padval=0,
                                         dtype=np.float64, onlyreal=True, **p)
        rref.append(cutout(fref))
    dataref = np.array(rref).flatten().view(float)

    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_3d_tilted(sino, angles, padval=0,
                                             dtype=np.float64, onlyreal=True,
                                             **p)
        r.append(cutout(f))
    data = np.array(r).flatten().view(float)
    assert np.allclose(data, dataref)
Esempio n. 3
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))
Esempio n. 4
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))
def test_3d_backprop_phase_real():
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    # reference
    rref = list()
    for p in parameters:
        fref = odtbrain._Back_3D.backpropagate_3d(sino, angles, padval=0, dtype=np.float64, onlyreal=True, **p)
        rref.append(cutout(fref))
    dataref = np.array(rref).flatten().view(float)

    r = list()
    for p in parameters:
        f = odtbrain._Back_3D_tilted.backpropagate_3d_tilted(
            sino, angles, padval=0, dtype=np.float64, onlyreal=True, **p
        )
        r.append(cutout(f))
    data = np.array(r).flatten().view(float)
    assert np.allclose(data, dataref)
Esempio n. 6
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))
Esempio n. 7
0
def test_3d_backprop_phase32():
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain._Back_3D.backpropagate_3d(sino, angles,
            dtype=np.float32, padval=0, **p)
        r.append(cutout(f))
    data32 = np.array(r).flatten().view(np.float32)
    data64 = test_3d_backprop_phase()
    assert np.allclose(data32, data64, atol=6e-7, rtol=0)
Esempio n. 8
0
def test_3d_backprop_phase32():
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_3d(sino,
                                      angles,
                                      dtype=np.float32,
                                      padval=0,
                                      **p)
        r.append(cutout(f))
    data32 = np.array(r).flatten().view(np.float32)
    data64 = test_3d_backprop_phase()
    assert np.allclose(data32, data64, atol=6e-7, rtol=0)
Esempio n. 9
0
def test_3d_backprop_phase():
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain._Back_3D.backpropagate_3d(sino, angles, padval=0,
                                               dtype=np.float64, **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    data = np.array(r).flatten().view(float)
    assert np.allclose(data, get_results(myframe))
    return data
Esempio n. 10
0
def test_3d_backprop_phase():
    myframe = sys._getframe()
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_3d(sino,
                                      angles,
                                      padval=0,
                                      dtype=np.float64,
                                      **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    data = np.array(r).flatten().view(float)
    assert np.allclose(data, get_results(myframe))
    return data
Esempio n. 11
0
def test_3d_backprop_nopadreal():
    """
    - no padding
    - only real result
    """
    platform.system = lambda:"Windows"
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain._Back_3D.backpropagate_3d(sino, angles, padding=(False,False),
                                               dtype=np.float64, onlyreal=True, **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    data = np.array(r).flatten().view(float)
    assert np.allclose(data, get_results(myframe))
def test_3d_backprop_plane_rotation():
    """
    A very soft test to check if planar rotation works fine
    in the reconstruction with tilted angles.
    """
    myframe = sys._getframe()
    myname = myframe.f_code.co_name
    print("running ", myname)

    parameters = get_test_parameter_set(1)
    results = []

    # These are specially selected angles that don't give high results.
    # Probably due to phase-wrapping, errors >2 may appear. Hence, we
    # call it a soft test.
    tilts = [1.1, 0.0, 0.234, 2.80922, -0.29, 9.87]

    for angz in tilts:
        sino, angles = create_test_sino_3d_tilted(tilt_plane=angz, A=21)
        rotmat = np.array([[np.cos(angz), -np.sin(angz), 0], [np.sin(angz), np.cos(angz), 0], [0, 0, 1]])
        # rotate `tilted_axis` onto the y-z plane.
        tilted_axis = np.dot(rotmat, [0, 1, 0])

        rref = list()
        for p in parameters:
            fref = odtbrain._Back_3D_tilted.backpropagate_3d_tilted(
                sino,
                angles,
                padval=None,
                tilted_axis=tilted_axis,
                padding=(False, False),
                dtype=np.float64,
                onlyreal=False,
                **p
            )
            rref.append(cutout(fref))
        data = np.array(rref).flatten().view(float)
        results.append(data)

    for ii in np.arange(len(results)):
        assert np.allclose(results[ii], results[ii - 1], atol=0.2, rtol=0.2)
Esempio n. 13
0
def test_3d_backprop_nopadreal():
    """
    - no padding
    - only real result
    """
    platform.system = lambda: "Windows"
    myframe = sys._getframe()
    sino, angles = create_test_sino_3d()
    parameters = get_test_parameter_set(2)
    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_3d(sino,
                                      angles,
                                      padding=(False, False),
                                      dtype=np.float64,
                                      onlyreal=True,
                                      **p)
        r.append(cutout(f))
    if WRITE_RES:
        write_results(myframe, r)
    data = np.array(r).flatten().view(float)
    assert np.allclose(data, get_results(myframe))
Esempio n. 14
0
def test_3d_backprop_plane_rotation():
    """
    A very soft test to check if planar rotation works fine
    in the reconstruction with tilted angles.
    """
    parameters = get_test_parameter_set(1)
    results = []

    # These are specially selected angles that don't give high results.
    # Probably due to phase-wrapping, errors >2 may appear. Hence, we
    # call it a soft test.
    tilts = [1.1, 0.0, 0.234, 2.80922, -.29, 9.87]

    for angz in tilts:
        sino, angles = create_test_sino_3d_tilted(tilt_plane=angz, A=21)
        rotmat = np.array([
            [np.cos(angz), -np.sin(angz), 0],
            [np.sin(angz),  np.cos(angz), 0],
            [0,             0, 1],
        ])
        # rotate `tilted_axis` onto the y-z plane.
        tilted_axis = np.dot(rotmat, [0, 1, 0])

        rref = list()
        for p in parameters:
            fref = odtbrain.backpropagate_3d_tilted(sino, angles,
                                                    padval="edge",
                                                    tilted_axis=tilted_axis,
                                                    padding=(False, False),
                                                    dtype=np.float64,
                                                    onlyreal=False,
                                                    **p)
            rref.append(cutout(fref))
        data = np.array(rref).flatten().view(float)
        results.append(data)

    for ii in np.arange(len(results)):
        assert np.allclose(results[ii], results[ii-1], atol=.2, rtol=.2)