示例#1
0
def prepPrimitive(prim):
    if prim.x is None or prim.y is None:
        return 0
    if not isinstance(prim.x[0], (list, tuple)):
        prim.x = [
            prim.x,
        ]
    if not isinstance(prim.y[0], (list, tuple)):
        prim.y = [
            prim.y,
        ]
    if vcs.isfillarea(prim):
        atts = ["x", "y", "color", "style", "index"]
    elif vcs.ismarker(prim):
        atts = ["x", "y", "color", "size", "type"]
    elif vcs.isline(prim):
        atts = ["x", "y", "color", "width", "type"]
    n = 0
    for a in atts:
        n = max(n, len(getattr(prim, a)))
    for a in atts:
        v = getattr(prim, a)
        while len(v) < n:
            v.append(v[-1])
        setattr(prim, a, v)
    return n
示例#2
0
def prepPrimitive(prim):
  if prim.x is None or prim.y is None:
    return 0
  if not isinstance(prim.x[0],(list,tuple)):
    prim.x = [prim.x,]
  if not isinstance(prim.y[0],(list,tuple)):
    prim.y = [prim.y,]
  if vcs.isfillarea(prim):
    atts = ["x","y","color","style","index"]
  elif vcs.ismarker(prim):
    atts = ["x","y","color","size","type"]
  elif vcs.isline(prim):
    atts = ["x","y","color","width","type"]
  n=0
  for a in atts:
    n = max(n,len(getattr(prim,a)))
  for a in atts:
    v = getattr(prim,a)
    while len(v)<n:
      v.append(v[-1])
    setattr(prim,a,v)
  return n
示例#3
0
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
示例#4
0
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 '*************************************************************************************'
示例#5
0
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 '*************************************************************************************'