#NEWLINE# def save( self , path , method = 'mg2' , disp_layers = [ 'rois' ] , extra_disp = None , **kwargs ) : #NEWLINE# #INDENT# 'Save CTM file for static html display. \n\n        Parameters\n        ----------\n        path : string filepath\n        method : idkwtf\n        disp_layers : tuple|list\n            list of strings; names of layers from rois.svg to show\n        extra_disp : tuple\n            (svgfile,[layers]) - tuple of (external display .svg filename, [list_of,layers_in_file,to_display])\n        ' #NEWLINE# ctmname = ( path + '.ctm' ) #NEWLINE# svgname = ( path + '.svg' ) #NEWLINE# jsname = ( path + '.json' ) #NEWLINE# ( ( lpts , _ , _ ) , lbin ) = self . left . save ( method = method , ** kwargs ) #NEWLINE# ( ( rpts , _ , _ ) , rbin ) = self . right . save ( method = method , ** kwargs ) #NEWLINE# offsets = [ 0 ] #NEWLINE# with open ( ( path + '.ctm' ) , 'w' ) as fp : #NEWLINE# #INDENT# fp . write ( lbin ) #NEWLINE# offsets . append ( fp . tell ( ) ) #NEWLINE# fp . write ( rbin ) #NEWLINE# #UNINDENT# jsdict = dict ( rois = os . path . split ( svgname ) [ 1 ] , data = os . path . split ( ctmname ) [ 1 ] , names = self . types , materials = [ ] , offsets = offsets ) #NEWLINE# if ( self . flatlims is not None ) : #NEWLINE# #INDENT# jsdict [ 'flatlims' ] = self . flatlims #NEWLINE# #UNINDENT# json . dump ( jsdict , open ( jsname , 'w' ) ) #NEWLINE# if ( method != 'raw' ) : #NEWLINE# #INDENT# ( ptmap , inverse ) = ( [ ] , [ ] ) #NEWLINE# for ( hemi , pts ) in zip ( [ self . left , self . right ] , [ lpts , rpts ] ) : #NEWLINE# #INDENT# kdt = cKDTree ( hemi . pts ) #NEWLINE# ( diff , idx ) = kdt . query ( pts ) #NEWLINE# ptmap . append ( idx ) #NEWLINE# inverse . append ( idx . argsort ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ptmap = inverse = ( np . arange ( len ( self . left . ctm ) ) , np . arange ( len ( self . right . ctm ) ) ) #NEWLINE# #UNINDENT# if ( eroipack . left . flat is not None ) : #NEWLINE# #INDENT# flatpts = np . vstack ( [ self . left . flat , self . right . flat ] ) #NEWLINE# roipack = db . get_overlay ( self . subject , pts = flatpts , otype = disp_layers ) #NEWLINE# if ( not ( extra_disp is None ) ) : #NEWLINE# #INDENT# ( esvgfile , elayerlist ) = extra_disp #NEWLINE# eroipack = db . get_overlay ( self . subject , pts = flatpts , otype = 'external' , svgfile = esvgfile , layer = elayerlist ) #NEWLINE# roipack = ( roipack + eroipack ) #NEWLINE# #UNINDENT# layers = roipack . setup_labels ( ) #NEWLINE# if ( not isinstance ( layers , ( tuple , list ) ) ) : #NEWLINE# #INDENT# layers = ( layers , ) #NEWLINE# #UNINDENT# with open ( svgname , 'w' ) as fp : #NEWLINE# #INDENT# for layer in layers : #NEWLINE# #INDENT# for element in layer . findall ( './/{http://www.w3.org/2000/svg}text' ) : #NEWLINE# #INDENT# idx = int ( element . attrib [ 'data-ptidx' ] ) #NEWLINE# if ( idx < len ( inverse [ 0 ] ) ) : #NEWLINE# #INDENT# idx = inverse [ 0 ] [ idx ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# idx -= len ( inverse [ 0 ] ) #NEWLINE# idx = ( inverse [ 1 ] [ idx ] + len ( inverse [ 0 ] ) ) #NEWLINE# #UNINDENT# element . attrib [ 'data-ptidx' ] = str ( idx ) #NEWLINE# #UNINDENT# #UNINDENT# fp . write ( roipack . toxml ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ptmap