Skip to content

Commit 8d5d70d

Browse files
committed
fix: do not allow saving of images without intent
1 parent b560da6 commit 8d5d70d

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,4 +1442,6 @@ def save(img, filename):
14421442
filename : str
14431443
filename to which to save image
14441444
"""
1445+
if img.nifti_header.get_intent()[0] == 'none':
1446+
raise AttributeError("CIFTI image has an invalid intent code.")
14451447
Cifti2Image.instance_to_filename(img, filename)

nibabel/cifti2/tests/test_new_cifti2.py

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

373373

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-
384-
with InTemporaryDirectory():
385-
ci.save(img, 'test.plabel.nii')
386-
img2 = ci.load('test.plabel.nii')
387-
assert_true(isinstance(img2, ci.Cifti2Image))
388-
assert_true((img2.get_data() == data).all())
389-
check_label_map(img2.header.matrix.get_index_map(0))
390-
check_parcel_map(img2.header.matrix.get_index_map(1))
391-
del img2
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
392394

393395

394396
def test_pconn():

0 commit comments

Comments
 (0)