8
8
"""
9
9
import numpy as np
10
10
11
+ import nibabel as nib
11
12
from nibabel import cifti2 as ci
12
13
from nibabel .tmpdirs import InTemporaryDirectory
13
14
@@ -212,10 +213,12 @@ def test_dtseries():
212
213
hdr = ci .Cifti2Header (matrix )
213
214
data = np .random .randn (13 , 9 )
214
215
img = ci .Cifti2Image (data , hdr )
216
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES' )
215
217
216
218
with InTemporaryDirectory ():
217
219
ci .save (img , 'test.dtseries.nii' )
218
- img2 = ci .load ('test.dtseries.nii' )
220
+ img2 = nib .load ('test.dtseries.nii' )
221
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
219
222
assert_true ((img2 .get_data () == data ).all ())
220
223
check_series_map (img2 .header .matrix .get_index_map (0 ))
221
224
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -231,10 +234,12 @@ def test_dscalar():
231
234
hdr = ci .Cifti2Header (matrix )
232
235
data = np .random .randn (2 , 9 )
233
236
img = ci .Cifti2Image (data , hdr )
237
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_SCALARS' )
234
238
235
239
with InTemporaryDirectory ():
236
240
ci .save (img , 'test.dscalar.nii' )
237
- img2 = ci .load ('test.dscalar.nii' )
241
+ img2 = nib .load ('test.dscalar.nii' )
242
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
238
243
assert_true ((img2 .get_data () == data ).all ())
239
244
check_scalar_map (img2 .header .matrix .get_index_map (0 ))
240
245
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -250,10 +255,12 @@ def test_dlabel():
250
255
hdr = ci .Cifti2Header (matrix )
251
256
data = np .random .randn (2 , 9 )
252
257
img = ci .Cifti2Image (data , hdr )
258
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_LABELS' )
253
259
254
260
with InTemporaryDirectory ():
255
261
ci .save (img , 'test.dlabel.nii' )
256
- img2 = ci .load ('test.dlabel.nii' )
262
+ img2 = nib .load ('test.dlabel.nii' )
263
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
257
264
assert_true ((img2 .get_data () == data ).all ())
258
265
check_label_map (img2 .header .matrix .get_index_map (0 ))
259
266
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -267,10 +274,12 @@ def test_dconn():
267
274
hdr = ci .Cifti2Header (matrix )
268
275
data = np .random .randn (9 , 9 )
269
276
img = ci .Cifti2Image (data , hdr )
277
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE' )
270
278
271
279
with InTemporaryDirectory ():
272
280
ci .save (img , 'test.dconn.nii' )
273
- img2 = ci .load ('test.dconn.nii' )
281
+ img2 = nib .load ('test.dconn.nii' )
282
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
274
283
assert_true ((img2 .get_data () == data ).all ())
275
284
assert_equal (img2 .header .matrix .get_index_map (0 ),
276
285
img2 .header .matrix .get_index_map (1 ))
@@ -287,10 +296,12 @@ def test_ptseries():
287
296
hdr = ci .Cifti2Header (matrix )
288
297
data = np .random .randn (13 , 3 )
289
298
img = ci .Cifti2Image (data , hdr )
299
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SERIES' )
290
300
291
301
with InTemporaryDirectory ():
292
302
ci .save (img , 'test.ptseries.nii' )
293
- img2 = ci .load ('test.ptseries.nii' )
303
+ img2 = nib .load ('test.ptseries.nii' )
304
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
294
305
assert_true ((img2 .get_data () == data ).all ())
295
306
check_series_map (img2 .header .matrix .get_index_map (0 ))
296
307
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -306,10 +317,12 @@ def test_pscalar():
306
317
hdr = ci .Cifti2Header (matrix )
307
318
data = np .random .randn (2 , 3 )
308
319
img = ci .Cifti2Image (data , hdr )
320
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SCALAR' )
309
321
310
322
with InTemporaryDirectory ():
311
323
ci .save (img , 'test.pscalar.nii' )
312
- img2 = ci .load ('test.pscalar.nii' )
324
+ img2 = nib .load ('test.pscalar.nii' )
325
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
313
326
assert_true ((img2 .get_data () == data ).all ())
314
327
check_scalar_map (img2 .header .matrix .get_index_map (0 ))
315
328
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -325,10 +338,12 @@ def test_pdconn():
325
338
hdr = ci .Cifti2Header (matrix )
326
339
data = np .random .randn (2 , 3 )
327
340
img = ci .Cifti2Image (data , hdr )
341
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_PARCELLATED' )
328
342
329
343
with InTemporaryDirectory ():
330
344
ci .save (img , 'test.pdconn.nii' )
331
345
img2 = ci .load ('test.pdconn.nii' )
346
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
332
347
assert_true ((img2 .get_data () == data ).all ())
333
348
check_geometry_map (img2 .header .matrix .get_index_map (0 ))
334
349
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -344,10 +359,12 @@ def test_dpconn():
344
359
hdr = ci .Cifti2Header (matrix )
345
360
data = np .random .randn (2 , 3 )
346
361
img = ci .Cifti2Image (data , hdr )
362
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_PARCELLATED' )
347
363
348
364
with InTemporaryDirectory ():
349
365
ci .save (img , 'test.dpconn.nii' )
350
366
img2 = ci .load ('test.dpconn.nii' )
367
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
351
368
assert_true ((img2 .get_data () == data ).all ())
352
369
check_parcel_map (img2 .header .matrix .get_index_map (0 ))
353
370
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -367,6 +384,7 @@ def test_plabel():
367
384
with InTemporaryDirectory ():
368
385
ci .save (img , 'test.plabel.nii' )
369
386
img2 = ci .load ('test.plabel.nii' )
387
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
370
388
assert_true ((img2 .get_data () == data ).all ())
371
389
check_label_map (img2 .header .matrix .get_index_map (0 ))
372
390
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -380,10 +398,12 @@ def test_pconn():
380
398
hdr = ci .Cifti2Header (matrix )
381
399
data = np .random .randn (3 , 3 )
382
400
img = ci .Cifti2Image (data , hdr )
401
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED' )
383
402
384
403
with InTemporaryDirectory ():
385
404
ci .save (img , 'test.pconn.nii' )
386
405
img2 = ci .load ('test.pconn.nii' )
406
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
387
407
assert_true ((img2 .get_data () == data ).all ())
388
408
assert_equal (img2 .header .matrix .get_index_map (0 ),
389
409
img2 .header .matrix .get_index_map (1 ))
@@ -394,17 +414,19 @@ def test_pconn():
394
414
def test_pconnseries ():
395
415
parcel_map = create_parcel_map ((0 , 1 ))
396
416
series_map = create_series_map ((2 , ))
397
-
398
417
matrix = ci .Cifti2Matrix ()
399
418
matrix .append (parcel_map )
400
419
matrix .append (series_map )
401
420
hdr = ci .Cifti2Header (matrix )
402
421
data = np .random .randn (3 , 3 , 13 )
403
422
img = ci .Cifti2Image (data , hdr )
423
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
424
+ 'PARCELLATED_SERIES' )
404
425
405
426
with InTemporaryDirectory ():
406
427
ci .save (img , 'test.pconnseries.nii' )
407
428
img2 = ci .load ('test.pconnseries.nii' )
429
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
408
430
assert_true ((img2 .get_data () == data ).all ())
409
431
assert_equal (img2 .header .matrix .get_index_map (0 ),
410
432
img2 .header .matrix .get_index_map (1 ))
@@ -416,17 +438,19 @@ def test_pconnseries():
416
438
def test_pconnscalar ():
417
439
parcel_map = create_parcel_map ((0 , 1 ))
418
440
scalar_map = create_scalar_map ((2 , ))
419
-
420
441
matrix = ci .Cifti2Matrix ()
421
442
matrix .append (parcel_map )
422
443
matrix .append (scalar_map )
423
444
hdr = ci .Cifti2Header (matrix )
424
445
data = np .random .randn (3 , 3 , 13 )
425
446
img = ci .Cifti2Image (data , hdr )
447
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
448
+ 'PARCELLATED_SCALAR' )
426
449
427
450
with InTemporaryDirectory ():
428
451
ci .save (img , 'test.pconnscalar.nii' )
429
452
img2 = ci .load ('test.pconnscalar.nii' )
453
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
430
454
assert_true ((img2 .get_data () == data ).all ())
431
455
assert_equal (img2 .header .matrix .get_index_map (0 ),
432
456
img2 .header .matrix .get_index_map (1 ))
0 commit comments