Skip to content

Commit a6c3049

Browse files
committed
RF: Extract nifti header update from to_filename
1 parent 2eab490 commit a6c3049

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

nibabel/cifti2/cifti2.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,11 @@ def update_headers(self):
15261526
>>> img.nifti_header.get_data_shape() == (2, 3, 4)
15271527
True
15281528
"""
1529-
self._nifti_header.set_data_shape(self._dataobj.shape)
1529+
header = self._nifti_header
1530+
header.set_data_shape(self._dataobj.shape)
1531+
# if intent code is not set, default to unknown
1532+
if header.get_intent()[0] == 'none':
1533+
header.set_intent('NIFTI_INTENT_CONNECTIVITY_UNKNOWN')
15301534

15311535
def get_data_dtype(self):
15321536
return self._nifti_header.get_data_dtype()
@@ -1546,8 +1550,6 @@ def to_filename(self, filename, validate=True):
15461550
for the expected IndicesMaps attributes.
15471551
If validation fails, an error will be raised instead.
15481552
"""
1549-
nheader = self._nifti_header
1550-
# try to infer intent code based on filename suffix
15511553
if validate:
15521554
ext = _extract_cifti_extension(filename)
15531555
try:
@@ -1557,7 +1559,7 @@ def to_filename(self, filename, validate=True):
15571559
f"Validation failed: No information for extension {ext} available"
15581560
) from err
15591561
intent = CIFTI_CODES.niistring[ext]
1560-
nheader.set_intent(intent)
1562+
self._nifti_header.set_intent(intent)
15611563
# validate matrix indices
15621564
for idx, mtype in enumerate(CIFTI_CODES.map_types[ext]):
15631565
try:
@@ -1567,9 +1569,6 @@ def to_filename(self, filename, validate=True):
15671569
f"Validation failed: Cifti2Matrix index map {idx} does "
15681570
f"not match expected type {mtype}"
15691571
)
1570-
# if intent code is not set, default to unknown
1571-
if nheader.get_intent()[0] == 'none':
1572-
nheader.set_intent('NIFTI_INTENT_CONNECTIVITY_UNKNOWN')
15731572
super().to_filename(filename)
15741573

15751574

0 commit comments

Comments
 (0)