@@ -222,9 +222,9 @@ def test_qform():
222
222
yield assert_true , np .allclose (A , qA , atol = 1e-5 )
223
223
yield assert_true , np .allclose (Z , ehdr ['pixdim' ][1 :4 ])
224
224
xfas = nifti1 .xform_codes
225
- yield assert_true , ehdr ['qform_code' ] == xfas ['scanner' ]
226
- ehdr .set_qform (A , 'aligned' )
227
225
yield assert_true , ehdr ['qform_code' ] == xfas ['aligned' ]
226
+ ehdr .set_qform (A , 'scanner' )
227
+ yield assert_true , ehdr ['qform_code' ] == xfas ['scanner' ]
228
228
ehdr .set_qform (A , xfas ['aligned' ])
229
229
yield assert_true , ehdr ['qform_code' ] == xfas ['aligned' ]
230
230
@@ -236,9 +236,9 @@ def test_sform():
236
236
sA = ehdr .get_sform ()
237
237
yield assert_true , np .allclose (A , sA , atol = 1e-5 )
238
238
xfas = nifti1 .xform_codes
239
- yield assert_true , ehdr ['sform_code' ] == xfas ['scanner' ]
240
- ehdr .set_sform (A , 'aligned' )
241
239
yield assert_true , ehdr ['sform_code' ] == xfas ['aligned' ]
240
+ ehdr .set_sform (A , 'scanner' )
241
+ yield assert_true , ehdr ['sform_code' ] == xfas ['scanner' ]
242
242
ehdr .set_sform (A , xfas ['aligned' ])
243
243
yield assert_true , ehdr ['sform_code' ] == xfas ['aligned' ]
244
244
@@ -615,3 +615,37 @@ def test_load_pixdims():
615
615
assert_array_equal (rimg_hdr .get_qform (), qaff )
616
616
assert_array_equal (rimg_hdr .get_sform (), saff )
617
617
assert_array_equal (rimg_hdr .get_zooms (), [2 ,3 ,4 ])
618
+
619
+
620
+ def test_affines_init ():
621
+ # Test we are doing vaguely spec-related qform things. The 'spec' here is
622
+ # some thoughts by Mark Jenkinson:
623
+ # http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/qsform_brief_usage
624
+ arr = np .arange (24 ).reshape ((2 ,3 ,4 ))
625
+ aff = np .diag ([2 , 3 , 4 , 1 ])
626
+ # Default is sform set, qform not set
627
+ img = Nifti1Image (arr , aff )
628
+ hdr = img .get_header ()
629
+ assert_equal (hdr ['qform_code' ], 0 )
630
+ assert_equal (hdr ['sform_code' ], 2 )
631
+ # This is also true for affines with header passed
632
+ qaff = np .diag ([3 , 4 , 5 , 1 ])
633
+ saff = np .diag ([6 , 7 , 8 , 1 ])
634
+ hdr .set_qform (qaff , code = 'scanner' )
635
+ hdr .set_sform (saff , code = 'talairach' )
636
+ img = Nifti1Image (arr , aff , hdr )
637
+ new_hdr = img .get_header ()
638
+ # Again affine is sort of anonymous space
639
+ assert_equal (new_hdr ['qform_code' ], 0 )
640
+ assert_equal (new_hdr ['sform_code' ], 2 )
641
+ assert_array_equal (new_hdr .get_sform (), aff )
642
+ # But if no affine passed, codes and matrices stay the same
643
+ img = Nifti1Image (arr , None , hdr )
644
+ new_hdr = img .get_header ()
645
+ assert_equal (new_hdr ['qform_code' ], 1 ) # scanner
646
+ assert_array_equal (new_hdr .get_qform (), qaff )
647
+ assert_equal (new_hdr ['sform_code' ], 3 ) # Still talairach
648
+ assert_array_equal (new_hdr .get_sform (), saff )
649
+
650
+
651
+
0 commit comments