88"""
99import numpy as np
1010
11+ import nibabel as nib
1112from nibabel import cifti2 as ci
1213from nibabel .tmpdirs import InTemporaryDirectory
1314
@@ -212,10 +213,12 @@ def test_dtseries():
212213 hdr = ci .Cifti2Header (matrix )
213214 data = np .random .randn (13 , 9 )
214215 img = ci .Cifti2Image (data , hdr )
216+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_SERIES' )
215217
216218 with InTemporaryDirectory ():
217219 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 ))
219222 assert_true ((img2 .get_data () == data ).all ())
220223 check_series_map (img2 .header .matrix .get_index_map (0 ))
221224 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -231,10 +234,12 @@ def test_dscalar():
231234 hdr = ci .Cifti2Header (matrix )
232235 data = np .random .randn (2 , 9 )
233236 img = ci .Cifti2Image (data , hdr )
237+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_SCALARS' )
234238
235239 with InTemporaryDirectory ():
236240 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 ))
238243 assert_true ((img2 .get_data () == data ).all ())
239244 check_scalar_map (img2 .header .matrix .get_index_map (0 ))
240245 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -250,10 +255,12 @@ def test_dlabel():
250255 hdr = ci .Cifti2Header (matrix )
251256 data = np .random .randn (2 , 9 )
252257 img = ci .Cifti2Image (data , hdr )
258+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_LABELS' )
253259
254260 with InTemporaryDirectory ():
255261 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 ))
257264 assert_true ((img2 .get_data () == data ).all ())
258265 check_label_map (img2 .header .matrix .get_index_map (0 ))
259266 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -267,10 +274,12 @@ def test_dconn():
267274 hdr = ci .Cifti2Header (matrix )
268275 data = np .random .randn (9 , 9 )
269276 img = ci .Cifti2Image (data , hdr )
277+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE' )
270278
271279 with InTemporaryDirectory ():
272280 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 ))
274283 assert_true ((img2 .get_data () == data ).all ())
275284 assert_equal (img2 .header .matrix .get_index_map (0 ),
276285 img2 .header .matrix .get_index_map (1 ))
@@ -287,10 +296,12 @@ def test_ptseries():
287296 hdr = ci .Cifti2Header (matrix )
288297 data = np .random .randn (13 , 3 )
289298 img = ci .Cifti2Image (data , hdr )
299+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SERIES' )
290300
291301 with InTemporaryDirectory ():
292302 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 ))
294305 assert_true ((img2 .get_data () == data ).all ())
295306 check_series_map (img2 .header .matrix .get_index_map (0 ))
296307 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -306,10 +317,12 @@ def test_pscalar():
306317 hdr = ci .Cifti2Header (matrix )
307318 data = np .random .randn (2 , 3 )
308319 img = ci .Cifti2Image (data , hdr )
320+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SCALAR' )
309321
310322 with InTemporaryDirectory ():
311323 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 ))
313326 assert_true ((img2 .get_data () == data ).all ())
314327 check_scalar_map (img2 .header .matrix .get_index_map (0 ))
315328 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -325,10 +338,12 @@ def test_pdconn():
325338 hdr = ci .Cifti2Header (matrix )
326339 data = np .random .randn (2 , 3 )
327340 img = ci .Cifti2Image (data , hdr )
341+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_PARCELLATED' )
328342
329343 with InTemporaryDirectory ():
330344 ci .save (img , 'test.pdconn.nii' )
331345 img2 = ci .load ('test.pdconn.nii' )
346+ assert_true (isinstance (img2 , ci .Cifti2Image ))
332347 assert_true ((img2 .get_data () == data ).all ())
333348 check_geometry_map (img2 .header .matrix .get_index_map (0 ))
334349 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -344,10 +359,12 @@ def test_dpconn():
344359 hdr = ci .Cifti2Header (matrix )
345360 data = np .random .randn (2 , 3 )
346361 img = ci .Cifti2Image (data , hdr )
362+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_PARCELLATED' )
347363
348364 with InTemporaryDirectory ():
349365 ci .save (img , 'test.dpconn.nii' )
350366 img2 = ci .load ('test.dpconn.nii' )
367+ assert_true (isinstance (img2 , ci .Cifti2Image ))
351368 assert_true ((img2 .get_data () == data ).all ())
352369 check_parcel_map (img2 .header .matrix .get_index_map (0 ))
353370 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -367,6 +384,7 @@ def test_plabel():
367384 with InTemporaryDirectory ():
368385 ci .save (img , 'test.plabel.nii' )
369386 img2 = ci .load ('test.plabel.nii' )
387+ assert_true (isinstance (img2 , ci .Cifti2Image ))
370388 assert_true ((img2 .get_data () == data ).all ())
371389 check_label_map (img2 .header .matrix .get_index_map (0 ))
372390 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -380,10 +398,12 @@ def test_pconn():
380398 hdr = ci .Cifti2Header (matrix )
381399 data = np .random .randn (3 , 3 )
382400 img = ci .Cifti2Image (data , hdr )
401+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED' )
383402
384403 with InTemporaryDirectory ():
385404 ci .save (img , 'test.pconn.nii' )
386405 img2 = ci .load ('test.pconn.nii' )
406+ assert_true (isinstance (img2 , ci .Cifti2Image ))
387407 assert_true ((img2 .get_data () == data ).all ())
388408 assert_equal (img2 .header .matrix .get_index_map (0 ),
389409 img2 .header .matrix .get_index_map (1 ))
@@ -394,17 +414,19 @@ def test_pconn():
394414def test_pconnseries ():
395415 parcel_map = create_parcel_map ((0 , 1 ))
396416 series_map = create_series_map ((2 , ))
397-
398417 matrix = ci .Cifti2Matrix ()
399418 matrix .append (parcel_map )
400419 matrix .append (series_map )
401420 hdr = ci .Cifti2Header (matrix )
402421 data = np .random .randn (3 , 3 , 13 )
403422 img = ci .Cifti2Image (data , hdr )
423+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
424+ 'PARCELLATED_SERIES' )
404425
405426 with InTemporaryDirectory ():
406427 ci .save (img , 'test.pconnseries.nii' )
407428 img2 = ci .load ('test.pconnseries.nii' )
429+ assert_true (isinstance (img2 , ci .Cifti2Image ))
408430 assert_true ((img2 .get_data () == data ).all ())
409431 assert_equal (img2 .header .matrix .get_index_map (0 ),
410432 img2 .header .matrix .get_index_map (1 ))
@@ -416,17 +438,19 @@ def test_pconnseries():
416438def test_pconnscalar ():
417439 parcel_map = create_parcel_map ((0 , 1 ))
418440 scalar_map = create_scalar_map ((2 , ))
419-
420441 matrix = ci .Cifti2Matrix ()
421442 matrix .append (parcel_map )
422443 matrix .append (scalar_map )
423444 hdr = ci .Cifti2Header (matrix )
424445 data = np .random .randn (3 , 3 , 13 )
425446 img = ci .Cifti2Image (data , hdr )
447+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
448+ 'PARCELLATED_SCALAR' )
426449
427450 with InTemporaryDirectory ():
428451 ci .save (img , 'test.pconnscalar.nii' )
429452 img2 = ci .load ('test.pconnscalar.nii' )
453+ assert_true (isinstance (img2 , ci .Cifti2Image ))
430454 assert_true ((img2 .get_data () == data ).all ())
431455 assert_equal (img2 .header .matrix .get_index_map (0 ),
432456 img2 .header .matrix .get_index_map (1 ))
0 commit comments