def test(): import vcs import cdms2 as cdms import os import support # import vcs and cdms bg = support.bg f = cdms.open(os.path.join(vcs.sample_data, 'clt.nc')) # open clt file u = f('u') # get slab u x = vcs.init() # construct vcs canvas x.plot(u, 'default', 'yxvsx', 'ASD7', bg=bg) # plot slab the old way support.check_plot(x) if support.dogui: x.geometry(450, 337, 100, 0) # change the geometry and location x.flush() support.check_plot(x) a = x.getyxvsx('ASD7') # get 'ASD7' yxvsx # test object 'a' for graphics method if not vcs.isgraphicsmethod(a): raise Exception("Error not a gm") else: if not vcs.isyxvsx(a): # test object 'a' if yxvsx raise Exception("Error wrong type of gm") # save 'ASD7' yxvsx as a Python script a.script('test', 'w') a.xticlabels('', '') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) ########################################################################## # Change the yxvsx line # ########################################################################## a.line = 0 # same as 'solid' support.check_plot(x) a.line = 1 # same as 'dash' support.check_plot(x) a.line = 2 # same as 'dot' support.check_plot(x) a.line = 3 # same as 'dash-dot' support.check_plot(x) a.line = 4 # same as 'long-dash' support.check_plot(x) if '--extended' not in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ########################################################################## # Change the yxvsx line color # ########################################################################## a.linecolor = (77) support.check_plot(x) a.linecolor = 16 support.check_plot(x) a.linecolor = 44 # same as a.color=(44) support.check_plot(x) a.linecolor = None support.check_plot(x) ########################################################################## # Change the yxvsx marker # ########################################################################## a.marker = 1 # Same as a.marker='dot' support.check_plot(x) a.marker = 2 # Same as a.marker='plus' support.check_plot(x) a.marker = 3 # Same as a.marker='star' support.check_plot(x) a.marker = 4 # Same as a.marker='circle' support.check_plot(x) a.marker = 5 # Same as a.marker='cross' support.check_plot(x) a.marker = 6 # Same as a.marker='diamond' support.check_plot(x) a.marker = 7 # Same as a.marker='triangle_up' support.check_plot(x) a.marker = 8 # Same as a.marker='triangle_down' support.check_plot(x) a.marker = 9 # Same as a.marker='triangle_left' support.check_plot(x) a.marker = 10 # Same as a.marker='triangle_right' support.check_plot(x) a.marker = 11 # Same as a.marker='square' support.check_plot(x) a.marker = 12 # Same as a.marker='diamond_fill' support.check_plot(x) a.marker = 13 # Same as a.marker='triangle_up_fill' support.check_plot(x) # Same as a.marker='triangle_down_fill' a.marker = 14 support.check_plot(x) # Same as a.marker='triangle_left_fill' a.marker = 15 support.check_plot(x) # Same as a.marker='triangle_right_fill' a.marker = 16 support.check_plot(x) a.marker = 17 # Same as a.marker='square_fill' support.check_plot(x) a.marker = None # Draw no markers support.check_plot(x) ########################################################################## # Change the yxvsx marker color # ########################################################################## a.marker = 'dot' support.check_plot(x) a.markercolor = 16 support.check_plot(x) a.markercolor = 44 # same as a.markercolor=(44) support.check_plot(x) a.markercolor = None support.check_plot(x) ########################################################################## # Change the yxvsx marker size # ########################################################################## a.markersize = 5 support.check_plot(x) a.markersize = 55 support.check_plot(x) a.markersize = 10 support.check_plot(x) a.markersize = 100 support.check_plot(x) a.markersize = 300 support.check_plot(x) a.markersize = None support.check_plot(x) x.clear() # clear the VCS Canvas x.yxvsx(u, a, 'default', bg=bg) # plot yxvsx using 'default' template support.check_plot(x) # show the list of templates # create template 'test' from 'default' template t = x.createtemplate('test') # test whether 't' is a template or not if not vcs.istemplate(t): raise Exception("Error creating tmeplate") x.clear() # clear the VCS Canvas # plot yxvsx template 't', outline 'a', and arrays 'u':'v' x.plot(t, a, u, bg=bg) support.check_plot(x) x.clear() # clear the VCS Canvas # plot using outline 'a', array 'u':'v', and template 't' x.yxvsx(a, u, t, bg=bg) support.check_plot(x) # show the list of line secondary objects l = x.getline('red') # get line 'red' # check to see if it is a secondary object if not vcs.issecondaryobject(l): raise Exception("Error did not get line") else: if not vcs.isline(l): # check to see if it is a line raise Exception("Error object created is not line") ########################################################################### # Use the create line object 'm' from above and modify the line object # ########################################################################### a.line = l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type = 'dot' # change the line type support.check_plot(x) l.width = 4 # change the line size support.check_plot(x) # show the list of marker secondary objects m = x.getmarker('red') # get marker 'red' # check to see if it is a secondary object if not vcs.issecondaryobject(m): raise Exception("Error did not get marker") else: # check to see if it is a line if not vcs.ismarker(m): raise Exception("Error object created is not marker") ########################################################################### # Use the create marker object 'm' from above and modify the line object # ########################################################################### a.marker = m # use the marker object support.check_plot(x) m.color = 44 # change the marker color support.check_plot(x) m.type = 'square' # change the marker type support.check_plot(x) m.size = 20 # change the marker size support.check_plot(x) a = x.listelements('yxvsx') # show list of xyvsy r = x.createyxvsx('test2', 'ASD1') # create xyvsy 'test2' a2 = x.listelements('yxvsx') # show list of xyvsy if a2 == a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('yxvsx') # show list of xyvsy if a3 != a: raise "error gm not removed" ########################################################################## # to see how x.update and x.mode work, see testoutline.py # ########################################################################## # x.update() # x.mode=1 # x.mode=0 print '*************************************************************************************' print '****** ******' print '****** Y x v s x T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cdms bg=support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) s=f('clt') # get slab clt x=vcs.init() # construct vcs canvas x.plot(s,'default','boxfill','quick',bg=bg)# plot slab the old way #support.check_plot(x) if bg==0: x.geometry(450,337) # change the geometry x.flush() #support.check_plot(x) a=x.getboxfill('quick') # get 'quick' boxfill graphics method if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isboxfill(a): # check for boxfill raise Exception, "Error gm is not right type" # Change boxfill's legend a.legend={0:'Great',20:'Outstanding',40:'Wonderful',60:'Happy',80:'Exciting!',100:'Best'} support.check_plot(x) a.legend={0:'100',20:'80',40:'60',60:'40',80:'20',100:'0'} support.check_plot(x) a.legend={0:'Blue',20:'Green',40:'Yellow',60:'Red',80:'Burgundy',100:'Magenta'} support.check_plot(x) a.legend=(90) support.check_plot(x) a.legend=[10,90] support.check_plot(x) a.legend=(1.5,45.8,89.7) support.check_plot(x) a.legend=None support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() a.color_1=50 # change color_1 index attribute support.check_plot(x) a.xticlabels('lon30','lon30') # change xlabels attribute support.check_plot(x) a.xticlabels('','') # change remove xlables from plot support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change region support.check_plot(x) a.datawc(1e20,1e20,1e20,1e20) # change region back support.check_plot(x) a.xticlabels('*') # change attribute labels back support.check_plot(x) x.mode=0 # turn atomatic update off a.color_1=100 # change color_1 attribute a.color_2=200 # change color_2 index value a.xticlabels('lon30','lon30') # change attribute a.yticlabels('','') # change y-labels off attribute a.datawc(-45.0, 45.0, -90.0, 90.0) # change region support.check_plot(x) x.update() # view changes now support.check_plot(x) # Test log10 boxfill plot x.clear() # clear the VCS Canvas a.boxfill_type = 'log10' # Change the Boxfill type to log10 a.datawc(1e20,1e20,1e20,1e20) # change region a.level_1=1e20 # change level_1 a.level_2=1e20 # change level_2 a.color_1=16 # change color_1 attribute a.color_2=239 # change color_2 index value x.boxfill(s,a,bg=bg) # plot using default template support.check_plot(x) # Test custom boxfill plot x.clear() # clear the VCS Canvas a.boxfill_type = 'custom' # Change the Boxfill type to custom a.levels=(0,20,35,40,75,100) # Set the custom ranges a.fillareacolors=(16,25,38,55,100,166) # Set the color indices x.boxfill(s,a,bg=bg) # plot using default template support.check_plot(x) # Test legend with fillareacolors boxfill plot x.clear() # clear the VCS Canvas a.boxfill_type = 'linear' # Change the Boxfill type back to linear a.fillareacolors=(254,) # Set the color indices a.level_1=0 # change level_1 a.level_2=0 # change level_2 x.boxfill(s,a,bg=bg) # plot using default template support.check_plot(x) a.script('test','w') # save 'quick' boxfill as a Python script x.mode=1 # turn atomatic update mode back on a.color_1=16 # change color_1 attribute support.check_plot(x) a.color_2=239 # change color_2 index value support.check_plot(x) a.level_1=20 # change level_1 support.check_plot(x) a.level_2=80 # change level_2 support.check_plot(x) a.datawc(1e20,1e20,1e20,1e20) # change region back support.check_plot(x) a.yticlabels('*') # change y-labels attribute support.check_plot(x) x.scriptobject(a,'test', 'a') # append 'quick' to the existing file a.script('test.scr','w') # save 'quick' as a VCS script file objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" x.clear() # clear the VCS Canvas x.boxfill(s,a,'default',bg=bg) # plot using default template support.check_plot(x) x.clear() # clear the VCS Canvas x.boxfill(a,'default',s,bg=bg) # plot using default template, but, reverse the order support.check_plot(x) x.clear() # clear the VCS Canvas x.boxfill(s,a,t,bg=bg) # plot using template 'test' support.check_plot(x) x.clear() # clear the VCS Canvas x.boxfill(a,s,t,bg=bg) # plot using template 'test', but reverse the objects support.check_plot(x) x.clear() # clear the VCS Canvas x.boxfill(t,a,s,bg=bg) # plot using template 'test', but reverse the objects support.check_plot(x) x.clear() # clear the VCS Canvas x.plot(t,a,s,bg=bg) # plot using the new way support.check_plot(x) x.clear() # clear the VCS Canvas x.plot(a,t,s,bg=bg) # plot using the new way support.check_plot(x) x.clear() # clear the VCS Canvas x.plot(s,t,a,bg=bg) # plot using the new way support.check_plot(x) x.clear() # clear the VCS Canvas x.plot('default',a,s,bg=bg) # plot using the new way support.check_plot(x) x.clear() # clear the VCS Canvas x.plot('default',s,bg=bg) # plot using the new way support.check_plot(x) a = x.listelements('boxfill') # show list of xyvsy r=x.createboxfill('test2','quick') # create xyvsy 'test2' a2 = x.listelements('boxfill') # show list of xyvsy if a2==a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('boxfill') # show list of xyvsy if a3!=a: raise "error gm not removed" a=x.getboxfill('quick') # get 'quick' boxfill graphics method x.clear() x.plot(s,a,bg=bg) support.check_plot(x) if support.dogui: x.graphicsmethodgui('boxfill','quick') # display the boxfill graphics method GUI raw_input("Press enter when done with gui testing") print '*************************************************************************************' print '****** ******' print '****** B O X F I L L T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def test(): import vcs, cdms2 as cdms, time, os, sys, support # import vcs and cdms bg = support.bg f = cdms.open(os.path.join(cdms.__path__[0], "..", "..", "..", "..", "sample_data", "clt.nc")) # open clt file u = f("u") # get slab u x = vcs.init() # construct vcs canvas x.plot(u, "default", "xyvsy", "ASD7", bg=bg) # plot slab the old way support.check_plot(x) if bg == 0: x.geometry(450, 337, 100, 0) # change the geometry and location x.flush() support.check_plot(x) a = x.getxyvsy("ASD7") # get 'ASD1' xyvsy if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isxyvsy(a): # test object 'a' if xyvsy raise Exception, "Error gm is not right type" a.script("test", "w") # save 'ASD7' xyvsy as a Python script a.xticlabels("", "") # remove the x-axis support.check_plot(x) a.xticlabels("*") # put the x-axis support.check_plot(x) ############################################################################ # Change the xyvsy line # ############################################################################ a.line = 0 # same as 'solid' support.check_plot(x) a.line = 1 # same as 'dash' support.check_plot(x) a.line = 2 # same as 'dot' support.check_plot(x) a.line = 3 # same as 'dash-dot' support.check_plot(x) a.line = 4 # same as 'long-dash' support.check_plot(x) if not "--extended" in sys.argv: print "\n************* PARTIAL TEST *****************" print "FOR COMPLETE TEST OF THIS MODULE USE " print " -F (--full) or -E (--extended) option" print "************* PARTIAL TEST *****************\n" sys.exit() ############################################################################ # Change the xyvsy line color # ############################################################################ a.linecolor = 77 support.check_plot(x) a.linecolor = 16 support.check_plot(x) a.linecolor = 44 # same as a.color=(44) support.check_plot(x) a.linecolor = None support.check_plot(x) ############################################################################ # Change the xyvsy marker # ############################################################################ a.marker = 1 # Same as a.marker='dot' support.check_plot(x) a.marker = 2 # Same as a.marker='plus' support.check_plot(x) a.marker = 3 # Same as a.marker='star' support.check_plot(x) a.marker = 4 # Same as a.marker='circle' support.check_plot(x) a.marker = 5 # Same as a.marker='cross' support.check_plot(x) a.marker = 6 # Same as a.marker='diamond' support.check_plot(x) a.marker = 7 # Same as a.marker='triangle_up' support.check_plot(x) a.marker = 8 # Same as a.marker='triangle_down' support.check_plot(x) a.marker = 9 # Same as a.marker='triangle_left' support.check_plot(x) a.marker = 10 # Same as a.marker='triangle_right' support.check_plot(x) a.marker = 11 # Same as a.marker='square' support.check_plot(x) a.marker = 12 # Same as a.marker='diamond_fill' support.check_plot(x) a.marker = 13 # Same as a.marker='triangle_up_fill' support.check_plot(x) a.marker = 14 # Same as a.marker='triangle_down_fill' support.check_plot(x) a.marker = 15 # Same as a.marker='triangle_left_fill' support.check_plot(x) a.marker = 16 # Same as a.marker='triangle_right_fill' support.check_plot(x) a.marker = 17 # Same as a.marker='square_fill' support.check_plot(x) a.marker = None # Draw no markers support.check_plot(x) ############################################################################ # Change the xyvsy marker color # ############################################################################ a.marker = "dot" support.check_plot(x) a.markercolor = 16 support.check_plot(x) a.markercolor = 44 # same as a.markercolor=(44) support.check_plot(x) a.markercolor = None support.check_plot(x) ############################################################################ # Change the xyvsy marker size # ############################################################################ a.markersize = 5 support.check_plot(x) a.markersize = 55 support.check_plot(x) a.markersize = 10 support.check_plot(x) a.markersize = 100 support.check_plot(x) a.markersize = 300 support.check_plot(x) a.markersize = None support.check_plot(x) x.clear() # clear the VCS Canvas x.xyvsy(u, a, "default", bg=bg) # plot xyvsy using 'default' template support.check_plot(x) objs = x.listelements("template") # get the list of templates t = x.createtemplate("test") # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception, "Error template not created" else: a2 = x.listelements("template") # get the list of templates if objs == a2: raise Exception, "Error template not created or added to list" x.clear() # clear the VCS Canvas x.plot(t, a, u, bg=bg) # plot xyvsy template 't', outline 'a', and arrays 'u':'v' support.check_plot(x) x.clear() # clear the VCS Canvas x.xyvsy(a, u, t, bg=bg) # plot using outline 'a', array 'u':'v', and template 't' support.check_plot(x) objs = x.listelements("line") # show the list of line secondary objects l = x.getline("red") # get line 'red' if not vcs.issecondaryobject(l): # check to see if it is a secondary object raise Exception, "Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" ########################################################################### # Use the create line object 'm' from above and modify the line object # ########################################################################### a.line = l # use the line object l.color = 44 # change the line color support.check_plot(x) l.type = "dot" # change the line type support.check_plot(x) l.width = 4 # change the line size support.check_plot(x) objs = x.listelements("marker") # show the list of marker secondary objects m = x.getmarker("red") # get marker 'red' if not vcs.issecondaryobject(m): # check to see if it is a secondary object raise Exception, "Error did not get marker" else: if not vcs.ismarker(m): # check to see if it is a line raise Exception, "Error object created is not marker" ########################################################################### # Use the create marker object 'm' from above and modify the line object # ########################################################################### a.marker = m # use the marker object support.check_plot(x) m.color = 44 # change the marker color support.check_plot(x) m.type = "square" # change the marker type support.check_plot(x) m.size = 20 # change the marker size support.check_plot(x) a = x.listelements("xyvsy") # show list of xyvsy r = x.createxyvsy("test2", "ASD1") # create xyvsy 'test2' a2 = x.listelements("xyvsy") # show list of xyvsy if a2 == a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements("xyvsy") # show list of xyvsy if a3 != a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testoutline.py # ################################################################################# # x.update() # x.mode=1 # x.mode=0 print "*************************************************************************************" print "****** ******" print "****** X y v s y T E S T C O M P L E T E D S U C E S S F U L L Y ******" print "****** ******" print "*************************************************************************************"
def test(): import vcs import cdms2 as cdms import os import support # import vcs and cu bg = support.bg f = cdms.open(os.path.join(vcs.sample_data, 'clt.nc')) # open clt file u = f.getslab('u', ':', ':', -10., 0., 0, 10) # get slab u v = f.getslab('v', ':', ':', -10., 0., 0, 10) # get slab v x = vcs.init() # construct vcs canvas x.plot(u, v, 'default', 'vector', 'quick', bg=bg) # plot slab the old way support.check_plot(x) if bg == 0: x.geometry(450, 337, 100, 0) # change the geometry and location x.flush() support.check_plot(x) a = x.getvector('quick') # get 'quick' vector # test object 'a' for graphics method if not vcs.isgraphicsmethod(a): raise Exception("Error did not retrieve the gm") else: if not vcs.isvector(a): # test object 'a' if vector raise Exception("Error gm is not right type") # save 'quick' vector as a Python script a.script('test', 'w') a.xticlabels('', '') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) ########################################################################## # Change the vector scale # ########################################################################## a.scale = 2.0 support.check_plot(x) a.scale = 5.0 support.check_plot(x) a.scale = 1.5 support.check_plot(x) a.scale = 0.0 support.check_plot(x) a.scale = -1.5 support.check_plot(x) a.scale = -2.0 support.check_plot(x) a.scale = -5.0 support.check_plot(x) ########################################################################## # Change the vector typeiiiiiii # ########################################################################## a.type = 0 # same as a.type = 'arrows' support.check_plot(x) a.type = 1 # same as a.type = 'barbs' support.check_plot(x) # a.type=2 # same as a.type = 'solidarrows' # support.check_plot(x) # raw_input("Done...") if '--extended' not in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ########################################################################## # Change the vector reference # ########################################################################## a.reference = 10. support.check_plot(x) a.reference = 100. support.check_plot(x) a.reference = 4. support.check_plot(x) a.reference = 5. support.check_plot(x) ########################################################################## # Change the vector alignment # ########################################################################## a.alignment = 'head' # same as a.alignment=0 support.check_plot(x) a.alignment = 'center' # same as a.alignment=1 support.check_plot(x) a.alignment = 'tail' # same as a.alignment=2 support.check_plot(x) ########################################################################## # Change the vector line # ########################################################################## a.line = 0 # same as 'solid' support.check_plot(x) a.line = 1 # same as 'dash' support.check_plot(x) a.line = 2 # same as 'dot' support.check_plot(x) a.line = 3 # same as 'dash-dot' support.check_plot(x) a.line = 4 # same as 'long-dash' support.check_plot(x) a.line = None # use default line support.check_plot(x) ########################################################################## # Change the vector line color # ########################################################################## a.linecolor = (77) support.check_plot(x) a.linecolor = 16 support.check_plot(x) a.linecolor = 44 # same as a.color=(44) support.check_plot(x) a.linecolor = None support.check_plot(x) x.clear() # clear the VCS Canvas x.vector(u, v, a, 'default', bg=bg) # plot vector using 'default' template support.check_plot(x) # get the list of templates objs = x.listelements('template') # create template 'test' from 'default' template t = x.createtemplate('test') # test whether 't' is a template or not if not vcs.istemplate(t): raise Exception("Error template not created") else: # get the list of templates a2 = x.listelements('template') if objs == a2: raise Exception("Error template not created or added to list") x.clear() # clear the VCS Canvas # plot vector template 't', outline 'a', and arrays 'u':'v' x.plot(t, a, u, v, bg=bg) support.check_plot(x) x.clear() # clear the VCS Canvas # plot using outline 'a', array 'u':'v', and template 't' x.vector(a, u, v, t, bg=bg) support.check_plot(x) l = x.getline('red') # get line 'red' # check to see if it is a secondary object if not vcs.issecondaryobject(l): raise Exception("Error did not get line") else: if not vcs.isline(l): # check to see if it is a line raise Exception("Error object created is not line") ########################################################################### # Use the create line object 'm' from above and modify the line object # ########################################################################### a.line = l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type = 'dot' # change the line type support.check_plot(x) l.width = 4 # change the line size support.check_plot(x) a = x.listelements('vector') # show list of gm r = x.createvector('test2', 'quick') # create xyvsy 'test2' a2 = x.listelements('vector') # show list of gm if a2 == a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('vector') # show list of gm if a3 != a: raise "error gm not removed" ########################################################################## # to see how x.update and x.mode work, see testoutline.py # ########################################################################## # x.update() # x.mode=1 # x.mode=0 print '*************************************************************************************' print '****** ******' print '****** V E C T O R T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cdms bg=support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) # open clt file s=f('clt') # get slab clt x=vcs.init() # construct vcs canvas tt=x.createtext() a = x.listelements('template') # show the list of templates t=x.createtemplate('test','ASD') # create template 'test' from ASD t.ylabel1.texttable=tt t.ylabel1.textorientation=tt a2 = x.listelements('template') # show the list of templates if a2==a: raise Excpetion,"Error, template not added to list" if not vcs.istemplate(t): raise Exception,"Error obj created is not a template!" t.script('test','w') # save test template as a Python script g=x.createisofill('test') # create isofill 'test' from 'default' isofill x.plot(g,s,t,bg=bg) # make isofill plot support.check_plot(x) ############################################################################# # Show the many different ways to show the template members (attributes) # # and their values. # ############################################################################# ## t.list() # list the templates members ## t.list('text') # list only text members, same as t.list('Pt') ## t.list('format') # list only format members, same as t.list('Pf') ## t.list('xtickmarks') # list only xtickmarks members, same as t.list('Pxt') ## t.list('ytickmarks') # list only ytickmarks members, same as t.list('Pyt') ## t.list('xlabels') # list only xlabels members, same as t.list('Pxl') ## t.list('ylabels') # list only ylabels members, same as t.list('Pyl') ## t.list('boxeslines') # list only boxeslines members, same as t.list('Pbl') ## t.list('legend') # list only legend member, same as t.list('Pls') ## t.list('data') # list only data member, same as t.list('Pds') ## t.list('file') # list only file member and its values ## t.file.list() # list only file member and its values ## t.list('mean') # list only mean member and its values ## t.mean.list() # list only mean member and its values ############################################################################# # The screen x and y positions on the screen are normalized between 0 and 1 # # for both the x and y axis. # ############################################################################# t.mean.priority = 0 # remove the "Mean" text from the plot support.check_plot(x) t.mean.priority = 1 # re-display the "Mean" text on the plot support.check_plot(x) t.mean.x=0.5 # move the "Mean" text to x-axis center support.check_plot(x) t.mean.y=0.5 # move the "Mean" text to y-axis center support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ############################################################################# # Position the data in front of the "Mean" text, then move the "Mean" text # # in front of the data. # ############################################################################# t.data.priority = 2 support.check_plot(x) t.data.priority=3 support.check_plot(x) # The above does not work. I will fix this later when time permits. # seems to work now 2007-07-16 t.data.priority=1 # back to normal support.check_plot(x) ############################################################################# # Change the font representation for the "Mean" text. # # You can set the text by using text objects or text names. # ############################################################################# tt = x.createtexttable('test') to = x.createtextorientation('test') t.mean.texttable = tt # set texttable by using texttable object support.check_plot(x) t.mean.textorientation = 'test' # set textorientation by using textorientation name support.check_plot(x) t.mean.list() # show the mean member and their new values tt.font=2 # change the font support.check_plot(x) to.height=40 # change the height support.check_plot(x) ############################################################################# # Change the legend space. # ############################################################################# t.legend.list() # list the legend members x.mode=0 # turn the automatic update off t.legend.x1=0.85 support.check_plot(x) t.legend.y1=0.90 support.check_plot(x) t.legend.x2=0.95 support.check_plot(x) t.legend.y2=0.16 support.check_plot(x) x.update() support.check_plot(x) # The above does not work. I will fix this later when time permits. print '***************************************************************************************' print '****** ******' print '****** T E M P L A T E T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '***************************************************************************************'
def __init__(self,name=None,source='default',x=None,template=None): self._saves={} self.g_nslabs=1 if not self.g_type in vcsaddons.gms.keys(): vcsaddons.gms[self.g_type]={} if name is None: cont = True while cont: num= numpy.random.randint(1000) nm = self.g_type + '_'+str(num) if not nm in vcsaddons.gms[self.g_type].keys(): name = nm cont = False if x is None: self.x=vcs.init() else: self.x=x if template is None: self.template = self.x.gettemplate() elif isinstance(template,str): self.template = self.x.gettemplate(template) elif vcs.istemplate(template): self.template = template else: raise "Error did not know what to do with template: %s" % template if name in vcsaddons.gms[self.g_type].keys(): raise "Error graphic method %s already exists" % name if source=='default': self.datawc_x1=1.e20 self.datawc_x2=1.e20 self.datawc_y1=1.e20 self.datawc_y2=1.e20 self.colormap="default" self.xmtics1='' self.xmtics2='' self.ymtics1='' self.ymtics2='' self.xticlabels1='*' self.xticlabels2='*' self.yticlabels1='*' self.yticlabels2='*' self.xaxisconvert= 'linear' self.yaxisconvert= 'linear' self.color_1 = 16 self.color_2 = 239 self.legend = None self.projection='linear' else: if isinstance(source, (str, unicode)): gm = vcsaddons.gms[self.g_type].get(source,None) if gm is None: raise "error could not find graphic method %s (of type %s)" % (source, self.g_type) else: gm = source self.datawc_x1=gm.datawc_x1 self.datawc_x2=gm.datawc_x2 self.datawc_y1=gm.datawc_y1 self.datawc_y2=gm.datawc_y2 self.colormap=gm.colormap self.xmtics1=gm.xmtics1 self.xmtics2=gm.xmtics2 self.ymtics1=gm.ymtics1 self.ymtics2=gm.ymtics2 self.xticlabels1=gm.xticlabels1 self.xticlabels2=gm.xticlabels2 self.yticlabels1=gm.yticlabels1 self.yticlabels2=gm.yticlabels2 self.xaxisconvert=gm.xaxisconvert self.yaxisconvert= gm.yaxisconvert self.color_1 = gm.color_1 self.color_2 = gm.color_2 self.legend = gm.legend self.projection=gm.projection self.name = name vcsaddons.gms[self.g_type][name]=self
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cdms bg=support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) # open clt file s=f('clt') # get slab clt x=vcs.init() # construct vcs canvas x.plot(s,'default','outfill','ASD_map',bg=bg)# plot slab the old way support.check_plot(x) if bg==0: x.geometry(450,337,100,0) # change the geometry and location support.check_plot(x) x.flush() support.check_plot(x) s=f('u') # get u slab x.clear() # clear the VCS Canvas x.plot(s,'default','outfill','ASD_map',bg=bg)# plot the surface data support.check_plot(x) a=x.createoutfill('quick') # create 'quick' outfill if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isoutfill(a): # check for isofill raise Exception, "Error gm is not right type" a.script('test','w') # save 'quick' outfill as a Python script a.xticlabels('lon30','lon30') # change the x-axis support.check_plot(x) a.xticlabels('','') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change the region support.check_plot(x) a.datawc(1e20,1e20,1e20,1e20) # put the region back support.check_plot(x) cont = False for anarg in sys.argv: if anarg in ['--extended', '--full','-E','-F']: cont = True break if cont is False: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() x.clear() # clear the VCS Canvas x.outfill(s,a,'default',bg=bg) # plot outfill using 'default' template a.fillareastyle='hatch' # change the fill style to hatch support.check_plot(x) a.fillareaindex=11 # change the hatch index pattern support.check_plot(x) a.fillareacolor=(77) # change the hatch color support.check_plot(x) a.fillareacolor=16 # chnage the hatch color support.check_plot(x) a.fillareacolor=44 # same as a.fillareacolor=(44) support.check_plot(x) a.fillareacolor=None # use the default hatch color (black) support.check_plot(x) a.outfill=([0]) # set the outfill value support.check_plot(x) a.outfill=([1]) # set the outfill value support.check_plot(x) a.outfill=([0,1]) # set the outfill value support.check_plot(x) a.outfill=([0]) # set the outfill value support.check_plot(x) support.check_plot(x) objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" x.clear() # clear the VCS Canvas x.plot(a, t, s,bg=bg) # plot outfill template 't', outfill 'a', and array 's' support.check_plot(x) x.clear() # clear the VCS Canvas x.outfill(a,s,t,bg=bg) # plot using outfill 'a', array 's', and template 't' support.check_plot(x) objs = x.listelements('fillarea') # show the list of fillarea secondary objects f=x.getfillarea('AuTo_1') # get fillarea 'red' if not vcs.issecondaryobject(f): # check to see if it is a secondary object raise Exception,"Error did not get fillarea" else: if not vcs.isfillarea(f): # check to see if it is a fillarea raise Exception, "Error object created is not fillarea" a.fillareastyle=f support.check_plot(x) f.color=44 # change the fillarea object's color support.check_plot(x) f.style='hatch' # change the fillarea object's fill style support.check_plot(x) a = x.listelements('outfill') # show list of gm r=x.createoutfill('test2','quick') # create xyvsy 'test2' a2 = x.listelements('outfill') # show list of gm if a2==a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('outfill') # show list of gm if a3!=a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testoutfill.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** O U T F I L L T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************' return x, s
def plot(self,data,data2,template = None, bg=0, x=None): if x is None: x = self.x if template is None: template = self.template elif isinstance(template,str): template = x.gettemplate(template) elif not vcs.istemplate(template): raise "Error did not know what to do with template: %s" % template if not isinstance(data,cdms2.tvariable.TransientVariable): mode= cdms2.getAutoBounds() cdms2.setAutoBounds("on") data = MV2.array(data) data.getAxis(-1).getBounds() cdms2.setAutoBounds(mode) while data.rank()>1: data = data[0] while data2.rank()>1: data2 = data2[0] # ok now we have a good x and a good data npts1 = len(data) npts2 = len(data2) # create the primitive fill = x.createfillarea() line = x.createline() fill.viewport = [template.data.x1,template.data.x2,template.data.y1,template.data.y2] line.viewport = [template.data.x1,template.data.x2,template.data.y1,template.data.y2] ax = data.getAxis(0)[:] ax2 = data.getAxis(0)[:] xmn,xmx = vcs.minmax(ax,ax2) ymn,ymx = vcs.minmax(data,data2) xmn,xmx,ymn,ymx = self.prep_plot(xmn,xmx,ymn,ymx) fill.worldcoordinate=[xmn,xmx,ymn,ymx] line.worldcoordinate=[xmn,xmx,ymn,ymx] fill.style = [self.fillareastyle,] fill.color = [self.fillareacolor,] fill.index = [self.fillareaindex,] line.type = [self.line,] line.width = [self.linewidth,] line.color = [self.linecolor,] xs = [] ys = [] xs = numpy.concatenate((ax[:],ax2[::-1])).tolist() ys = numpy.concatenate((data[:],data2[::-1])).tolist() xs.append(xs[0]) ys.append(ys[0]) fill.x = xs fill.y = ys line.x = xs line.y = ys displays = [] displays.append(x.plot(fill,bg=bg)) displays.append(x.plot(line,bg=bg)) x.worldcoordinate = fill.worldcoordinate dsp = template.plot(data,self,bg=bg) for d in dsp: displays.append(d) self.restore() return displays
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cu bg=support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) # open clt file u=f('u') # get slab u v=f('v') # get slab v x=vcs.init() # construct vcs canvas a=x.createxvsy('quick') # create 'quick' xvsy if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isxvsy(a): # test object 'a' if xvsy raise Exception, "Error gm is not right type" x.plot(u, v, 'default','xvsy','quick',bg=bg) # plot slabs the old way support.check_plot(x) if bg==0: x.geometry(450,337,100,0) # change the geometry and location x.flush() support.check_plot(x) a.script('test','w') # save 'quick' xvsy as a Python script a.xticlabels('','') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) ############################################################################ # Change the xvsy line # ############################################################################ a.line=0 # same as 'solid' support.check_plot(x) a.line=1 # same as 'dash' support.check_plot(x) a.line=2 # same as 'dot' support.check_plot(x) a.line=3 # same as 'dash-dot' support.check_plot(x) a.line=4 # same as 'long-dash' support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ############################################################################ # Change the xvsy line color # ############################################################################ a.linecolor=(77) support.check_plot(x) a.linecolor=16 support.check_plot(x) a.linecolor=44 # same as a.color=(44) support.check_plot(x) a.linecolor=None support.check_plot(x) ############################################################################ # Change the xvsy marker # ############################################################################ a.marker=1 # Same as a.marker='dot' support.check_plot(x) a.marker=2 # Same as a.marker='plus' support.check_plot(x) a.marker=3 # Same as a.marker='star' support.check_plot(x) a.marker=4 # Same as a.marker='circle' support.check_plot(x) a.marker=5 # Same as a.marker='cross' support.check_plot(x) a.marker=6 # Same as a.marker='diamond' support.check_plot(x) a.marker=7 # Same as a.marker='triangle_up' support.check_plot(x) a.marker=8 # Same as a.marker='triangle_down' support.check_plot(x) a.marker=9 # Same as a.marker='triangle_left' support.check_plot(x) a.marker=10 # Same as a.marker='triangle_right' support.check_plot(x) a.marker=11 # Same as a.marker='square' support.check_plot(x) a.marker=12 # Same as a.marker='diamond_fill' support.check_plot(x) a.marker=13 # Same as a.marker='triangle_up_fill' support.check_plot(x) a.marker=14 # Same as a.marker='triangle_down_fill' support.check_plot(x) a.marker=15 # Same as a.marker='triangle_left_fill' support.check_plot(x) a.marker=16 # Same as a.marker='triangle_right_fill' support.check_plot(x) a.marker=17 # Same as a.marker='square_fill' support.check_plot(x) a.marker=None # Draw no markers support.check_plot(x) ############################################################################ # Change the xvsy marker color # ############################################################################ a.marker='dot' support.check_plot(x) a.markercolor=16 support.check_plot(x) a.markercolor=44 # same as a.markercolor=(44) support.check_plot(x) a.markercolor=None support.check_plot(x) ############################################################################ # Change the xvsy marker size # ############################################################################ a.markersize=5 support.check_plot(x) a.markersize=55 support.check_plot(x) a.markersize=10 support.check_plot(x) a.markersize=100 support.check_plot(x) a.markersize=300 support.check_plot(x) a.markersize=None support.check_plot(x) x.clear() # clear the VCS Canvas x.xvsy(u, v, a,'default',bg=bg) # plot xvsy using 'default' template support.check_plot(x) ######################################################################### # Create template 'test' from the default template # ######################################################################### objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" x.clear() # clear the VCS Canvas x.plot(t,a,u,v,bg=bg) # plot xvsy template 't', outline 'a', and arrays 'u':'v' support.check_plot(x) x.clear() # clear the VCS Canvas x.xvsy(a,u,v,t,bg=bg) # plot using outline 'a', array 'u':'v', and template 't' support.check_plot(x) l=x.getline('red') # get line 'red' if not vcs.issecondaryobject(l): # check to see if it is a secondary object raise Exception,"Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" ########################################################################### # Use the create line object 'm' from above and modify the line object # ########################################################################### a.line=l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type ='dot' # change the line type support.check_plot(x) l.width=4 # change the line size support.check_plot(x) m=x.getmarker('red') # get marker 'red' if not vcs.issecondaryobject(m): # check to see if it is a secondary object raise Exception,"Error did not get marker" else: if not vcs.ismarker(m): # check to see if it is a line raise Exception, "Error object created is not marker" ########################################################################### # Use the create marker object 'm' from above and modify the line object # ########################################################################### a.marker=m # use the marker object support.check_plot(x) m.color = 44 # change the marker color support.check_plot(x) m.type ='square' # change the marker type support.check_plot(x) m.size=20 # change the marker size support.check_plot(x) a = x.listelements('xvsy') # show list of gm r=x.createxvsy('test2','quick') # create xyvsy 'test2' a2 = x.listelements('xvsy') # show list of gm if a2==a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('xvsy') # show list of gm if a3!=a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testoutline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** X v s Y T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def plot(self,data,template = None, bg=0, x=None): if x is None: x = self.x if template is None: template = self.template elif isinstance(template,str): template = x.gettemplate(template) elif not vcs.istemplate(template): raise "Error did not know what to do with template: %s" % template if not isinstance(data,cdms2.tvariable.TransientVariable): mode= cdms2.getAutoBounds() cdms2.setAutoBounds("on") data = MV2.array(data) data.getAxis(-1).getBounds() cdms2.setAutoBounds(mode) while data.rank()>1: data = data[0] # ok now we have a good x and a good data nbars = len(data) # create the primitive fill = x.createfillarea() line = x.createline() fill.viewport = [template.data.x1,template.data.x2,template.data.y1,template.data.y2] line.viewport = [template.data.x1,template.data.x2,template.data.y1,template.data.y2] axb = data.getAxis(0).getBounds() xmn,xmx = vcs.minmax(axb) ymn,ymx = vcs.minmax(data) xmn,xmx,ymn,ymx = self.prep_plot(xmn,xmx,ymn,ymx) fill.worldcoordinate=[xmn,xmx,ymn,ymx] line.worldcoordinate=[xmn,xmx,ymn,ymx] styles =[] cols = [] indices = [] lt = [] lw =[] lc = [] xs = [] ys = [] for i in range(nbars): if i < len(self.fillareastyles): styles.append(self.fillareastyles[i]) else: styles.append(self.fillareastyles[-1]) if i < len(self.fillareacolors): cols.append(self.fillareacolors[i]) else: cols.append(self.fillareacolors[-1]) if i < len(self.fillareaindices): indices.append(self.fillareaindices[i]) else: indices.append(self.fillareaindices[-1]) if i < len(self.line): lt.append( self.line[i]) else: lt.append(self.line[-1]) if i < len(self.linewidth): lw.append( self.linewidth[i]) else: lw.append(self.linewidth[-1]) if i < len(self.line): lc.append( self.linecolors[i]) else: lc.append(self.linecolors[-1]) xs.append( [axb[i][0],axb[i][1],axb[i][1],axb[i][0],axb[i][0]]) ys.append( [0,0,data[i],data[i],0]) fill.style = styles fill.x = xs fill.y = ys fill.style fill.index = indices fill.color = cols line.x = xs line.y = ys line.type = lt line.width = lw line.color = lc displays = [] displays.append(x.plot(fill,bg=bg)) displays.append(x.plot(line,bg=bg)) x.worldcoordinate = fill.worldcoordinate dsp = template.plot(data,self,bg=bg) for d in dsp: displays.append(d) self.restore() return displays
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cu bg= support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) # open clt file s=f('clt') # get slab clt x=vcs.init() # construct vcs canvas a=x.createoutline('test') # create 'test' outline if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isoutline(a): # check for outline raise Exception, "Error gm is not right type" x.plot(s,'default','outline','test',bg=bg)# plot slab the old way support.check_plot(x) if bg==0: x.geometry(450,337,100,0) # change the geometry and location x.flush() support.check_plot(x) s=f('u') # get u slab x.clear() # clear the VCS Canvas x.plot(s,'default','outline','test',bg=bg)# plot the surface data support.check_plot(x) a.script('test','w') # save 'test' outline as a Python script a.xticlabels('lon30','lon30') # change the x-axis support.check_plot(x) a.xticlabels('','') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change the region support.check_plot(x) a.datawc(1e20,1e20,1e20,1e20) # put the region back support.check_plot(x) cont = False for anarg in sys.argv: if anarg in ['--extended', '--full','-E','-F']: cont = True break if cont is False: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() a.outline=([0]) # set the outline value support.check_plot(x) a.line=0 # same as 'solid', change the line style support.check_plot(x) a.line=1 # same as 'dash', change the line style support.check_plot(x) a.line=2 # same as 'dot', change the line style support.check_plot(x) a.line=3 # same as 'dash-dot', change the line style support.check_plot(x) a.line=4 # same as 'long-dash', change the line style support.check_plot(x) a.linecolor=(77) # change the line color support.check_plot(x) a.linecolor=16 # change the line color support.check_plot(x) a.linecolor=44 # same as a.linecolor=(44) support.check_plot(x) a.linecolor=None # use the default line color, black support.check_plot(x) a.line=None # use default line style, solid black line support.check_plot(x) a.outline=([1]) # set the outline value support.check_plot(x) a.outline=([0,1]) # set the outline value support.check_plot(x) a.outline=([0]) # set the outline value support.check_plot(x) x.clear() # clear the VCS Canvas x.outline(s,a,'default',bg=bg) # plot outline using 'default' template support.check_plot(x) objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" x.clear() # clear the VCS Canvas x.plot(t,a,s,bg=bg) # plot outline template 't', outline 'a', and array 's' support.check_plot(x) x.clear() # clear the VCS Canvas x.outline(a,s,t,bg=bg) # plot using outline 'a', array 's', and template 't' support.check_plot(x) ######################################################################### # Create line object 'l' from the default line # ######################################################################### ######################################################################### objs = x.listelements('line') # show the list of line secondary objects l=x.createline('test') if not vcs.issecondaryobject(l): # check to see if it is a secondary object raise Exception,"Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" ######################################################################### # Use the create line object 'l' from above and modify the line object # ######################################################################### a.line=l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type ='dash' # change the line type support.check_plot(x) a = x.listelements('outline') # show list of gm r=x.createoutline('test2','quick') # create xyvsy 'test2' a2 = x.listelements('outline') # show list of gm if a2==a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('outline') # show list of gm if a3!=a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testoutline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** O U T F I L L T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def plot(self, x=None, template=None, bg=0, ratio=None): try: if x is None: x = vcs.init() if ratio is None: ratio = x.ratio if not template is None: ## print 'you passed a template' if not vcs.istemplate(template): ## print 'Getting it from string' t = x.gettemplate(template) else: ## print 'Getting it from object' t = template else: t = x.gettemplate() ovp = x.viewport owc = copy.copy(x.worldcoordinate) ## print 'OWC',owc wc = x.worldcoordinate if not (self.datawc_x1 is None) and self.datawc_x1 != '*': wc[0] = self.datawc_x1 if not (self.datawc_x2 is None) and self.datawc_x2 != '*': wc[1] = self.datawc_x2 if not (self.datawc_y1 is None) and self.datawc_y1 != '*': wc[2] = self.datawc_y1 if not (self.datawc_y2 is None) and self.datawc_y2 != '*': wc[3] = self.datawc_y2 ## print 'Ratio:',x.ratio if ratio in ['auto', 'autot']: t.ratio_linear_projection(wc[0], wc[1], wc[2], wc[3]) elif isinstance(ratio, str): if ratio[-1] == 't': r = float(ratio[:-1]) else: r = float(ratio) t.ratio(r) elif ratio != 0: t.ratio(ratio) ## t.data.list() vp = [t.data.x1, t.data.x2, t.data.y1, t.data.y2] fa = x.createfillarea() li = x.createline() fa.projection = self.projection li.projection = self.projection fa.viewport = vp fa.worldcoordinate = wc fa.priority = t.data.priority + 1 li.worldcoordinate = wc li.viewport = vp li.priority = t.data.priority + 1 # Now plots the stuff xs, ys = self.readData() ## xs=xs[15] ## ys=ys[15] fa.x = xs fa.y = ys fa.color = self.fill_color fa.priority = t.data.priority + 1 li.x = xs li.y = ys li.color = self.line_color li.width = self.line_width li.priority = t.data.priority + 1 if self.fill == 'y': x.plot(fa, bg=bg) if self.line == 'y': x.plot(li, bg=bg) xs = fa.x for i in range(len(xs)): for j in range(len(xs[i])): xs[i][j] = xs[i][j] - 360. fa2 = x.createfillarea() li2 = x.createline() fa2.viewport = vp fa2.worldcoordinate = wc fa2.x = xs li2.x = xs if self.fill == 'y': x.plot(fa2, bg=bg) if self.line == 'y': x.plot(li2, bg=bg) xs = fa2.x for i in range(len(xs)): for j in range(len(xs[i])): xs[i][j] = xs[i][j] + 720. icont = 1 fa3 = x.createfillarea(source=fa.name) li3 = x.createline(source=li.name) fa3.viewport = vp fa3.worldcoordinate = wc fa3.x = xs li3.x = xs if self.fill == 'y': x.plot(fa3, bg=bg) if self.line == 'y': x.plot(li3, bg=bg) ## x.viewport=ovp ## x.worldcoordinate=owc except Exception, err: print 'Error in continents:', err
def test(): import vcs, cdms2 as cdms, time, os, sys, support # import vcs and cdms bg = support.bg f = cdms.open( os.path.join(cdms.__path__[0], '..', '..', '..', '..', 'sample_data', 'clt.nc')) # open clt file u = f('u') # get slab u x = vcs.init() # construct vcs canvas x.plot(u, 'default', 'yxvsx', 'ASD7', bg=bg) # plot slab the old way support.check_plot(x) if support.dogui: x.geometry(450, 337, 100, 0) # change the geometry and location x.flush() support.check_plot(x) a = x.getyxvsx('ASD7') # get 'ASD7' yxvsx if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error not a gm" else: if not vcs.isyxvsx(a): # test object 'a' if yxvsx raise Exception, "Error wrong type of gm" a.script('test', 'w') # save 'ASD7' yxvsx as a Python script a.xticlabels('', '') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) ############################################################################ # Change the yxvsx line # ############################################################################ a.line = 0 # same as 'solid' support.check_plot(x) a.line = 1 # same as 'dash' support.check_plot(x) a.line = 2 # same as 'dot' support.check_plot(x) a.line = 3 # same as 'dash-dot' support.check_plot(x) a.line = 4 # same as 'long-dash' support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ############################################################################ # Change the yxvsx line color # ############################################################################ a.linecolor = (77) support.check_plot(x) a.linecolor = 16 support.check_plot(x) a.linecolor = 44 # same as a.color=(44) support.check_plot(x) a.linecolor = None support.check_plot(x) ############################################################################ # Change the yxvsx marker # ############################################################################ a.marker = 1 # Same as a.marker='dot' support.check_plot(x) a.marker = 2 # Same as a.marker='plus' support.check_plot(x) a.marker = 3 # Same as a.marker='star' support.check_plot(x) a.marker = 4 # Same as a.marker='circle' support.check_plot(x) a.marker = 5 # Same as a.marker='cross' support.check_plot(x) a.marker = 6 # Same as a.marker='diamond' support.check_plot(x) a.marker = 7 # Same as a.marker='triangle_up' support.check_plot(x) a.marker = 8 # Same as a.marker='triangle_down' support.check_plot(x) a.marker = 9 # Same as a.marker='triangle_left' support.check_plot(x) a.marker = 10 # Same as a.marker='triangle_right' support.check_plot(x) a.marker = 11 # Same as a.marker='square' support.check_plot(x) a.marker = 12 # Same as a.marker='diamond_fill' support.check_plot(x) a.marker = 13 # Same as a.marker='triangle_up_fill' support.check_plot(x) a.marker = 14 # Same as a.marker='triangle_down_fill' support.check_plot(x) a.marker = 15 # Same as a.marker='triangle_left_fill' support.check_plot(x) a.marker = 16 # Same as a.marker='triangle_right_fill' support.check_plot(x) a.marker = 17 # Same as a.marker='square_fill' support.check_plot(x) a.marker = None # Draw no markers support.check_plot(x) ############################################################################ # Change the yxvsx marker color # ############################################################################ a.marker = 'dot' support.check_plot(x) a.markercolor = 16 support.check_plot(x) a.markercolor = 44 # same as a.markercolor=(44) support.check_plot(x) a.markercolor = None support.check_plot(x) ############################################################################ # Change the yxvsx marker size # ############################################################################ a.markersize = 5 support.check_plot(x) a.markersize = 55 support.check_plot(x) a.markersize = 10 support.check_plot(x) a.markersize = 100 support.check_plot(x) a.markersize = 300 support.check_plot(x) a.markersize = None support.check_plot(x) x.clear() # clear the VCS Canvas x.yxvsx(u, a, 'default', bg=bg) # plot yxvsx using 'default' template support.check_plot(x) objs = x.listelements('template') # show the list of templates t = x.createtemplate( 'test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception, "Error creating tmeplate" x.clear() # clear the VCS Canvas x.plot(t, a, u, bg=bg) # plot yxvsx template 't', outline 'a', and arrays 'u':'v' support.check_plot(x) x.clear() # clear the VCS Canvas x.yxvsx(a, u, t, bg=bg) # plot using outline 'a', array 'u':'v', and template 't' support.check_plot(x) objs = x.listelements('line') # show the list of line secondary objects l = x.getline('red') # get line 'red' if not vcs.issecondaryobject( l): # check to see if it is a secondary object raise Exception, "Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" ########################################################################### # Use the create line object 'm' from above and modify the line object # ########################################################################### a.line = l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type = 'dot' # change the line type support.check_plot(x) l.width = 4 # change the line size support.check_plot(x) objs = x.listelements( 'marker') # show the list of marker secondary objects m = x.getmarker('red') # get marker 'red' if not vcs.issecondaryobject( m): # check to see if it is a secondary object raise Exception, "Error did not get marker" else: if not vcs.ismarker(m): # check to see if it is a line raise Exception, "Error object created is not marker" ########################################################################### # Use the create marker object 'm' from above and modify the line object # ########################################################################### a.marker = m # use the marker object support.check_plot(x) m.color = 44 # change the marker color support.check_plot(x) m.type = 'square' # change the marker type support.check_plot(x) m.size = 20 # change the marker size support.check_plot(x) a = x.listelements('yxvsx') # show list of xyvsy r = x.createyxvsx('test2', 'ASD1') # create xyvsy 'test2' a2 = x.listelements('yxvsx') # show list of xyvsy if a2 == a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('yxvsx') # show list of xyvsy if a3 != a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testoutline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** Y x v s x T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def plot(self, data, template=None, bg=0, x=None): if x is None: x = self.x if template is None: template = self.template elif isinstance(template, str): template = x.gettemplate(template) elif not vcs.istemplate(template): raise "Error did not know what to do with template: %s" % template if not isinstance(data, cdms2.tvariable.TransientVariable): mode = cdms2.getAutoBounds() cdms2.setAutoBounds("on") data = MV2.array(data) data.getAxis(-1).getBounds() cdms2.setAutoBounds(mode) while data.rank() > 1: data = data[0] # ok now we have a good x and a good data nbars = len(data) # create the primitive fill = x.createfillarea() line = x.createline() fill.viewport = [ template.data.x1, template.data.x2, template.data.y1, template.data.y2 ] line.viewport = [ template.data.x1, template.data.x2, template.data.y1, template.data.y2 ] axb = data.getAxis(0).getBounds() xmn, xmx = vcs.minmax(axb) ymn, ymx = vcs.minmax(data) xmn, xmx, ymn, ymx = self.prep_plot(xmn, xmx, ymn, ymx) fill.worldcoordinate = [xmn, xmx, ymn, ymx] line.worldcoordinate = [xmn, xmx, ymn, ymx] styles = [] cols = [] indices = [] lt = [] lw = [] lc = [] xs = [] ys = [] for i in range(nbars): if i < len(self.fillareastyles): styles.append(self.fillareastyles[i]) else: styles.append(self.fillareastyles[-1]) if i < len(self.fillareacolors): cols.append(self.fillareacolors[i]) else: cols.append(self.fillareacolors[-1]) if i < len(self.fillareaindices): indices.append(self.fillareaindices[i]) else: indices.append(self.fillareaindices[-1]) if i < len(self.line): lt.append(self.line[i]) else: lt.append(self.line[-1]) if i < len(self.linewidth): lw.append(self.linewidth[i]) else: lw.append(self.linewidth[-1]) if i < len(self.line): lc.append(self.linecolors[i]) else: lc.append(self.linecolors[-1]) xs.append([axb[i][0], axb[i][1], axb[i][1], axb[i][0], axb[i][0]]) ys.append([0, 0, data[i], data[i], 0]) fill.style = styles fill.x = xs fill.y = ys fill.style fill.index = indices fill.color = cols line.x = xs line.y = ys line.type = lt line.width = lw line.color = lc displays = [] displays.append(x.plot(fill, bg=bg)) displays.append(x.plot(line, bg=bg)) x.worldcoordinate = fill.worldcoordinate dsp = template.plot(data, self, bg=bg) for d in dsp: displays.append(d) self.restore() return displays
def plot(self,x=None,template=None,bg=0,ratio=None): try: if x is None: x=vcs.init() if ratio is None: ratio=x.ratio if not template is None: ## print 'you passed a template' if not vcs.istemplate(template): ## print 'Getting it from string' t=x.gettemplate(template) else: ## print 'Getting it from object' t=template else: t=x.gettemplate() ovp=x.viewport owc=copy.copy(x.worldcoordinate) ## print 'OWC',owc wc=x.worldcoordinate if not (self.datawc_x1 is None) and self.datawc_x1!='*': wc[0]=self.datawc_x1 if not (self.datawc_x2 is None) and self.datawc_x2!='*': wc[1]=self.datawc_x2 if not (self.datawc_y1 is None) and self.datawc_y1!='*': wc[2]=self.datawc_y1 if not (self.datawc_y2 is None) and self.datawc_y2!='*': wc[3]=self.datawc_y2 ## print 'Ratio:',x.ratio if ratio in ['auto','autot']: t.ratio_linear_projection(wc[0],wc[1],wc[2],wc[3]) elif isinstance(ratio,str): if ratio[-1]=='t': r=float(ratio[:-1]) else: r=float(ratio) t.ratio(r) elif ratio!=0: t.ratio(ratio) ## t.data.list() vp = [ t.data.x1, t.data.x2, t.data.y1, t.data.y2 ] fa=x.createfillarea() li=x.createline() fa.projection=self.projection li.projection=self.projection fa.viewport=vp fa.worldcoordinate=wc fa.priority=t.data.priority+1 li.worldcoordinate=wc li.viewport=vp li.priority=t.data.priority+1 # Now plots the stuff xs,ys=self.readData() ## xs=xs[15] ## ys=ys[15] fa.x=xs fa.y=ys fa.color=self.fill_color fa.priority=t.data.priority+1 li.x=xs li.y=ys li.color=self.line_color li.width=self.line_width li.priority=t.data.priority+1 if self.fill=='y': x.plot(fa,bg=bg) if self.line=='y': x.plot(li,bg=bg) xs=fa.x for i in range(len(xs)): for j in range(len(xs[i])): xs[i][j]=xs[i][j]-360. fa2=x.createfillarea() li2=x.createline() fa2.viewport=vp fa2.worldcoordinate=wc fa2.x=xs li2.x=xs if self.fill=='y': x.plot(fa2,bg=bg) if self.line=='y': x.plot(li2,bg=bg) xs=fa2.x for i in range(len(xs)): for j in range(len(xs[i])): xs[i][j]=xs[i][j]+720. icont=1 fa3=x.createfillarea(source = fa.name) li3=x.createline(source = li.name) fa3.viewport=vp fa3.worldcoordinate=wc fa3.x=xs li3.x=xs if self.fill=='y': x.plot(fa3,bg=bg) if self.line=='y': x.plot(li3,bg=bg) ## x.viewport=ovp ## x.worldcoordinate=owc except Exception,err: print 'Error in continents:',err
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cu bg=support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) # open clt file u=f.getslab('u',':',':',-10.,0.,0,10)# get slab u v=f.getslab('v',':',':',-10.,0.,0,10)# get slab v x=vcs.init() # construct vcs canvas x.plot(u, v, 'default','vector','quick',bg=bg) # plot slab the old way support.check_plot(x) if bg==0: x.geometry(450,337,100,0) # change the geometry and location x.flush() support.check_plot(x) a=x.getvector('quick') # get 'quick' vector if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isvector(a): # test object 'a' if vector raise Exception, "Error gm is not right type" a.script('test','w') # save 'quick' vector as a Python script a.xticlabels('','') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) ############################################################################ # Change the vector scale # ############################################################################ a.scale=2.0 support.check_plot(x) a.scale=5.0 support.check_plot(x) a.scale=1.5 support.check_plot(x) a.scale=0.0 support.check_plot(x) a.scale=-1.5 support.check_plot(x) a.scale=-2.0 support.check_plot(x) a.scale=-5.0 support.check_plot(x) ############################################################################ # Change the vector typeiiiiiii # ############################################################################ a.type=0 # same as a.type = 'arrows' support.check_plot(x) a.type=1 # same as a.type = 'barbs' support.check_plot(x) ## a.type=2 # same as a.type = 'solidarrows' ## support.check_plot(x) ## raw_input("Done...") if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ############################################################################ # Change the vector reference # ############################################################################ a.reference=10. support.check_plot(x) a.reference=100. support.check_plot(x) a.reference=4. support.check_plot(x) a.reference=5. support.check_plot(x) ############################################################################ # Change the vector alignment # ############################################################################ a.alignment='head' # same as a.alignment=0 support.check_plot(x) a.alignment='center' # same as a.alignment=1 support.check_plot(x) a.alignment='tail' # same as a.alignment=2 support.check_plot(x) ############################################################################ # Change the vector line # ############################################################################ a.line=0 # same as 'solid' support.check_plot(x) a.line=1 # same as 'dash' support.check_plot(x) a.line=2 # same as 'dot' support.check_plot(x) a.line=3 # same as 'dash-dot' support.check_plot(x) a.line=4 # same as 'long-dash' support.check_plot(x) a.line=None # use default line support.check_plot(x) ############################################################################ # Change the vector line color # ############################################################################ a.linecolor=(77) support.check_plot(x) a.linecolor=16 support.check_plot(x) a.linecolor=44 # same as a.color=(44) support.check_plot(x) a.linecolor=None support.check_plot(x) x.clear() # clear the VCS Canvas x.vector(u, v, a,'default',bg=bg) # plot vector using 'default' template support.check_plot(x) objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" x.clear() # clear the VCS Canvas x.plot(t,a,u,v,bg=bg) # plot vector template 't', outline 'a', and arrays 'u':'v' support.check_plot(x) x.clear() # clear the VCS Canvas x.vector(a,u,v,t,bg=bg) # plot using outline 'a', array 'u':'v', and template 't' support.check_plot(x) l=x.getline('red') # get line 'red' if not vcs.issecondaryobject(l): # check to see if it is a secondary object raise Exception,"Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" ########################################################################### # Use the create line object 'm' from above and modify the line object # ########################################################################### a.line=l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type ='dot' # change the line type support.check_plot(x) l.width=4 # change the line size support.check_plot(x) a = x.listelements('vector') # show list of gm r=x.createvector('test2','quick') # create xyvsy 'test2' a2 = x.listelements('vector') # show list of gm if a2==a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('vector') # show list of gm if a3!=a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testoutline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** V E C T O R T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def test(): import vcs,cdms2 as cdms,time,os,sys,support # import vcs and cu bg=support.bg f=cdms.open(os.path.join(cdms.__path__[0],'..','..','..','..','sample_data','clt.nc')) # open clt file s=f('clt') # get slab clt x=vcs.init() # construct vcs canvas x.plot(s,'default','isoline','quick',bg=support.bg)# plot slab the old way support.check_plot(x) if bg == 0: x.geometry(450,337,0,0) # change geometry and location support.check_plot(x) x.geometry(900,675,10,0) # change geometry and location support.check_plot(x) x.flush() support.check_plot(x) a=x.getisoline('quick') # get 'quick' isoline graphics method if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isisoline(a): # check for isoline raise Exception, "Error gm is not right type" a.script('test','w') # save 'quick' isoline as a Python script a.xticlabels('lon30','lon30') # change the x-axis support.check_plot(x) a.xticlabels('','') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis back support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change the region support.check_plot(x) a.datawc(1e20,1e20,1e20,1e20) # put the region back support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ######################################################################### # Set the isoline level vales # ######################################################################### a.level=([20,0.0],[30,0],[50,0],[60,0]) # change the isoline values support.check_plot(x) a.level=[[20,0.0],[30,0],[50,0]] # change the isoline values support.check_plot(x) a.level=((20,0.0),(30,0),(50,0),(60,0),(70,0)) # change the isoline values support.check_plot(x) a.level=(25,35,45,55) # change the isoline values support.check_plot(x) a.level=[(22,33,44,55,66)] # change the isoline values support.check_plot(x) a.level=[(23,32,45,50,76),] # change the isoline values support.check_plot(x) a.level=[0] # same as a.level=(0,) support.check_plot(x) a.level=[[0,1e20]] # same as a.level=((0,1e20),), use default settings support.check_plot(x) ######################################################################### # Turn on and off the isoline level labels # ######################################################################### a.label='y' # same as a.label=1 support.check_plot(x) a.label='n' # same as a.label=0 support.check_plot(x) ######################################################################### # Set the line style and line color # ######################################################################### a.level=((20,0.0),(30,0),(50,0),(60,0),(70,0)) # change the isoline values support.check_plot(x) a.line=[1,3,0,4] # same as a.line=(1,3,0,4) support.check_plot(x) a.line=(['dash','long-dash','solid'])# same as a.line=([2,4,0]) support.check_plot(x) a.line=[2,4,1,3,2,0] support.check_plot(x) a.linecolors=([22,33,44,55,66,77]) # change the line color support.check_plot(x) a.linecolors=(16,19,33,44) # change the line color support.check_plot(x) a.linecolors=None # use the default line color support.check_plot(x) a.line=None # use the default line style, which is solid support.check_plot(x) ######################################################################### # Set the text font and text color # ######################################################################### a.label='y' # same as a.label=1 support.check_plot(x) a.text=(1,2,3,4,5,6,7,8,9) # select fonts from 1 through 9 support.check_plot(x) a.text=[9,8,7,6,5,4,3,2,1] support.check_plot(x) a.text=([1,3,5,6,9,2]) support.check_plot(x) a.textcolors=([22,33,44,55,66,77]) # set the text color support.check_plot(x) a.textcolors=(16,19,33,44) support.check_plot(x) a.textcolors=None # use default text color, black support.check_plot(x) a.text=None # use default font, 1 support.check_plot(x) ######################################################################### # Create template 'test' from the default template # ######################################################################### objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" ######################################################################### # Create line object 'l' from the default line # ######################################################################### l=x.createline('test') objs = x.listelements('line') # show the list of line secondary objects if not vcs.issecondaryobject(l): # check to see if it is a secondary object raise Exception,"Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" x.clear() # clear the VCS Canvas x.isoline(s,a,t,bg=support.bg) # plot the array using the template and isoline object support.check_plot(x) x.clear() # clear the VCS Canvas x.plot(t,a,s,bg=support.bg) # plot again using the new way support.check_plot(x) ######################################################################### # Use the create line object 'l' from above and modify the line object # ######################################################################### a.line=[1,3,0,4] # same as a.line=(1,3,0,4) support.check_plot(x) a.line=([2,4,0]) # same as a.line=(['dash', 'long-dash', 'solid']) support.check_plot(x) a.line=(l,4,l,0) # use the line object support.check_plot(x) a.line=(l,3,4,2,0) support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type ='dash' # change the line type support.check_plot(x) ######################################################################### # Create the three types of text objects # ######################################################################### tc = x.createtextcombined('testc','std', 'testc','7left') if not vcs.istextcombined(tc): raise Exception,"Error not textcombined!" tt = x.createtexttable('testt', 'default') if not vcs.istexttable(tt): raise Exception,"Error not texttable" to = x.createtextorientation('testo') if not vcs.istextorientation(to): raise Exception,"Error not textorientation" ######################################################################### # Use the text objects in the isoline plot # ######################################################################### a.label='y' # make sure that the labels are turn on support.check_plot(x) a.text=([1,3,5,6,9,2]) # set the font support.check_plot(x) a.text=([tc,tt,to,6,9,2]) # use the created text objects and fonts support.check_plot(x) ######################################################################### # Change the text object values # ######################################################################### tc.font = 3 # changing isoline level 20 support.check_plot(x) tc.height=15 support.check_plot(x) tc.angle=180 support.check_plot(x) tc.color=242 support.check_plot(x) tt.font=2 # changing isoline level 30 support.check_plot(x) tt.spacing=20 support.check_plot(x) to.height=15 # changing isoline level 50 support.check_plot(x) to.path='down' support.check_plot(x) a.text=None # use default font, which is font 1 support.check_plot(x) a.line=None # use default line, which is solid support.check_plot(x) a = x.listelements('isoline') # show list of gm r=x.createisoline('test2','quick') # create xyvsy 'test2' a2 = x.listelements('isoline') # show list of gm if a2==a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('isoline') # show list of gm if a3!=a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testisoline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** I S O L I N E T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def plot(self,data=None,template = None, bg=0, x=None): if x is None: x = self.x if template is None: template = self.template elif isinstance(template,str): template = x.gettemplate(template) elif not vcs.istemplate(template): raise "Error did not know what to do with template: %s" % template if data.getLongitude() is None or data.getLatitude() is None: raise Exception,["Error data do not have lat/lon"] if data is None: xmn=-180. xmx=180 ymn=-90 ymx=90 else: xmn,xmx = vcs.minmax(data.getLongitude()[:]) ymn,ymx = vcs.minmax(data.getLatitude()[:]) xmn,xmx,ymn,ymx = self.prep_plot(xmn,xmx,ymn,ymx) n = len(self.sources) for i in range(n): type = self.types[i] source = self.sources[i] if type == 'ngdc' or type == 1: fnm = self.gen_cont_file(xmn,xmx,ymn,ymx,source) f=open(fnm) data=f.read() f.close() if self.HAVE_BZ2: import bz2 data = bz2.decompress(data) elif type == "file" or type == 0: source = self.sources[i] f=open(source) data=f.read() f.close() if fnm[-3:]=='bz2': if self.HAVE_BZ2 : import bz2 data = bz2.decompress(data) else: raise Excetpion, ["Cannot uncompress bzipped data"] elif type == "shapefile" or type==2: source = self.sources[i] data = self.load_shapefile(source) f = open(os.path.join(os.environ.get("HOME","."),"PCMDI_GRAPHICS","data_continent_other10"),"w") f.write(data) f.close() c = x.createcontinents() j=i if i>=len(self.colors): j=-1 c.linecolor=self.colors[j] j=i if i>=len(self.widths): j=-1 c.linewidth=self.widths[j] j=i if i>=len(self.lines): j=-1 c.line=self.lines[j] c.type=10 c.datawc_x1 = xmn c.datawc_x2 = xmx c.datawc_y1 = ymn c.datawc_y2 = ymx c.xmtics1=self.xmtics1 c.xmtics2=self.xmtics2 c.ymtics1=self.ymtics1 c.ymtics2=self.ymtics2 c.xticlabels1=self.xticlabels1 c.xticlabels2=self.xticlabels2 c.yticlabels1=self.yticlabels1 c.yticlabels2=self.yticlabels2 c.xaxisconvert=self.xaxisconvert c.yaxisconvert= self.yaxisconvert c.legend = self.legend c.projection=self.projection self.x.plot(c,template,bg=bg)
def test(): import vcs import cdms2 as cdms import os import support # import vcs and cdms bg = support.bg f = cdms.open(os.path.join(vcs.sample_data, 'clt.nc')) s = f('clt') # get slab clt x = vcs.init() # construct vcs canvas x.plot(s, 'default', 'isofill', 'quick', bg=bg) # plot slab the old way support.check_plot(x) # Check the legend g = x.createisofill('vcsmoduletest') x.clear() # clear the VCS Canvas x.plot(s, g, bg=bg) # plot slab the new way support.check_plot(x) g.legend = (10, 30, 70, 120) support.check_plot(x) g.legend = {0: 'test string1', 50: 'test string2', 100: 'test string3'} support.check_plot(x) g.legend = None support.check_plot(x) if bg == 0: x.geometry(450, 337, 100, 0) # change the geometry and location x.flush() support.check_plot(x) # open and plot a missing data with isofill f = cdms.open(os.path.join(vcs.sample_data, 'tas_cru_1979.nc')) s = f('tas', longitude=(-180, 180), latitude=(-90, 90)) + 273.15 x.clear() # clear the VCS Canvas x.plot( s, 'default', 'isofill', 'quick', bg=bg) # plot missing value slabe the old way support.check_plot(x) a = x.getisofill('quick') # get 'quick' isofill graphics method # test object 'a' for graphics method if not vcs.isgraphicsmethod(a): raise Exception("Error did not retrieve the gm") else: if not vcs.isisofill(a): # check for isofill raise Exception("Error gm is not right type") a.script('test', 'w') # save 'quick' isofill as a Python script x.setcolormap("AMIP") # change the colormap from default to AMIP a.missing = 241 # change the missing background color to black support.check_plot(x) if '--extended' not in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() a.xticlabels('lon30', 'lon30') # change the x-axis support.check_plot(x) a.xticlabels('', '') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change the region support.check_plot(x) a.datawc(1e20, 1e20, 1e20, 1e20) # put the region back support.check_plot(x) a.levels = ([0, 220], [230, 240], [250, 260]) # change the isofill levels support.check_plot(x) # change the isofill levels a.levels = ([0, 220, 225, 230, 235, 240], [230, 240], [250, 260]) support.check_plot(x) a.levels = ([0, 220, 225, 230, 235, 240],) # change the isofill levels support.check_plot(x) # change the isofill levels a.levels = ([0, 220, 225, 230, 235, 240, 245, 250]) support.check_plot(x) a.levels = [0, 220, 225, 230, 235, 240] # change the isofill levels support.check_plot(x) a.levels = ( 0.0, 220.0, 225.0, 230.0, 235.0, 240.0, 250.0) # change the isofill levels support.check_plot(x) a.levels = ([1e20],) # change back to default settings support.check_plot(x) a.levels = ( 0, 220, 225, 230, 235, 240, 250, 260, 270) # change the isofill levels support.check_plot(x) ########################################################################## # Below will produce an error. Later, if needed, I will add this functionality. # # a.levels=('0','20','25','30') # this will produce an error # ########################################################################## a.ext_1 = 'y' # add the extended legend arrow to the left support.check_plot(x) a.ext_1 = 'n' # remove the extended legend arrow to the left support.check_plot(x) a.ext_2 = 'y' # add the extended legend arrow to the right support.check_plot(x) a.ext_2 = 'n' # remove the extended legend arrow to the right support.check_plot(x) a.exts('y', 'y') # add the extended legend arrow to left and right support.check_plot(x) a.exts('n', 'n') # remove the extended legend arrow to left and right support.check_plot(x) a.fillareastyle = 'pattern' # change the fill style to pattern support.check_plot(x) a.fillareastyle = 'hatch' # change the fill style to hatch support.check_plot(x) a.fillareaindices = ([1, 3, 5, 6, 9, 18]) # set the hatch index patterns support.check_plot(x) # set the fill area color indices a.fillareacolors = ([22, 33, 44, 55, 66, 77]) support.check_plot(x) a.fillareacolors = None # use default color indices support.check_plot(x) a.fillareastyle = 'solid' # change the fill style back to solid support.check_plot(x) x.clear() # clear the VCS Canvas x.plot(s, a, 'default', bg=bg) # plot isofill using 'default' template support.check_plot(x) # get the list of templates objs = x.listelements('template') # create template 'test' from 'default' template t = x.createtemplate('test') # test whether 't' is a template or not if not vcs.istemplate(t): raise Exception("Error template not created") else: # get the list of templates a2 = x.listelements('template') if objs == a2: raise Exception("Error template not created or added to list") # show the list of fillarea secondary objects objs = x.listelements('fillarea') f = x.getfillarea('AuTo_1') # get fillarea 'red' # check to see if it is a secondary object if not vcs.issecondaryobject(f): raise Exception("Error did not get fillarea") else: # check to see if it is a fillarea if not vcs.isfillarea(f): raise Exception("Error object created is not fillarea") a.levels = ( 220, 225, 230, 235, 240, 250, 260, 270, 280, 290, 300, 310) # change the isofill levels x.clear() # clear the VCS Canvas x.plot(a, t, s, bg=bg) # plot array using isofill 'a' and template 't' support.check_plot(x) a.fillareaindices = (3, 4, 7, 9, 11) # set the indices support.check_plot(x) a.fillareaindices = ( f, f, f, f, f, f) # set the indices using the fillarea object support.check_plot(x) a.fillareaindices = ( f, 2, 4, 7) # reset the indices using the fillarea object support.check_plot(x) a.fillareaindices = ( 7, f, f, f, 8) # resett the indices using the fillare object support.check_plot(x) f.color = 44 # change the fillarea object's color support.check_plot(x) f.style = 'hatch' # change the fillarea object's fill style support.check_plot(x) x.scriptobject(a, 'test') # save 'quick' isofill as a Python script x.scriptobject(f, 'test') # save 'def37' fill area as a Python script a = x.listelements('isofill') # show list of gm r = x.createisofill('test2', 'quick') # create xyvsy 'test2' a2 = x.listelements('isofill') # show list of gm if a2 == a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('isofill') # show list of gm if a3 != a: raise "error gm not removed" ########################################################################## # to see how x.update and x.mode work, see testisofill.py # ########################################################################## # x.update() # x.mode=1 # x.mode=0 print '*************************************************************************************' print '****** ******' print '****** I S O F I L L T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'
def test(): import vcs,time,support,sys,os # import vcs and cu bg=support.bg x=vcs.init() # construct vcs canvas x.plot('default','continents','ASD',bg=bg)# plot slab the old way support.check_plot(x) if bg==0: x.geometry(450,337,100,0) # change the geometry and location x.flush() support.check_plot(x) obj = x.listelements('continents') # show list of continents a=x.createcontinents('quick') # get 'quick' continents if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error not a gm" else: if not vcs.iscontinents(a): # test object 'a' if continents raise Exception,"Error wrong type of gm" x.clear() x.plot(a,bg=bg) support.check_plot(x) a.script('test','w') # save 'quick' continents as a Python script a.xticlabels('','') # remove the x-axis support.check_plot(x) a.xticlabels('lon30','lon30') # change the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change the region support.check_plot(x) a.datawc(1e20,1e20,1e20,1e20) # put the region back support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() a.line=1 # same as 'dash', change the line style support.check_plot(x) a.line=2 # same as 'dot', change the line style support.check_plot(x) a.line=3 # same as 'dash-dot', change the line style support.check_plot(x) a.line=0 # same as 'solid', change the line style support.check_plot(x) a.line=4 # same as 'long-dash', change the line style support.check_plot(x) a.linecolor=(77) # change the line color support.check_plot(x) a.linecolor=16 # change the line color support.check_plot(x) a.linecolor=44 # same as a.linecolor=(44) support.check_plot(x) a.linecolor=None # use the default line color, black support.check_plot(x) a.line=None # use default line style, solid black line support.check_plot(x) x.clear() # clear the VCS Canvas x.continents(a,'default',bg=bg) # plot continents using 'default' template support.check_plot(x) objs =x.listelements('template') # get the list of templates t=x.createtemplate('test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception,"Error template not created" else: a2 =x.listelements('template') # get the list of templates if objs==a2: raise Exception,"Error template not created or added to list" x.clear() # clear the VCS Canvas x.plot(t,a,bg=bg) # plot continents using template 't', and continents 'a' support.check_plot(x) x.clear() # clear the VCS Canvas x.continents(a,t,bg=bg) # plot continents support.check_plot(x) ######################################################################### # Create line object 'l' from the default line # ######################################################################### objs = x.listelements('line') # show the list of line secondary objects l=x.getline('red') # get line 'red' if not vcs.issecondaryobject(l): # check to see if it is a secondary object raise Exception,"Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" ######################################################################### # Use the create line object 'l' from above and modify the line object # ######################################################################### a.line=l # use the line object support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type ='dash' # change the line type support.check_plot(x) a = x.listelements('continents') # show list of xyvsy r=x.createcontinents('test2','quick') # create xyvsy 'test2' a2 = x.listelements('continents') # show list of xyvsy if a2==a: raise "error gm not created or not added to list" ## x.removeobject(r) # remove xyvsy 'test2' ## a3 = x.listelements('continents') # show list of xyvsy ## if a3!=a: ## raise "error gm not removed" a=x.getcontinents('quick') # get 'quick' boxfill graphics method x.clear() x.plot(a,bg=bg) support.check_plot(x) if support.dogui: x.graphicsmethodgui('continents','quick') # display the continents graphics method GUI ################################################################################# # to see how x.update and x.mode work, see testoutline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*******************************************************************************************' print '****** ******' print '****** C O N T I N E N T S T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*******************************************************************************************'
def plot(self, data, template=None, bg=0, x=None, **kwargs): if x is None: x = self.x if template is None: template = self.template elif isinstance(template, str): template = x.gettemplate(template) elif not vcs.istemplate(template): # pragma: no cover raise ValueError("Error did not know what to do with template: %s" % template) # pragma: no cover try: data_name = data.title except AttributeError: try: data_name = data.long_name except AttributeError: try: data_name = data.id + data.units except AttributeError: try: data_name = data.id except AttributeError: data_name = "array" # We'll just flatten the data... if they want to be more precise, should pass in more precise data if isinstance(data, cdms2.avariable.AbstractVariable): data = data.asma() data = data.flatten() # ok now we have a good x and a good data if not self.bins: self.bins = vcs.utils.mkscale(*vcs.minmax(data)) # Sort the bins self.bins.sort() # Prune duplicates pruned_bins = [] for bin in self.bins: if pruned_bins and numpy.allclose(bin, pruned_bins[-1]): continue pruned_bins.append(bin) self.bins = pruned_bins data_bins = numpy.digitize(data, self.bins) - 1 binned = [data[data_bins==i] for i in range(len(self.bins))] means = [] stds = [] max_possible_deviance = 0 for ind, databin in enumerate(binned): if len(databin) > 0: means.append(databin.mean()) stds.append(databin.std()) else: means.append(0) stds.append(0) if len(self.bins) > ind + 1: max_possible_deviance = max(means[ind] - self.bins[ind], self.bins[ind + 1] - means[ind], max_possible_deviance) else: max_possible_deviance = max(means[ind] - self.bins[ind], max_possible_deviance) color_values = [std / max_possible_deviance for std in stds] y_values = [len(databin) for databin in binned] nbars = len(self.bins) - 1 # create the primitive fill = x.createfillarea() line = x.createline() fill.viewport = [ template.data.x1, template.data.x2, template.data.y1, template.data.y2] line.viewport = [ template.data.x1, template.data.x2, template.data.y1, template.data.y2] vcs_min_max = vcs.minmax(self.bins) if numpy.allclose(self.datawc_x1, 1e20): xmn = vcs_min_max[0] else: xmn = self.datawc_x1 if numpy.allclose(self.datawc_x2, 1e20): xmx = vcs_min_max[1] else: xmx = self.datawc_x2 if numpy.allclose(self.datawc_y2, 1e20): # Make the y scale be slightly larger than the largest bar ymx = max(y_values) * 1.25 else: ymx = self.datawc_y2 if numpy.allclose(self.datawc_y1, 1e20): ymn = 0 else: ymn = self.datawc_y1 fill.worldcoordinate = [xmn, xmx, ymn, ymx] line.worldcoordinate = [xmn, xmx, ymn, ymx] styles = [] cols = [] indices = [] lt = [] lw = [] lc = [] xs = [] ys = [] levels = [.1 * i for i in range(11)] # Extend fillarea and line attrs to levels if self.fillareastyles: while len(self.fillareastyles) < (len(levels) - 1): self.fillareastyles.append(self.fillareastyles[-1]) else: self.fillareastyles = ["solid"] * (len(levels) - 1) if self.fillareacolors: while len(self.fillareacolors) < (len(levels) - 1): self.fillareacolors.append(self.fillareacolors[-1]) else: for lev in levels[:-1]: self.fillareacolors.append(int((self.color_2 - self.color_1) * lev) + self.color_1) if self.fillareaindices: while len(self.fillareaindices) < (len(levels) - 1): self.fillareaindices.append(self.fillareaindices[-1]) else: self.fillareaindices = [1] * (len(levels) - 1) if self.line: while len(self.line) < (len(levels) - 1): self.line.append(self.line[-1]) else: self.line = ["solid"] * (len(levels) - 1) if self.linewidth: while len(self.linewidth) < (len(levels) - 1): self.linewidth.append(self.linewidth[-1]) else: self.linewidth = [1] * (len(levels) - 1) if self.linecolors: while len(self.linecolors) < (len(levels) - 1): self.linecolors.append(self.linecolors[-1]) else: self.linecolors = ["black"] * (len(levels) - 1) for i in range(nbars): # Calculate level for bar value = color_values[i] for lev_ind in range(len(levels)): if levels[lev_ind] > value: if lev_ind > 0: lev_ind -= 1 break else: # Shouldn't ever get here since level 0 is 0 assert False # pragma: no cover else: assert False # pragma: no cover styles.append(self.fillareastyles[lev_ind]) cols.append(self.fillareacolors[lev_ind]) indices.append(self.fillareaindices[lev_ind]) lt.append(self.line[lev_ind]) lw.append(self.linewidth[lev_ind]) lc.append(self.linecolors[lev_ind]) xs.append([self.bins[i], self.bins[i], self.bins[i + 1], self.bins[i + 1]]) ys.append([0, y_values[i], y_values[i], 0]) fill.style = styles fill.x = xs fill.y = ys fill.style fill.index = indices fill.color = cols fill.colormap = self.colormap line.x = xs line.y = ys line.type = lt line.width = lw line.color = lc displays = [] x_axis = cdms2.createAxis(self.bins, id=data_name) y_axis = cdms2.createAxis(vcs.mkscale(ymn, ymx), id="bin_size") displays.append(x.plot(fill, bg=bg, render=False)) arr = MV2.masked_array(y_values) arr.setAxis(0, x_axis) dsp = template.plot(x, arr, self, bg=bg, X=x_axis, Y=y_axis) for d in dsp: if d is not None: displays.append(d) legend_labels = {0: "No Variance", .1: "", .2: "", .3: "", .4: "", .5: "", .6: "", .7: "", .8: "", .9: "", 1: "High Variance"} template.drawColorBar(self.fillareacolors, levels, legend=legend_labels, x=x, style=self.fillareastyles, index=self.fillareaindices) displays.append(x.plot(line, bg=bg)) x.worldcoordinate = fill.worldcoordinate self.restore() return displays
def test(): import vcs, cdms2 as cdms, time, os, sys, support # import vcs and cu bg = support.bg f = cdms.open( os.path.join(cdms.__path__[0], '..', '..', '..', '..', 'sample_data', 'clt.nc')) # open clt file s = f('clt') # get slab clt x = vcs.init() # construct vcs canvas x.plot(s, 'default', 'isoline', 'quick', bg=support.bg) # plot slab the old way support.check_plot(x) if bg == 0: x.geometry(450, 337, 0, 0) # change geometry and location support.check_plot(x) x.geometry(900, 675, 10, 0) # change geometry and location support.check_plot(x) x.flush() support.check_plot(x) a = x.getisoline('quick') # get 'quick' isoline graphics method if not vcs.isgraphicsmethod(a): # test object 'a' for graphics method raise Exception, "Error did not retrieve the gm" else: if not vcs.isisoline(a): # check for isoline raise Exception, "Error gm is not right type" a.script('test', 'w') # save 'quick' isoline as a Python script a.xticlabels('lon30', 'lon30') # change the x-axis support.check_plot(x) a.xticlabels('', '') # remove the x-axis support.check_plot(x) a.xticlabels('*') # put the x-axis back support.check_plot(x) a.datawc(-45.0, 45.0, -90.0, 90.0) # change the region support.check_plot(x) a.datawc(1e20, 1e20, 1e20, 1e20) # put the region back support.check_plot(x) if not '--extended' in sys.argv: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ######################################################################### # Set the isoline level vales # ######################################################################### a.level = ([20, 0.0], [30, 0], [50, 0], [60, 0]) # change the isoline values support.check_plot(x) a.level = [[20, 0.0], [30, 0], [50, 0]] # change the isoline values support.check_plot(x) a.level = ((20, 0.0), (30, 0), (50, 0), (60, 0), (70, 0) ) # change the isoline values support.check_plot(x) a.level = (25, 35, 45, 55) # change the isoline values support.check_plot(x) a.level = [(22, 33, 44, 55, 66)] # change the isoline values support.check_plot(x) a.level = [ (23, 32, 45, 50, 76), ] # change the isoline values support.check_plot(x) a.level = [0] # same as a.level=(0,) support.check_plot(x) a.level = [[0, 1e20]] # same as a.level=((0,1e20),), use default settings support.check_plot(x) ######################################################################### # Turn on and off the isoline level labels # ######################################################################### a.label = 'y' # same as a.label=1 support.check_plot(x) a.label = 'n' # same as a.label=0 support.check_plot(x) ######################################################################### # Set the line style and line color # ######################################################################### a.level = ((20, 0.0), (30, 0), (50, 0), (60, 0), (70, 0) ) # change the isoline values support.check_plot(x) a.line = [1, 3, 0, 4] # same as a.line=(1,3,0,4) support.check_plot(x) a.line = (['dash', 'long-dash', 'solid']) # same as a.line=([2,4,0]) support.check_plot(x) a.line = [2, 4, 1, 3, 2, 0] support.check_plot(x) a.linecolors = ([22, 33, 44, 55, 66, 77]) # change the line color support.check_plot(x) a.linecolors = (16, 19, 33, 44) # change the line color support.check_plot(x) a.linecolors = None # use the default line color support.check_plot(x) a.line = None # use the default line style, which is solid support.check_plot(x) ######################################################################### # Set the text font and text color # ######################################################################### a.label = 'y' # same as a.label=1 support.check_plot(x) a.text = (1, 2, 3, 4, 5, 6, 7, 8, 9) # select fonts from 1 through 9 support.check_plot(x) a.text = [9, 8, 7, 6, 5, 4, 3, 2, 1] support.check_plot(x) a.text = ([1, 3, 5, 6, 9, 2]) support.check_plot(x) a.textcolors = ([22, 33, 44, 55, 66, 77]) # set the text color support.check_plot(x) a.textcolors = (16, 19, 33, 44) support.check_plot(x) a.textcolors = None # use default text color, black support.check_plot(x) a.text = None # use default font, 1 support.check_plot(x) ######################################################################### # Create template 'test' from the default template # ######################################################################### objs = x.listelements('template') # get the list of templates t = x.createtemplate( 'test') # create template 'test' from 'default' template if not vcs.istemplate(t): # test whether 't' is a template or not raise Exception, "Error template not created" else: a2 = x.listelements('template') # get the list of templates if objs == a2: raise Exception, "Error template not created or added to list" ######################################################################### # Create line object 'l' from the default line # ######################################################################### l = x.createline('test') objs = x.listelements('line') # show the list of line secondary objects if not vcs.issecondaryobject( l): # check to see if it is a secondary object raise Exception, "Error did not get line" else: if not vcs.isline(l): # check to see if it is a line raise Exception, "Error object created is not line" x.clear() # clear the VCS Canvas x.isoline( s, a, t, bg=support.bg) # plot the array using the template and isoline object support.check_plot(x) x.clear() # clear the VCS Canvas x.plot(t, a, s, bg=support.bg) # plot again using the new way support.check_plot(x) ######################################################################### # Use the create line object 'l' from above and modify the line object # ######################################################################### a.line = [1, 3, 0, 4] # same as a.line=(1,3,0,4) support.check_plot(x) a.line = ([2, 4, 0]) # same as a.line=(['dash', 'long-dash', 'solid']) support.check_plot(x) a.line = (l, 4, l, 0) # use the line object support.check_plot(x) a.line = (l, 3, 4, 2, 0) support.check_plot(x) l.color = 44 # change the line color support.check_plot(x) l.type = 'dash' # change the line type support.check_plot(x) ######################################################################### # Create the three types of text objects # ######################################################################### tc = x.createtextcombined('testc', 'std', 'testc', '7left') if not vcs.istextcombined(tc): raise Exception, "Error not textcombined!" tt = x.createtexttable('testt', 'default') if not vcs.istexttable(tt): raise Exception, "Error not texttable" to = x.createtextorientation('testo') if not vcs.istextorientation(to): raise Exception, "Error not textorientation" ######################################################################### # Use the text objects in the isoline plot # ######################################################################### a.label = 'y' # make sure that the labels are turn on support.check_plot(x) a.text = ([1, 3, 5, 6, 9, 2]) # set the font support.check_plot(x) a.text = ([tc, tt, to, 6, 9, 2]) # use the created text objects and fonts support.check_plot(x) ######################################################################### # Change the text object values # ######################################################################### tc.font = 3 # changing isoline level 20 support.check_plot(x) tc.height = 15 support.check_plot(x) tc.angle = 180 support.check_plot(x) tc.color = 242 support.check_plot(x) tt.font = 2 # changing isoline level 30 support.check_plot(x) tt.spacing = 20 support.check_plot(x) to.height = 15 # changing isoline level 50 support.check_plot(x) to.path = 'down' support.check_plot(x) a.text = None # use default font, which is font 1 support.check_plot(x) a.line = None # use default line, which is solid support.check_plot(x) a = x.listelements('isoline') # show list of gm r = x.createisoline('test2', 'quick') # create xyvsy 'test2' a2 = x.listelements('isoline') # show list of gm if a2 == a: raise "error gm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('isoline') # show list of gm if a3 != a: raise "error gm not removed" ################################################################################# # to see how x.update and x.mode work, see testisoline.py # ################################################################################# #x.update() #x.mode=1 #x.mode=0 print '*************************************************************************************' print '****** ******' print '****** I S O L I N E T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '*************************************************************************************'