@@ -44,10 +44,22 @@ def test_linear_typeerrors1(matrix):
44
44
45
45
def test_linear_typeerrors2 (data_path ):
46
46
"""Exercise errors in Affine creation."""
47
- with pytest .raises (TypeError ):
47
+ with pytest .raises (io . TransformFileError ):
48
48
nitl .Affine .from_filename (data_path / "itktflist.tfm" , fmt = "itk" )
49
49
50
50
51
+ def test_linear_filenotfound (data_path ):
52
+ """Exercise errors in Affine creation."""
53
+ with pytest .raises (FileNotFoundError ):
54
+ nitl .Affine .from_filename ("doesnotexist.tfm" , fmt = "itk" )
55
+
56
+ with pytest .raises (FileNotFoundError ):
57
+ nitl .LinearTransformsMapping .from_filename ("doesnotexist.tfm" , fmt = "itk" )
58
+
59
+ with pytest .raises (FileNotFoundError ):
60
+ nitl .LinearTransformsMapping .from_filename ("doesnotexist.mat" , fmt = "fsl" )
61
+
62
+
51
63
def test_linear_valueerror ():
52
64
"""Exercise errors in Affine creation."""
53
65
with pytest .raises (ValueError ):
@@ -85,6 +97,38 @@ def test_loadsave_itk(tmp_path, data_path, testdata_path):
85
97
)
86
98
87
99
100
+ @pytest .mark .parametrize (
101
+ "image_orientation" ,
102
+ [
103
+ "RAS" ,
104
+ "LAS" ,
105
+ "LPS" ,
106
+ "oblique" ,
107
+ ],
108
+ )
109
+ def test_itkmat_loadsave (tmpdir , data_path , image_orientation ):
110
+ tmpdir .chdir ()
111
+
112
+ io .itk .ITKLinearTransform .from_filename (
113
+ data_path / f"affine-{ image_orientation } .itk.tfm"
114
+ ).to_filename (f"affine-{ image_orientation } .itk.mat" )
115
+
116
+ xfm = nitl .load (data_path / f"affine-{ image_orientation } .itk.tfm" , fmt = "itk" )
117
+ mat1 = nitl .load (f"affine-{ image_orientation } .itk.mat" , fmt = "itk" )
118
+
119
+ assert xfm == mat1
120
+
121
+ mat2 = nitl .Affine .from_filename (f"affine-{ image_orientation } .itk.mat" , fmt = "itk" )
122
+
123
+ assert xfm == mat2
124
+
125
+ mat3 = nitl .LinearTransformsMapping .from_filename (
126
+ f"affine-{ image_orientation } .itk.mat" , fmt = "itk"
127
+ )
128
+
129
+ assert xfm == mat3
130
+
131
+
88
132
@pytest .mark .parametrize ("autofmt" , (False , True ))
89
133
@pytest .mark .parametrize ("fmt" , ["itk" , "fsl" , "afni" , "lta" ])
90
134
def test_loadsave (tmp_path , data_path , testdata_path , autofmt , fmt ):
0 commit comments