Skip to content

Commit

Permalink
Add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-T-McCann committed Oct 15, 2024
1 parent 8dc1a2a commit bff2ee3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 42 deletions.
53 changes: 11 additions & 42 deletions scico/test/linop/xray/test_xray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import pytest

import scico
from scico.linop.xray import XRayTransform2D, XRayTransform3D
import scico.linop
from scico.linop.xray import XRayTransform2D


@pytest.mark.filterwarnings("error")
Expand Down Expand Up @@ -71,44 +72,12 @@ def test_apply_adjoint():
assert y.shape[1] == det_count


def test_3d_scaling():
x = jnp.zeros((4, 4, 1))
x = x.at[1:3, 1:3, 0].set(1.0)

input_shape = x.shape
output_shape = x.shape[:2]

# default spacing
M = XRayTransform3D.matrices_from_euler_angles(input_shape, output_shape, "X", [0.0])
H = XRayTransform3D(input_shape, matrices=M, det_shape=output_shape)
# fmt: off
truth = jnp.array(
[[[0.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 1.0, 0.0],
[0.0, 1.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 0.0]]]
) # fmt: on
np.testing.assert_allclose(H @ x, truth)

# bigger voxels in the x (first index) direction
M = XRayTransform3D.matrices_from_euler_angles(
input_shape, output_shape, "X", [0.0], voxel_spacing=[2.0, 1.0, 1.0]
)
H = XRayTransform3D(input_shape, matrices=M, det_shape=output_shape)
# fmt: off
truth = jnp.array(
[[[0. , 0.5, 0.5, 0. ],
[0. , 0.5, 0.5, 0. ],
[0. , 0.5, 0.5, 0. ],
[0. , 0.5, 0.5, 0. ]]]
) # fmt: on
np.testing.assert_allclose(H @ x, truth)

# bigger detector pixels in the x (first index) direction
M = XRayTransform3D.matrices_from_euler_angles(
input_shape, output_shape, "X", [0.0], det_spacing=[2.0, 1.0]
)
H = XRayTransform3D(input_shape, matrices=M, det_shape=output_shape)
# fmt: off
truth = None # fmt: on # TODO: Check this case more closely.
# np.testing.assert_allclose(H @ x, truth)
def test_matched_adjoint():
"""See https://github.com/lanl/scico/issues/560."""
N = 16
det_count = int(N * 1.05 / np.sqrt(2.0))
dx = 1.0 / np.sqrt(2)
n_projection = 3
angles = np.linspace(0, np.pi, n_projection, endpoint=False)
A = XRayTransform2D((N, N), angles, det_count=det_count, dx=dx)
assert scico.linop.valid_adjoint(A, A.T, eps=1e-5)
66 changes: 66 additions & 0 deletions scico/test/linop/xray/test_xray_3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import numpy as np

import jax.numpy as jnp

import scico.linop
from scico.linop.xray import XRayTransform3D


def test_matched_adjoint():
"""See https://github.com/lanl/scico/issues/560."""
N = 16
det_count = int(N * 1.05 / np.sqrt(2.0))
n_projection = 3

input_shape = (N, N, N)
det_shape = (det_count, det_count)

M = XRayTransform3D.matrices_from_euler_angles(
input_shape, det_shape, "X", np.linspace(0, np.pi, n_projection, endpoint=False)
)
H = XRayTransform3D(input_shape, matrices=M, det_shape=det_shape)

assert scico.linop.valid_adjoint(H, H.T, eps=1e-5)


def test_scaling():
x = jnp.zeros((4, 4, 1))
x = x.at[1:3, 1:3, 0].set(1.0)

input_shape = x.shape
det_shape = x.shape[:2]

# default spacing
M = XRayTransform3D.matrices_from_euler_angles(input_shape, det_shape, "X", [0.0])
H = XRayTransform3D(input_shape, matrices=M, det_shape=det_shape)
# fmt: off
truth = jnp.array(
[[[0.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 1.0, 0.0],
[0.0, 1.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 0.0]]]
) # fmt: on
np.testing.assert_allclose(H @ x, truth)

# bigger voxels in the x (first index) direction
M = XRayTransform3D.matrices_from_euler_angles(
input_shape, det_shape, "X", [0.0], voxel_spacing=[2.0, 1.0, 1.0]
)
H = XRayTransform3D(input_shape, matrices=M, det_shape=det_shape)
# fmt: off
truth = jnp.array(
[[[0. , 0.5, 0.5, 0. ],
[0. , 0.5, 0.5, 0. ],
[0. , 0.5, 0.5, 0. ],
[0. , 0.5, 0.5, 0. ]]]
) # fmt: on
np.testing.assert_allclose(H @ x, truth)

# bigger detector pixels in the x (first index) direction
M = XRayTransform3D.matrices_from_euler_angles(
input_shape, det_shape, "X", [0.0], det_spacing=[2.0, 1.0]
)
H = XRayTransform3D(input_shape, matrices=M, det_shape=det_shape)
# fmt: off
truth = None # fmt: on # TODO: Check this case more closely.
# np.testing.assert_allclose(H @ x, truth)

0 comments on commit bff2ee3

Please sign in to comment.