24
24
from .volumeutils import Recoder , array_from_file
25
25
26
26
_attr_dic = {
27
- 'string' : str ,
28
- 'integer' : int ,
29
- 'float' : float
27
+ 'string' : str ,
28
+ 'integer' : int ,
29
+ 'float' : float
30
30
}
31
31
32
32
_endian_dict = {
33
- 'LSB_FIRST' : '<' ,
34
- 'MSB_FIRST' : '>' ,
33
+ 'LSB_FIRST' : '<' ,
34
+ 'MSB_FIRST' : '>' ,
35
35
}
36
36
37
37
_dtype_dict = {
38
- 0 : 'B' ,
39
- 1 : 'h' ,
40
- 3 : 'f' ,
41
- 5 : 'D' ,
38
+ 0 : 'B' ,
39
+ 1 : 'h' ,
40
+ 3 : 'f' ,
41
+ 5 : 'D' ,
42
42
}
43
43
44
44
_orient_dict = {
45
- 0 : 'R' ,
46
- 1 : 'L' ,
47
- 2 : 'P' ,
48
- 3 : 'A' ,
49
- 4 : 'I' ,
50
- 5 : 'S'
45
+ 0 : 'R' ,
46
+ 1 : 'L' ,
47
+ 2 : 'P' ,
48
+ 3 : 'A' ,
49
+ 4 : 'I' ,
50
+ 5 : 'S'
51
51
}
52
52
53
53
space_codes = Recoder ((
54
54
(0 , 'unknown' , '' ),
55
55
(1 , 'scanner' , 'ORIG' ),
56
56
(3 , 'talairach' , 'TLRC' ),
57
- (4 , 'mni' , 'MNI' )), fields = ('code' ,'label' ,'space' ))
57
+ (4 , 'mni' , 'MNI' )), fields = ('code' , 'label' , 'space' ))
58
58
59
59
60
60
class AFNIError (Exception ):
@@ -85,7 +85,7 @@ def _unpack_var(var):
85
85
aname = NAME_RE .findall (var )[0 ]
86
86
87
87
atype = _attr_dic .get (atype , str )
88
- attr = ' ' .join (var .strip ().split ('\n ' )[3 :])
88
+ attr = ' ' .join (var .strip ().split ('\n ' )[3 :])
89
89
90
90
if atype is not str :
91
91
attr = [atype (f ) for f in attr .split ()]
@@ -116,7 +116,7 @@ def _get_datatype(info):
116
116
if bt is None :
117
117
raise AFNIError ('Can\' t deduce image data type.' )
118
118
119
- return np .dtype (bo + bt )
119
+ return np .dtype (bo + bt )
120
120
121
121
122
122
def parse_AFNI_header (fobj ):
@@ -135,7 +135,7 @@ def parse_AFNI_header(fobj):
135
135
136
136
head = fobj .read ().split ('\n \n ' )
137
137
138
- all_info = {key : value for key , value in map (_unpack_var , head )}
138
+ all_info = {key : value for key , value in map (_unpack_var , head )}
139
139
140
140
return all_info
141
141
@@ -292,7 +292,7 @@ def _calc_zooms(self):
292
292
zooms : tuple
293
293
"""
294
294
xyz_step = tuple (np .abs (self .info ['DELTA' ]))
295
- t_step = self .info .get ('TAXIS_FLOATS' ,())
295
+ t_step = self .info .get ('TAXIS_FLOATS' , ())
296
296
297
297
if len (t_step ) > 0 :
298
298
t_step = (t_step [1 ],)
@@ -329,14 +329,14 @@ def get_space(self):
329
329
def get_affine (self ):
330
330
# AFNI default is RAI/DICOM order (i.e., RAI are - axis)
331
331
# need to flip RA sign to align with nibabel RAS+ system
332
- affine = np .asarray (self .info ['IJK_TO_DICOM_REAL' ]).reshape (3 ,4 )
333
- affine = np .row_stack ((affine * [[- 1 ],[- 1 ],[1 ]],
334
- [0 ,0 , 0 , 1 ]))
332
+ affine = np .asarray (self .info ['IJK_TO_DICOM_REAL' ]).reshape (3 , 4 )
333
+ affine = np .row_stack ((affine * [[- 1 ], [- 1 ], [1 ]],
334
+ [0 , 0 , 0 , 1 ]))
335
335
336
336
return affine
337
337
338
338
def get_data_scaling (self ):
339
- floatfacs = self .info .get ('BRICK_FLOAT_FACS' ,None )
339
+ floatfacs = self .info .get ('BRICK_FLOAT_FACS' , None )
340
340
341
341
if floatfacs is None or not np .any (floatfacs ):
342
342
return None
@@ -367,9 +367,9 @@ class AFNIImage(SpatialImage):
367
367
"""
368
368
369
369
header_class = AFNIHeader
370
- valid_exts = ('.brik' ,'.head' )
371
- files_types = (('image' , '.brik' ),('header' , '.head' ))
372
- _compressed_suffixes = ('.gz' ,'.bz2' )
370
+ valid_exts = ('.brik' , '.head' )
371
+ files_types = (('image' , '.brik' ), ('header' , '.head' ))
372
+ _compressed_suffixes = ('.gz' , '.bz2' )
373
373
374
374
makeable = False
375
375
rw = False
0 commit comments