1
1
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
2
# vi: set ft=python sts=4 ts=4 sw=4 et:
3
3
"""Exercise the standalone ``apply()`` implementation."""
4
+
4
5
import os
5
6
import pytest
6
7
import numpy as np
50
51
}
51
52
52
53
53
- @pytest .mark .parametrize ("image_orientation" , ["RAS" , "LAS" , "LPS" , 'oblique' , ])
54
+ @pytest .mark .parametrize (
55
+ "image_orientation" ,
56
+ [
57
+ "RAS" ,
58
+ "LAS" ,
59
+ "LPS" ,
60
+ "oblique" ,
61
+ ],
62
+ )
54
63
@pytest .mark .parametrize ("sw_tool" , ["itk" , "fsl" , "afni" , "fs" ])
55
- def test_apply_linear_transform (tmpdir , get_testdata , get_testmask , image_orientation , sw_tool ):
64
+ def test_apply_linear_transform (
65
+ tmpdir , get_testdata , get_testmask , image_orientation , sw_tool
66
+ ):
56
67
"""Check implementation of exporting affines to formats."""
57
68
tmpdir .chdir ()
58
69
@@ -107,7 +118,7 @@ def test_apply_linear_transform(tmpdir, get_testdata, get_testmask, image_orient
107
118
nt_moved_mask .to_filename ("ntmask.nii.gz" )
108
119
diff = np .asanyarray (sw_moved_mask .dataobj ) - np .asanyarray (nt_moved_mask .dataobj )
109
120
110
- assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL_LINEAR
121
+ assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL_LINEAR
111
122
brainmask = np .asanyarray (nt_moved_mask .dataobj , dtype = bool )
112
123
113
124
cmd = APPLY_LINEAR_CMD [sw_tool ](
@@ -123,19 +134,17 @@ def test_apply_linear_transform(tmpdir, get_testdata, get_testmask, image_orient
123
134
sw_moved .set_data_dtype (img .get_data_dtype ())
124
135
125
136
nt_moved = apply (xfm , img , order = 0 )
126
- diff = (
127
- np .asanyarray (sw_moved .dataobj , dtype = sw_moved .get_data_dtype ())
128
- - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
129
- )
137
+ diff = np .asanyarray (
138
+ sw_moved .dataobj , dtype = sw_moved .get_data_dtype ()
139
+ ) - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
130
140
131
141
# A certain tolerance is necessary because of resampling at borders
132
142
assert np .sqrt ((diff [brainmask ] ** 2 ).mean ()) < RMSE_TOL_LINEAR
133
143
134
144
nt_moved = apply (xfm , "img.nii.gz" , order = 0 )
135
- diff = (
136
- np .asanyarray (sw_moved .dataobj , dtype = sw_moved .get_data_dtype ())
137
- - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
138
- )
145
+ diff = np .asanyarray (
146
+ sw_moved .dataobj , dtype = sw_moved .get_data_dtype ()
147
+ ) - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
139
148
# A certain tolerance is necessary because of resampling at borders
140
149
assert np .sqrt ((diff [brainmask ] ** 2 ).mean ()) < RMSE_TOL_LINEAR
141
150
@@ -281,7 +290,8 @@ def test_apply_transformchain(tmp_path, testdata_path):
281
290
282
291
ref_fname = tmp_path / "reference.nii.gz"
283
292
nb .Nifti1Image (
284
- np .zeros (xfm .reference .shape , dtype = "uint16" ), xfm .reference .affine ,
293
+ np .zeros (xfm .reference .shape , dtype = "uint16" ),
294
+ xfm .reference .affine ,
285
295
).to_filename (str (ref_fname ))
286
296
287
297
# Then apply the transform and cross-check with software
@@ -310,7 +320,9 @@ def test_apply_transformchain(tmp_path, testdata_path):
310
320
311
321
312
322
@pytest .mark .parametrize ("serialize_4d" , [True , False ])
313
- def test_LinearTransformsMapping_apply (tmp_path , data_path , testdata_path , serialize_4d ):
323
+ def test_LinearTransformsMapping_apply (
324
+ tmp_path , data_path , testdata_path , serialize_4d
325
+ ):
314
326
"""Apply transform mappings."""
315
327
hmc = nitl .load (
316
328
data_path / "hmc-itk.tfm" , fmt = "itk" , reference = testdata_path / "sbref.nii.gz"
@@ -333,7 +345,8 @@ def test_LinearTransformsMapping_apply(tmp_path, data_path, testdata_path, seria
333
345
)
334
346
335
347
nii = apply (
336
- hmcinv , testdata_path / "fmap.nii.gz" ,
348
+ hmcinv ,
349
+ testdata_path / "fmap.nii.gz" ,
337
350
order = 1 ,
338
351
serialize_nvols = 2 if serialize_4d else np .inf ,
339
352
)
0 commit comments