15
15
import numpy as np
16
16
17
17
from ... import gifti as gi
18
+ from ...loadsave import load , save
19
+
18
20
from ..util import gifti_endian_codes
19
21
from ...nifti1 import xform_codes
20
22
@@ -102,23 +104,23 @@ def test_read_ordering():
102
104
# DATA_FILE1 has an expected darray[0].data shape of (3,3). However if we
103
105
# read another image first (DATA_FILE2) then the shape is wrong
104
106
# Read an image
105
- img2 = gi . read (DATA_FILE2 )
107
+ img2 = load (DATA_FILE2 )
106
108
assert_equal (img2 .darrays [0 ].data .shape , (143479 , 1 ))
107
109
# Read image for which we know output shape
108
- img = gi . read (DATA_FILE1 )
110
+ img = load (DATA_FILE1 )
109
111
assert_equal (img .darrays [0 ].data .shape , (3 ,3 ))
110
112
111
113
112
114
def test_load_metadata ():
113
115
for i , dat in enumerate (datafiles ):
114
- img = gi . read (dat )
116
+ img = load (dat )
115
117
me = img .meta
116
118
assert_equal (numDA [i ], img .numDA )
117
119
assert_equal (img .version ,'1.0' )
118
120
119
121
120
122
def test_metadata_deprecations ():
121
- img = gi . read (datafiles [0 ])
123
+ img = load (datafiles [0 ])
122
124
me = img .meta
123
125
124
126
# Test deprecation
@@ -133,12 +135,11 @@ def test_metadata_deprecations():
133
135
134
136
135
137
def test_load_dataarray1 ():
136
- img1 = gi .read (DATA_FILE1 )
137
-
138
+ img1 = load (DATA_FILE1 )
138
139
# Round trip
139
140
with InTemporaryDirectory ():
140
- gi . write (img1 , 'test.gii' )
141
- bimg = gi . read ('test.gii' )
141
+ save (img1 , 'test.gii' )
142
+ bimg = load ('test.gii' )
142
143
for img in (img1 , bimg ):
143
144
assert_array_almost_equal (img .darrays [0 ].data , DATA_FILE1_darr1 )
144
145
assert_array_almost_equal (img .darrays [1 ].data , DATA_FILE1_darr2 )
@@ -152,40 +153,36 @@ def test_load_dataarray1():
152
153
153
154
154
155
def test_load_dataarray2 ():
155
- img2 = gi .read (DATA_FILE2 )
156
-
156
+ img2 = load (DATA_FILE2 )
157
157
# Round trip
158
158
with InTemporaryDirectory ():
159
- gi . write (img2 , 'test.gii' )
160
- bimg = gi . read ('test.gii' )
159
+ save (img2 , 'test.gii' )
160
+ bimg = load ('test.gii' )
161
161
for img in (img2 , bimg ):
162
162
assert_array_almost_equal (img .darrays [0 ].data [:10 ], DATA_FILE2_darr1 )
163
163
164
164
165
165
def test_load_dataarray3 ():
166
- img3 = gi .read (DATA_FILE3 )
167
-
166
+ img3 = load (DATA_FILE3 )
168
167
with InTemporaryDirectory ():
169
- gi . write (img3 , 'test.gii' )
170
- bimg = gi . read ('test.gii' )
168
+ save (img3 , 'test.gii' )
169
+ bimg = load ('test.gii' )
171
170
for img in (img3 , bimg ):
172
171
assert_array_almost_equal (img .darrays [0 ].data [30 :50 ], DATA_FILE3_darr1 )
173
172
174
173
175
174
def test_load_dataarray4 ():
176
- img4 = gi .read (DATA_FILE4 )
177
-
175
+ img4 = load (DATA_FILE4 )
178
176
# Round trip
179
177
with InTemporaryDirectory ():
180
- gi . write (img4 , 'test.gii' )
181
- bimg = gi . read ('test.gii' )
178
+ save (img4 , 'test.gii' )
179
+ bimg = load ('test.gii' )
182
180
for img in (img4 , bimg ):
183
181
assert_array_almost_equal (img .darrays [0 ].data [:10 ], DATA_FILE4_darr1 )
184
182
185
183
186
184
def test_dataarray5 ():
187
- img5 = gi .read (DATA_FILE5 )
188
-
185
+ img5 = load (DATA_FILE5 )
189
186
for da in img5 .darrays :
190
187
assert_equal (gifti_endian_codes .byteorder [da .endian ], 'little' )
191
188
assert_array_almost_equal (img5 .darrays [0 ].data , DATA_FILE5_darr1 )
@@ -204,8 +201,8 @@ def test_base64_written():
204
201
assert_false (b'Base64Binary' in contents )
205
202
assert_false (b'LittleEndian' in contents )
206
203
# Round trip
207
- img5 = gi . read (DATA_FILE5 )
208
- gi . write (img5 , 'fixed.gii' )
204
+ img5 = load (DATA_FILE5 )
205
+ save (img5 , 'fixed.gii' )
209
206
with open ('fixed.gii' , 'rb' ) as fobj :
210
207
contents = fobj .read ()
211
208
# The bad codes have gone, replaced by the good ones
@@ -216,17 +213,17 @@ def test_base64_written():
216
213
assert_true (b'LittleEndian' in contents )
217
214
else :
218
215
assert_true (b'BigEndian' in contents )
219
- img5_fixed = gi . read ('fixed.gii' )
216
+ img5_fixed = load ('fixed.gii' )
220
217
darrays = img5_fixed .darrays
221
218
assert_array_almost_equal (darrays [0 ].data , DATA_FILE5_darr1 )
222
219
assert_array_almost_equal (darrays [1 ].data , DATA_FILE5_darr2 )
223
220
224
221
225
222
def test_readwritedata ():
226
- img = gi . read (DATA_FILE2 )
223
+ img = load (DATA_FILE2 )
227
224
with InTemporaryDirectory ():
228
- gi . write (img , 'test.gii' )
229
- img2 = gi . read ('test.gii' )
225
+ save (img , 'test.gii' )
226
+ img2 = load ('test.gii' )
230
227
assert_equal (img .numDA ,img2 .numDA )
231
228
assert_array_almost_equal (img .darrays [0 ].data ,
232
229
img2 .darrays [0 ].data )
@@ -247,8 +244,7 @@ def test_write_newmetadata():
247
244
248
245
249
246
def test_load_getbyintent ():
250
- img = gi .read (DATA_FILE1 )
251
-
247
+ img = load (DATA_FILE1 )
252
248
da = img .get_arrays_from_intent ("NIFTI_INTENT_POINTSET" )
253
249
assert_equal (len (da ), 1 )
254
250
@@ -268,12 +264,11 @@ def test_load_getbyintent():
268
264
269
265
270
266
def test_load_labeltable ():
271
- img6 = gi .read (DATA_FILE6 )
272
-
267
+ img6 = load (DATA_FILE6 )
273
268
# Round trip
274
269
with InTemporaryDirectory ():
275
- gi . write (img6 , 'test.gii' )
276
- bimg = gi . read ('test.gii' )
270
+ save (img6 , 'test.gii' )
271
+ bimg = load ('test.gii' )
277
272
for img in (img6 , bimg ):
278
273
assert_array_almost_equal (img .darrays [0 ].data [:3 ], DATA_FILE6_darr1 )
279
274
assert_equal (len (img .labeltable .labels ), 36 )
@@ -288,7 +283,7 @@ def test_load_labeltable():
288
283
289
284
290
285
def test_labeltable_deprecations ():
291
- img = gi . read (DATA_FILE6 )
286
+ img = load (DATA_FILE6 )
292
287
lt = img .labeltable
293
288
294
289
# Test deprecation
@@ -307,7 +302,7 @@ def test_parse_dataarrays():
307
302
img = gi .GiftiImage ()
308
303
309
304
with InTemporaryDirectory ():
310
- gi . write (img , fn )
305
+ save (img , fn )
311
306
with open (fn , 'r' ) as fp :
312
307
txt = fp .read ()
313
308
# Make a bad gifti.
@@ -317,6 +312,6 @@ def test_parse_dataarrays():
317
312
318
313
with clear_and_catch_warnings () as w :
319
314
warnings .filterwarnings ('once' , category = UserWarning )
320
- gi . read (fn )
315
+ load (fn )
321
316
assert_equal (len (w ), 1 )
322
317
assert_equal (img .numDA , 0 )
0 commit comments