Skip to content

Commit 957f799

Browse files
author
Ben Cipollini
committed
Use gifti's to_file_map as XmlBasedImage's default implementation.
1 parent 20d8a38 commit 957f799

File tree

2 files changed

+43
-49
lines changed

2 files changed

+43
-49
lines changed

nibabel/gifti/gifti.py

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,33 @@ def metadata(self):
386386

387387

388388
class GiftiImage(xml.XmlBasedImage):
389+
"""
390+
The Gifti spec suggests using the following suffixes to your
391+
filename when saving each specific type of data:
392+
393+
.gii
394+
Generic GIFTI File
395+
.coord.gii
396+
Coordinates
397+
.func.gii
398+
Functional
399+
.label.gii
400+
Labels
401+
.rgba.gii
402+
RGB or RGBA
403+
.shape.gii
404+
Shape
405+
.surf.gii
406+
Surface
407+
.tensor.gii
408+
Tensors
409+
.time.gii
410+
Time Series
411+
.topo.gii
412+
Topology
413+
414+
The Gifti file is stored in endian convention of the current machine.
415+
"""
389416
valid_exts = ('.gii',)
390417
files_types = (('image', '.gii'),)
391418

@@ -550,51 +577,3 @@ def from_file_map(klass, file_map):
550577
from .parse_gifti_fast import parse_gifti_file
551578
return parse_gifti_file(
552579
fptr=file_map['image'].get_prepare_fileobj('rb'))
553-
554-
def to_file_map(self, file_map=None):
555-
""" Save the current image to the specified file_map
556-
557-
Parameters
558-
----------
559-
file_map : string
560-
561-
Returns
562-
-------
563-
None
564-
565-
Notes
566-
-----
567-
We write all files with utf-8 encoding, and specify this at the top of
568-
the XML file with the ``encoding`` attribute.
569-
570-
The Gifti spec suggests using the following suffixes to your
571-
filename when saving each specific type of data:
572-
573-
.gii
574-
Generic GIFTI File
575-
.coord.gii
576-
Coordinates
577-
.func.gii
578-
Functional
579-
.label.gii
580-
Labels
581-
.rgba.gii
582-
RGB or RGBA
583-
.shape.gii
584-
Shape
585-
.surf.gii
586-
Surface
587-
.tensor.gii
588-
Tensors
589-
.time.gii
590-
Time Series
591-
.topo.gii
592-
Topology
593-
594-
The Gifti file is stored in endian convention of the current machine.
595-
"""
596-
# Our giftis are always utf-8 encoded - see GiftiImage.to_xml
597-
if file_map is None:
598-
file_map = self.file_map
599-
f = file_map['image'].get_prepare_fileobj('wb')
600-
f.write(self.to_xml())

nibabel/xmlbasedimages.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,19 @@ class XmlBasedHeader(FileBasedHeader, XmlSerializable):
3232

3333

3434
class XmlBasedImage(FileBasedImage, XmlSerializable):
35-
pass
35+
36+
def to_file_map(self, file_map=None):
37+
""" Save the current image to the specified file_map
38+
39+
Parameters
40+
----------
41+
file_map : string
42+
43+
Returns
44+
-------
45+
None
46+
"""
47+
if file_map is None:
48+
file_map = self.file_map
49+
f = file_map['image'].get_prepare_fileobj('wb')
50+
f.write(self.to_xml())

0 commit comments

Comments
 (0)