Skip to content

Commit bc3535a

Browse files
committed
ENH: Add to/from_bytes interface to GiftiImage
1 parent 7a98e16 commit bc3535a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

nibabel/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from .minc1 import Minc1Image
5353
from .minc2 import Minc2Image
5454
from .cifti2 import Cifti2Header, Cifti2Image
55+
from .gifti import GiftiImage
5556
# Deprecated backwards compatiblity for MINC1
5657
from .deprecated import ModuleProxy as _ModuleProxy
5758
minc = _ModuleProxy('nibabel.minc')

nibabel/gifti/gifti.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import numpy as np
1919

2020
from .. import xmlutils as xml
21-
from ..filebasedimages import FileBasedImage
21+
from ..filebasedimages import SerializableImage
2222
from ..nifti1 import data_type_codes, xform_codes, intent_codes
2323
from .util import (array_index_order_codes, gifti_encoding_codes,
2424
gifti_endian_codes, KIND2FMT)
@@ -534,7 +534,7 @@ def metadata(self):
534534
return self.meta.metadata
535535

536536

537-
class GiftiImage(xml.XmlSerializable, FileBasedImage):
537+
class GiftiImage(xml.XmlSerializable, SerializableImage):
538538
""" GIFTI image object
539539
540540
The Gifti spec suggests using the following suffixes to your
@@ -724,6 +724,9 @@ def to_xml(self, enc='utf-8'):
724724
<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">
725725
""" + xml.XmlSerializable.to_xml(self, enc)
726726

727+
# Avoid the indirection of going through to_file_map
728+
to_bytes = to_xml
729+
727730
def to_file_map(self, file_map=None):
728731
""" Save the current image to the specified file_map
729732

nibabel/tests/test_image_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
from .. import (AnalyzeImage, Spm99AnalyzeImage, Spm2AnalyzeImage,
4040
Nifti1Pair, Nifti1Image, Nifti2Pair, Nifti2Image,
41+
GiftiImage,
4142
MGHImage, Minc1Image, Minc2Image, is_proxy)
4243
from ..spatialimages import SpatialImage
4344
from .. import minc1, minc2, parrec, brikhead
@@ -689,6 +690,12 @@ class TestMGHAPI(ImageHeaderAPI, SerializeMixin):
689690
standard_extension = '.mgh'
690691

691692

693+
class TestGiftiAPI(LoadImageAPI, SerializeMixin):
694+
klass = image_maker = GiftiImage
695+
can_save = True
696+
standard_extension = '.gii'
697+
698+
692699
class TestAFNIAPI(LoadImageAPI):
693700
loader = brikhead.load
694701
klass = image_maker = brikhead.AFNIImage

0 commit comments

Comments
 (0)