12
12
import numpy as np
13
13
from .. import load , save , MGHImage
14
14
from ..mghformat import MGHError
15
- from ...tmpdirs import TemporaryDirectory
15
+ from ...tmpdirs import InTemporaryDirectory
16
16
from ...testing import data_path
17
17
from numpy .testing import assert_equal , assert_array_equal , \
18
18
assert_array_almost_equal , assert_almost_equal , assert_raises
@@ -52,23 +52,23 @@ def test_write_mgh():
52
52
v = v .reshape ((5 , 4 , 3 , 2 )).astype (np .float32 )
53
53
# form a MGHImage object using data and vox2ras matrix
54
54
img = MGHImage (v , v2r )
55
- with TemporaryDirectory () as tmpdir :
56
- save (img , os . path . join ( tmpdir , 'tmpsave.mgz' ) )
55
+ with InTemporaryDirectory () :
56
+ save (img , 'tmpsave.mgz' )
57
57
# read from the tmp file and see if it checks out
58
- mgz = load (os .path .join (tmpdir , 'tmpsave.mgz' ))
59
-
58
+ mgz = load ('tmpsave.mgz' )
59
+ h = mgz .get_header ()
60
+ dat = mgz .get_data ()
61
+ # Delete loaded image to allow file deletion by windows
62
+ del mgz
60
63
# header
61
- h = mgz .get_header ()
62
64
assert_equal (h ['version' ], 1 )
63
65
assert_equal (h ['type' ], 3 )
64
66
assert_equal (h ['dof' ], 0 )
65
67
assert_equal (h ['goodRASFlag' ], 1 )
66
68
assert_array_equal (h ['dims' ], [5 , 4 , 3 , 2 ])
67
69
assert_array_almost_equal (h ['mrparms' ], [0.0 , 0.0 , 0.0 , 0.0 ])
68
70
assert_array_almost_equal (h .get_vox2ras (), v2r )
69
-
70
71
# data
71
- dat = mgz .get_data ()
72
72
assert_almost_equal (dat , v , 7 )
73
73
74
74
@@ -79,20 +79,20 @@ def test_write_noaffine_mgh():
79
79
# form a MGHImage object using data
80
80
# and the default affine matrix (Note the "None")
81
81
img = MGHImage (v , None )
82
- with TemporaryDirectory () as tmpdir :
83
- save (img , os . path . join ( tmpdir , 'tmpsave.mgz' ) )
82
+ with InTemporaryDirectory () :
83
+ save (img , 'tmpsave.mgz' )
84
84
# read from the tmp file and see if it checks out
85
- mgz = load (os .path .join (tmpdir , 'tmpsave.mgz' ))
86
-
85
+ mgz = load ('tmpsave.mgz' )
86
+ h = mgz .get_header ()
87
+ # Delete loaded image to allow file deletion by windows
88
+ del mgz
87
89
# header
88
- h = mgz .get_header ()
89
90
assert_equal (h ['version' ], 1 )
90
91
assert_equal (h ['type' ], 0 ) # uint8 for mgh
91
92
assert_equal (h ['dof' ], 0 )
92
93
assert_equal (h ['goodRASFlag' ], 1 )
93
94
assert_array_equal (h ['dims' ], [7 , 13 , 3 , 22 ])
94
95
assert_array_almost_equal (h ['mrparms' ], [0.0 , 0.0 , 0.0 , 0.0 ])
95
-
96
96
# important part -- whether default affine info is stored
97
97
ex_mdc = np .array ([[- 1 , 0 , 0 ],
98
98
[0 , 0 , - 1 ],
0 commit comments