|
18 | 18 | from ..mghformat import MGHHeader, MGHError, MGHImage
|
19 | 19 | from ...tmpdirs import InTemporaryDirectory
|
20 | 20 | from ...fileholders import FileHolder
|
| 21 | +from ...volumeutils import sys_is_le |
21 | 22 |
|
22 | 23 | from nose.tools import assert_true, assert_false
|
23 | 24 |
|
@@ -286,6 +287,42 @@ def test_mgh_set_data_shape():
|
286 | 287 | hdr.set_data_shape((5, 4, 3, 2, 1))
|
287 | 288 |
|
288 | 289 |
|
| 290 | +def test_mghheader_default_structarr(): |
| 291 | + hdr = MGHHeader.default_structarr() |
| 292 | + assert_equal(hdr['version'], 1) |
| 293 | + assert_array_equal(hdr['dims'], 1) |
| 294 | + assert_equal(hdr['type'], 3) |
| 295 | + assert_equal(hdr['dof'], 0) |
| 296 | + assert_equal(hdr['goodRASFlag'], 1) |
| 297 | + assert_array_equal(hdr['delta'], 1) |
| 298 | + assert_array_equal(hdr['Mdc'], [[-1, 0, 0], [0, 0, 1], [0, -1, 0]]) |
| 299 | + assert_array_equal(hdr['Pxyz_c'], 0) |
| 300 | + assert_equal(hdr['tr'], 0) |
| 301 | + assert_equal(hdr['flip_angle'], 0) |
| 302 | + assert_equal(hdr['te'], 0) |
| 303 | + assert_equal(hdr['ti'], 0) |
| 304 | + assert_equal(hdr['fov'], 0) |
| 305 | + |
| 306 | + big_codes = ('>', 'big', 'BIG', 'b', 'be', 'B', 'BE') |
| 307 | + little_codes = ('<', 'little', 'l', 'le', 'L', 'LE') |
| 308 | + |
| 309 | + if sys_is_le: |
| 310 | + big_codes += ('swapped', 's', 'S', '!') |
| 311 | + little_codes += ('native', 'n', 'N', '=', '|', 'i', 'I') |
| 312 | + else: |
| 313 | + big_codes += ('native', 'n', 'N', '=', '|', 'i', 'I') |
| 314 | + little_codes += ('swapped', 's', 'S', '!') |
| 315 | + |
| 316 | + for endianness in big_codes: |
| 317 | + hdr2 = MGHHeader.default_structarr(endianness=endianness) |
| 318 | + assert_equal(hdr2, hdr) |
| 319 | + assert_equal(hdr2.newbyteorder('>'), hdr) |
| 320 | + |
| 321 | + for endianness in little_codes: |
| 322 | + with assert_raises(ValueError): |
| 323 | + MGHHeader.default_structarr(endianness=endianness) |
| 324 | + |
| 325 | + |
289 | 326 | class TestMGHImage(tsi.TestSpatialImage, tsi.MmapImageMixin):
|
290 | 327 | """ Apply general image tests to MGHImage
|
291 | 328 | """
|
|
0 commit comments