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,14 @@ 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_equal (img2 .nifti_header .get_intent ()[0 ],
222+ 'ConnDenseSeries' )
223+ assert_true (isinstance (img2 , ci .Cifti2Image ))
219224 assert_true ((img2 .get_data () == data ).all ())
220225 check_series_map (img2 .header .matrix .get_index_map (0 ))
221226 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -231,10 +236,13 @@ def test_dscalar():
231236 hdr = ci .Cifti2Header (matrix )
232237 data = np .random .randn (2 , 9 )
233238 img = ci .Cifti2Image (data , hdr )
239+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_SCALARS' )
234240
235241 with InTemporaryDirectory ():
236242 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 ))
238246 assert_true ((img2 .get_data () == data ).all ())
239247 check_scalar_map (img2 .header .matrix .get_index_map (0 ))
240248 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -250,10 +258,13 @@ def test_dlabel():
250258 hdr = ci .Cifti2Header (matrix )
251259 data = np .random .randn (2 , 9 )
252260 img = ci .Cifti2Image (data , hdr )
261+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_LABELS' )
253262
254263 with InTemporaryDirectory ():
255264 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 ))
257268 assert_true ((img2 .get_data () == data ).all ())
258269 check_label_map (img2 .header .matrix .get_index_map (0 ))
259270 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -267,10 +278,13 @@ def test_dconn():
267278 hdr = ci .Cifti2Header (matrix )
268279 data = np .random .randn (9 , 9 )
269280 img = ci .Cifti2Image (data , hdr )
281+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE' )
270282
271283 with InTemporaryDirectory ():
272284 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 ))
274288 assert_true ((img2 .get_data () == data ).all ())
275289 assert_equal (img2 .header .matrix .get_index_map (0 ),
276290 img2 .header .matrix .get_index_map (1 ))
@@ -287,10 +301,13 @@ def test_ptseries():
287301 hdr = ci .Cifti2Header (matrix )
288302 data = np .random .randn (13 , 3 )
289303 img = ci .Cifti2Image (data , hdr )
304+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SERIES' )
290305
291306 with InTemporaryDirectory ():
292307 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 ))
294311 assert_true ((img2 .get_data () == data ).all ())
295312 check_series_map (img2 .header .matrix .get_index_map (0 ))
296313 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -306,10 +323,13 @@ def test_pscalar():
306323 hdr = ci .Cifti2Header (matrix )
307324 data = np .random .randn (2 , 3 )
308325 img = ci .Cifti2Image (data , hdr )
326+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_SCALAR' )
309327
310328 with InTemporaryDirectory ():
311329 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 ))
313333 assert_true ((img2 .get_data () == data ).all ())
314334 check_scalar_map (img2 .header .matrix .get_index_map (0 ))
315335 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -325,10 +345,13 @@ def test_pdconn():
325345 hdr = ci .Cifti2Header (matrix )
326346 data = np .random .randn (2 , 3 )
327347 img = ci .Cifti2Image (data , hdr )
348+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_DENSE' )
328349
329350 with InTemporaryDirectory ():
330351 ci .save (img , 'test.pdconn.nii' )
331352 img2 = ci .load ('test.pdconn.nii' )
353+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnParcelDense' )
354+ assert_true (isinstance (img2 , ci .Cifti2Image ))
332355 assert_true ((img2 .get_data () == data ).all ())
333356 check_geometry_map (img2 .header .matrix .get_index_map (0 ))
334357 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -344,10 +367,13 @@ def test_dpconn():
344367 hdr = ci .Cifti2Header (matrix )
345368 data = np .random .randn (2 , 3 )
346369 img = ci .Cifti2Image (data , hdr )
370+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_DENSE_PARCELLATED' )
347371
348372 with InTemporaryDirectory ():
349373 ci .save (img , 'test.dpconn.nii' )
350374 img2 = ci .load ('test.dpconn.nii' )
375+ assert_equal (img2 .nifti_header .get_intent ()[0 ], 'ConnDenseParcel' )
376+ assert_true (isinstance (img2 , ci .Cifti2Image ))
351377 assert_true ((img2 .get_data () == data ).all ())
352378 check_parcel_map (img2 .header .matrix .get_index_map (0 ))
353379 check_geometry_map (img2 .header .matrix .get_index_map (1 ))
@@ -367,6 +393,8 @@ def test_plabel():
367393 with InTemporaryDirectory ():
368394 ci .save (img , 'test.plabel.nii' )
369395 img2 = ci .load ('test.plabel.nii' )
396+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnUnknown' )
397+ assert_true (isinstance (img2 , ci .Cifti2Image ))
370398 assert_true ((img2 .get_data () == data ).all ())
371399 check_label_map (img2 .header .matrix .get_index_map (0 ))
372400 check_parcel_map (img2 .header .matrix .get_index_map (1 ))
@@ -380,10 +408,13 @@ def test_pconn():
380408 hdr = ci .Cifti2Header (matrix )
381409 data = np .random .randn (3 , 3 )
382410 img = ci .Cifti2Image (data , hdr )
411+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED' )
383412
384413 with InTemporaryDirectory ():
385414 ci .save (img , 'test.pconn.nii' )
386415 img2 = ci .load ('test.pconn.nii' )
416+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnParcels' )
417+ assert_true (isinstance (img2 , ci .Cifti2Image ))
387418 assert_true ((img2 .get_data () == data ).all ())
388419 assert_equal (img2 .header .matrix .get_index_map (0 ),
389420 img2 .header .matrix .get_index_map (1 ))
@@ -401,10 +432,14 @@ def test_pconnseries():
401432 hdr = ci .Cifti2Header (matrix )
402433 data = np .random .randn (3 , 3 , 13 )
403434 img = ci .Cifti2Image (data , hdr )
435+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
436+ 'PARCELLATED_SERIES' )
404437
405438 with InTemporaryDirectory ():
406439 ci .save (img , 'test.pconnseries.nii' )
407440 img2 = ci .load ('test.pconnseries.nii' )
441+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnPPSr' )
442+ assert_true (isinstance (img2 , ci .Cifti2Image ))
408443 assert_true ((img2 .get_data () == data ).all ())
409444 assert_equal (img2 .header .matrix .get_index_map (0 ),
410445 img2 .header .matrix .get_index_map (1 ))
@@ -423,10 +458,14 @@ def test_pconnscalar():
423458 hdr = ci .Cifti2Header (matrix )
424459 data = np .random .randn (3 , 3 , 13 )
425460 img = ci .Cifti2Image (data , hdr )
461+ img .nifti_header .set_intent ('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_'
462+ 'PARCELLATED_SCALAR' )
426463
427464 with InTemporaryDirectory ():
428465 ci .save (img , 'test.pconnscalar.nii' )
429466 img2 = ci .load ('test.pconnscalar.nii' )
467+ assert_equal (img .nifti_header .get_intent ()[0 ], 'ConnPPSc' )
468+ assert_true (isinstance (img2 , ci .Cifti2Image ))
430469 assert_true ((img2 .get_data () == data ).all ())
431470 assert_equal (img2 .header .matrix .get_index_map (0 ),
432471 img2 .header .matrix .get_index_map (1 ))
0 commit comments