@@ -29,7 +29,7 @@ class GiftiMetaData(xml.XmlSerializable):
29
29
the list self.data """
30
30
def __init__ (self , nvpair = None ):
31
31
self .data = []
32
- if not nvpair is None :
32
+ if nvpair is not None :
33
33
self .data .append (nvpair )
34
34
35
35
@classmethod
@@ -296,7 +296,7 @@ def from_array(klass,
296
296
cda .intent = intent_codes .code [intent ]
297
297
cda .encoding = gifti_encoding_codes .code [encoding ]
298
298
cda .endian = gifti_endian_codes .code [endian ]
299
- if not coordsys is None :
299
+ if coordsys is not None :
300
300
cda .coordsys = coordsys
301
301
cda .ind_ord = array_index_order_codes .code [ordering ]
302
302
cda .meta = GiftiMetaData .from_dict (meta )
@@ -371,7 +371,7 @@ def print_summary(self):
371
371
print ('Endian: ' , gifti_endian_codes .specs [self .endian ])
372
372
print ('ExternalFileName: ' , self .ext_fname )
373
373
print ('ExternalFileOffset: ' , self .ext_offset )
374
- if not self .coordsys is None :
374
+ if self .coordsys is not None :
375
375
print ('----' )
376
376
print ('Coordinate System:' )
377
377
print (self .coordsys .print_summary ())
@@ -386,14 +386,44 @@ def metadata(self):
386
386
return self .meta .metadata
387
387
388
388
389
- class GiftiImage (FileBasedImage , xml .XmlSerializable ):
389
+ class GiftiImage (xml .XmlSerializable , FileBasedImage ):
390
+ """
391
+ The Gifti spec suggests using the following suffixes to your
392
+ filename when saving each specific type of data:
393
+
394
+ .gii
395
+ Generic GIFTI File
396
+ .coord.gii
397
+ Coordinates
398
+ .func.gii
399
+ Functional
400
+ .label.gii
401
+ Labels
402
+ .rgba.gii
403
+ RGB or RGBA
404
+ .shape.gii
405
+ Shape
406
+ .surf.gii
407
+ Surface
408
+ .tensor.gii
409
+ Tensors
410
+ .time.gii
411
+ Time Series
412
+ .topo.gii
413
+ Topology
414
+
415
+ The Gifti file is stored in endian convention of the current machine.
416
+ """
390
417
valid_exts = ('.gii' ,)
391
418
files_types = (('image' , '.gii' ),)
392
419
393
420
def __init__ (self , header = None , extra = None , file_map = None , meta = None ,
394
421
labeltable = None , darrays = None , version = "1.0" ):
395
- FileBasedImage .__init__ (self , header = header , extra = extra ,
396
- file_map = file_map )
422
+ super (GiftiImage , self ).__init__ (header = header , extra = extra ,
423
+ file_map = file_map )
424
+ # placed here temporarily for git diff purposes
425
+ from .parse_gifti_fast import GiftiImageParser
426
+ GiftiImage .parser = GiftiImageParser
397
427
398
428
if darrays is None :
399
429
darrays = []
@@ -501,7 +531,7 @@ def getArraysFromIntent(self, intent):
501
531
502
532
def print_summary (self ):
503
533
print ('----start----' )
504
- print ('Source filename: ' , self .filename )
534
+ print ('Source filename: ' , self .get_filename () )
505
535
print ('Number of data arrays: ' , self .numDA )
506
536
print ('Version: ' , self .version )
507
537
if self .meta is not None :
@@ -536,22 +566,6 @@ def to_xml(self, enc='utf-8'):
536
566
<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">
537
567
""" + xml .XmlSerializable .to_xml (self , enc )
538
568
539
- @classmethod
540
- def from_file_map (klass , file_map ):
541
- """ Load a Gifti image from a file_map
542
-
543
- Parameters
544
- file_map : string
545
-
546
- Returns
547
- -------
548
- img : GiftiImage
549
- Returns a GiftiImage
550
- """
551
- from .parse_gifti_fast import parse_gifti_file
552
- return parse_gifti_file (
553
- fptr = file_map ['image' ].get_prepare_fileobj ('rb' ))
554
-
555
569
def to_file_map (self , file_map = None ):
556
570
""" Save the current image to the specified file_map
557
571
@@ -562,40 +576,31 @@ def to_file_map(self, file_map=None):
562
576
Returns
563
577
-------
564
578
None
565
-
566
- Notes
567
- -----
568
- We write all files with utf-8 encoding, and specify this at the top of
569
- the XML file with the ``encoding`` attribute.
570
-
571
- The Gifti spec suggests using the following suffixes to your
572
- filename when saving each specific type of data:
573
-
574
- .gii
575
- Generic GIFTI File
576
- .coord.gii
577
- Coordinates
578
- .func.gii
579
- Functional
580
- .label.gii
581
- Labels
582
- .rgba.gii
583
- RGB or RGBA
584
- .shape.gii
585
- Shape
586
- .surf.gii
587
- Surface
588
- .tensor.gii
589
- Tensors
590
- .time.gii
591
- Time Series
592
- .topo.gii
593
- Topology
594
-
595
- The Gifti file is stored in endian convention of the current machine.
596
579
"""
597
- # Our giftis are always utf-8 encoded - see GiftiImage.to_xml
598
580
if file_map is None :
599
581
file_map = self .file_map
600
582
f = file_map ['image' ].get_prepare_fileobj ('wb' )
601
583
f .write (self .to_xml ())
584
+
585
+ @classmethod
586
+ def from_file_map (klass , file_map , buffer_size = 35000000 ):
587
+ """ Load a Gifti image from a file_map
588
+
589
+ Parameters
590
+ file_map : string
591
+
592
+ Returns
593
+ -------
594
+ img : GiftiImage
595
+ Returns a GiftiImage
596
+ """
597
+ parser = klass .parser (buffer_size = buffer_size )
598
+ parser .parse (fptr = file_map ['image' ].get_prepare_fileobj ('rb' ))
599
+ img = parser .img
600
+ return img
601
+
602
+ @classmethod
603
+ def from_filename (klass , filename , buffer_size = 35000000 ):
604
+ file_map = klass .filespec_to_file_map (filename )
605
+ img = klass .from_file_map (file_map , buffer_size = buffer_size )
606
+ return img
0 commit comments