Create new gifti image with nibabel gifti class - how do I access meta data and data attributes?

Hi,

I am trying to write a python script that will write out a set of vertices as a new gifti image using the nibabel gifti class. I am running into problems with trying to access all of the various meta data and data array attributes (e.g., datatype, intent, key, rgba, label table, etc.).

I am still fairly new to python and very new to trying to use nibabel’s gifti class, so forgive me if what I am asking is obvious.

I am creating an empty gifti image object using this command:

S = nibabel.gifti.gifti.GiftiImage()

However, if I go to try and assign name/value pairs to the data attribute of the meta data:

S._meta.data.name = 'AnatomicalStructurePrimary'

I get the following error:

*** AttributeError: 'list' object has no attribute 'name'

When I check what attributes my new gifti image object has, I can see the first level attributes:

vars(S)
{'_header': <nibabel.filebasedimages.FileBasedHeader object at 0x122dc84e0>,
'extra': {}, 'file_map': {'image': <nibabel.fileholders.FileHolder object at 0x122dc8390>}, '_labeltable':
 <nibabel.gifti.gifti.GiftiLabelTable object at 0x122dc8320>,
 '_meta': <nibabel.gifti.gifti.GiftiMetaData object at 0x122dc83c8>, 'darrays': [], 'version': '1.0'}

but none of these appears to have any of the necessary sub-attributes (if you understand what I mean) created.

I have tried assigning the various attributes such as datatype this way:

nibabel.gifti.gifti.GiftiDataArray().datatype = 'NIFTI_TYPE_FLOAT32'

but this does not seem to be populating the datatype attribute to my original gifti image object ‘S’. I still get the same AttributeError if I try and now print out the datatype:

print(S.darrays.datatype)
*** AttributeError: 'list' object has no attribute 'datatype'

Any help would be much appreciated. Or if anyone can point just me towards some more documentation for nibabel’s gifti class with worked out examples (not sure if this exists?), that would work too.

Thanks in advance,

suzanne