@@ -81,7 +81,8 @@ def test_data_scaling(self):
81
81
assert_true (np .all (data == data_back ))
82
82
83
83
84
- class TestSpm99AnalyzeHeader (test_analyze .TestAnalyzeHeader , HeaderScalingMixin ):
84
+ class TestSpm99AnalyzeHeader (test_analyze .TestAnalyzeHeader ,
85
+ HeaderScalingMixin ):
85
86
header_class = Spm99AnalyzeHeader
86
87
87
88
def test_empty (self ):
@@ -210,9 +211,10 @@ def test_header_scaling(self):
210
211
# For images that implement scaling, test effect of scaling
211
212
#
212
213
# This tests the affect of creating an image with a header containing
213
- # the scaling, then writing the image and reading again. So the scaling
214
- # can be affected by the processing of the header when creating the
215
- # image, or by interpretation of the scaling when creating the array.
214
+ # the scaling, then writing the image and reading again. So the
215
+ # scaling can be affected by the processing of the header when creating
216
+ # the image, or by interpretation of the scaling when creating the
217
+ # array.
216
218
#
217
219
# Analyze does not implement any scaling, but this test class is the
218
220
# base class for all Analyze-derived classes, such as NIfTI
@@ -227,9 +229,12 @@ def test_header_scaling(self):
227
229
if not hdr_class .has_data_intercept :
228
230
return
229
231
invalid_inters = (np .nan , np .inf , - np .inf )
230
- invalid_pairs = tuple (itertools .product (invalid_slopes , invalid_inters ))
231
- bad_slopes_good_inter = tuple (itertools .product (invalid_slopes , (0 , 1 )))
232
- good_slope_bad_inters = tuple (itertools .product ((1 , 2 ), invalid_inters ))
232
+ invalid_pairs = tuple (
233
+ itertools .product (invalid_slopes , invalid_inters ))
234
+ bad_slopes_good_inter = tuple (
235
+ itertools .product (invalid_slopes , (0 , 1 )))
236
+ good_slope_bad_inters = tuple (
237
+ itertools .product ((1 , 2 ), invalid_inters ))
233
238
for slope , inter in (invalid_pairs + bad_slopes_good_inter +
234
239
good_slope_bad_inters ):
235
240
self .assert_null_scaling (arr , slope , inter )
@@ -240,8 +245,8 @@ def _check_write_scaling(self,
240
245
effective_slope ,
241
246
effective_inter ):
242
247
# Test that explicit set of slope / inter forces write of data using
243
- # this slope, inter
244
- # We use this helper function for children of the Analyze header
248
+ # this slope, inter. We use this helper function for children of the
249
+ # Analyze header
245
250
img_class = self .image_class
246
251
arr = np .arange (24 , dtype = np .float32 ).reshape ((2 , 3 , 4 ))
247
252
# We're going to test rounding later
@@ -316,11 +321,12 @@ def test_int_int_scaling(self):
316
321
317
322
@scipy_skip
318
323
def test_no_scaling (self ):
319
- # Test writing image converting types when no scaling
324
+ # Test writing image converting types when not calculating scaling
320
325
img_class = self .image_class
321
326
hdr_class = img_class .header_class
322
327
hdr = hdr_class ()
323
328
supported_types = supported_np_types (hdr )
329
+ # Any old non-default slope and intercept
324
330
slope = 2
325
331
inter = 10 if hdr .has_data_intercept else 0
326
332
for in_dtype , out_dtype in itertools .product (
@@ -331,6 +337,7 @@ def test_no_scaling(self):
331
337
arr = np .array ([mn_in , - 1 , 0 , 1 , 10 , mx_in ], dtype = in_dtype )
332
338
img = img_class (arr , np .eye (4 ), hdr )
333
339
img .set_data_dtype (out_dtype )
340
+ # Setting the scaling means we don't calculate it later
334
341
img .header .set_slope_inter (slope , inter )
335
342
with np .errstate (invalid = 'ignore' ):
336
343
rt_img = bytesio_round_trip (img )
@@ -437,16 +444,17 @@ def test_mat_read(self):
437
444
to_111 = np .eye (4 )
438
445
to_111 [:3 ,3 ] = 1
439
446
assert_array_equal (mats ['mat' ], np .dot (aff , from_111 ))
440
- # The M matrix does not include flips, so if we only
441
- # have the M matrix in the mat file, and we have default flipping, the
442
- # mat resulting should have a flip. The 'mat' matrix does include flips
443
- # and so should be unaffected by the flipping. If both are present we
444
- # prefer the the 'mat' matrix.
447
+ # The M matrix does not include flips, so if we only have the M matrix
448
+ # in the mat file, and we have default flipping, the mat resulting
449
+ # should have a flip. The 'mat' matrix does include flips and so
450
+ # should be unaffected by the flipping. If both are present we prefer
451
+ # the the 'mat' matrix.
445
452
assert_true (img .header .default_x_flip ) # check the default
446
453
flipper = np .diag ([- 1 ,1 ,1 ,1 ])
447
454
assert_array_equal (mats ['M' ], np .dot (aff , np .dot (flipper , from_111 )))
448
455
mat_fileobj .seek (0 )
449
- savemat (mat_fileobj , dict (M = np .diag ([3 ,4 ,5 ,1 ]), mat = np .diag ([6 ,7 ,8 ,1 ])))
456
+ savemat (mat_fileobj ,
457
+ dict (M = np .diag ([3 ,4 ,5 ,1 ]), mat = np .diag ([6 ,7 ,8 ,1 ])))
450
458
# Check we are preferring the 'mat' matrix
451
459
r_img = img_klass .from_file_map (fm )
452
460
assert_array_equal (r_img .get_data (), arr )
0 commit comments