@@ -344,63 +344,48 @@ def get_metadata(self):
344
344
345
345
346
346
class GiftiImage (object ):
347
-
348
- numDA = int
349
- version = str
350
- filename = str
351
-
352
347
def __init__ (self , meta = None , labeltable = None , darrays = None ,
353
348
version = "1.0" ):
354
349
if darrays is None :
355
350
darrays = []
356
- self .darrays = darrays
357
351
if meta is None :
358
- self .meta = GiftiMetaData ()
359
- else :
360
- self .meta = meta
352
+ meta = GiftiMetaData ()
361
353
if labeltable is None :
362
- self .labeltable = GiftiLabelTable ()
363
- else :
364
- self .labeltable = labeltable
365
- self .numDA = len (self .darrays )
354
+ labeltable = GiftiLabelTable ()
355
+
356
+ self ._labeltable = labeltable
357
+ self ._meta = meta
358
+
359
+ self .darrays = darrays
366
360
self .version = version
367
361
368
- # @classmethod
369
- # def from_array(cls):
370
- # pass
371
- #def GiftiImage_fromarray(data, intent = GiftiIntentCode.NIFTI_INTENT_NONE, encoding=GiftiEncoding.GIFTI_ENCODING_B64GZ, endian = GiftiEndian.GIFTI_ENDIAN_LITTLE):
372
- # """ Returns a GiftiImage from a Numpy array with a given intent code and
373
- # encoding """
374
-
375
- # @classmethod
376
- # def from_vertices_and_triangles(cls):
377
- # pass
378
- # def from_vertices_and_triangles(cls, vertices, triangles, coordsys = None, \
379
- # encoding = GiftiEncoding.GIFTI_ENCODING_B64GZ,\
380
- # endian = GiftiEndian.GIFTI_ENDIAN_LITTLE):
381
- # """ Returns a GiftiImage from two numpy arrays representing the vertices
382
- # and the triangles. Additionally defining the coordinate system and encoding """
383
-
384
- def get_labeltable (self ):
385
- return self .labeltable
386
-
387
- def set_labeltable (self , labeltable ):
362
+ @property
363
+ def numDA (self ):
364
+ return len (self .darrays )
365
+
366
+ @property
367
+ def labeltable (self ):
368
+ return self ._labeltable
369
+
370
+ @labeltable .setter
371
+ def labeltable (self , labeltable ):
388
372
""" Set the labeltable for this GiftiImage
389
373
390
374
Parameters
391
375
----------
392
376
labeltable : GiftiLabelTable
393
377
394
378
"""
395
- if isinstance (labeltable , GiftiLabelTable ):
396
- self .labeltable = labeltable
397
- else :
398
- print ("Not a valid GiftiLabelTable instance" )
379
+ if not isinstance (labeltable , GiftiLabelTable ):
380
+ raise ValueError ("Not a valid GiftiLabelTable instance" )
381
+ self ._labeltable = labeltable
399
382
400
- def get_metadata (self ):
401
- return self .meta
383
+ @property
384
+ def meta (self ):
385
+ return self ._meta
402
386
403
- def set_metadata (self , meta ):
387
+ @meta .setter
388
+ def meta (self , meta ):
404
389
""" Set the metadata for this GiftiImage
405
390
406
391
Parameters
@@ -411,13 +396,10 @@ def set_metadata(self, meta):
411
396
-------
412
397
None
413
398
"""
414
- if isinstance (meta , GiftiMetaData ):
415
- self .meta = meta
416
- print ("New Metadata set. Be aware of changing "
417
- "coordinate transformation!" )
418
- else :
419
- print ("Not a valid GiftiMetaData instance" )
420
-
399
+ if not isinstance (meta , GiftiMetaData ):
400
+ raise ValueError ("Not a valid GiftiMetaData instance" )
401
+ self ._meta = meta
402
+
421
403
def add_gifti_data_array (self , dataarr ):
422
404
""" Adds a data array to the GiftiImage
423
405
@@ -427,22 +409,19 @@ def add_gifti_data_array(self, dataarr):
427
409
"""
428
410
if isinstance (dataarr , GiftiDataArray ):
429
411
self .darrays .append (dataarr )
430
- self .numDA += 1
431
412
else :
432
413
print ("dataarr paramater must be of tzpe GiftiDataArray" )
433
414
434
415
def remove_gifti_data_array (self , ith ):
435
416
""" Removes the ith data array element from the GiftiImage """
436
417
self .darrays .pop (ith )
437
- self .numDA -= 1
438
418
439
419
def remove_gifti_data_array_by_intent (self , intent ):
440
420
""" Removes all the data arrays with the given intent type """
441
421
intent2remove = intent_codes .code [intent ]
442
422
for dele in self .darrays :
443
423
if dele .intent == intent2remove :
444
424
self .darrays .remove (dele )
445
- self .numDA -= 1
446
425
447
426
def get_arrays_from_intent (self , intent ):
448
427
""" Returns a a list of GiftiDataArray elements matching
0 commit comments