10
10
from StringIO import StringIO
11
11
import numpy as np
12
12
13
- from ..testing import assert_equal , assert_not_equal , \
14
- assert_true , assert_false , assert_raises
13
+ import nibabel
15
14
16
- from numpy .testing import (assert_array_equal ,
17
- assert_array_almost_equal )
15
+ from ..ecat import EcatHeader , EcatMlist , EcatSubHeader , EcatImage
18
16
17
+ from unittest import TestCase
19
18
20
- from ..ecat import EcatHeader , EcatMlist , EcatSubHeader , EcatImage
21
- import test_binary as tb
22
- from ..testing import parametric , data_path , ParametricTestCase
19
+ from nose .tools import (assert_true , assert_false , assert_equal ,
20
+ assert_not_equal , assert_raises )
21
+
22
+ from numpy .testing import assert_array_equal , assert_array_almost_equal
23
23
24
- ecat_file = os .path .join (data_path , 'tinypet.v' )
24
+ data_path = os .path .dirname (nibabel .__file__ )
25
+ ecat_file = os .path .join (data_path , 'tests' ,'data' ,'tinypet.v' )
25
26
26
- class TestEcatHeader (ParametricTestCase ):
27
+ class TestEcatHeader (TestCase ):
27
28
header_class = EcatHeader
28
29
example_file = ecat_file
29
30
30
31
def test_header_size (self ):
31
- yield assert_equal (self .header_class ._dtype .itemsize , 502 )
32
+ assert_equal (self .header_class ._dtype .itemsize , 502 )
32
33
33
34
def test_empty (self ):
34
35
hdr = self .header_class ()
35
- yield assert_true (len (hdr .binaryblock ) == 502 )
36
- yield assert_true (hdr ['magic_number' ] == 'MATRIX72' )
37
- yield assert_true (hdr ['sw_version' ] == 74 )
38
- yield assert_true (hdr ['num_frames' ] == 0 )
39
- yield assert_true (hdr ['file_type' ] == 0 )
40
- yield assert_true (hdr ['ecat_calibration_factor' ] == 1.0 )
41
-
36
+ assert_true (len (hdr .binaryblock ) == 502 )
37
+ assert_true (hdr ['magic_number' ] == 'MATRIX72' )
38
+ assert_true (hdr ['sw_version' ] == 74 )
39
+ assert_true (hdr ['num_frames' ] == 0 )
40
+ assert_true (hdr ['file_type' ] == 0 )
41
+ assert_true (hdr ['ecat_calibration_factor' ] == 1.0 )
42
+
42
43
def test_dtype (self ):
43
44
#dtype not specified in header, only in subheaders
44
45
hdr = self .header_class ()
45
- yield assert_raises (NotImplementedError ,
46
+ assert_raises (NotImplementedError ,
46
47
hdr .get_data_dtype )
47
48
48
49
def test_header_codes (self ):
49
50
fid = open (ecat_file )
50
51
hdr = self .header_class ()
51
52
newhdr = hdr .from_fileobj (fid )
52
53
fid .close ()
53
- yield assert_true (newhdr .get_filetype () == 'ECAT7_VOLUME16' )
54
- yield assert_equal (newhdr .get_patient_orient (),
54
+ assert_true (newhdr .get_filetype () == 'ECAT7_VOLUME16' )
55
+ assert_equal (newhdr .get_patient_orient (),
55
56
'ECAT7_Unknown_Orientation' )
56
57
57
58
def test_copy (self ):
58
59
hdr = self .header_class ()
59
60
hdr2 = hdr .copy ()
60
- yield assert_true (hdr == hdr2 )
61
- yield assert_true (not hdr .binaryblock == hdr2 ._header_data .byteswap ().tostring ())
62
- yield assert_true (hdr .keys () == hdr2 .keys ())
63
-
61
+ assert_true (hdr == hdr2 )
62
+ assert_true (not hdr .binaryblock == hdr2 ._header_data .byteswap ().tostring ())
63
+ assert_true (hdr .keys () == hdr2 .keys ())
64
+
64
65
def test_update (self ):
65
66
hdr = self .header_class ()
66
- yield assert_true (hdr ['num_frames' ] == 0 )
67
+ assert_true (hdr ['num_frames' ] == 0 )
67
68
hdr ['num_frames' ] = 2
68
- yield assert_true (hdr ['num_frames' ] == 2 )
69
+ assert_true (hdr ['num_frames' ] == 2 )
69
70
70
71
def test_endianness (self ):
71
72
fid = open (ecat_file )
72
73
hdr = self .header_class ()
73
74
newhdr = hdr .from_fileobj (fid )
74
75
fid .close ()
75
- yield assert_true (hdr .endianness == '<' )
76
- yield assert_true (newhdr .endianness == '>' )
77
-
78
- class TestEcatMlist (ParametricTestCase ):
76
+ assert_true (hdr .endianness == '<' )
77
+ assert_true (newhdr .endianness == '>' )
78
+
79
+ class TestEcatMlist (TestCase ):
79
80
header_class = EcatHeader
80
81
mlist_class = EcatMlist
81
82
example_file = ecat_file
@@ -91,11 +92,11 @@ def test_mlist(self):
91
92
dt = dt .newbyteorder ('>' )
92
93
mats = np .recarray (shape = (32 ,4 ), dtype = dt , buf = dat )
93
94
fid .close ()
94
- yield assert_true (mats ['matlist' ][0 ,0 ] + mats ['matlist' ][0 ,3 ] == 31 )
95
- yield assert_true (mlist .get_frame_order ()[0 ][0 ] == 0 )
96
- yield assert_true (mlist .get_frame_order ()[0 ][1 ] == 16842758.0 )
97
-
98
- class TestEcatSubHeader (ParametricTestCase ):
95
+ assert_true (mats ['matlist' ][0 ,0 ] + mats ['matlist' ][0 ,3 ] == 31 )
96
+ assert_true (mlist .get_frame_order ()[0 ][0 ] == 0 )
97
+ assert_true (mlist .get_frame_order ()[0 ][1 ] == 16842758.0 )
98
+
99
+ class TestEcatSubHeader (TestCase ):
99
100
header_class = EcatHeader
100
101
mlist_class = EcatMlist
101
102
subhdr_class = EcatSubHeader
@@ -107,47 +108,50 @@ class TestEcatSubHeader(ParametricTestCase):
107
108
108
109
109
110
def test_subheader_size (self ):
110
- yield assert_equal (self .subhdr_class ._subhdrdtype .itemsize , 242 )
111
+ assert_equal (self .subhdr_class ._subhdrdtype .itemsize , 242 )
111
112
112
113
def test_subheader (self ):
113
- yield assert_equal (self .subhdr .get_shape () , (10 ,10 ,3 ))
114
- yield assert_equal (self .subhdr .get_nframes () , 1 )
115
- yield assert_equal (self .subhdr .get_nframes (),
116
- len (self .subhdr .subheaders ))
117
- yield assert_equal (self .subhdr ._check_affines (), True )
118
- yield assert_array_almost_equal (np .diag (self .subhdr .get_frame_affine ()),
119
- np .array ([ 2.20241979 , 2.20241979 , 3.125 , 1. ]))
120
- yield assert_equal (self .subhdr .get_zooms ()[0 ], 2.20241978764534 )
121
- yield assert_equal (self .subhdr .get_zooms ()[2 ], 3.125 )
122
- yield assert_equal (self .subhdr ._get_data_dtype (0 ),np .uint16 )
123
- yield assert_equal (self .subhdr ._get_frame_offset (), 1536 )
114
+ assert_equal (self .subhdr .get_shape () , (10 ,10 ,3 ))
115
+ assert_equal (self .subhdr .get_nframes () , 1 )
116
+ assert_equal (self .subhdr .get_nframes (),
117
+ len (self .subhdr .subheaders ))
118
+ assert_equal (self .subhdr ._check_affines (), True )
119
+ assert_array_almost_equal (np .diag (self .subhdr .get_frame_affine ()),
120
+ np .array ([ 2.20241979 , 2.20241979 , 3.125 , 1. ]))
121
+ assert_equal (self .subhdr .get_zooms ()[0 ], 2.20241978764534 )
122
+ assert_equal (self .subhdr .get_zooms ()[2 ], 3.125 )
123
+ assert_equal (self .subhdr ._get_data_dtype (0 ),np .uint16 )
124
+ assert_equal (self .subhdr ._get_frame_offset (), 1536 )
124
125
dat = self .subhdr .raw_data_from_fileobj ()
125
- yield assert_equal (dat .shape , self .subhdr .get_shape ())
126
+ assert_equal (dat .shape , self .subhdr .get_shape ())
126
127
scale_factor = self .subhdr .subheaders [0 ]['scale_factor' ]
128
+ assert_equal (self .subhdr .subheaders [0 ]['scale_factor' ].item (),1.0 )
129
+
127
130
ecat_calib_factor = self .hdr ['ecat_calibration_factor' ]
131
+ assert_equal (ecat_calib_factor , 25007614.0 )
128
132
scaled_dat = self .subhdr .data_from_fileobj ()
129
- yield assert_array_equal ( dat * scale_factor * ecat_calib_factor ,
130
- scaled_dat )
133
+ tmpdat = scale_factor * ecat_calib_factor * dat
134
+ assert_array_equal ( tmpdat , scaled_dat )
131
135
132
136
133
- class TestEcatImage (ParametricTestCase ):
137
+ class TestEcatImage (TestCase ):
134
138
image_class = EcatImage
135
139
example_file = ecat_file
136
140
img = image_class .load (example_file )
137
141
138
142
def test_file (self ):
139
- yield assert_equal (self .img .file_map ['header' ].filename ,
140
- self .example_file )
141
- yield assert_equal (self .img .file_map ['image' ].filename ,
142
- self .example_file )
143
- yield assert_raises (NotImplementedError ,
144
- self .img .to_filename ,
145
- 'tmp.v' )
143
+ assert_equal (self .img .file_map ['header' ].filename ,
144
+ self .example_file )
145
+ assert_equal (self .img .file_map ['image' ].filename ,
146
+ self .example_file )
147
+ assert_raises (NotImplementedError ,
148
+ self .img .to_filename ,
149
+ 'tmp.v' )
146
150
147
151
def test_data (self ):
148
152
dat = self .img .get_data ()
149
- yield assert_equal (dat .shape , self .img .get_shape ())
153
+ assert_equal (dat .shape , self .img .get_shape ())
150
154
frame = self .img .get_frame (0 )
151
- yield assert_array_equal (frame , dat [:,:,:,0 ])
155
+ assert_array_equal (frame , dat [:,:,:,0 ])
152
156
153
157
0 commit comments