File tree Expand file tree Collapse file tree 2 files changed +13
-18
lines changed Expand file tree Collapse file tree 2 files changed +13
-18
lines changed Original file line number Diff line number Diff line change @@ -473,26 +473,18 @@ def print_summary(self):
473
473
print 'DataArray %s:' % i
474
474
print da .print_summary ()
475
475
print '----end----'
476
-
476
+
477
477
def to_xml (self ):
478
-
478
+ """ Return XML corresponding to image content """
479
479
res = """<?xml version="1.0" encoding="UTF-8"?>
480
480
<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">
481
481
<GIFTI Version="%s" NumberOfDataArrays="%s">\n """ % (self .version , str (self .numDA ))
482
-
483
482
if not self .meta is None :
484
483
res += self .meta .to_xml ()
485
-
486
484
if not self .labeltable is None :
487
485
res += self .labeltable .to_xml ()
488
-
489
486
for dar in self .darrays :
490
487
res += dar .to_xml ()
491
-
492
488
res += "</GIFTI>"
493
-
494
489
return res
495
-
496
-
497
-
498
490
Original file line number Diff line number Diff line change 11
11
##############
12
12
13
13
import os
14
+ import codecs
14
15
15
16
from . import parse_gifti_fast as gfp
16
17
17
18
def read (filename ):
18
19
""" Load a Gifti image from a file
19
-
20
+
20
21
Parameters
21
22
----------
22
23
filename : string
23
24
The Gifti file to open, it has usually ending .gii
24
-
25
+
25
26
Returns
26
27
-------
27
28
img : GiftiImage
28
29
Returns a GiftiImage
29
-
30
30
"""
31
31
if not os .path .isfile (filename ):
32
32
raise IOError ("No such file or directory: '%s'" % filename )
@@ -42,13 +42,16 @@ def write(image, filename):
42
42
A GiftiImage instance to store
43
43
filename : string
44
44
Filename to store the Gifti file to
45
-
45
+
46
46
Returns
47
47
-------
48
48
None
49
-
49
+
50
50
Notes
51
51
-----
52
+ We write all files with utf-8 encoding, and specify this at the top of the
53
+ XML file with the ``encoding`` attribute.
54
+
52
55
The Gifti spec suggests using the following suffixes to your
53
56
filename when saving each specific type of data:
54
57
@@ -72,10 +75,10 @@ def write(image, filename):
72
75
Time Series
73
76
.topo.gii
74
77
Topology
75
-
78
+
76
79
The Gifti file is stored in endian convention of the current machine.
77
80
"""
78
- f = open (filename , 'wb' )
79
81
# Our giftis are always utf-8 encoded - see GiftiImage.to_xml
80
- f .write (image .to_xml ().encode ('utf-8' ))
82
+ f = codecs .open (filename , 'wb' , encoding = 'utf-8' )
83
+ f .write (image .to_xml ())
81
84
f .close ()
You can’t perform that action at this time.
0 commit comments