#NEWLINE# def gii_cut( fname , subject , hemi ) : #NEWLINE# #INDENT# '\n    Add gifti surface to blender\n    ' #NEWLINE# from .. database import db #NEWLINE# hemis = dict ( lh = 'left' , rh = 'right' ) #NEWLINE# ( wpts , polys ) = db . get_surf ( subject , 'wm' , hemi ) #NEWLINE# ( ipts , _ ) = db . get_surf ( subject , 'very_inflated' , hemi ) #NEWLINE# curvature = db . getSurfInfo ( subject , 'curvature' ) #NEWLINE# rcurv = curvature . __getattribute__ ( hemis [ hemi ] ) #NEWLINE# p = xdrlib . Packer ( ) #NEWLINE# p . pack_array ( wpts . ravel ( ) , p . pack_double ) #NEWLINE# p . pack_array ( ipts . ravel ( ) , p . pack_double ) #NEWLINE# p . pack_array ( polys . ravel ( ) , p . pack_uint ) #NEWLINE# p . pack_array ( rcurv . ravel ( ) , p . pack_double ) #NEWLINE# with tempfile . NamedTemporaryFile ( ) as tf : #NEWLINE# #INDENT# tf . write ( p . get_buffer ( ) ) #NEWLINE# tf . flush ( ) #NEWLINE# code = "with open('{tfname}', 'rb') as fp:\n            u = xdrlib.Unpacker(fp.read())\n            wpts = u.unpack_array(u.unpack_double)\n            ipts = u.unpack_array(u.unpack_double)\n            polys = u.unpack_array(u.unpack_uint)\n            curv = u.unpack_array(u.unpack_double)\n            blendlib.init_subject(wpts, ipts, polys, curv)\n        " . format ( tfname = tf . name ) #NEWLINE# _call_blender ( fname , code )