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

Add human readable ids to test #485

Merged
merged 8 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion tests/algorithms/test_cg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
(1, 32, False),
(4, 32, True),
(4, 32, False),
]
],
ids=['complex_single', 'real_single', 'complex_batch', 'real_batch'],
)
def system(request):
"""Generate data for creating a system Hx=b with linear and self-adjoint
Expand Down
300 changes: 151 additions & 149 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,178 +233,180 @@ def create_uniform_traj(nk, k_shape):
return k


def create_traj(k_shape, nkx, nky, nkz, sx, sy, sz):
def create_traj(k_shape, nkx, nky, nkz, type_kx, type_ky, type_kz):
"""Create trajectory with random entries."""
random_generator = RandomGenerator(seed=0)
k_list = []
for spacing, nk in zip([sz, sy, sx], [nkz, nky, nkx], strict=True):
if spacing == 'nuf':
for spacing, nk in zip([type_kz, type_ky, type_kx], [nkz, nky, nkx], strict=True):
if spacing == 'non-uniform':
k = random_generator.float32_tensor(size=nk)
elif spacing == 'uf':
elif spacing == 'uniform':
k = create_uniform_traj(nk, k_shape=k_shape)
elif spacing == 'z':
elif spacing == 'zero':
k = torch.zeros(nk)
k_list.append(k)
trajectory = KTrajectory(k_list[0], k_list[1], k_list[2], repeat_detection_tolerance=None)
return trajectory


COMMON_MR_TRAJECTORIES = pytest.mark.parametrize(
('im_shape', 'k_shape', 'nkx', 'nky', 'nkz', 'sx', 'sy', 'sz', 's0', 's1', 's2'),
('im_shape', 'k_shape', 'nkx', 'nky', 'nkz', 'type_kx', 'type_ky', 'type_kz', 'type_k0', 'type_k1', 'type_k2'),
[
# (0) 2d cart mri with 1 coil, no oversampling
(
(1, 1, 1, 96, 128), # img shape
(1, 1, 1, 96, 128), # k shape
(1, 1, 1, 128), # kx
(1, 1, 96, 1), # ky
(1, 1, 1, 1), # kz
'uf', # kx is uniform
'uf', # ky is uniform
'z', # zero so no Fourier transform is performed along that dimension
'uf', # k0 is uniform
'uf', # k1 is uniform
'z', # k2 is singleton
( # (0) 2d Cartesian single coil, no oversampling
(1, 1, 1, 96, 128), # im_shape
(1, 1, 1, 96, 128), # k_shape
(1, 1, 1, 128), # nkx
(1, 1, 96, 1), # nky
(1, 1, 1, 1), # nkz
'uniform', # type_kx
'uniform', # type_ky
'zero', # type_kz
'uniform', # type_k0
'uniform', # type_k1
'zero', # type_k2
),
# (1) 2d cart mri with 1 coil, with oversampling
(
(1, 1, 1, 96, 128),
(1, 1, 1, 128, 192),
(1, 1, 1, 192),
(1, 1, 128, 1),
(1, 1, 1, 1),
'uf',
'uf',
'z',
'uf',
'uf',
'z',
( # (1) 2d Cartesian single coil, with oversampling
(1, 1, 1, 96, 128), # im_shape
(1, 1, 1, 128, 192), # k_shape
(1, 1, 1, 192), # nkx
(1, 1, 128, 1), # nky
(1, 1, 1, 1), # nkz
'uniform', # type_kx
'uniform', # type_ky
'zero', # type_kz
'uniform', # type_k0
'uniform', # type_k1
'zero', # type_k2
),
# (2) 2d non-Cartesian mri with 2 coils
(
(1, 2, 1, 96, 128),
(1, 2, 1, 16, 192),
(1, 1, 16, 192),
(1, 1, 16, 192),
(1, 1, 1, 1),
'nuf', # kx is non-uniform
'nuf',
'z',
'nuf',
'nuf',
'z',
( # (2) 2d non-Cartesian mri with 2 coils
(1, 2, 1, 96, 128), # im_shape
(1, 2, 1, 16, 192), # k_shape
(1, 1, 16, 192), # nkx
(1, 1, 16, 192), # nky
(1, 1, 1, 1), # nkz
'non-uniform', # type_kx
'non-uniform', # type_ky
'zero', # type_kz
'non-uniform', # type_k0
'non-uniform', # type_k1
'zero', # type_k2
),
# (3) 2d cart mri with irregular sampling
(
(1, 1, 1, 96, 128),
(1, 1, 1, 1, 192),
(1, 1, 1, 192),
(1, 1, 1, 192),
(1, 1, 1, 1),
'uf',
'uf',
'z',
'uf',
'z',
'z',
( # (3) 2d Cartesian with irregular sampling
(1, 1, 1, 96, 128), # im_shape
(1, 1, 1, 1, 192), # k_shape
(1, 1, 1, 192), # nkx
(1, 1, 1, 192), # nky
(1, 1, 1, 1), # nkz
'uniform', # type_kx
'uniform', # type_ky
'zero', # type_kz
'uniform', # type_k0
'zero', # type_k1
'zero', # type_k2
),
# (4) 2d single shot spiral
(
(1, 2, 1, 96, 128),
(1, 1, 1, 1, 192),
(1, 1, 1, 192),
(1, 1, 1, 192),
(1, 1, 1, 1),
'nuf',
'nuf',
'z',
'nuf',
'z',
'z',
( # (4) 2d single shot spiral
(1, 2, 1, 96, 128), # im_shape
(1, 1, 1, 1, 192), # k_shape
(1, 1, 1, 192), # nkx
(1, 1, 1, 192), # nky
(1, 1, 1, 1), # nkz
'non-uniform', # type_kx
'non-uniform', # type_ky
'zero', # type_kz
'non-uniform', # type_k0
'zero', # type_k1
'zero', # type_k2
),
# (5) 3d nuFFT mri, 4 coils, 2 other
(
(2, 4, 16, 32, 64),
(2, 4, 16, 32, 64),
(2, 16, 32, 64),
(2, 16, 32, 64),
(2, 16, 32, 64),
'nuf',
'nuf',
'nuf',
'nuf',
'nuf',
'nuf',
( # (5) 3d non-uniform, 4 coils, 2 other
(2, 4, 16, 32, 64), # im_shape
(2, 4, 16, 32, 64), # k_shape
(2, 16, 32, 64), # nkx
(2, 16, 32, 64), # nky
(2, 16, 32, 64), # nkz
'non-uniform', # type_kx
'non-uniform', # type_ky
'non-uniform', # type_kz
'non-uniform', # type_k0
'non-uniform', # type_k1
'non-uniform', # type_k2
),
# (6) 2d nuFFT cine mri with 8 cardiac phases, 5 coils
(
(8, 5, 1, 64, 64),
(8, 5, 1, 18, 128),
(8, 1, 18, 128),
(8, 1, 18, 128),
(8, 1, 1, 1),
'nuf',
'nuf',
'z',
'nuf',
'nuf',
'z',
( # (6) 2d non-uniform cine with 8 cardiac phases, 5 coils
(8, 5, 1, 64, 64), # im_shape
(8, 5, 1, 18, 128), # k_shape
(8, 1, 18, 128), # nkx
(8, 1, 18, 128), # nky
(8, 1, 1, 1), # nkz
'non-uniform', # type_kx
'non-uniform', # type_ky
'zero', # type_kz
'non-uniform', # type_k0
'non-uniform', # type_k1
'zero', # type_k2
),
# (7) 2d cart cine mri with 9 cardiac phases, 6 coils
(
(9, 6, 1, 96, 128),
(9, 6, 1, 128, 192),
(9, 1, 1, 192),
(9, 1, 128, 1),
(9, 1, 1, 1),
'uf',
'uf',
'z',
'uf',
'uf',
'z',
( # (7) 2d cartesian cine with 9 cardiac phases, 6 coils
(9, 6, 1, 96, 128), # im_shape
(9, 6, 1, 128, 192), # k_shape
(9, 1, 1, 192), # nkx
(9, 1, 128, 1), # nky
(9, 1, 1, 1), # nkz
'uniform', # type_kx
'uniform', # type_ky
'zero', # type_kz
'uniform', # type_k0
'uniform', # type_k1
'zero', # type_k2
),
# (8) radial phase encoding (RPE), 8 coils, with oversampling in both FFT and nuFFT directions
(
(2, 8, 64, 32, 48),
(2, 8, 8, 64, 96),
(2, 1, 1, 96),
(2, 8, 64, 1),
(2, 8, 64, 1),
'uf',
'nuf',
'nuf',
'uf',
'nuf',
'nuf',
( # (8) radial phase encoding (RPE), 8 coils, with oversampling in both FFT and non-uniform directions
(2, 8, 64, 32, 48), # im_shape
(2, 8, 8, 64, 96), # k_shape
(2, 1, 1, 96), # nkx
(2, 8, 64, 1), # nky
(2, 8, 64, 1), # nkz
'uniform', # type_kx
'non-uniform', # type_ky
'non-uniform', # type_kz
'uniform', # type_k0
'non-uniform', # type_k1
'non-uniform', # type_k2
),
# (9) radial phase encoding (RPE) , 8 coils with non-Cartesian sampling along readout
(
(2, 8, 64, 32, 48),
(2, 8, 8, 64, 96),
(2, 1, 1, 96),
(2, 8, 64, 1),
(2, 8, 64, 1),
'nuf',
'nuf',
'nuf',
'nuf',
'nuf',
'nuf',
( # (9) radial phase encoding (RPE), 8 coils with non-Cartesian sampling along readout
(2, 8, 64, 32, 48), # im_shape
(2, 8, 8, 64, 96), # k_shape
(2, 1, 1, 96), # nkx
(2, 8, 64, 1), # nky
(2, 8, 64, 1), # nkz
'non-uniform', # type_kx
'non-uniform', # type_ky
'non-uniform', # type_kz
'non-uniform', # type_k0
'non-uniform', # type_k1
'non-uniform', # type_k2
),
# (10) stack of stars, 5 other, 3 coil, oversampling in both FFT and nuFFT directions
(
(5, 3, 48, 16, 32),
(5, 3, 96, 18, 64),
(5, 1, 18, 64),
(5, 1, 18, 64),
(5, 96, 1, 1),
'nuf',
'nuf',
'uf',
'nuf',
'nuf',
'uf',
( # (10) stack of stars, 5 other, 3 coil, oversampling in both FFT and non-uniform directions
(5, 3, 48, 16, 32), # im_shape
(5, 3, 96, 18, 64), # k_shape
(5, 1, 18, 64), # nkx
(5, 1, 18, 64), # nky
(5, 96, 1, 1), # nkz
'non-uniform', # type_kx
'non-uniform', # type_ky
'uniform', # type_kz
'non-uniform', # type_k0
'non-uniform', # type_k1
'uniform', # type_k2
),
],
ids=[
'2d_cartesian_1_coil_no_oversampling',
'2d_cartesian_1_coil_with_oversampling',
'2d_non_cartesian_mri_2_coils',
'2d_cartesian_irregular_sampling',
'2d_single_shot_spiral',
'3d_nonuniform_4_coils_2_other',
'2d_nnonuniform_cine_mri_8_cardiac_phases_5_coils',
'2d_cartesian_cine_9_cardiac_phases_6_coils',
'radial_phase_encoding_8_coils_with_oversampling',
'radial_phase_encoding_8_coils_non_cartesian_sampling',
'stack_of_stars_5_other_3_coil_with_oversampling',
],
)
8 changes: 4 additions & 4 deletions tests/data/test_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def _test_stats(error: torch.Tensor, mean_max: float, rms_max: float) -> None:
assert torch.all(rms < rms_max)


@pytest.mark.parametrize('seq_tuple', permutations('xyz'))
@pytest.mark.parametrize('seq_tuple', permutations('xyz'), ids=str)
@pytest.mark.parametrize('intrinsic', [False, True])
def test_as_euler_asymmetric_axes(seq_tuple, intrinsic):
rnd = RandomGenerator(0)
Expand All @@ -555,7 +555,7 @@ def test_as_euler_asymmetric_axes(seq_tuple, intrinsic):
_test_stats(angles_quat - angles, 1e-15, 1e-14)


@pytest.mark.parametrize('seq_tuple', permutations('xyz'))
@pytest.mark.parametrize('seq_tuple', permutations('xyz'), ids=str)
@pytest.mark.parametrize('intrinsic', [False, True])
def test_as_euler_symmetric_axes(seq_tuple, intrinsic):
rnd = RandomGenerator(0)
Expand All @@ -576,7 +576,7 @@ def test_as_euler_symmetric_axes(seq_tuple, intrinsic):
_test_stats(angles_quat - angles, 1e-16, 1e-14)


@pytest.mark.parametrize('seq_tuple', permutations('xyz'))
@pytest.mark.parametrize('seq_tuple', permutations('xyz'), ids=str)
@pytest.mark.parametrize('intrinsic', [False, True])
def test_as_euler_degenerate_asymmetric_axes(seq_tuple, intrinsic):
# Since we cannot check for angle equality, we check for rotation matrix
Expand All @@ -598,7 +598,7 @@ def test_as_euler_degenerate_asymmetric_axes(seq_tuple, intrinsic):
torch.testing.assert_close(mat_expected, mat_estimated)


@pytest.mark.parametrize('seq_tuple', permutations('xyz'))
@pytest.mark.parametrize('seq_tuple', permutations('xyz'), ids=str)
@pytest.mark.parametrize('intrinsic', [False, True])
def test_as_euler_degenerate_symmetric_axes(seq_tuple, intrinsic):
# Since we cannot check for angle equality, we check for rotation matrix
Expand Down
Loading