Skip to content

Commit dffd0fb

Browse files
committed
fix: move cifti to check to top level function
- create property is_cifti - rename conversion function as_cifti
1 parent 9a092d5 commit dffd0fb

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

nibabel/loadsave.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ def load(filename):
3939
img : ``SpatialImage``
4040
Image of guessed type
4141
'''
42-
return guessed_image_type(filename).from_filename(filename)
42+
43+
img = guessed_image_type(filename).from_filename(filename)
44+
if isinstance(img, Nifti2Image):
45+
if img.is_cifti:
46+
return img.as_cifti()
47+
return img
4348

4449

4550
def guessed_image_type(filename):

nibabel/nifti2.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,17 @@ class Nifti2Pair(Nifti1Pair):
232232
class Nifti2Image(Nifti1Image):
233233
header_class = Nifti2Header
234234

235-
@classmethod
236-
def from_file_map(klass, file_map):
237-
img = super(Nifti2Image, klass).from_file_map(file_map)
238-
hdr = img.get_header()
235+
@property
236+
def is_cifti(self):
237+
hdr = self.get_header()
239238
intent_code = hdr.get_intent('code')[0]
240-
img.is_cifti = False
239+
cifti_header = False
241240
if intent_code >= 3000 and intent_code < 3100:
242-
img.is_cifti = True
243-
img = img.to_cifti()
244-
return img
241+
cifti_header = True
242+
return cifti_header
245243

246-
def to_cifti(self):
244+
def as_cifti(self):
245+
"""Convert NIFTI-2 file to CIFTI"""
247246
if not self.is_cifti:
248247
TypeError('Nifti2 image is not a CIFTI file')
249248
hdr = self.get_header()

0 commit comments

Comments
 (0)