Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def update_header(self):
# the header, update the heaader
if self._affine is None:
return
if np.all(self._affine == hdr.get_best_affine()):
if np.allclose(self._affine, hdr.get_best_affine()):
return
RZS = self._affine[:3, :3]
vox = np.sqrt(np.sum(RZS * RZS, axis=0))
Expand Down
2 changes: 1 addition & 1 deletion nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ def update_header(self):
# the header, update the heaader
if self._affine is None:
return
if np.all(self._affine == hdr.get_best_affine()):
if np.allclose(self._affine, hdr.get_best_affine()):
return
# Set affine into sform with default code
hdr.set_sform(self._affine, code='aligned')
Expand Down
12 changes: 12 additions & 0 deletions nibabel/tests/test_nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ def test_qform_cycle(self):
assert_array_equal(hdr_back.get_sform(), exp_aff)
assert_array_equal(hdr_back.get_qform(), exp_aff)

def test_header_update_affine(self):
# Test that updating occurs only if affine is not allclose
img = self.image_class(np.zeros((2,3,4)), np.eye(4))
hdr = img.get_header()
aff = img.get_affine()
aff[:] = np.diag([1.1, 1.1, 1.1, 1]) # inexact floats
hdr.set_qform(aff, 2)
hdr.set_sform(aff, 2)
img.update_header()
assert_equal(hdr['sform_code'], 2)
assert_equal(hdr['qform_code'], 2)


class TestNifti1Pair(TestNifti1Image):
# Run analyze-flavor spatialimage tests
Expand Down