Skip to content

Commit b6141a4

Browse files
committed
TEST: Update tests for refactor
1 parent 6bc9603 commit b6141a4

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_read_mgh():
5353
assert_equal(h['version'], 1)
5454
assert_equal(h['type'], 3)
5555
assert_equal(h['dof'], 0)
56-
assert_equal(h['goodRASFlag'], 1)
56+
assert_equal(h['ras_good'], 1)
5757
assert_array_equal(h['dims'], [3, 4, 5, 2])
5858
assert_array_almost_equal(h['mrparms'], [2.0, 0.0, 0.0, 0.0])
5959
assert_array_almost_equal(h.get_zooms(), 1)
@@ -84,7 +84,7 @@ def test_write_mgh():
8484
assert_equal(h['version'], 1)
8585
assert_equal(h['type'], 3)
8686
assert_equal(h['dof'], 0)
87-
assert_equal(h['goodRASFlag'], 1)
87+
assert_equal(h['ras_good'], 1)
8888
assert_array_equal(h['dims'], [5, 4, 3, 2])
8989
assert_array_almost_equal(h['mrparms'], [0.0, 0.0, 0.0, 0.0])
9090
assert_array_almost_equal(h.get_vox2ras(), v2r)
@@ -110,17 +110,15 @@ def test_write_noaffine_mgh():
110110
assert_equal(h['version'], 1)
111111
assert_equal(h['type'], 0) # uint8 for mgh
112112
assert_equal(h['dof'], 0)
113-
assert_equal(h['goodRASFlag'], 1)
113+
assert_equal(h['ras_good'], 1)
114114
assert_array_equal(h['dims'], [7, 13, 3, 22])
115115
assert_array_almost_equal(h['mrparms'], [0.0, 0.0, 0.0, 0.0])
116116
# important part -- whether default affine info is stored
117-
ex_mdc = np.array([[-1, 0, 0],
118-
[0, 0, -1],
119-
[0, 1, 0]], dtype=np.float32)
120-
assert_array_almost_equal(h['Mdc'], ex_mdc)
117+
assert_array_almost_equal(h['x_ras'].T, [[-1, 0, 0]])
118+
assert_array_almost_equal(h['y_ras'].T, [[0, 0, 1]])
119+
assert_array_almost_equal(h['z_ras'].T, [[0, -1, 0]])
121120

122-
ex_pxyzc = np.array([0, 0, 0], dtype=np.float32)
123-
assert_array_almost_equal(h['Pxyz_c'], ex_pxyzc)
121+
assert_array_almost_equal(h['c_ras'].T, [[0, 0, 0]])
124122

125123

126124
def bad_dtype_mgh():
@@ -178,14 +176,15 @@ def test_header_updating():
178176
assert_almost_equal(mgz.affine, exp_aff, 6)
179177
assert_almost_equal(hdr.get_affine(), exp_aff, 6)
180178
# Test that initial wonky header elements have not changed
181-
assert_equal(hdr['delta'], 1)
182-
assert_almost_equal(hdr['Mdc'], exp_aff[:3, :3].T)
179+
assert_equal(hdr['voxelsize'], 1)
180+
assert_almost_equal(np.hstack((hdr['x_ras'], hdr['y_ras'], hdr['z_ras'])),
181+
exp_aff[:3, :3])
183182
# Save, reload, same thing
184183
img_fobj = io.BytesIO()
185184
mgz2 = _mgh_rt(mgz, img_fobj)
186185
hdr2 = mgz2.header
187186
assert_almost_equal(hdr2.get_affine(), exp_aff, 6)
188-
assert_equal(hdr2['delta'], 1)
187+
assert_equal(hdr2['voxelsize'], 1)
189188
# Change affine, change underlying header info
190189
exp_aff_d = exp_aff.copy()
191190
exp_aff_d[0, -1] = -14
@@ -194,8 +193,10 @@ def test_header_updating():
194193
mgz2.update_header()
195194
assert_almost_equal(hdr2.get_affine(), exp_aff_d, 6)
196195
RZS = exp_aff_d[:3, :3]
197-
assert_almost_equal(hdr2['delta'], np.sqrt(np.sum(RZS ** 2, axis=0)))
198-
assert_almost_equal(hdr2['Mdc'], (RZS / hdr2['delta']).T)
196+
assert_almost_equal(hdr2['voxelsize'], np.sqrt(np.sum(RZS ** 2, axis=0)))
197+
assert_almost_equal(
198+
np.hstack((hdr2['x_ras'], hdr2['y_ras'], hdr2['z_ras'])),
199+
RZS / hdr2['voxelsize'])
199200

200201

201202
def test_cosine_order():
@@ -210,8 +211,10 @@ def test_cosine_order():
210211
hdr2 = img2.header
211212
RZS = aff[:3, :3]
212213
zooms = np.sqrt(np.sum(RZS ** 2, axis=0))
213-
assert_almost_equal(hdr2['Mdc'], (RZS / zooms).T)
214-
assert_almost_equal(hdr2['delta'], zooms)
214+
assert_almost_equal(
215+
np.hstack((hdr2['x_ras'], hdr2['y_ras'], hdr2['z_ras'])),
216+
RZS / zooms)
217+
assert_almost_equal(hdr2['voxelsize'], zooms)
215218

216219

217220
def test_eq():

0 commit comments

Comments
 (0)