File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ ''' CSA header reader from SPM spec
2
+
3
+ '''
4
+ from struct import unpack
5
+
6
+
7
+ class CSAReadError (Exception ):
8
+ pass
9
+
10
+
11
+ def read (fileobj ):
12
+ ''' Read CSA header from fileobj
13
+
14
+ Parameters
15
+ ----------
16
+ fileobj : file-like
17
+ file-like object implementing ``read, seek, tell`. The data is
18
+ taken to start at position 0 and end at the end of the file.
19
+
20
+ Returns
21
+ -------
22
+ header : dict
23
+ header information
24
+ tags : sequence
25
+ sequence of tags from header
26
+ '''
27
+ fileobj .seek (0 )
28
+ hdr_id = fileobj .read (4 )
29
+ hdr = {}
30
+ tags = []
31
+ if hdr_id != 'SV10' :
32
+ hdr ['type' ] = 1
33
+ hdr ['n_tags' ], = unpack ('<i' , hdr_id )
34
+ else :
35
+ hdr ['type' ] = 2
36
+ hdr ['unused1' ] = fileobj .read (4 )
37
+ hdr ['n_tags' ], = unpack ('<I' , fileobj .read (4 ))
38
+ hdr ['unused3' ], = unpack ('<I' , fileobj .read (4 ))
39
+ return hdr , tags
Original file line number Diff line number Diff line change
1
+ """ Testing Siemens CSA header reader
2
+ """
3
+ import os
4
+ from os .path import join as pjoin
5
+
6
+ import numpy as np
7
+
8
+ import dipy .io .csareader as csa
9
+
10
+ from nose .tools import assert_true , assert_false , \
11
+ assert_equal , assert_raises
12
+
13
+ from numpy .testing import assert_array_equal , assert_array_almost_equal
14
+
15
+ from dipy .testing import parametric
16
+
17
+
18
+ data_path = pjoin (os .path .dirname (__file__ ), 'data' )
19
+
20
+ CSA2_B0 = pjoin (data_path , 'csa2_b0.bin' )
21
+ CSA2_B1000 = pjoin (data_path , 'csa2_b1000.bin' )
22
+
23
+
24
+ @parametric
25
+ def test_csa ():
26
+ csa_f = open (CSA2_B0 , 'rb' )
27
+ hdr , tags = csa .read (csa_f )
28
+ yield assert_equal (hdr ['type' ], 2 )
29
+ yield assert_equal (hdr ['n_tags' ], 83 )
30
+ yield assert_equal (len (tags ), 83 )
31
+
You can’t perform that action at this time.
0 commit comments