Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add .content, .text and .json properties to NIfTI extensions #1336

Merged
merged 13 commits into from
Sep 23, 2024
Merged
2 changes: 1 addition & 1 deletion nibabel/cifti2/cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ def to_file_map(self, file_map=None, dtype=None):

self.update_headers()
header = self._nifti_header
extension = Cifti2Extension(content=self.header.to_xml())
extension = Cifti2Extension.from_bytes(self.header.to_xml())
header.extensions = Nifti1Extensions(
ext for ext in header.extensions if not isinstance(ext, Cifti2Extension)
)
Expand Down
12 changes: 4 additions & 8 deletions nibabel/cifti2/parse_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,15 @@
)


class Cifti2Extension(Nifti1Extension):
class Cifti2Extension(Nifti1Extension[Cifti2Header]):
code = 32

def __init__(self, code=None, content=None):
Nifti1Extension.__init__(self, code=code or self.code, content=content)

def _unmangle(self, value):
def _unmangle(self, value: bytes) -> Cifti2Header:
parser = Cifti2Parser()
parser.parse(string=value)
self._content = parser.header
return self._content
return parser.header

def _mangle(self, value):
def _mangle(self, value: Cifti2Header) -> bytes:
if not isinstance(value, Cifti2Header):
raise ValueError('Can only mangle a Cifti2Header.')
return value.to_xml()
Expand Down
Loading
Loading