Skip to content

Commit 8efba75

Browse files
committed
TEST: Minimal tests for AFNI BRIK/HEAD files
Includes new test file `example_4d+orig.BRIK/HEAD`
1 parent 53807a5 commit 8efba75

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed
198 KB
Binary file not shown.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
type = string-attribute
3+
name = DATASET_NAME
4+
count = 5
5+
'none~
6+
7+
type = string-attribute
8+
name = TYPESTRING
9+
count = 15
10+
'3DIM_HEAD_ANAT~
11+
12+
type = string-attribute
13+
name = IDCODE_STRING
14+
count = 27
15+
'AFN_-zxZ0OyZs8eEtm9syGBNdA~
16+
17+
type = string-attribute
18+
name = IDCODE_DATE
19+
count = 25
20+
'Sun Oct 1 21:13:09 2017~
21+
22+
type = integer-attribute
23+
name = SCENE_DATA
24+
count = 8
25+
0 2 0 -999 -999
26+
-999 -999 -999
27+
28+
type = string-attribute
29+
name = LABEL_1
30+
count = 5
31+
'none~
32+
33+
type = string-attribute
34+
name = LABEL_2
35+
count = 5
36+
'none~
37+
38+
type = integer-attribute
39+
name = ORIENT_SPECIFIC
40+
count = 3
41+
0 3 4
42+
43+
type = float-attribute
44+
name = ORIGIN
45+
count = 3
46+
-49.5 -82.312 -52.3511
47+
48+
type = float-attribute
49+
name = DELTA
50+
count = 3
51+
3 3 3
52+
53+
type = float-attribute
54+
name = IJK_TO_DICOM
55+
count = 12
56+
3 0 0 -49.5 0
57+
3 0 -82.312 0 0
58+
3 -52.3511
59+
60+
type = float-attribute
61+
name = IJK_TO_DICOM_REAL
62+
count = 12
63+
3 0 0 -49.5 0
64+
3 0 -82.312 0 0
65+
3 -52.3511
66+
67+
type = float-attribute
68+
name = BRICK_STATS
69+
count = 6
70+
0 13722 0 10051 0
71+
9968
72+
73+
type = integer-attribute
74+
name = TAXIS_NUMS
75+
count = 8
76+
3 25 77002 -999 -999
77+
-999 -999 -999
78+
79+
type = float-attribute
80+
name = TAXIS_FLOATS
81+
count = 8
82+
0 3 0 -52.3511 3
83+
-999999 -999999 -999999
84+
85+
type = float-attribute
86+
name = TAXIS_OFFSETS
87+
count = 25
88+
0.3260869 1.826087 0.3913043 1.891304 0.4565217
89+
1.956521 0.5217391 2.021739 0.5869564 2.086956
90+
0.6521738 2.152174 0.7173912 2.217391 0.7826086
91+
2.282609 0.8478259 2.347826 0.9130433 2.413044
92+
0.9782607 2.478261 1.043478 2.543479 1.108696
93+
94+
type = integer-attribute
95+
name = DATASET_RANK
96+
count = 8
97+
3 3 0 0 0
98+
0 0 0
99+
100+
type = integer-attribute
101+
name = DATASET_DIMENSIONS
102+
count = 5
103+
33 41 25 0 0
104+
105+
type = integer-attribute
106+
name = BRICK_TYPES
107+
count = 3
108+
1 1 1
109+
110+
type = float-attribute
111+
name = BRICK_FLOAT_FACS
112+
count = 3
113+
0 0 0
114+
115+
type = string-attribute
116+
name = TEMPLATE_SPACE
117+
count = 5
118+
'ORIG~
119+
120+
type = integer-attribute
121+
name = INT_CMAP
122+
count = 1
123+
0
124+
125+
type = string-attribute
126+
name = BYTEORDER_STRING
127+
count = 10
128+
'LSB_FIRST~
129+
130+
type = string-attribute
131+
name = BRICK_LABS
132+
count = 9
133+
'#0~#1~#2~

nibabel/tests/test_brikhead.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
4+
#
5+
# See COPYING file distributed along with the NiBabel package for the
6+
# copyright and license terms.
7+
#
8+
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9+
from __future__ import division, print_function, absolute_import
10+
11+
from os.path import join as pjoin
12+
13+
import numpy as np
14+
15+
from .. import load, Nifti1Image
16+
from .. import brikhead
17+
18+
from nose.tools import (assert_true, assert_equal)
19+
from numpy.testing import assert_array_equal
20+
from ..testing import data_path
21+
22+
from .test_fileslice import slicer_samples
23+
from .test_helpers import assert_data_similar
24+
25+
EXAMPLE_IMAGES = [
26+
dict(
27+
fname=pjoin(data_path, 'example4d+orig.BRIK'),
28+
shape=(33, 41, 25, 3),
29+
dtype=np.int16,
30+
affine=np.array([[-3.0,0,0,49.5],
31+
[0,-3.0,0,82.312],
32+
[0,0,3.0,-52.3511],
33+
[0,0,0,1.0]]),
34+
zooms=(3., 3., 3., 3.),
35+
# These values from SPM2
36+
data_summary=dict(
37+
min=0,
38+
max=13722,
39+
mean=4266.76024636),
40+
is_proxy=True)
41+
]
42+
43+
44+
class TestAFNIImage(object):
45+
module = brikhead
46+
test_files = EXAMPLE_IMAGES
47+
48+
def test_brikheadfile(self):
49+
for tp in self.test_files:
50+
brik = self.module.load(tp['fname'])
51+
assert_equal(brik.get_data_dtype().type, tp['dtype'])
52+
assert_equal(brik.shape, tp['shape'])
53+
assert_equal(brik.header.get_zooms(), tp['zooms'])
54+
assert_array_equal(brik.affine, tp['affine'])
55+
data = brik.get_data()
56+
assert_equal(data.shape, tp['shape'])
57+
58+
def test_load(self):
59+
# Check highest level load of brikhead works
60+
for tp in self.test_files:
61+
img = load(tp['fname'])
62+
data = img.get_data()
63+
assert_equal(data.shape, tp['shape'])
64+
# min, max, mean values
65+
assert_data_similar(data, tp)
66+
# check if file can be converted to nifti
67+
ni_img = Nifti1Image.from_image(img)
68+
assert_array_equal(ni_img.affine, tp['affine'])
69+
assert_array_equal(ni_img.get_data(), data)
70+
71+
def test_array_proxy_slicing(self):
72+
# Test slicing of array proxy
73+
for tp in self.test_files:
74+
img = load(tp['fname'])
75+
arr = img.get_data()
76+
prox = img.dataobj
77+
assert_true(prox.is_proxy)
78+
for sliceobj in slicer_samples(img.shape):
79+
assert_array_equal(arr[sliceobj], prox[sliceobj])

0 commit comments

Comments
 (0)