Beispiel #1
0
def test_back3d_tilted():
    sino, angles = create_test_sino_3d(Nx=10, Ny=10)
    parameters = get_test_parameter_set(2)
    # complex
    r = list()
    for p in parameters:
        f = odtbrain.backpropagate_3d_tilted(sino,
                                             angles,
                                             padval=0,
                                             dtype=np.float64,
                                             save_memory=False,
                                             **p)
        r.append(f)
    # real
    r2 = list()
    for p in parameters:
        f = odtbrain.backpropagate_3d_tilted(sino,
                                             angles,
                                             padval=0,
                                             dtype=np.float64,
                                             save_memory=True,
                                             **p)
        r2.append(f)

    assert np.allclose(np.array(r), np.array(r2))
Beispiel #2
0
def test_back3d_tilted():
    sino, angles = create_test_sino_3d(Nx=10, Ny=10)
    p = get_test_parameter_set(1)[0]
    # complex
    jmc = mp.Value("i", 0)
    jmm = mp.Value("i", 0)
    odtbrain.backpropagate_3d_tilted(sino,
                                     angles,
                                     padval=0,
                                     dtype=np.float64,
                                     count=jmc,
                                     max_count=jmm,
                                     **p)
    assert jmc.value == jmm.value
    assert jmc.value != 0
Beispiel #3
0
def test_3d_backprop_plane_alignment_along_axes():
    """
    Tests whether the reconstruction is always aligned with
    the rotational axis (and not antiparallel).
    """
    parameters = get_test_parameter_set(1)
    p = parameters[0]
    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 = [0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi]

    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])
        fref = odtbrain.backpropagate_3d_tilted(sino, angles,
                                                padval="edge",
                                                tilted_axis=tilted_axis,
                                                padding=(False, False),
                                                dtype=np.float64,
                                                onlyreal=True,
                                                **p)
        results.append(fref)

    for ii in np.arange(len(results)):
        assert np.allclose(results[ii], results[ii-1], atol=.2, rtol=.2)
Beispiel #4
0
def test_back3d_tilted():
    sino, angles = create_test_sino_3d(Nx=10, Ny=10)
    p = get_test_parameter_set(1)[0]
    f1 = odtbrain.backpropagate_3d_tilted(sino,
                                          angles,
                                          padval=0,
                                          dtype=np.float64,
                                          copy=False,
                                          **p)
    f2 = odtbrain.backpropagate_3d_tilted(sino,
                                          angles,
                                          padval=0,
                                          dtype=np.float64,
                                          copy=True,
                                          **p)
    assert np.allclose(f1, f2)
Beispiel #5
0
def test_3d_backprop_tilted_weights_even():
    """
    even weights
    """
    platform.system = lambda: "Windows"
    sino, angles = create_test_sino_3d()
    p = get_test_parameter_set(1)[0]
    f1 = odtbrain.backpropagate_3d_tilted(sino,
                                          angles,
                                          weight_angles=False,
                                          **p)
    f2 = odtbrain.backpropagate_3d_tilted(sino,
                                          angles,
                                          weight_angles=True,
                                          **p)
    data1 = np.array(f1).flatten().view(float)
    data2 = np.array(f2).flatten().view(float)
    assert np.allclose(data1, data2)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
# Perform naive backpropagation
f_naiv = odt.backpropagate_3d(uSin=sinoRytov,
                              angles=angles,
                              res=cfg["res"],
                              nm=cfg["nm"],
                              lD=cfg["lD"])

print("Performing tilted backpropagation.")
# Determine tilted axis
tilted_axis = [0, np.cos(cfg["tilt_yz"]), np.sin(cfg["tilt_yz"])]

# Perform tilted backpropagation
f_tilt = odt.backpropagate_3d_tilted(
    uSin=sinoRytov,
    angles=angles,
    res=cfg["res"],
    nm=cfg["nm"],
    lD=cfg["lD"],
    tilted_axis=tilted_axis,
)

# compute refractive index n from object function
n_naiv = odt.odt_to_ri(f_naiv, res=cfg["res"], nm=cfg["nm"])
n_tilt = odt.odt_to_ri(f_tilt, res=cfg["res"], nm=cfg["nm"])

sx, sy, sz = n_tilt.shape
px, py, pz = phantom.shape

sino_phase = np.angle(sino)

# compare phantom and reconstruction in plot
fig, axes = plt.subplots(2, 3, figsize=(8, 4.5))
    tilted_axis = [0, np.cos(cfg["tilt_yz"]), np.sin(cfg["tilt_yz"])]
    rotmat = np.array([ 
                       [np.cos(rotang), -np.sin(rotang),0],
                       [np.sin(rotang), np.cos(rotang),0],
                       [0,0,1],
                       ])
    tilted_axis = np.dot(rotmat, tilted_axis)

    print("Performing tilted backpropagation.")
    ## Perform tilted backpropagation
    f_name_tilt = "f_tilt2.npy"
    if not os.path.exists(f_name_tilt):
        f_tilt = odt.backpropagate_3d_tilted( uSin=sinoRytov,
                                              angles=angles,
                                              res=cfg["res"],
                                              nm=cfg["nm"],
                                              lD=cfg["lD"],
                                              tilted_axis=tilted_axis,
                                              )
        np.save(f_name_tilt, f_tilt)
    else:
        f_tilt = np.load(f_name_tilt)

    ## compute refractive index n from object function
    n_tilt = odt.odt_to_ri(f_tilt, res=cfg["res"], nm=cfg["nm"])

    sx, sy, sz = n_tilt.shape
    px, py, pz = phantom.shape


    sino_phase = np.angle(sino)