Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore running of astra tests #568

Merged
merged 9 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- id: files
uses: Ana06/get-changed-files@v2.2.0
uses: Ana06/get-changed-files@v2.3.0
continue-on-error: true
- run: |
for f in ${{ steps.files.outputs.added }}; do
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pytest_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ jobs:
coverage combine coverage?/.coverage
coverage report
coverage xml
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
env_vars: OS,PYTHON
fail_ci_if_error: false
Expand Down
2 changes: 1 addition & 1 deletion scico/linop/xray/astra.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def volume_coords_to_world_coords(idx: np.ndarray, vol_geom: VolumeGeometry) ->

def _volume_index_to_astra_world_2d(idx: np.ndarray, vol_geom: VolumeGeometry) -> np.ndarray:
"""Convert a 2D volume coordinate into a 2D world coordinate."""
coord = idx[..., [2, 1]] # x:col, y:row,
coord = idx[..., [1, 0]] # x:col, y:row,
nx = np.array( # (x, y) order
(
vol_geom["GridColCount"],
Expand Down
9 changes: 9 additions & 0 deletions scico/test/linop/test_convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def testobj(request):
yield ConvolveTestObj()


def test_init(testobj):
with pytest.raises(ValueError):
A = Convolve(input_shape=(16, 16), h=testobj.psf_A)
with pytest.raises(ValueError):
A = Convolve(input_shape=(16,), h=testobj.psf_A, mode="invalid")
A = Convolve(input_shape=(16,), input_dtype=None, h=testobj.psf_A)
assert A.input_dtype == testobj.psf_A.dtype


@pytest.mark.parametrize("operator", [op.mul, op.truediv])
def test_scalar_left(testobj, operator):
A = operator(testobj.A, testobj.scalar)
Expand Down
44 changes: 43 additions & 1 deletion scico/test/linop/xray/test_astra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import scico.numpy as snp
from scico.linop import DiagonalStack
from scico.test.linop.test_linop import adjoint_test
from scico.test.linop.xray.test_svmbir import make_im

try:
from scico.linop.xray.astra import (
Expand All @@ -30,6 +29,17 @@
RTOL_GPU_RANDOM_INPUT = 1.0


def make_im(Nx, Ny, is_3d=True):
x, y = snp.meshgrid(snp.linspace(-1, 1, Nx), snp.linspace(-1, 1, Ny), indexing="ij")

im = snp.where((x - 0.25) ** 2 / 3 + y**2 < 0.1, 1.0, 0.0)
if is_3d:
im = im[snp.newaxis, :, :]
im = im.astype(snp.float32)

return im


def get_tol():
if jax.devices()[0].device_kind == "cpu":
rtol = RTOL_CPU
Expand Down Expand Up @@ -70,6 +80,31 @@ def testobj(request):
yield XRayTransform2DTest(request.param)


def test_init(testobj):
with pytest.raises(ValueError):
A = XRayTransform2D(
input_shape=(16, 16, 16),
det_count=16,
det_spacing=1.0,
angles=np.linspace(0, np.pi, 32, False),
)
with pytest.raises(ValueError):
A = XRayTransform2D(
input_shape=(16, 16),
det_count=16.3,
det_spacing=1.0,
angles=np.linspace(0, np.pi, 32, False),
)
with pytest.raises(ValueError):
A = XRayTransform2D(
input_shape=(16, 16),
det_count=16,
det_spacing=1.0,
angles=np.linspace(0, np.pi, 32, False),
device="invalid",
)


def test_ATA_call(testobj):
# Test for the call-based interface
Ax = testobj.A(testobj.x)
Expand Down Expand Up @@ -280,6 +315,13 @@ def test_convert_from_scico_geometry(test_geometry):
np.testing.assert_allclose(vectors[0, 6:], proj_geom_truth["Vectors"][0, 6:])


def test_vol_coord_to_world_coord():
vol_geom = scico.linop.xray.astra.astra.create_vol_geom(16, 16)
vc = np.array([[0.0, 0.0], [1.0, 1.0]])
wc = scico.linop.xray.astra.volume_coords_to_world_coords(vc, vol_geom)
assert wc.shape == (2, 2)


def test_ensure_writeable():
assert isinstance(_ensure_writeable(np.ones((2, 1))), np.ndarray)
assert isinstance(_ensure_writeable(snp.ones((2, 1))), np.ndarray)
2 changes: 1 addition & 1 deletion scico/test/linop/xray/test_svmbir.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def pytest_generate_tests(metafunc):


def make_im(Nx, Ny, is_3d=True):
x, y = snp.meshgrid(snp.linspace(-1, 1, Nx), snp.linspace(-1, 1, Ny))
x, y = snp.meshgrid(snp.linspace(-1, 1, Nx), snp.linspace(-1, 1, Ny), indexing="ij")

im = snp.where((x - 0.25) ** 2 / 3 + y**2 < 0.1, 1.0, 0.0)
if is_3d:
Expand Down
Loading