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,14 @@ 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_equal (img2 .nifti_header .get_intent ()[0 ],
222
+ 'ConnDenseSeries' )
223
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
219
224
assert_true ((img2 .get_data () == data ).all ())
220
225
check_series_map (img2 .header .matrix .get_index_map (0 ))
221
226
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -231,10 +236,13 @@ def test_dscalar():
231
236
hdr = ci .Cifti2Header (matrix )
232
237
data = np .random .randn (2 , 9 )
233
238
img = ci .Cifti2Image (data , hdr )
239
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_SCALARS' )
234
240
235
241
with InTemporaryDirectory ():
236
242
ci .save (img , 'test.dscalar.nii' )
237
- img2 = ci .load ('test.dscalar.nii' )
243
+ img2 = nib .load ('test.dscalar.nii' )
244
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnDenseScalar' )
245
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
238
246
assert_true ((img2 .get_data () == data ).all ())
239
247
check_scalar_map (img2 .header .matrix .get_index_map (0 ))
240
248
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -250,10 +258,13 @@ def test_dlabel():
250
258
hdr = ci .Cifti2Header (matrix )
251
259
data = np .random .randn (2 , 9 )
252
260
img = ci .Cifti2Image (data , hdr )
261
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_LABELS' )
253
262
254
263
with InTemporaryDirectory ():
255
264
ci .save (img , 'test.dlabel.nii' )
256
- img2 = ci .load ('test.dlabel.nii' )
265
+ img2 = nib .load ('test.dlabel.nii' )
266
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnDenseLabel' )
267
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
257
268
assert_true ((img2 .get_data () == data ).all ())
258
269
check_label_map (img2 .header .matrix .get_index_map (0 ))
259
270
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -267,10 +278,13 @@ def test_dconn():
267
278
hdr = ci .Cifti2Header (matrix )
268
279
data = np .random .randn (9 , 9 )
269
280
img = ci .Cifti2Image (data , hdr )
281
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE' )
270
282
271
283
with InTemporaryDirectory ():
272
284
ci .save (img , 'test.dconn.nii' )
273
- img2 = ci .load ('test.dconn.nii' )
285
+ img2 = nib .load ('test.dconn.nii' )
286
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnDense' )
287
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
274
288
assert_true ((img2 .get_data () == data ).all ())
275
289
assert_equal (img2 .header .matrix .get_index_map (0 ),
276
290
img2 .header .matrix .get_index_map (1 ))
@@ -287,10 +301,13 @@ def test_ptseries():
287
301
hdr = ci .Cifti2Header (matrix )
288
302
data = np .random .randn (13 , 3 )
289
303
img = ci .Cifti2Image (data , hdr )
304
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SERIES' )
290
305
291
306
with InTemporaryDirectory ():
292
307
ci .save (img , 'test.ptseries.nii' )
293
- img2 = ci .load ('test.ptseries.nii' )
308
+ img2 = nib .load ('test.ptseries.nii' )
309
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnParcelSries' )
310
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
294
311
assert_true ((img2 .get_data () == data ).all ())
295
312
check_series_map (img2 .header .matrix .get_index_map (0 ))
296
313
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -306,10 +323,13 @@ def test_pscalar():
306
323
hdr = ci .Cifti2Header (matrix )
307
324
data = np .random .randn (2 , 3 )
308
325
img = ci .Cifti2Image (data , hdr )
326
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SCALAR' )
309
327
310
328
with InTemporaryDirectory ():
311
329
ci .save (img , 'test.pscalar.nii' )
312
- img2 = ci .load ('test.pscalar.nii' )
330
+ img2 = nib .load ('test.pscalar.nii' )
331
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnParcelScalr' )
332
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
313
333
assert_true ((img2 .get_data () == data ).all ())
314
334
check_scalar_map (img2 .header .matrix .get_index_map (0 ))
315
335
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -325,10 +345,13 @@ def test_pdconn():
325
345
hdr = ci .Cifti2Header (matrix )
326
346
data = np .random .randn (2 , 3 )
327
347
img = ci .Cifti2Image (data , hdr )
348
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_DENSE' )
328
349
329
350
with InTemporaryDirectory ():
330
351
ci .save (img , 'test.pdconn.nii' )
331
352
img2 = ci .load ('test.pdconn.nii' )
353
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnParcelDense' )
354
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
332
355
assert_true ((img2 .get_data () == data ).all ())
333
356
check_geometry_map (img2 .header .matrix .get_index_map (0 ))
334
357
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -344,10 +367,13 @@ def test_dpconn():
344
367
hdr = ci .Cifti2Header (matrix )
345
368
data = np .random .randn (2 , 3 )
346
369
img = ci .Cifti2Image (data , hdr )
370
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_PARCELLATED' )
347
371
348
372
with InTemporaryDirectory ():
349
373
ci .save (img , 'test.dpconn.nii' )
350
374
img2 = ci .load ('test.dpconn.nii' )
375
+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnDenseParcel' )
376
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
351
377
assert_true ((img2 .get_data () == data ).all ())
352
378
check_parcel_map (img2 .header .matrix .get_index_map (0 ))
353
379
check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -367,6 +393,8 @@ def test_plabel():
367
393
with InTemporaryDirectory ():
368
394
ci .save (img , 'test.plabel.nii' )
369
395
img2 = ci .load ('test.plabel.nii' )
396
+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnUnknown' )
397
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
370
398
assert_true ((img2 .get_data () == data ).all ())
371
399
check_label_map (img2 .header .matrix .get_index_map (0 ))
372
400
check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -380,10 +408,13 @@ def test_pconn():
380
408
hdr = ci .Cifti2Header (matrix )
381
409
data = np .random .randn (3 , 3 )
382
410
img = ci .Cifti2Image (data , hdr )
411
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED' )
383
412
384
413
with InTemporaryDirectory ():
385
414
ci .save (img , 'test.pconn.nii' )
386
415
img2 = ci .load ('test.pconn.nii' )
416
+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnParcels' )
417
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
387
418
assert_true ((img2 .get_data () == data ).all ())
388
419
assert_equal (img2 .header .matrix .get_index_map (0 ),
389
420
img2 .header .matrix .get_index_map (1 ))
@@ -401,10 +432,14 @@ def test_pconnseries():
401
432
hdr = ci .Cifti2Header (matrix )
402
433
data = np .random .randn (3 , 3 , 13 )
403
434
img = ci .Cifti2Image (data , hdr )
435
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
436
+ 'PARCELLATED_SERIES' )
404
437
405
438
with InTemporaryDirectory ():
406
439
ci .save (img , 'test.pconnseries.nii' )
407
440
img2 = ci .load ('test.pconnseries.nii' )
441
+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnPPSr' )
442
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
408
443
assert_true ((img2 .get_data () == data ).all ())
409
444
assert_equal (img2 .header .matrix .get_index_map (0 ),
410
445
img2 .header .matrix .get_index_map (1 ))
@@ -423,10 +458,14 @@ def test_pconnscalar():
423
458
hdr = ci .Cifti2Header (matrix )
424
459
data = np .random .randn (3 , 3 , 13 )
425
460
img = ci .Cifti2Image (data , hdr )
461
+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
462
+ 'PARCELLATED_SCALAR' )
426
463
427
464
with InTemporaryDirectory ():
428
465
ci .save (img , 'test.pconnscalar.nii' )
429
466
img2 = ci .load ('test.pconnscalar.nii' )
467
+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnPPSc' )
468
+ assert_true (isinstance (img2 , ci .Cifti2Image ))
430
469
assert_true ((img2 .get_data () == data ).all ())
431
470
assert_equal (img2 .header .matrix .get_index_map (0 ),
432
471
img2 .header .matrix .get_index_map (1 ))
0 commit comments