Skip to content

Commit 2a0badb

Browse files
committed
ENH: Add bytestring serialization to CIFTI-2
1 parent 6547fbe commit 2a0badb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

nibabel/cifti2/cifti2.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
from collections.abc import MutableSequence, MutableMapping, Iterable
2121
from collections import OrderedDict
2222
from .. import xmlutils as xml
23-
from ..filebasedimages import FileBasedHeader
23+
from ..filebasedimages import FileBasedHeader, SerializableImage
2424
from ..dataobj_images import DataobjImage
25+
from ..nifti1 import Nifti1Extensions
2526
from ..nifti2 import Nifti2Image, Nifti2Header
2627
from ..arrayproxy import reshape_dataobj
2728
from warnings import warn
@@ -1255,6 +1256,9 @@ def _to_xml_element(self):
12551256
cifti.append(mat_xml)
12561257
return cifti
12571258

1259+
def __eq__(self, other):
1260+
return self.to_xml() == other.to_xml()
1261+
12581262
@classmethod
12591263
def may_contain_header(klass, binaryblock):
12601264
from .parse_cifti2 import _Cifti2AsNiftiHeader
@@ -1326,7 +1330,7 @@ def from_axes(cls, axes):
13261330
return cifti2_axes.to_header(axes)
13271331

13281332

1329-
class Cifti2Image(DataobjImage):
1333+
class Cifti2Image(DataobjImage, SerializableImage):
13301334
""" Class for single file CIFTI-2 format image
13311335
"""
13321336
header_class = Cifti2Header
@@ -1454,6 +1458,9 @@ def to_file_map(self, file_map=None):
14541458
self.update_headers()
14551459
header = self._nifti_header
14561460
extension = Cifti2Extension(content=self.header.to_xml())
1461+
header.extensions = Nifti1Extensions(
1462+
ext for ext in header.extensions if not isinstance(ext, Cifti2Extension)
1463+
)
14571464
header.extensions.append(extension)
14581465
if self._dataobj.shape != self.header.matrix.get_data_shape():
14591466
raise ValueError(

0 commit comments

Comments
 (0)