Skip to content

Commit

Permalink
fix: reconstruction volume rotated by 180° due to floating point inac…
Browse files Browse the repository at this point in the history
…curacies (tilted bpg)
  • Loading branch information
paulmueller committed Apr 8, 2019
1 parent a3918ad commit f020ac6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.2.5
- fix: reconstruction volume rotated by 180° due to floating point
inaccuracies (affects `backpropagate_3d_tilted`).
0.2.4
- maintenance release
0.2.3
- enh: employ slice-wise padding to reduce the memory usage (and
possibly the computation time) of
Expand Down
7 changes: 6 additions & 1 deletion odtbrain/_alg3d_bppt.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ def sphere_points_from_angles_and_tilt(angles, tilted_axis):

# (b) This is the polar angle measured in the x-z plane starting
# at the x-axis and measured towards the positive z-axis.
phi = np.arctan2(u, w)
if np.allclose(u, 0) and np.allclose(w, 0):
# Avoid flipping the axis of rotation due to numerical
# errors during its computation.
phi = 0
else:
phi = np.arctan2(u, w)

# Determine the projection points on the unit sphere.
# The resulting circle meets the x-z-plane at phi, and
Expand Down
36 changes: 36 additions & 0 deletions tests/test_alg3d_bppt.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ def test_3d_backprop_plane_rotation():
assert np.allclose(results[ii], results[ii-1], atol=.2, rtol=.2)


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=None,
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)


if __name__ == "__main__":
# Run all tests
loc = locals()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_spherecoords_from_angles_and_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def test_simple_sphere():
[0.87965281125489458, s2/3*2, 0.063156230327168605],
[s2/3, s2/3*4, s2/3]],
])

assert np.allclose(correct.flatten(), np.array(results).flatten())
assert np.allclose(correct, np.array(results))


if __name__ == "__main__":
Expand Down

0 comments on commit f020ac6

Please sign in to comment.