@@ -38,7 +38,12 @@ def from_dict(klass, data_dict):
38
38
meda .data .append (nv )
39
39
return meda
40
40
41
+ @np .deprecate_with_doc ("Use the metadata property instead." )
41
42
def get_metadata (self ):
43
+ return self .metadata
44
+
45
+ @property
46
+ def metadata (self ):
42
47
""" Returns metadata as dictionary """
43
48
self .data_as_dict = {}
44
49
for ele in self .data :
@@ -59,7 +64,7 @@ def to_xml(self):
59
64
return res
60
65
61
66
def print_summary (self ):
62
- print (self .get_metadata () )
67
+ print (self .metadata )
63
68
64
69
65
70
class GiftiNVPairs (object ):
@@ -128,10 +133,27 @@ def __init__(self, key=0, label='', red=None, green=None, blue=None,
128
133
self .blue = blue
129
134
self .alpha = alpha
130
135
136
+ @np .deprecate_with_doc ("Use the rgba property instead." )
131
137
def get_rgba (self ):
138
+ return self .rgba
139
+
140
+ @property
141
+ def rgba (self ):
132
142
""" Returns RGBA as tuple """
133
143
return (self .red , self .green , self .blue , self .alpha )
134
144
145
+ @rgba .setter
146
+ def rgba (self , rgba ):
147
+ """ Set RGBA via tuple
148
+
149
+ Parameters
150
+ ----------
151
+ rgba : tuple (red, green, blue, alpha)
152
+
153
+ """
154
+ if len (rgba ) != 4 :
155
+ raise ValueError ('rgba must be length 4.' )
156
+ self .red , self .green , self .blue , self .alpha = rgba
135
157
136
158
def _arr2txt (arr , elem_fmt ):
137
159
arr = np .asarray (arr )
@@ -338,69 +360,67 @@ def print_summary(self):
338
360
print ('Coordinate System:' )
339
361
print (self .coordsys .print_summary ())
340
362
363
+ @np .deprecate_with_doc ("Use the metadata property instead." )
341
364
def get_metadata (self ):
365
+ return self .meta .metadata
366
+
367
+ @property
368
+ def metadata (self ):
342
369
""" Returns metadata as dictionary """
343
- return self .meta .get_metadata ()
370
+ return self .meta .metadata
344
371
345
372
346
373
class GiftiImage (object ):
347
-
348
- numDA = int
349
- version = str
350
- filename = str
351
-
352
374
def __init__ (self , meta = None , labeltable = None , darrays = None ,
353
375
version = "1.0" ):
354
376
if darrays is None :
355
377
darrays = []
356
- self .darrays = darrays
357
378
if meta is None :
358
- self .meta = GiftiMetaData ()
359
- else :
360
- self .meta = meta
379
+ meta = GiftiMetaData ()
361
380
if labeltable is None :
362
- self .labeltable = GiftiLabelTable ()
363
- else :
364
- self .labeltable = labeltable
365
- self .numDA = len (self .darrays )
381
+ labeltable = GiftiLabelTable ()
382
+
383
+ self ._labeltable = labeltable
384
+ self ._meta = meta
385
+
386
+ self .darrays = darrays
366
387
self .version = version
367
388
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 """
389
+ @property
390
+ def numDA (self ):
391
+ return len (self .darrays )
383
392
384
- def get_labeltable (self ):
385
- return self .labeltable
393
+ @property
394
+ def labeltable (self ):
395
+ return self ._labeltable
386
396
387
- def set_labeltable (self , labeltable ):
397
+ @labeltable .setter
398
+ def labeltable (self , labeltable ):
388
399
""" Set the labeltable for this GiftiImage
389
400
390
401
Parameters
391
402
----------
392
403
labeltable : GiftiLabelTable
393
404
394
405
"""
395
- if isinstance (labeltable , GiftiLabelTable ):
396
- self .labeltable = labeltable
397
- else :
398
- print ("Not a valid GiftiLabelTable instance" )
406
+ if not isinstance (labeltable , GiftiLabelTable ):
407
+ raise ValueError ("Not a valid GiftiLabelTable instance" )
408
+ self ._labeltable = labeltable
399
409
400
- def get_metadata (self ):
401
- return self .meta
410
+ @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
411
+ def set_labeltable (self , labeltable ):
412
+ self .labeltable = labeltable
402
413
403
- def set_metadata (self , meta ):
414
+ @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
415
+ def get_labeltable (self ):
416
+ return self .labeltable
417
+
418
+ @property
419
+ def meta (self ):
420
+ return self ._meta
421
+
422
+ @meta .setter
423
+ def meta (self , meta ):
404
424
""" Set the metadata for this GiftiImage
405
425
406
426
Parameters
@@ -411,12 +431,17 @@ def set_metadata(self, meta):
411
431
-------
412
432
None
413
433
"""
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" )
434
+ if not isinstance (meta , GiftiMetaData ):
435
+ raise ValueError ("Not a valid GiftiMetaData instance" )
436
+ self ._meta = meta
437
+
438
+ @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
439
+ def set_metadata (self , meta ):
440
+ self .meta = meta
441
+
442
+ @np .deprecate_with_doc ("Use the gifti_img.labeltable property instead." )
443
+ def get_meta (self ):
444
+ return self .meta
420
445
421
446
def add_gifti_data_array (self , dataarr ):
422
447
""" Adds a data array to the GiftiImage
@@ -427,22 +452,19 @@ def add_gifti_data_array(self, dataarr):
427
452
"""
428
453
if isinstance (dataarr , GiftiDataArray ):
429
454
self .darrays .append (dataarr )
430
- self .numDA += 1
431
455
else :
432
456
print ("dataarr paramater must be of tzpe GiftiDataArray" )
433
457
434
458
def remove_gifti_data_array (self , ith ):
435
459
""" Removes the ith data array element from the GiftiImage """
436
460
self .darrays .pop (ith )
437
- self .numDA -= 1
438
461
439
462
def remove_gifti_data_array_by_intent (self , intent ):
440
463
""" Removes all the data arrays with the given intent type """
441
464
intent2remove = intent_codes .code [intent ]
442
465
for dele in self .darrays :
443
466
if dele .intent == intent2remove :
444
467
self .darrays .remove (dele )
445
- self .numDA -= 1
446
468
447
469
def get_arrays_from_intent (self , intent ):
448
470
""" Returns a a list of GiftiDataArray elements matching
0 commit comments