|
7 | 7 | from ..io.lta import FSLinearTransformArray as LTA
|
8 | 8 |
|
9 | 9 |
|
| 10 | +def test_concatenation(data_path): |
| 11 | + """Check replacement to lta_concat.""" |
| 12 | + lta0 = _l.load( |
| 13 | + data_path / "regressions" / "from-scanner_to-fsnative_mode-image.lta", fmt="lta" |
| 14 | + ) |
| 15 | + lta1 = _l.load( |
| 16 | + data_path / "regressions" / "from-fsnative_to-bold_mode-image.lta", fmt="lta" |
| 17 | + ) |
| 18 | + |
| 19 | + lta_combined = _l.load( |
| 20 | + data_path / "regressions" / "from-scanner_to-bold_mode-image.lta", fmt="lta" |
| 21 | + ) |
| 22 | + |
| 23 | + assert np.allclose(lta1.matrix.dot(lta0.matrix), lta_combined.matrix) |
| 24 | + |
| 25 | + |
10 | 26 | @pytest.mark.parametrize(
|
11 | 27 | "filename",
|
12 | 28 | [
|
|
18 | 34 | )
|
19 | 35 | def test_lta2itk_conversions(data_path, filename):
|
20 | 36 | """Check conversions between formats."""
|
21 |
| - lta = _l.load(data_path / "regressions" / ".".join((filename, "lta")), fmt="lta") |
22 |
| - itk = _l.load(data_path / "regressions" / ".".join((filename, "tfm")), fmt="itk") |
| 37 | + lta = _l.load(data_path / "regressions" / f"{filename}.lta", fmt="lta") |
| 38 | + itk = _l.load(data_path / "regressions" / f"{filename}.tfm", fmt="itk") |
23 | 39 | assert np.allclose(lta.matrix, itk.matrix)
|
24 | 40 |
|
25 | 41 |
|
@@ -59,17 +75,63 @@ def test_itk2lta_conversions(
|
59 | 75 | assert np.allclose(converted_lta["xforms"][0]["m_L"], exp_lta["xforms"][0]["m_L"])
|
60 | 76 |
|
61 | 77 |
|
62 |
| -def test_concatenation(data_path): |
63 |
| - """Check replacement to lta_concat.""" |
64 |
| - lta0 = _l.load( |
65 |
| - data_path / "regressions" / "from-scanner_to-fsnative_mode-image.lta", fmt="lta" |
| 78 | +@pytest.mark.parametrize( |
| 79 | + "fromto", |
| 80 | + [ |
| 81 | + ("fsnative", "bold"), |
| 82 | + ("fsnative", "scanner"), |
| 83 | + ("scanner", "bold"), |
| 84 | + ("scanner", "fsnative"), |
| 85 | + ], |
| 86 | +) |
| 87 | +def test_lta2fsl_conversions(data_path, fromto, testdata_path): |
| 88 | + """Check conversions between formats.""" |
| 89 | + filename = f"from-{fromto[0]}_to-{fromto[1]}_mode-image" |
| 90 | + movname = "bold.nii.gz" if fromto[1] == "bold" else f"T1w_{fromto[1]}.nii.gz" |
| 91 | + |
| 92 | + lta = _l.load(data_path / "regressions" / f"{filename}.lta", fmt="lta") |
| 93 | + fsl = _l.load( |
| 94 | + data_path / "regressions" / f"{filename}.fsl", |
| 95 | + moving=testdata_path / movname, |
| 96 | + reference=testdata_path / f"T1w_{fromto[0]}.nii.gz", |
| 97 | + fmt="fsl", |
66 | 98 | )
|
67 |
| - lta1 = _l.load( |
68 |
| - data_path / "regressions" / "from-fsnative_to-bold_mode-image.lta", fmt="lta" |
| 99 | + assert np.allclose(lta.matrix, fsl.matrix, atol=1e-4) |
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.parametrize( |
| 103 | + "fromto", |
| 104 | + [ |
| 105 | + ("fsnative", "bold"), |
| 106 | + ("fsnative", "scanner"), |
| 107 | + ("scanner", "bold"), |
| 108 | + ("scanner", "fsnative"), |
| 109 | + ], |
| 110 | +) |
| 111 | +def test_fsl2lta_conversions( |
| 112 | + data_path, testdata_path, tmp_path, fromto, |
| 113 | +): |
| 114 | + """Check conversions between formats.""" |
| 115 | + filename = f"from-{fromto[0]}_to-{fromto[1]}_mode-image" |
| 116 | + refname = "bold.nii.gz" if fromto[1] == "bold" else f"T1w_{fromto[1]}.nii.gz" |
| 117 | + |
| 118 | + fsl = _l.load( |
| 119 | + data_path / "regressions" / f"{filename}.fsl", |
| 120 | + reference=testdata_path / f"T1w_{fromto[0]}.nii.gz", |
| 121 | + moving=testdata_path / refname, |
| 122 | + fmt="fsl" |
| 123 | + ) |
| 124 | + fsl.to_filename( |
| 125 | + tmp_path / "test.lta", |
| 126 | + fmt="fs", |
69 | 127 | )
|
70 | 128 |
|
71 |
| - lta_combined = _l.load( |
72 |
| - data_path / "regressions" / "from-scanner_to-bold_mode-image.lta", fmt="lta" |
| 129 | + converted_lta = LTA.from_filename(tmp_path / "test.lta") |
| 130 | + expected_fname = ( |
| 131 | + data_path / "regressions" / "".join((filename, "_type-ras2ras.lta")) |
73 | 132 | )
|
| 133 | + if not expected_fname.exists(): |
| 134 | + expected_fname = data_path / "regressions" / "".join((filename, ".lta")) |
74 | 135 |
|
75 |
| - assert np.allclose(lta1.matrix.dot(lta0.matrix), lta_combined.matrix) |
| 136 | + exp_lta = LTA.from_filename(expected_fname) |
| 137 | + assert np.allclose(converted_lta["xforms"][0]["m_L"], exp_lta["xforms"][0]["m_L"], atol=1e-4) |
0 commit comments