Skip to content

Commit fc619c0

Browse files
committed
fix: use unknown CIFTI type, raise ValueError if incorrect intent code
1 parent 8d5d70d commit fc619c0

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,5 +1443,5 @@ def save(img, filename):
14431443
filename to which to save image
14441444
"""
14451445
if img.nifti_header.get_intent()[0] == 'none':
1446-
raise AttributeError("CIFTI image has an invalid intent code.")
1446+
raise ValueError("CIFTI image has an invalid intent code.")
14471447
Cifti2Image.instance_to_filename(img, filename)

nibabel/cifti2/tests/test_new_cifti2.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,25 @@ def test_dpconn():
371371
del img2
372372

373373

374-
# SKIP until intent code is specified
375-
# https://www.nitrc.org/forum/attachment.php?attachid=341&group_id=454&forum_id=1955
376-
# def test_plabel():
377-
# label_map = create_label_map((0, ))
378-
# parcel_map = create_parcel_map((1, ))
379-
# matrix = ci.Cifti2Matrix()
380-
# matrix.append(label_map)
381-
# matrix.append(parcel_map)
382-
# hdr = ci.Cifti2Header(matrix)
383-
# data = np.random.randn(2, 3)
384-
# img = ci.Cifti2Image(data, hdr)
385-
#
386-
# with InTemporaryDirectory():
387-
# ci.save(img, 'test.plabel.nii')
388-
# img2 = ci.load('test.plabel.nii')
389-
# assert_true(isinstance(img2, ci.Cifti2Image))
390-
# assert_true((img2.get_data() == data).all())
391-
# check_label_map(img2.header.matrix.get_index_map(0))
392-
# check_parcel_map(img2.header.matrix.get_index_map(1))
393-
# del img2
374+
def test_plabel():
375+
label_map = create_label_map((0, ))
376+
parcel_map = create_parcel_map((1, ))
377+
matrix = ci.Cifti2Matrix()
378+
matrix.append(label_map)
379+
matrix.append(parcel_map)
380+
hdr = ci.Cifti2Header(matrix)
381+
data = np.random.randn(2, 3)
382+
img = ci.Cifti2Image(data, hdr
383+
img.nifti_header.set_intent('NIFTI_INTENT_CONNECTIVITY_UNKNOWN')
384+
385+
with InTemporaryDirectory():
386+
ci.save(img, 'test.plabel.nii')
387+
img2 = ci.load('test.plabel.nii')
388+
assert_true(isinstance(img2, ci.Cifti2Image))
389+
assert_true((img2.get_data() == data).all())
390+
check_label_map(img2.header.matrix.get_index_map(0))
391+
check_parcel_map(img2.header.matrix.get_index_map(1))
392+
del img2
394393

395394

396395
def test_pconn():

0 commit comments

Comments
 (0)