@@ -38,7 +38,12 @@ def from_dict(klass, data_dict):
3838 meda .data .append (nv )
3939 return meda
4040
41+ @np .deprecate_with_doc ("Use the metadata property instead." )
4142 def get_metadata (self ):
43+ return self .metadata
44+
45+ @property
46+ def metadata (self ):
4247 """ Returns metadata as dictionary """
4348 self .data_as_dict = {}
4449 for ele in self .data :
@@ -59,7 +64,7 @@ def to_xml(self):
5964 return res
6065
6166 def print_summary (self ):
62- print (self .get_metadata () )
67+ print (self .metadata )
6368
6469
6570class GiftiNVPairs (object ):
@@ -128,10 +133,27 @@ def __init__(self, key=0, label='', red=None, green=None, blue=None,
128133 self .blue = blue
129134 self .alpha = alpha
130135
136+ @np .deprecate_with_doc ("Use the rgba property instead." )
131137 def get_rgba (self ):
138+ return self .rgba
139+
140+ @property
141+ def rgba (self ):
132142 """ Returns RGBA as tuple """
133143 return (self .red , self .green , self .blue , self .alpha )
134144
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
135157
136158def _arr2txt (arr , elem_fmt ):
137159 arr = np .asarray (arr )
@@ -338,69 +360,67 @@ def print_summary(self):
338360 print ('Coordinate System:' )
339361 print (self .coordsys .print_summary ())
340362
363+ @np .deprecate_with_doc ("Use the metadata property instead." )
341364 def get_metadata (self ):
365+ return self .meta .metadata
366+
367+ @property
368+ def metadata (self ):
342369 """ Returns metadata as dictionary """
343- return self .meta .get_metadata ()
370+ return self .meta .metadata
344371
345372
346373class GiftiImage (object ):
347-
348- numDA = int
349- version = str
350- filename = str
351-
352374 def __init__ (self , meta = None , labeltable = None , darrays = None ,
353375 version = "1.0" ):
354376 if darrays is None :
355377 darrays = []
356- self .darrays = darrays
357378 if meta is None :
358- self .meta = GiftiMetaData ()
359- else :
360- self .meta = meta
379+ meta = GiftiMetaData ()
361380 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
366387 self .version = version
367388
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 )
383392
384- def get_labeltable (self ):
385- return self .labeltable
393+ @property
394+ def labeltable (self ):
395+ return self ._labeltable
386396
387- def set_labeltable (self , labeltable ):
397+ @labeltable .setter
398+ def labeltable (self , labeltable ):
388399 """ Set the labeltable for this GiftiImage
389400
390401 Parameters
391402 ----------
392403 labeltable : GiftiLabelTable
393404
394405 """
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
399409
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
402413
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 ):
404424 """ Set the metadata for this GiftiImage
405425
406426 Parameters
@@ -411,12 +431,17 @@ def set_metadata(self, meta):
411431 -------
412432 None
413433 """
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
420445
421446 def add_gifti_data_array (self , dataarr ):
422447 """ Adds a data array to the GiftiImage
@@ -427,22 +452,19 @@ def add_gifti_data_array(self, dataarr):
427452 """
428453 if isinstance (dataarr , GiftiDataArray ):
429454 self .darrays .append (dataarr )
430- self .numDA += 1
431455 else :
432456 print ("dataarr paramater must be of tzpe GiftiDataArray" )
433457
434458 def remove_gifti_data_array (self , ith ):
435459 """ Removes the ith data array element from the GiftiImage """
436460 self .darrays .pop (ith )
437- self .numDA -= 1
438461
439462 def remove_gifti_data_array_by_intent (self , intent ):
440463 """ Removes all the data arrays with the given intent type """
441464 intent2remove = intent_codes .code [intent ]
442465 for dele in self .darrays :
443466 if dele .intent == intent2remove :
444467 self .darrays .remove (dele )
445- self .numDA -= 1
446468
447469 def get_arrays_from_intent (self , intent ):
448470 """ Returns a a list of GiftiDataArray elements matching
0 commit comments