From 50ab5bc082e70ff2822dcd123a4032bd4905babb Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Tue, 23 Aug 2016 17:52:23 -0700 Subject: [PATCH 1/8] Fixing indentation in Canvas.py --- vcs/Canvas.py | 2395 ++++++++++++++++++++++++------------------------- 1 file changed, 1181 insertions(+), 1214 deletions(-) diff --git a/vcs/Canvas.py b/vcs/Canvas.py index 0e458b8cf..5cf1d267c 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -784,18 +784,18 @@ def _reconstruct_tv(self, arglist, keyargs): def objecthelp(self, *arg): """ - Print out information on the VCS object. See example below on its use. + Print out information on the VCS object. See example below on its use. - :Example: + :Example: - :: + :: - a=vcs.init() - # Get a VCS line object - ln=a.getline('red') - # This will print out information on how to use ln - a.objecthelp(ln) - """ + a=vcs.init() + # Get a VCS line object + ln=a.getline('red') + # This will print out information on how to use ln + a.objecthelp(ln) + """ for x in arg: print getattr(x, "__doc__", "") @@ -953,80 +953,79 @@ def initLogoDrawing(self): def update(self, *args, **kargs): """ - If a series of commands are given to VCS and the Canvas Mode is - set to manual, then use this function to update the plot(s) - manually. - - :Example: - - :: - - a=vcs.init() - a.plot(s,'default','boxfill','quick') - # Go to manual mode - a.mode = 0 - box=x.getboxfill('quick') - box.color_1=100 - box.xticlabels('lon30','lon30') - box.xticlabels('','') - box.datawc(1e20,1e20,1e20,1e20) - box.datawc(-45.0, 45.0, -90.0, 90.0) - # Update the changes manually - a.update() -""" + If a series of commands are given to VCS and the Canvas Mode is + set to manual, then use this function to update the plot(s) + manually. - return self.backend.update(*args, **kargs) - - def scriptobject(self, obj, script_filename=None, mode=None): - """ - Save individual attributes sets (i.e., individual primary class - objects and/or secondary class objects). These attribute sets - are saved in the user's current directory in one of two formats: - Python script, or a Javascript Object. + :Example: - .. note:: - If the the filename has a ".py" at the end, it will produce a - Python script. If the filename has a ".scr" at the end, it will - produce a VCS script. If neither extensions are given, then by - default a Javascript Object will be produced. + :: - .. attention:: - VCS does not allow the modification of 'default' attribute sets, - it will not allow them to be saved as individual script files. - However, a 'default' attribute set that has been copied under a - different name can be saved as a script file. + a=vcs.init() + a.plot(s,'default','boxfill','quick') + # Go to manual mode + a.mode = 0 + box=x.getboxfill('quick') + box.color_1=100 + box.xticlabels('lon30','lon30') + box.xticlabels('','') + box.datawc(1e20,1e20,1e20,1e20) + box.datawc(-45.0, 45.0, -90.0, 90.0) + # Update the changes manually + a.update() + """ - .. admonition:: VCS Scripts Deprecated + return self.backend.update(*args, **kargs) - SCR scripts are no longer generated by this function + def scriptobject(self, obj, script_filename=None, mode=None): + """ + Save individual attributes sets (i.e., individual primary class + objects and/or secondary class objects). These attribute sets + are saved in the user's current directory in one of two formats: + Python script, or a Javascript Object. + .. note:: + If the the filename has a ".py" at the end, it will produce a + Python script. If the filename has a ".scr" at the end, it will + produce a VCS script. If neither extensions are given, then by + default a Javascript Object will be produced. + .. attention:: - :Example: + VCS does not allow the modification of 'default' attribute sets, + it will not allow them to be saved as individual script files. + However, a 'default' attribute set that has been copied under a + different name can be saved as a script file. - :: + .. admonition:: VCS Scripts Deprecated - a=vcs.init() - # To Modify an existing line object - l=a.getline('red') - # Create an instance of default isoline object - i=a.createisoline('dean') - #... - # Save isoline object as a Python file 'isoline.py' - a.scriptobject(i,'ex_isoline.py') - # Save isoline object as a JSON object 'isoline2.json' - a.scriptobject(i,'ex_isoline2') + SCR scripts are no longer generated by this function -:param script_filename: Name of the output script file. -:type script_filename: str + :Example: -:param mode: Mode is either "w" for replace or "a" for append. -:type mode: str + :: -:param obj: Any VCS primary class or secondary class object. -:type obj: VCS object -""" + a=vcs.init() + # To Modify an existing line object + l=a.getline('red') + # Create an instance of default isoline object + i=a.createisoline('dean') + #... + # Save isoline object as a Python file 'isoline.py' + a.scriptobject(i,'ex_isoline.py') + # Save isoline object as a JSON object 'isoline2.json' + a.scriptobject(i,'ex_isoline2') + + :param script_filename: Name of the output script file. + :type script_filename: str + + :param mode: Mode is either "w" for replace or "a" for append. + :type mode: str + + :param obj: Any VCS primary class or secondary class object. + :type obj: VCS object + """ if istemplate(obj): template.P.script(obj, script_filename, mode) elif isgraphicsmethod(obj): @@ -1073,24 +1072,15 @@ def scriptobject(self, obj, script_filename=None, mode=None): print 'This is not a template, graphics method or secondary method object.' def removeobject(self, obj): - """ - Removes a VCS object from the cache of available objects that can be referred to by name. - - :param obj: The VCS object to be removed. - :type obj: a VCS object - - :returns: A string stating the object was removed, its type, and its name - :rtype: str - """ - __doc__ = vcs.removeobject.__doc__ # noqa return vcs.removeobject(obj) + removeobject.__doc__ = vcs.removeobject.__doc__ # noqa def removeP(self, *args): return vcs.removeP(*args) def clean_auto_generated_objects(self, type=None): """ - Cleans up all automaticaly generated VCS objects. + Cleans up all automatically generated VCS objects. This function will delete all references to objects that VCS created automatically in response to user actions but are @@ -1167,11 +1157,6 @@ def createboxfill(self, name=None, source='default'): createboxfill.__doc__ = vcs.manageElements.createboxfill.__doc__ def getboxfill(self, Gfb_name_src='default'): - """ - - :param Gfb_name_src: - :return: - """ return vcs.getboxfill(Gfb_name_src) getboxfill.__doc__ = vcs.manageElements.getboxfill @@ -1214,12 +1199,12 @@ def boxfill(self, *args, **parms): # Use 'AMIP' template and 'quick' boxfill a.boxfill('AMIP','quick',array) -%s -%s -%s -%s -%s -""" + %s + %s + %s + %s + %s + """ arglist = _determine_arg_list('boxfill', args) return self.__plot(arglist, parms) boxfill.__doc__ = boxfill.__doc__ % ( @@ -1244,18 +1229,18 @@ def taylordiagram(self, *args, **parms): :: - a=vcs.init() - # Show all the existing taylordiagram graphics methods - a.show('taylordiagram') - # Create instance of 'default' - td=a.gettaylordiagram() - # Plot array using specified iso and default template - a.taylordiagram(array,td) - # Clear VCS canvas - a.clear() - # Plot array using specified iso and template - a.taylordiagram(array,td,template) -""" + a=vcs.init() + # Show all the existing taylordiagram graphics methods + a.show('taylordiagram') + # Create instance of 'default' + td=a.gettaylordiagram() + # Plot array using specified iso and default template + a.taylordiagram(array,td) + # Clear VCS canvas + a.clear() + # Plot array using specified iso and template + a.taylordiagram(array,td,template) + """ arglist = _determine_arg_list('taylordiagram', args) return self.__plot(arglist, parms) @@ -1269,44 +1254,44 @@ def getmeshfill(self, Gfm_name_src='default'): def meshfill(self, *args, **parms): # noqa """ - Generate a meshfill plot given the data, the mesh, a meshfill graphics method, and - a template. If no meshfill class object is given, then the 'default' meshfill - graphics method is used. Similarly, if no template class object is given, - then the 'default' template is used. - - Format: - This function expects 1D data (any extra dimension will be used for animation) - In addition the mesh array must be of the same shape than data with 2 additional dimension - representing the vertices coordinates for the Y (0) and X (1) dimension - Let's say you want to plot a spatial assuming mesh containing 10,000 grid cell, then data must be shape (10000,) - or (n1,n2,n3,...,10000) if additional dimensions exist (ex time,level), these dimension would be used only - for animation and will be ignored in the rest of this example. - The shape of the mesh, assuming 4 vertices per grid cell, must be (1000,2,4), where the array [:,0,:] - represent the Y coordinates of the vertices (clockwise or counterclockwise) and the array [:,1:] - represents the X coordinates of the vertices (the same clockwise/counterclockwise than the Y coordinates) - In brief you'd have: - data.shape=(10000,) - mesh.shape=(10000,2,4) - - :Example: + Generate a meshfill plot given the data, the mesh, a meshfill graphics method, and + a template. If no meshfill class object is given, then the 'default' meshfill + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. + + Format: + This function expects 1D data (any extra dimension will be used for animation) + In addition the mesh array must be of the same shape than data with 2 additional dimension + representing the vertices coordinates for the Y (0) and X (1) dimension + Let's say you want to plot a spatial assuming mesh containing 10,000 grid cell, then data must be shape (10000,) + or (n1,n2,n3,...,10000) if additional dimensions exist (ex time,level), these dimension would be used only + for animation and will be ignored in the rest of this example. + The shape of the mesh, assuming 4 vertices per grid cell, must be (1000,2,4), where the array [:,0,:] + represent the Y coordinates of the vertices (clockwise or counterclockwise) and the array [:,1:] + represents the X coordinates of the vertices (the same clockwise/counterclockwise than the Y coordinates) + In brief you'd have: + data.shape=(10000,) + mesh.shape=(10000,2,4) + + :Example: :: - a=vcs.init() - # Show all the existing meshfill graphics methods - a.show('meshfill') - # Create instance of 'default' - mesh=a.getmeshfill() - # Plot array using specified mesh and default template - a.meshfill(array,mesh) - # Clear VCS canvas - a.clear() - # Plot array using specified mesh mesh graphic method and template - a.meshfill(array,mesh,mesh_graphic_method,template) - -:returns: ??? -:rtype: ??? -""" + a=vcs.init() + # Show all the existing meshfill graphics methods + a.show('meshfill') + # Create instance of 'default' + mesh=a.getmeshfill() + # Plot array using specified mesh and default template + a.meshfill(array,mesh) + # Clear VCS canvas + a.clear() + # Plot array using specified mesh mesh graphic method and template + a.meshfill(array,mesh,mesh_graphic_method,template) + + :returns: ??? + :rtype: ??? + """ arglist = _determine_arg_list('meshfill', args) return self.__plot(arglist, parms) @@ -1350,8 +1335,6 @@ def dual_scalar3d(self, *args, **parms): return self.__plot(arglist, parms) def createisofill(self, name=None, source='default'): - """ - """ return vcs.createisofill(name, source) createisofill.__doc__ = vcs.manageElements.createisofill.__doc__ @@ -1361,33 +1344,33 @@ def getisofill(self, Gfi_name_src='default'): def isofill(self, *args, **parms): """ - Generate a isofill plot given the data, isofill graphics method, and - template. If no isofill class object is given, then the 'default' isofill - graphics method is used. Similarly, if no template class object is given, - then the 'default' template is used. - - :Example: - - :: - - a=vcs.init() - # Show all the existing isofill graphics methods - a.show('isofill') - # Create instance of 'quick' - iso=a.getisofill('quick') - # Plot array using specified iso and default template - a.isofill(array,iso) - # Clear VCS canvas - a.clear() - # Plot array using specified iso and template - a.isofill(array,iso,template) - - %s - %s - %s - %s - %s -""" + Generate a isofill plot given the data, isofill graphics method, and + template. If no isofill class object is given, then the 'default' isofill + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. + + :Example: + + :: + + a=vcs.init() + # Show all the existing isofill graphics methods + a.show('isofill') + # Create instance of 'quick' + iso=a.getisofill('quick') + # Plot array using specified iso and default template + a.isofill(array,iso) + # Clear VCS canvas + a.clear() + # Plot array using specified iso and template + a.isofill(array,iso,template) + + %s + %s + %s + %s + %s + """ arglist = _determine_arg_list('isofill', args) return self.__plot(arglist, parms) isofill.__doc__ = isofill.__doc__ % ( @@ -1403,32 +1386,32 @@ def getisoline(self, Gi_name_src='default'): def isoline(self, *args, **parms): """ - Generate a isoline plot given the data, isoline graphics method, and - template. If no isoline class object is given, then the 'default' isoline - graphics method is used. Similarly, if no template class object is given, - then the 'default' template is used. + Generate a isoline plot given the data, isoline graphics method, and + template. If no isoline class object is given, then the 'default' isoline + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing isoline graphics methods - a.show('isoline') - # Create instance of 'quick' - iso=a.getisoline('quick') - # Plot array using specified iso and default template - a.isoline(array,iso) - # Clear VCS canvas - a.clear() - # Plot array using specified iso and template - a.isoline(array,iso,template) - -%s -%s -%s -%s -%s + a=vcs.init() + # Show all the existing isoline graphics methods + a.show('isoline') + # Create instance of 'quick' + iso=a.getisoline('quick') + # Plot array using specified iso and default template + a.isoline(array,iso) + # Clear VCS canvas + a.clear() + # Plot array using specified iso and template + a.isoline(array,iso,template) + + %s + %s + %s + %s + %s """ arglist = _determine_arg_list('isoline', args) return self.__plot(arglist, parms) @@ -1453,33 +1436,33 @@ def getxyvsy(self, GXy_name_src='default'): def xyvsy(self, *args, **parms): """ - Generate a Xyvsy plot given the data, Xyvsy graphics method, and - template. If no Xyvsy class object is given, then the 'default' Xyvsy - graphics method is used. Simerly, if no template class object is given, - then the 'default' template is used. + Generate a Xyvsy plot given the data, Xyvsy graphics method, and + template. If no Xyvsy class object is given, then the 'default' Xyvsy + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing Xyvsy graphics methods - a.show('xyvsy') - # Create instance of 'quick' - xyy=a.getxyvsy('quick') - # Plot array using specified xyy and default template - a.xyvsy(array,xyy) - # Clear VCS canvas - a.clear() - # Plot array using specified xyy and template - a.xyvsy(array,xyy,template) - -%s -%s -%s -%s -%s -""" + a=vcs.init() + # Show all the existing Xyvsy graphics methods + a.show('xyvsy') + # Create instance of 'quick' + xyy=a.getxyvsy('quick') + # Plot array using specified xyy and default template + a.xyvsy(array,xyy) + # Clear VCS canvas + a.clear() + # Plot array using specified xyy and template + a.xyvsy(array,xyy,template) + + %s + %s + %s + %s + %s + """ arglist = _determine_arg_list('xyvsy', args) return self.__plot(arglist, parms) xyvsy.__doc__ = xyvsy.__doc__ % ( @@ -1495,33 +1478,33 @@ def getyxvsx(self, GYx_name_src='default'): def yxvsx(self, *args, **parms): """ - Generate a Yxvsx plot given the data, Yxvsx graphics method, and - template. If no Yxvsx class object is given, then the 'default' Yxvsx - graphics method is used. Simerly, if no template class object is given, - then the 'default' template is used. + Generate a Yxvsx plot given the data, Yxvsx graphics method, and + template. If no Yxvsx class object is given, then the 'default' Yxvsx + graphics method is used. Simerly, if no template class object is given, + then the 'default' template is used. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing Yxvsx graphics methods - a.show('yxvsx') - # Create instance of 'quick' - yxx=a.getyxvsx('quick') - # Plot array using specified yxx and default template - a.yxvsx(array,yxx) - # Clear VCS canvas - a.clear() - # Plot array using specified yxx and template - a.yxvsx(array,yxx,template) - -%s -%s -%s -%s -%s -""" + a=vcs.init() + # Show all the existing Yxvsx graphics methods + a.show('yxvsx') + # Create instance of 'quick' + yxx=a.getyxvsx('quick') + # Plot array using specified yxx and default template + a.yxvsx(array,yxx) + # Clear VCS canvas + a.clear() + # Plot array using specified yxx and template + a.yxvsx(array,yxx,template) + + %s + %s + %s + %s + %s + """ arglist = _determine_arg_list('yxvsx', args) return self.__plot(arglist, parms) yxvsx.__doc__ = yxvsx.__doc__ % ( @@ -1537,33 +1520,33 @@ def getxvsy(self, GXY_name_src='default'): def xvsy(self, *args, **parms): """ - Generate a XvsY plot given the data, XvsY graphics method, and - template. If no XvsY class object is given, then the 'default' XvsY - graphics method is used. Similarly, if no template class object is given, - then the 'default' template is used. + Generate a XvsY plot given the data, XvsY graphics method, and + template. If no XvsY class object is given, then the 'default' XvsY + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing XvsY graphics methods - a.show('xvsy') - # Create instance of 'quick' - xy=a.getxvsy('quick') - # Plot array using specified xy and default template - a.xvsy(array,xy) - # Clear VCS canvas - a.clear() - # Plot array using specified xy and template - a.xvsy(array,xy,template) - -%s -%s -%s -%s -%s -""" + a=vcs.init() + # Show all the existing XvsY graphics methods + a.show('xvsy') + # Create instance of 'quick' + xy=a.getxvsy('quick') + # Plot array using specified xy and default template + a.xvsy(array,xy) + # Clear VCS canvas + a.clear() + # Plot array using specified xy and template + a.xvsy(array,xy,template) + + %s + %s + %s + %s + %s + """ arglist = _determine_arg_list('xvsy', args) return self.__plot(arglist, parms) xvsy.__doc__ = xvsy.__doc__ % (plot_keywords_doc, @@ -1582,27 +1565,27 @@ def getvector(self, Gv_name_src='default'): def vector(self, *args, **parms): """ - Generate a vector plot given the data, vector graphics method, and - template. If no vector class object is given, then the 'default' vector - graphics method is used. Similarly, if no template class object is given, - then the 'default' template is used. + Generate a vector plot given the data, vector graphics method, and + template. If no vector class object is given, then the 'default' vector + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing vector graphics methods - a.show('vector') - # Create instance of 'quick' - vec=a.getvector('quick') - # Plot array using specified vec and default template - a.vector(array,vec) - # Clear VCS canvas - a.clear() - # Plot array using specified vec and template - a.vector(array,vec,template) -""" + a=vcs.init() + # Show all the existing vector graphics methods + a.show('vector') + # Create instance of 'quick' + vec=a.getvector('quick') + # Plot array using specified vec and default template + a.vector(array,vec) + # Clear VCS canvas + a.clear() + # Plot array using specified vec and template + a.vector(array,vec,template) + """ arglist = _determine_arg_list('vector', args) return self.__plot(arglist, parms) @@ -1616,33 +1599,33 @@ def getscatter(self, GSp_name_src='default'): def scatter(self, *args, **parms): """ - Generate a scatter plot given the data, scatter graphics method, and - template. If no scatter class object is given, then the 'default' scatter - graphics method is used. Similarly, if no template class object is given, - then the 'default' template is used. + Generate a scatter plot given the data, scatter graphics method, and + template. If no scatter class object is given, then the 'default' scatter + graphics method is used. Similarly, if no template class object is given, + then the 'default' template is used. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing scatter graphics methods - a.show('scatter') - # Create instance of 'quick' - sct=a.getscatter('quick') - # Plot array using specified sct and default template - a.scatter(array,sct) - # Clear VCS canvas - a.clear() - # Plot array using specified sct and template - a.scatter(array,sct,template) - -%s -%s -%s -%s -%s -""" + a=vcs.init() + # Show all the existing scatter graphics methods + a.show('scatter') + # Create instance of 'quick' + sct=a.getscatter('quick') + # Plot array using specified sct and default template + a.scatter(array,sct) + # Clear VCS canvas + a.clear() + # Plot array using specified sct and template + a.scatter(array,sct,template) + + %s + %s + %s + %s + %s + """ arglist = _determine_arg_list('scatter', args) return self.__plot(arglist, parms) @@ -1667,32 +1650,31 @@ def getline(self, name='default', ltype=None, width=None, color=None, def line(self, *args, **parms): """ - Plot a line segment on the Vcs Canvas. If no line class - object is given, then an error will be returned. + Plot a line segment on the Vcs Canvas. If no line class + object is given, then an error will be returned. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing line objects - a.show('line') - # Create instance of 'red' - ln=a.getline('red') - # Set the line width - ln.width=4 - # Set the line color - ln.color = 242 - # Set the line type - ln.type = 4 - # Set the x value points - ln.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - ln.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified line object - a.line(ln) - -""" + a=vcs.init() + # Show all the existing line objects + a.show('line') + # Create instance of 'red' + ln=a.getline('red') + # Set the line width + ln.width=4 + # Set the line color + ln.color = 242 + # Set the line type + ln.type = 4 + # Set the x value points + ln.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] + # Set the y value points + ln.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] + # Plot using specified line object + a.line(ln) + """ arglist = _determine_arg_list('line', args) return self.__plot(arglist, parms) @@ -1701,59 +1683,60 @@ def drawline(self, name=None, ltype='solid', width=1, color=241, # noqa worldcoordinate=[0.0, 1.0, 0.0, 1.0], x=None, y=None, projection='default', bg=0): """ - Generate and draw a line object on the VCS Canvas. - - :Example: - - :: + Generate and draw a line object on the VCS Canvas. - a=vcs.init() - # Show all the existing line objects - a.show('line') - # Create instance of line object 'red' - ln=a.drawline(name='red', ltype='dash', width=2, - color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50], - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified line object - a.line(ln) + :Example: + :: -:param name: Name of created object -:type name: str + a=vcs.init() + # Show all the existing line objects + a.show('line') + # Create instance of line object 'red' + ln=a.drawline(name='red', ltype='dash', width=2, + color=242, priority=1, viewport=[0, 1.0, 0, 1.0], + worldcoordinate=[0,100, 0,50], + x=[0,20,40,60,80,100], + y=[0,10,20,30,40,50] ) + # Plot using specified line object + a.line(ln) + + :param name: Name of created object + :type name: str -:param ltype: One of "dash", "dash-dot", "solid", "dot", or "long-dash". -:type ltype: str + :param ltype: One of "dash", "dash-dot", "solid", "dot", or "long-dash". + :type ltype: str -:param width: Thickness of the line to be drawn -:type width: int + :param width: Thickness of the line to be drawn + :type width: int -:param color: A color name from the `X11 Color Names list `_, - or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) -:type color: str or int + :param color: A color name from the `X11 Color Names list `_, + or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) + :type color: str or int -:param priority: The layer on which the line will be drawn. -:type priority: int + :param priority: The layer on which the line will be drawn. + :type priority: int -:param viewport: 4 floats between 0 and 1. These specify the area that the X/Y values are mapped to inside of the canvas -:type viewport: list of floats + :param viewport: 4 floats between 0 and 1. + These specify the area that the X/Y values are mapped to inside of the canvas + :type viewport: list of floats -:param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) -:type worldcoordinate: list of floats + :param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) + :type worldcoordinate: list of floats -:param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. -:type x: list of floats + :param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. + :type x: list of floats -:param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. -:type y: list of floats + :param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. + :type y: list of floats -:param projection: Specify a geographic projection used to convert x/y from spherical coordinates into 2D coordinates. -:type projection: str or projection object + :param projection: Specify a geographic projection used to convert x/y + from spherical coordinates into 2D coordinates. + :type projection: str or projection object -:returns: A VCS line object -:rtype: vcs.line.Tl -""" + :returns: A VCS line object + :rtype: vcs.line.Tl + """ if (name is None) or (not isinstance(name, str)): raise vcsError('Must provide string name for the line.') else: @@ -1796,9 +1779,9 @@ def marker(self, *args, **parms): Plot a marker segment on the Vcs Canvas. If no marker class object is given, then an error will be returned. - :Example: + :Example: - :: + :: a=vcs.init() # Show all the existing marker objects @@ -1818,8 +1801,8 @@ def marker(self, *args, **parms): # Plot using specified marker object a.marker(mrk) -:returns: a VCS displayplot object -:rtype: vcs.displayplot.Dp + :returns: a VCS displayplot object + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('marker', args) return self.__plot(arglist, parms) @@ -1835,50 +1818,50 @@ def drawmarker(self, name=None, mtype='solid', size=1, color=241, :: - a=vcs.init() - # Show all the existing marker objects - a.show('marker') - # Create instance of marker object 'red' - mrk=a.drawmarker(name='red', mtype='dot', size=2, - color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified marker object - a.marker(mrk) - + a=vcs.init() + # Show all the existing marker objects + a.show('marker') + # Create instance of marker object 'red' + mrk=a.drawmarker(name='red', mtype='dot', size=2, + color=242, priority=1, viewport=[0, 1.0, 0, 1.0], + worldcoordinate=[0,100, 0,50] + x=[0,20,40,60,80,100], + y=[0,10,20,30,40,50] ) + # Plot using specified marker object + a.marker(mrk) -:param name: Name of created object -:type name: str + :param name: Name of created object + :type name: str -:param mtype: Marker type, i.e. 'dot', 'plus', 'star, etc. -:type mtype: str + :param mtype: Marker type, i.e. 'dot', 'plus', 'star, etc. + :type mtype: str -:param size: Size of the marker to draw -:type size: int + :param size: Size of the marker to draw + :type size: int -:param color: A color name from the `X11 Color Names list `_, - or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) -:type color: str or int + :param color: A color name from the `X11 Color Names list `_, + or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) + :type color: str or int -:param priority: The layer on which the marker will be drawn. -:type priority: int + :param priority: The layer on which the marker will be drawn. + :type priority: int -:param viewport: 4 floats between 0 and 1. These specify the area that the X/Y values are mapped to inside of the canvas -:type viewport: list of floats + :param viewport: 4 floats between 0 and 1. + These specify the area that the X/Y values are mapped to inside of the canvas + :type viewport: list of floats -:param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) -:type worldcoordinate: list of floats + :param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) + :type worldcoordinate: list of floats -:param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. -:type x: list of floats + :param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. + :type x: list of floats -:param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. -:type y: list of floats + :param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. + :type y: list of floats -:returns: A drawmarker object -:rtype: vcs.marker.Tm -""" + :returns: A drawmarker object + :rtype: vcs.marker.Tm + """ if (name is None) or (not isinstance(name, str)): raise vcsError('Must provide string name for the marker.') else: @@ -1918,38 +1901,38 @@ def getfillarea(self, name='default', style=None, def fillarea(self, *args, **parms): """ - Generate a fillarea plot + Generate a fillarea plot - Plot a fillarea segment on the Vcs Canvas. If no fillarea class - object is given, then an error will be returned. + Plot a fillarea segment on the Vcs Canvas. If no fillarea class + object is given, then an error will be returned. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing fillarea objects - a.show('fillarea') - # Create instance of 'red' - fa=a.createfillarea('red') - # Set the fillarea style - fa.style=1 - # Set the fillarea index - fa.index=4 - # Set the fillarea color - fa.color = 242 - # Set the fillarea type - fa.type = 4 - # Set the x value points - fa.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - fa.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified fillarea object - a.fillarea(fa) - -:returns: A fillarea object -:rtype: vcs.displayplot.Dp -""" + a=vcs.init() + # Show all the existing fillarea objects + a.show('fillarea') + # Create instance of 'red' + fa=a.createfillarea('red') + # Set the fillarea style + fa.style=1 + # Set the fillarea index + fa.index=4 + # Set the fillarea color + fa.color = 242 + # Set the fillarea type + fa.type = 4 + # Set the x value points + fa.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] + # Set the y value points + fa.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] + # Plot using specified fillarea object + a.fillarea(fa) + + :returns: A fillarea object + :rtype: vcs.displayplot.Dp + """ arglist = _determine_arg_list('fillarea', args) return self.__plot(arglist, parms) @@ -1961,58 +1944,60 @@ def drawfillarea(self, name=None, style=1, index=1, color=241, Generate and draw a fillarea object on the VCS Canvas. :Example: -:: - - a=vcs.init() - # Show all the existing fillarea objects - a.show('fillarea') - # Create instance of fillarea object 'red' - fa=a.drawfillarea(name='red', style=1, color=242, - priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50], bg=0 ) - # Plot using specified fillarea object - a.fillarea(fa) + :: -:param name: Name of created object -:type name: str + a=vcs.init() + # Show all the existing fillarea objects + a.show('fillarea') + # Create instance of fillarea object 'red' + fa=a.drawfillarea(name='red', style=1, color=242, + priority=1, viewport=[0, 1.0, 0, 1.0], + worldcoordinate=[0,100, 0,50] + x=[0,20,40,60,80,100], + y=[0,10,20,30,40,50], bg=0 ) + # Plot using specified fillarea object + a.fillarea(fa) + + :param name: Name of created object + :type name: str -:param style: One of "hatch", "solid", or "pattern". -:type style: str + :param style: One of "hatch", "solid", or "pattern". + :type style: str -:param index: Specifies which `pattern `_ -to fill the fillarea with. Accepts ints from 1-20. + :param index: Specifies which `pattern `_ + to fill the fillarea with. Accepts ints from 1-20. -:type index: int + :type index: int -:param color: A color name from the `X11 Color Names list `_, -or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) + :param color: A color name from the `X11 Color Names list `_, + or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) -:type color: str or int + :type color: str or int -:param priority: The layer on which the fillarea will be drawn. -:type priority: int + :param priority: The layer on which the fillarea will be drawn. + :type priority: int -:param viewport: 4 floats between 0 and 1. These specify the area that the X/Y values are mapped to inside of the canvas -:type viewport: list of floats + :param viewport: 4 floats between 0 and 1. + These specify the area that the X/Y values are mapped to inside of the canvas + :type viewport: list of floats -:param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) -:type worldcoordinate: list of floats + :param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) + :type worldcoordinate: list of floats -:param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. -:type x: list of floats + :param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. + :type x: list of floats -:param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. -:type y: list of floats + :param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. + :type y: list of floats -:param bg: Boolean value. True => object drawn in background (not shown on canvas). False => object shown on canvas. -:type bg: bool + :param bg: Boolean value. True => object drawn in background (not shown on canvas). + False => object shown on canvas. + :type bg: bool -:returns: A fillarea object -:rtype: vcs.fillarea.Tf -""" + :returns: A fillarea object + :rtype: vcs.fillarea.Tf + """ if (name is None) or (not isinstance(name, str)): raise vcsError('Must provide string name for the fillarea.') else: @@ -2087,38 +2072,42 @@ def textcombined(self, *args, **parms): """ Plot a textcombined segment on the Vcs Canvas. If no textcombined class object is given, then an error will be returned. - *This function can also be called using the format **text(self, *args, **parms)** * + + .. note:: + + The text() function is an alias for textcombined(). + See example for usage. :Example: :: - a=vcs.init() - # Show all the existing texttable objects - a.show('texttable') - # Show all the existing textorientation objects - a.show('textorientation') - # Create instance of 'std' and '7left' - tt=a.gettext('std','7left') - # Show the string "Text1" on the VCS Canvas - tt.string = 'Text1' - # Set the text size - tt.font=2 - # Set the text color - tt.color = 242 - # Set the text angle - tt.angle = 45 - # Set the x value points - tt.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - tt.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified text object - a.text(tt) - #Optionally you can pass a string, the coordinates, and any keyword - a.plot('Hi',.5,.5,color=241,angle=45) - -:returns: ??? -:rtype: ??? + a=vcs.init() + # Show all the existing texttable objects + a.show('texttable') + # Show all the existing textorientation objects + a.show('textorientation') + # Create instance of 'std' and '7left' + tt=a.gettext('std','7left') + # Show the string "Text1" on the VCS Canvas + tt.string = 'Text1' + # Set the text size + tt.font=2 + # Set the text color + tt.color = 242 + # Set the text angle + tt.angle = 45 + # Set the x value points + tt.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] + # Set the y value points + tt.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] + # Plot using specified text object + a.text(tt) + #Optionally you can pass a string, the coordinates, and any keyword + a.plot('Hi',.5,.5,color=241,angle=45) + + :returns: A plot object + :rtype: """ # First check if color is a string if 'color' in parms.keys(): @@ -2152,26 +2141,26 @@ def textcombined(self, *args, **parms): text = textcombined def gettextextent(self, textobject): - """Returns the coordinate of the box surrounding a text object once printed + """ + Returns the coordinate of the box surrounding a text object once printed :Example: :: - a=vcs.init() - t=a.createtext() - t.x=[.5] - t.y=[.5] - t.string=['Hello World'] - extent = a.gettextextent(t) - print extent - -:param textobject: A VCS text object -:type textobject: textcombined + a=vcs.init() + t=a.createtext() + t.x=[.5] + t.y=[.5] + t.string=['Hello World'] + extent = a.gettextextent(t) + print extent -:returns: ??? -:rtype: ??? + :param textobject: A VCS text object + :type textobject: textcombined + :returns: ??? + :rtype: ??? """ if not vcs.istext(textobject): raise vcsError('You must pass a text object') @@ -2190,59 +2179,61 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None, worldcoordinate=[0.0, 1.0, 0.0, 1.0], x=None, y=None, bg=0): """ - Generate and draw a textcombined object on the VCS Canvas. + Generate and draw a textcombined object on the VCS Canvas. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing texttable objects - a.show('texttable') - # Create instance of texttable object 'red' - tt=a.drawtexttable(Tt_name = 'red', To_name='7left', mtype='dash', size=2, - color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified texttable object - a.texttable(tt) - -:param name: Name of created object -:type name: str + a=vcs.init() + # Show all the existing texttable objects + a.show('texttable') + # Create instance of texttable object 'red' + tt=a.drawtexttable(Tt_name = 'red', To_name='7left', mtype='dash', size=2, + color=242, priority=1, viewport=[0, 1.0, 0, 1.0], + worldcoordinate=[0,100, 0,50] + x=[0,20,40,60,80,100], + y=[0,10,20,30,40,50] ) + # Plot using specified texttable object + a.texttable(tt) + + :param name: Name of created object + :type name: str -:param style: One of "hatch", "solid", or "pattern". -:type style: str + :param style: One of "hatch", "solid", or "pattern". + :type style: str -:param index: Specifies which `pattern `_ - to fill the fillarea with. Accepts ints from 1-20. -:type index: int + :param index: Specifies which `pattern `_ + to fill the fillarea with. Accepts ints from 1-20. + :type index: int -:param color: A color name from the `X11 Color Names list `_, - or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) -:type color: str or int + :param color: A color name from the `X11 Color Names list `_, + or an integer value from 0-255, or an RGB/RGBA tuple/list (e.g. (0,100,0), (100,100,0,50)) + :type color: str or int -:param priority: The layer on which the fillarea will be drawn. -:type priority: int + :param priority: The layer on which the fillarea will be drawn. + :type priority: int -:param viewport: 4 floats between 0 and 1. These specify the area that the X/Y values are mapped to inside of the canvas -:type viewport: list of floats + :param viewport: 4 floats between 0 and 1. + These specify the area that the X/Y values are mapped to inside of the canvas + :type viewport: list of floats -:param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) -:type worldcoordinate: list of floats + :param worldcoordinate: List of 4 floats (xmin, xmax, ymin, ymax) + :type worldcoordinate: list of floats -:param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. -:type x: list of floats + :param x: List of lists of x coordinates. Values must be between worldcoordinate[0] and worldcoordinate[1]. + :type x: list of floats -:param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. -:type y: list of floats + :param y: List of lists of y coordinates. Values must be between worldcoordinate[2] and worldcoordinate[3]. + :type y: list of floats -:param bg: Boolean value. True => object drawn in background (not shown on canvas). False => object shown on canvas. -:type bg: bool + :param bg: Boolean value. True => object drawn in background (not shown on canvas). + False => object shown on canvas. + :type bg: bool -:returns: A texttable object -:rtype: -""" + :returns: A texttable object + :rtype: vcs.texttable.Tt + """ if (Tt_name is None) or (not isinstance(Tt_name, str)): raise vcsError('Must provide string name for the texttable.') else: @@ -2297,189 +2288,188 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None, def plot(self, *actual_args, **keyargs): """ - Plot an array(s) of data given a template and graphics method. The VCS template is - used to define where the data and variable attributes will be displayed on the VCS - Canvas. The VCS graphics method is used to define how the array(s) will be shown - on the VCS Canvas. + Plot an array(s) of data given a template and graphics method. The VCS template is + used to define where the data and variable attributes will be displayed on the VCS + Canvas. The VCS graphics method is used to define how the array(s) will be shown + on the VCS Canvas. - .. describe:: Plot Usage: + .. describe:: Plot Usage: - .. code-block:: python + .. code-block:: python - plot(array1=None, array2=None, template_name=None, - graphics_method=None, graphics_name=None, - [key=value [, key=value [, ...]]]) + plot(array1=None, array2=None, template_name=None, + graphics_method=None, graphics_name=None, + [key=value [, key=value [, ...]]]) - .. note:: - array1 and array2 are NumPy arrays. + .. note:: + array1 and array2 are NumPy arrays. - .. describe:: Plot attribute keywords: + .. describe:: Plot attribute keywords: - .. note:: - More specific attributes take precedence over general attributes. In particular, - specific attributes override variable object attributes, dimension attributes and - arrays override axis objects, which override grid objects, which override variable - objects. + .. note:: + More specific attributes take precedence over general attributes. In particular, + specific attributes override variable object attributes, dimension attributes and + arrays override axis objects, which override grid objects, which override variable + objects. - For example, if both 'file_comment' and 'variable' keywords are specified, the value of - 'file_comment' is used instead of the file comment in the parent of variable. Similarly, - if both 'xaxis' and 'grid' keywords are specified, the value of 'xaxis' takes precedence - over the x-axis of grid. + For example, if both 'file_comment' and 'variable' keywords are specified, the value of + 'file_comment' is used instead of the file comment in the parent of variable. Similarly, + if both 'xaxis' and 'grid' keywords are specified, the value of 'xaxis' takes precedence + over the x-axis of grid. - * ratio [default is none] + * ratio [default is none] - * None: let the self.ratio attribute decide - * 0,'off': overwrite self.ratio and do nothing about the ratio - * 'auto': computes an automatic ratio - * '3',3: y dim will be 3 times bigger than x dim (restricted to original tempalte.data area - * Adding a 't' at the end of the ratio, makes the tickmarks and boxes move along. + * None: let the self.ratio attribute decide + * 0,'off': overwrite self.ratio and do nothing about the ratio + * 'auto': computes an automatic ratio + * '3',3: y dim will be 3 times bigger than x dim (restricted to original tempalte.data area + * Adding a 't' at the end of the ratio, makes the tickmarks and boxes move along. - * Dimension attribute keys (dimension length=n): + * Dimension attribute keys (dimension length=n): - * x or y Dimension values + * x or y Dimension values - .. code-block:: python + .. code-block:: python - [x|y|z|t|w]array = NumPy array of length n - [x|y|z|t|w]array = NumPy array of length n + [x|y|z|t|w]array = NumPy array of length n + [x|y|z|t|w]array = NumPy array of length n - * x or y Dimension boundaries + * x or y Dimension boundaries - .. code-block:: python + .. code-block:: python - [x|y]bounds = NumPy array of shape (n,2) + [x|y]bounds = NumPy array of shape (n,2) - * CDMS object: + * CDMS object: - * x or y Axis + * x or y Axis - .. code-block:: python + .. code-block:: python - [x|y|z|t|w]axis = CDMS axis object + [x|y|z|t|w]axis = CDMS axis object - * Grid object (e.g. grid=var.getGrid()) + * Grid object (e.g. grid=var.getGrid()) - .. code-block:: python + .. code-block:: python - grid = CDMS grid object + grid = CDMS grid object - * Variable object + * Variable object - .. code-block:: python + .. code-block:: python - variable = CDMS variable object + variable = CDMS variable object - * Other: + * Other: - * Reverse the direction of the x or y axis: + * Reverse the direction of the x or y axis: - .. code-block:: python + .. code-block:: python - [x|y]rev = 0|1 + [x|y]rev = 0|1 - .. note:: - For example, xrev = 1 would reverse the - direction of the x-axis + .. note:: + For example, xrev = 1 would reverse the + direction of the x-axis - * Continental outlines: + * Continental outlines: - .. code-block:: python + .. code-block:: python - continents = 0,1,2,3,4,5,6,7,8,9,10,11 - # VCS line object to define continent appearance - continents_line = vcs.getline("default") + continents = 0,1,2,3,4,5,6,7,8,9,10,11 + # VCS line object to define continent appearance + continents_line = vcs.getline("default") - .. note:: - If continents >=1, plot continental outlines. - By default: plot of xaxis is longitude, yaxis is latitude - -OR- xname is 'longitude' and yname is 'latitude' + .. note:: + If continents >=1, plot continental outlines. + By default: plot of xaxis is longitude, yaxis is latitude + -OR- xname is 'longitude' and yname is 'latitude' - * List of continents-type values (integers from 0-11) + * List of continents-type values (integers from 0-11) - * 0 signifies "No Continents" - * 1 signifies "Fine Continents" - * 2 signifies "Coarse Continents" - * 3 signifies "United States" - * 4 signifies "Political Borders" - * 5 signifies "Rivers" + * 0 signifies "No Continents" + * 1 signifies "Fine Continents" + * 2 signifies "Coarse Continents" + * 3 signifies "United States" + * 4 signifies "Political Borders" + * 5 signifies "Rivers" - .. note:: - Values 6 through 11 signify the line type defined by - the files data_continent_other7 through data_continent_other12. + .. note:: + Values 6 through 11 signify the line type defined by + the files data_continent_other7 through data_continent_other12. - * To set whether the displayplot object generated by this plot is stored + * To set whether the displayplot object generated by this plot is stored - .. code-block:: python + .. code-block:: python - donotstoredisplay = True|False + donotstoredisplay = True|False - * Whether to actually render the plot or not (useful for doing a bunch of plots in a row) + * Whether to actually render the plot or not (useful for doing a bunch of plots in a row) - .. code-block:: python + .. code-block:: python - render = True|False + render = True|False - * VCS Display plot name (used to prevent duplicate display plots) + * VCS Display plot name (used to prevent duplicate display plots) - .. code-block:: python + .. code-block:: python - display_name = "__display_123" + display_name = "__display_123" - * Ratio of height/width for the plot; autot and auto will choose a "good" ratio for you. + * Ratio of height/width for the plot; autot and auto will choose a "good" ratio for you. - .. code-block:: python + .. code-block:: python - ratio = 1.5|"autot"|"auto" + ratio = 1.5|"autot"|"auto" - * Plot the actual grid or the dual grid + * Plot the actual grid or the dual grid - .. code-block:: python + .. code-block:: python - plot_based_dual_grid = True | False + plot_based_dual_grid = True | False - .. note:: - This is based on what is needed by the plot: isofill, isoline, vector need - point attributes, boxfill and meshfill need cell attributes - the default is True (if the parameter is not specified). + .. note:: + This is based on what is needed by the plot: isofill, isoline, vector need + point attributes, boxfill and meshfill need cell attributes + the default is True (if the parameter is not specified). - * Graphics Output in Background Mode: + * Graphics Output in Background Mode: - .. code-block:: python + .. code-block:: python - # if ==1, create images in the background - bg = 0|1 + # if ==1, create images in the background + bg = 0|1 - - :Example: + :Example: :: - # x is an instance of the VCS class object (constructor) - x=vcs.init() - # this call will use default settings for template and boxfill - x.plot(array) - # this is specifying the template and graphics method - x.plot(array, 'AMIP', 'isofill','AMIP_psl') - # get a predefined the template 'AMIP' - t=x.gettemplate('AMIP') - # get a predefined the vector graphics method 'quick' - vec=x.getvector('quick') - # plot the data as a vector using the 'AMIP' template - x.plot(array1, array2, t, vec) - # clear the VCS Canvas of all plots - x.clear() - # create boxfill graphics method 'new' - box=x.createboxfill('new') - # plot array data using box 'new' and template 't' - x.plot(box,t,array) - -%s -%s -%s -%s -%s -%s -""" + # x is an instance of the VCS class object (constructor) + x=vcs.init() + # this call will use default settings for template and boxfill + x.plot(array) + # this is specifying the template and graphics method + x.plot(array, 'AMIP', 'isofill','AMIP_psl') + # get a predefined the template 'AMIP' + t=x.gettemplate('AMIP') + # get a predefined the vector graphics method 'quick' + vec=x.getvector('quick') + # plot the data as a vector using the 'AMIP' template + x.plot(array1, array2, t, vec) + # clear the VCS Canvas of all plots + x.clear() + # create boxfill graphics method 'new' + box=x.createboxfill('new') + # plot array data using box 'new' and template 't' + x.plot(box,t,array) + + %s + %s + %s + %s + %s + %s + """ self.__last_plot_actual_args = actual_args self.__last_plot_keyargs = keyargs passed_var = keyargs.get("variable", None) @@ -3925,8 +3915,8 @@ def cgm(self, file, mode='w'): """ Export an image in CGM format. -:param file: Filename to save -:param mode: Ignored. + :param file: Filename to save + :param mode: Ignored. """ if mode != 'w': @@ -3943,12 +3933,12 @@ def clear(self, *args, **kargs): :: - a=vcs.init() - a.plot(array,'default','isofill','quick') - #clear VCS displays from the page - a.clear() + a=vcs.init() + a.plot(array,'default','isofill','quick') + #clear VCS displays from the page + a.clear() -""" + """ if self.animate.created(): self.animate.close() if self.configurator is not None: @@ -3987,12 +3977,12 @@ def close(self, *args, **kargs): :: - a=vcs.init() - a.plot(array,'default','isofill','quick') - #close the vcs canvas - a.close() + a=vcs.init() + a.plot(array,'default','isofill','quick') + #close the vcs canvas + a.close() -""" + """ if self.configurator: self.endconfigure() a = self.backend.close(*args, **kargs) @@ -4002,17 +3992,17 @@ def close(self, *args, **kargs): def destroy(self): """ - Destroy the VCS Canvas. It will deallocate the VCS Canvas object. + Destroy the VCS Canvas. It will deallocate the VCS Canvas object. - :Example: + :Example: :: - a=vcs.init() - a.plot(array,'default','isofill','quick') - a.destory() + a=vcs.init() + a.plot(array,'default','isofill','quick') + a.destroy() -""" + """ import gc del self @@ -4020,7 +4010,7 @@ def destroy(self): gc.collect() def change_display_graphic_method(self, display, type, name): - ''' + """ Changes the type and graphic method of a plot. :param display: Display to change. @@ -4029,7 +4019,7 @@ def change_display_graphic_method(self, display, type, name): :type display: str or vcs.displayplot.Dp :type name: str :type type: str - ''' + """ if isinstance(display, (str, unicode)): display = vcs.elements["display"][display] @@ -4039,10 +4029,10 @@ def change_display_graphic_method(self, display, type, name): def get_selected_display(self): """ - .. deprecated:: ?.? + .. deprecated:: 2.0 - - """ + This function is no longer supported. + """ return self.canvas.get_selected_display(*()) def plot_annotation(self, *args): @@ -4050,32 +4040,30 @@ def plot_annotation(self, *args): def flush(self, *args): """ - The flush command executes all buffered X events in the queue. + The flush command executes all buffered X events in the queue. - :Example: + :Example: :: - a=vcs.init() - a.plot(array,'default','isofill','quick') - a.flush() - -""" + a=vcs.init() + a.plot(array,'default','isofill','quick') + a.flush() + """ return self.backend.flush(*args) def geometry(self, *args): """ - The geometry command is used to set the size and position of the VCS canvas. + The geometry command is used to set the size and position of the VCS canvas. - :Example: + :Example: :: - a=vcs.init() - a.plot(array,'default','isofill','quick') - a.geometry(450,337) - -""" + a=vcs.init() + a.plot(array,'default','isofill','quick') + a.geometry(450,337) + """ if len(args) == 0: return self.backend.geometry() @@ -4098,20 +4086,20 @@ def canvasinfo(self, *args, **kargs): def getcontinentstype(self, *args): """ - Retrieve continents type from VCS; either an integer between 0 and 11 or the - path to a custom continentstype. + Retrieve continents type from VCS; either an integer between 0 and 11 or the + path to a custom continentstype. - :Example: + :Example: :: - a=vcs.init() - # Get the continents type - cont_type = a.getcontinentstype() + a=vcs.init() + # Get the continents type + cont_type = a.getcontinentstype() -:returns: An int between 1 and 0, or the path to a custom continentstype -:rtype: int or system filepath -""" + :returns: An int between 1 and 0, or the path to a custom continentstype + :rtype: int or system filepath + """ try: return self._continents except: @@ -4119,31 +4107,31 @@ def getcontinentstype(self, *args): def pstogif(self, filename, *opt): """ - In some cases, the user may want to save the plot out as a gif image. This - routine allows the user to convert a postscript file to a gif file. + In some cases, the user may want to save the plot out as a gif image. This + routine allows the user to convert a postscript file to a gif file. - :Example: + :Example: :: - a=vcs.init() - a.plot(array) - # convert the postscript file to a gif file (l=landscape) - a.pstogif('filename.ps') - # convert the postscript file to a gif file (l=landscape) - a.pstogif('filename.ps','l') - # convert the postscript file to a gif file (p=portrait) - a.pstogif('filename.ps','p') + a=vcs.init() + a.plot(array) + # convert the postscript file to a gif file (l=landscape) + a.pstogif('filename.ps') + # convert the postscript file to a gif file (l=landscape) + a.pstogif('filename.ps','l') + # convert the postscript file to a gif file (p=portrait) + a.pstogif('filename.ps','p') -:param filename: String name of the desired output file -:type filename: str + :param filename: String name of the desired output file + :type filename: str -:param opt: One of 'l' or 'p', indicating landscape or portrait mode, respectively. -:type opt: str + :param opt: One of 'l' or 'p', indicating landscape or portrait mode, respectively. + :type opt: str -:returns: ??? -:rtype: ??? - """ + :returns: ??? + :rtype: ??? + """ from os import popen # Generate the VCS postscript file @@ -4174,18 +4162,18 @@ def pstogif(self, filename, *opt): def grid(self, *args): """ - Set the default plotting region for variables that have more dimension values - than the graphics method. This will also be used for animating plots over the - third and fourth dimensions. + Set the default plotting region for variables that have more dimension values + than the graphics method. This will also be used for animating plots over the + third and fourth dimensions. - :Example: + :Example: :: - a=vcs.init() - a.grid(12,12,0,71,0,45) -""" + a=vcs.init() + a.grid(12,12,0,71,0,45) + """ p = self.canvas.grid(*args) @@ -4193,54 +4181,56 @@ def grid(self, *args): def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0): """ - Change the VCS Canvas orientation to Landscape. - - .. note:: - The (width, height) and (x, y) arguments work in pairs. That is, you must - set (width, height) or (x, y) together to see any change in the VCS Canvas. - - If the portrait method is called with arguments before displaying a VCS Canvas, - then the arguments (width, height, x, y, and clear) will have no effect on the - canvas. + Change the VCS Canvas orientation to Landscape. - .. warning:: - If the visible plot on the VCS Canvas is not adjusted properly, then resize - the screen with the point. Some X servers are not handling the threads properly - to keep up with the demands of the X client. - - :Example: - - :: + .. note:: - a=vcs.init() - a.plot(array) - # Change the VCS Canvas orientation and set object flag to landscape - a.landscape() - # Change the VCS Canvas to landscape and clear the page - a.landscape(clear=1) - # Change to landscape and set the window size - a.landscape(width = 400, height = 337) - # Change to landscape and set the x and y screen position - a.landscape(x=100, y = 200) - # Change to landscape and give specifications - a.landscape(width = 400, height = 337, x=100, y = 200, clear=1) + The (width, height) and (x, y) arguments work in pairs. That is, you must + set (width, height) or (x, y) together to see any change in the VCS Canvas. -:param width: Width of the canvas, in pixels -:type width: int + If the portrait method is called with arguments before displaying a VCS Canvas, + then the arguments (width, height, x, y, and clear) will have no effect on the + canvas. -:param height: Height of the canvas, in pixels -:type height: int + .. warning:: -:param x: Unused -:type x: int + If the visible plot on the VCS Canvas is not adjusted properly, then resize + the screen with the point. Some X servers are not handling the threads properly + to keep up with the demands of the X client. -:param y: Unused -:type y: int + :Example: -:param clear: Indicates the canvas should be cleared (1), or should not be cleared (0), when orientation is changed. -:type clear: int + :: -""" + a=vcs.init() + a.plot(array) + # Change the VCS Canvas orientation and set object flag to landscape + a.landscape() + # Change the VCS Canvas to landscape and clear the page + a.landscape(clear=1) + # Change to landscape and set the window size + a.landscape(width = 400, height = 337) + # Change to landscape and set the x and y screen position + a.landscape(x=100, y = 200) + # Change to landscape and give specifications + a.landscape(width = 400, height = 337, x=100, y = 200, clear=1) + + :param width: Width of the canvas, in pixels + :type width: int + + :param height: Height of the canvas, in pixels + :type height: int + + :param x: Unused + :type x: int + + :param y: Unused + :type y: int + + :param clear: Indicates the canvas should be cleared (1), + or should not be cleared (0), when orientation is changed. + :type clear: int + """ if (self.orientation() == 'landscape'): return @@ -4281,17 +4271,16 @@ def listelements(self, *args): 'scatter', 'taylordiagram', 'template', 'textcombined', 'textorientation', 'texttable', 'vector', 'xvsy', 'xyvsy', 'yxvsx'] - :Example: + :Example: :: - a=vcs.init() - a.listelements() - -:returns: A list of string names of all VCS class objects -:rtype: list + a=vcs.init() + a.listelements() -""" + :returns: A list of string names of all VCS class objects + :rtype: list + """ f = vcs.listelements L = sorted(f(*args)) @@ -4299,45 +4288,44 @@ def listelements(self, *args): def updateorientation(self, *args): """ - .. deprecated:: ?.? - Use :func:`landscape` or :func:`portrait` instead. -""" + .. deprecated:: 2.0 + Use :func:`landscape` or :func:`portrait` instead. + """ a = self.canvas.updateorientation(*args) return a def open(self, width=None, height=None, **kargs): """ - Open VCS Canvas object. This routine really just manages the VCS canvas. It will - popup the VCS Canvas for viewing. It can be used to display the VCS Canvas. + Open VCS Canvas object. This routine really just manages the VCS canvas. It will + popup the VCS Canvas for viewing. It can be used to display the VCS Canvas. - :Example: + :Example: :: - a=vcs.init() - a.open() - a.open(800,600) - -:param width: Integer representing the desire width of the opened window in pixels -:type width: int + a=vcs.init() + a.open() + a.open(800,600) -:param height: Integer representing the desire height of the opened window in pixels -:type height: int + :param width: Integer representing the desire width of the opened window in pixels + :type width: int -""" + :param height: Integer representing the desire height of the opened window in pixels + :type height: int + """ a = self.backend.open(width, height, **kargs) return a def canvasid(self, *args): - ''' + """ Get the ID of this canvas. This ID number is found at the top of the VCS Canvas, as part of its title. - ''' + """ return self._canvas_id def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0): @@ -4345,41 +4333,42 @@ def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0): Change the VCS Canvas orientation to Portrait. .. note:: + If the current orientation of the canvas is already portrait, nothing happens. :Example: :: - a=vcs.init() - a.plot(array) - # Change the VCS Canvas orientation and set object flag to portrait - a.portrait() - # Change the VCS Canvas to portrait and clear the page - a.portrait(clear=1) - # Change to portrait and set the window size - a.portrait(width = 337, height = 400) - # Change to portrait and set the x and y screen position - a.portrait(x=100, y = 200) - # Change to portrait and give specifications - a.portrait(width = 337, height = 400, x=100, y = 200, clear=1) - -:param width: Width to set the canvas to (in pixels) -:type width: int - -:param height: Height to set the canvas to (in pixels) -:type height: int - -:param x: Unused. -:type x: None - -:param y: Unused. -:type y: None - -:param clear: 0: Do not clear the canvas when orientation is changed. 1: clear the canvas when orientation is changed. -:type clear: int - -""" + a=vcs.init() + a.plot(array) + # Change the VCS Canvas orientation and set object flag to portrait + a.portrait() + # Change the VCS Canvas to portrait and clear the page + a.portrait(clear=1) + # Change to portrait and set the window size + a.portrait(width = 337, height = 400) + # Change to portrait and set the x and y screen position + a.portrait(x=100, y = 200) + # Change to portrait and give specifications + a.portrait(width = 337, height = 400, x=100, y = 200, clear=1) + + :param width: Width to set the canvas to (in pixels) + :type width: int + + :param height: Height to set the canvas to (in pixels) + :type height: int + + :param x: Unused. + :type x: None + + :param y: Unused. + :type y: None + + :param clear: 0: Do not clear the canvas when orientation is changed. + 1: clear the canvas when orientation is changed. + :type clear: int + """ if (self.orientation() == 'portrait'): return @@ -4412,51 +4401,55 @@ def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0): def ffmpeg(self, movie, files, bitrate=1024, rate=None, options=None): """ - MPEG output from a list of valid files. - Can output to more than just mpeg format. + MPEG output from a list of valid files. + Can output to more than just mpeg format. - .. note:: - ffmpeg ALWAYS overwrites the output file + .. note:: + + ffmpeg ALWAYS overwrites the output file + + .. admonishment:: Audio configuration - :Example: + via the options arg you can add audio file to your movie (see ffmpeg help) + + :Example: :: - a=vcs.init() - #... code to generate png files ... - # here is a dummy example - files =[] - for i in range(10): - a.png('my_png__%i' % i) - files.append('my_png__%i.png' % i) - # generates mpeg from pattern - a.ffmpeg('mymovie.mpeg','my_png_%d.png') - # generates from list of files - a.ffmpeg('mymovie.mpeg',files) - # generates mpeg at 512kbit - a.ffmpeg('mymovie.mpeg','my_png_%d.png',bitrate=512) - # generates movie with 50 frame per second - a.ffmpeg('mymovie.mpeg','my_png_%d.png',rate=50) - # generates movie at 50 frame per sec and 1024k bitrate - a.ffmpeg('mymovie.mpeg','my_png_%d.png',options='-r 50 -b 1024k') - # NOTE: via the options arg you can add audio file to your movie (see ffmpeg help) - -:param movie: Output video file name -:type movie: str - -:param files: String file name -:type files: str, list, or tuple - -:param rate: Desired output framerate -:type rate: str - -:param options: Additional FFMPEG arguments -:type options: str - -:returns: The output string generated by ffmpeg program -:rtype: str + a=vcs.init() + #... code to generate png files ... + # here is a dummy example + files =[] + for i in range(10): + a.png('my_png__%i' % i) + files.append('my_png__%i.png' % i) + # generates mpeg from pattern + a.ffmpeg('mymovie.mpeg','my_png_%d.png') + # generates from list of files + a.ffmpeg('mymovie.mpeg',files) + # generates mpeg at 512kbit + a.ffmpeg('mymovie.mpeg','my_png_%d.png',bitrate=512) + # generates movie with 50 frame per second + a.ffmpeg('mymovie.mpeg','my_png_%d.png',rate=50) + # generates movie at 50 frame per sec and 1024k bitrate + a.ffmpeg('mymovie.mpeg','my_png_%d.png',options='-r 50 -b 1024k') + + :param movie: Output video file name + :type movie: str + + :param files: String file name + :type files: str, list, or tuple + + :param rate: Desired output framerate + :type rate: str + + :param options: Additional FFMPEG arguments + :type options: str + + :returns: The output string generated by ffmpeg program + :rtype: str -""" + """ args = ["ffmpeg", "-y"] if rate is not None: @@ -4539,10 +4532,11 @@ def getantialiasing(self): return self.backend.getantialiasing() def setantialiasing(self, antialiasing): - """ Set antialiasing rate. + """ + Set antialiasing rate. -:param antialiasing: Integer from 0-64, representing the antialising rate (0 means no antialiasing). -:type antialiasing: int + :param antialiasing: Integer from 0-64, representing the antialising rate (0 means no antialiasing). + :type antialiasing: int """ self.backend.setantialiasing(antialiasing) @@ -4550,7 +4544,7 @@ def setbgoutputdimensions(self, width=None, height=None, units='inches'): """ Sets dimensions for output in bg mode. - :Example: + :Example: :: @@ -4560,15 +4554,14 @@ def setbgoutputdimensions(self, width=None, height=None, units='inches'): # A4 a.setbgoutputdimensions(width=21, height=29.7, units='cm') -:param width: Float representing the desired width of the output, using the specified unit of measurement -:type width: float - -:param height: Float representing the desired height of the output, using the specified unit of measurement. -:type height: float + :param width: Float representing the desired width of the output, using the specified unit of measurement + :type width: float -:param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Defaults to 'inches'. -:type units: str + :param height: Float representing the desired height of the output, using the specified unit of measurement. + :type height: float + :param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Defaults to 'inches'. + :type units: str """ if units not in [ 'inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']: @@ -4597,32 +4590,32 @@ def put_png_on_canvas( def png(self, file, width=None, height=None, units=None, draw_white_background=True, **args): """ - PNG output, dimensions set via setbgoutputdimensions + PNG output, dimensions set via setbgoutputdimensions - :Example: + :Example: :: - a=vcs.init() - a.plot(array) - # Overwrite a png file - a.png('example') + a=vcs.init() + a.plot(array) + # Overwrite a png file + a.png('example') -:param file: Output image filename -:type file: str + :param file: Output image filename + :type file: str -:param width: Float representing the desired width of the output png, using the specified unit of measurement -:type width: float + :param width: Float representing the desired width of the output png, using the specified unit of measurement + :type width: float -:param height: Float representing the desired height of the output png, using the specified unit of measurement. -:type height: float + :param height: Float representing the desired height of the output png, using the specified unit of measurement + :type height: float -:param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Defaults to 'inches'. -:type units: str + :param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Defaults to 'inches'. + :type units: str -:param draw_white_background: Boolean value indicating whether or not the background should be white. Defaults to True. -:type draw_white_background: bool -""" + :param draw_white_background: Boolean value indicating if the background should be white. Defaults to True. + :type draw_white_background: bool + """ base = os.path.dirname(file) if base != "" and not os.path.exists(base): raise vcsError("Output path: %s does not exist" % base) @@ -4640,42 +4633,43 @@ def png(self, file, width=None, height=None, def pdf(self, file, width=None, height=None, units='inches', textAsPaths=True): """ - PDF output is another form of vector graphics. + PDF output is another form of vector graphics. - .. note:: - The textAsPaths parameter preserves custom fonts, but text can no longer be edited in the file + .. note:: - :Example: + The textAsPaths parameter preserves custom fonts, but text can no longer be edited in the file + + :Example: :: - a=vcs.init() - a.plot(array) - # Overwrite a postscript file - a.pdf('example') - # US Legal - a.pdf('example', width=11.5, height= 8.5) - # A4 - a.pdf('example', width=21, height=29.7, units='cm') + a=vcs.init() + a.plot(array) + # Overwrite a postscript file + a.pdf('example') + # US Legal + a.pdf('example', width=11.5, height= 8.5) + # A4 + a.pdf('example', width=21, height=29.7, units='cm') -:param file: Desired string name of the output file -:type file: str + :param file: Desired string name of the output file + :type file: str -:param width: Integer specifying the desired width of the output, measured in the chosen units -:type width: int + :param width: Integer specifying the desired width of the output, measured in the chosen units + :type width: int -:param height: Integer specifying the desired height of the output, measured in the chosen units -:type height: int + :param height: Integer specifying the desired height of the output, measured in the chosen units + :type height: int -:param units: Must be one of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Default is 'inches'. -:type units: str + :param units: Must be one of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Default is 'inches'. + :type units: str -:param textAsPaths: Specifies whether to render text objects as paths. -:type textAsPaths: bool + :param textAsPaths: Specifies whether to render text objects as paths. + :type textAsPaths: bool -:returns: ??? -:rtype: ??? -""" + :returns: ??? + :rtype: ??? + """ if units not in [ 'inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']: raise Exception( @@ -4691,42 +4685,40 @@ def pdf(self, file, width=None, height=None, units='inches', def svg(self, file, width=None, height=None, units='inches', textAsPaths=True): """ - SVG output is another form of vector graphics. + SVG output is another form of vector graphics. - .. note:: - The textAsPaths parameter preserves custom fonts, but text can no longer be edited in the file + .. note:: - :Example: + The textAsPaths parameter preserves custom fonts, but text can no longer be edited in the file - :: + :Example: - a=vcs.init() - a.plot(array) - # Overwrite a postscript file - a.svg('example') - # US Legal - a.svg('example', width=11.5, height= 8.5) - # A4 - a.svg('example', width=21, height=29.7, units='cm') + :: -:param file: -:type file: + a=vcs.init() + a.plot(array) + # Overwrite a postscript file + a.svg('example') + # US Legal + a.svg('example', width=11.5, height= 8.5) + # A4 + a.svg('example', width=21, height=29.7, units='cm') -:param width: Float to set width of output SVG, in specified unit of measurement -:type width: float + :param file: + :type file: -:param height: Float to set height of output SVG, in specified unit of measurement -:type height: float + :param width: Float to set width of output SVG, in specified unit of measurement + :type width: float -:param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Deafults to 'inches'. -:type units: str + :param height: Float to set height of output SVG, in specified unit of measurement + :type height: float -:param textAsPaths: Specifies whether to render text objects as paths. -:type textAsPaths: bool + :param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Deafults to 'inches'. + :type units: str -:returns: ??? -:rtype: ??? -""" + :param textAsPaths: Specifies whether to render text objects as paths. + :type textAsPaths: bool + """ if units not in [ 'inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']: raise Exception( @@ -4840,8 +4832,8 @@ def isopened(self): """ Returns a boolean value indicating whether the canvas is opened or not. -:returns: A boolean value indicating whether the Canvas is opened (1), or closed (0) -:rtype: bool + :returns: A boolean value indicating whether the Canvas is opened (1), or closed (0) + :rtype: bool """ return self.backend.isopened() @@ -4920,60 +4912,58 @@ def _compute_width_height(self, width, height, units, ps=False): def postscript(self, file, mode='r', orientation=None, width=None, height=None, units='inches', textAsPaths=True): """ - Postscript output is another form of vector graphics. It is larger than its CGM output - counter part, because it is stored out in ASCII format. + Postscript output is another form of vector graphics. It is larger than its CGM output + counter part, because it is stored out in ASCII format. + + There are two modes for saving a postscript file: `Append' (a) mode appends postscript + output to an existing postscript file; and `Replace' (r) mode overwrites an existing + postscript file with new postscript output. The default mode is to overwrite an existing + postscript file (i.e. mode (r)). - There are two modes for saving a postscript file: `Append' (a) mode appends postscript - output to an existing postscript file; and `Replace' (r) mode overwrites an existing - postscript file with new postscript output. The default mode is to overwrite an existing - postscript file (i.e. mode (r)). + .. note:: - .. note:: - The textAsPaths parameter preserves custom fonts, but text can no longer be edited in the file + The textAsPaths parameter preserves custom fonts, but text can no longer be edited in the file - :Example: + :Example: :: - a=vcs.init() - a.plot(array) - # Overwrite a postscript file - a.postscript('example') - # Append postscript to an existing file - a.postscript('example', 'a') - # Overwrite an existing file - a.postscript('example', 'r') - # Append postscript to an existing file - a.postscript('example', mode='a') - # US Legal (default) - a.postscript('example', width=11.5, height= 8.5) - # A4 - a.postscript('example', width=21, height=29.7, units='cm') - # US Legal output and control of margins (for printer friendly output), default units 'inches' - a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) - -:param file: String name of the desired output file -:type file: str - -:param mode: The mode in which to open the file. One of 'r' or 'a'. -:type mode: str - -:param orientation: Deprecated. -:type orientation: None - -:param width: Desired width of the postscript output, in the specified unit of measurement -:type width: int - -:param height: Desired height of the postscript output, in the specified unit of measurement -:type height: int -:type units: str - -:param textAsPaths: Specifies whether to render text objects as paths. -:type textAsPaths: bool - -:returns: ??? -:rtype: ??? -""" + a=vcs.init() + a.plot(array) + # Overwrite a postscript file + a.postscript('example') + # Append postscript to an existing file + a.postscript('example', 'a') + # Overwrite an existing file + a.postscript('example', 'r') + # Append postscript to an existing file + a.postscript('example', mode='a') + # US Legal (default) + a.postscript('example', width=11.5, height= 8.5) + # A4 + a.postscript('example', width=21, height=29.7, units='cm') + # US Legal output and control of margins (for printer friendly output), default units 'inches' + a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) + + :param file: String name of the desired output file + :type file: str + + :param mode: The mode in which to open the file. One of 'r' or 'a'. + :type mode: str + + :param orientation: Deprecated. + :type orientation: None + + :param width: Desired width of the postscript output, in the specified unit of measurement + :type width: int + + :param height: Desired height of the postscript output, in the specified unit of measurement + :type height: int + :type units: str + + :param textAsPaths: Specifies whether to render text objects as paths. + :type textAsPaths: bool + """ if units not in [ 'inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']: raise Exception( @@ -5011,12 +5001,11 @@ def scriptrun(self, aFile, *args, **kargs): def setcolormap(self, name): """ - It is necessary to change the colormap. This routine will change the VCS color map. - If the the visul display is 16-bit, 24-bit, or 32-bit TrueColor, then a redrawing - of the VCS Canvas is made evertime the colormap is changed. + If the the visual display is 16-bit, 24-bit, or 32-bit TrueColor, then a redrawing + of the VCS Canvas is made every time the colormap is changed. :Example: @@ -5026,11 +5015,8 @@ def setcolormap(self, name): a.plot(array,'default','isofill','quick') a.setcolormap("AMIP") - :param name: Name of the coormap to use + :param name: Name of the colormap to use :type name: str - - :returns: ??? - :rtype: ??? """ # Don't update the VCS segment if there is no Canvas. This condition # happens in the initalize function for VCDAT only. This will cause a @@ -5046,31 +5032,30 @@ def setcolormap(self, name): def setcolorcell(self, *args): """ - Set a individual color cell in the active colormap. If default is - the active colormap, then return an error string. + Set a individual color cell in the active colormap. If default is + the active colormap, then return an error string. - If the the visul display is 16-bit, 24-bit, or 32-bit TrueColor, then a redrawing - of the VCS Canvas is made evertime the color cell is changed. + If the the visul display is 16-bit, 24-bit, or 32-bit TrueColor, then a redrawing + of the VCS Canvas is made evertime the color cell is changed. - Note, the user can only change color cells 0 through 239 and R,G,B - value must range from 0 to 100. Where 0 represents no color intensity - and 100 is the greatest color intensity. + Note, the user can only change color cells 0 through 239 and R,G,B + value must range from 0 to 100. Where 0 represents no color intensity + and 100 is the greatest color intensity. - :Example: + :Example: :: - a=vcs.init() - a.plot(array,'default','isofill','quick') - a.setcolormap("AMIP") - a.setcolorcell(11,0,0,0) - a.setcolorcell(21,100,0,0) - a.setcolorcell(31,0,100,0) - a.setcolorcell(41,0,0,100) - a.setcolorcell(51,100,100,100) - a.setcolorcell(61,70,70,70) - -""" + a=vcs.init() + a.plot(array,'default','isofill','quick') + a.setcolormap("AMIP") + a.setcolorcell(11,0,0,0) + a.setcolorcell(21,100,0,0) + a.setcolorcell(31,0,100,0) + a.setcolorcell(41,0,0,100) + a.setcolorcell(51,100,100,100) + a.setcolorcell(61,70,70,70) + """ a = vcs.setcolorcell(self.colormap, *args) return a @@ -5084,19 +5069,16 @@ def setcontinentsline(self, line="default"): :: - a = vcs.init() - line = vcs.createline() - line.width = 5 - # Use custom continents line - a.setcontinentsline(line) - # Use default line - a.setcontinentsline("default") - -:param line: Line to use for drawing continents. Can be a string name of a line, or a VCS line object -:type line: str or vcs.line.Tl + a = vcs.init() + line = vcs.createline() + line.width = 5 + # Use custom continents line + a.setcontinentsline(line) + # Use default line + a.setcontinentsline("default") -:returns: ??? -:rtype: ??? + :param line: Line to use for drawing continents. Can be a string name of a line, or a VCS line object + :type line: str or :py:class:`vcs.line.Tl` """ linename = VCS_validation_functions.checkLine(self, "continentsline", line) line = vcs.getline(linename) @@ -5110,12 +5092,12 @@ def getcontinentsline(self): def setcontinentstype(self, value): """ - One has the option of using continental maps that are predefined or that - are user-defined. Predefined continental maps are either internal to VCS - or are specified by external files. User-defined continental maps are - specified by additional external files that must be read as input. + One has the option of using continental maps that are predefined or that + are user-defined. Predefined continental maps are either internal to VCS + or are specified by external files. User-defined continental maps are + specified by additional external files that must be read as input. - The continents-type values are integers ranging from 0 to 11, where: + The continents-type values are integers ranging from 0 to 11, where: 0 signifies "No Continents" 1 signifies "Fine Continents" 2 signifies "Coarse Continents" @@ -5125,22 +5107,19 @@ def setcontinentstype(self, value): 6 uses a custom continent set - You can also pass a file by path. + You can also pass a file by path. - :Example: + :Example: :: - a=vcs.init() - a.setcontinentstype(3) - a.plot(array,'default','isofill','quick') - -:param value: Integer representing continent type, as specified in function description -:type value: int + a=vcs.init() + a.setcontinentstype(3) + a.plot(array,'default','isofill','quick') -:returns: ??? -:rtype: ??? - """ + :param value: Integer representing continent type, as specified in function description + :type value: int + """ continent_path = VCS_validation_functions.checkContinents(self, value) self._continents = value if continent_path is not None and not os.path.exists( @@ -5164,41 +5143,39 @@ def _continentspath(self): def gif(self, filename='noname.gif', merge='r', orientation=None, geometry='1600x1200'): """ - Function: gif - - Description of Function: - In some cases, the user may want to save the plot out as a gif image. This - routine allows the user to save the VCS canvas output as a SUN gif file. - This file can be converted to other gif formats with the aid of xv and other - such imaging tools found freely on the web. - - If no path/file name is given and no previously created gif file has been - designated, then file - - /$HOME/%s/default.gif - - will be used for storing gif images. However, if a previously created gif - file is designated, that file will be used for gif output. - - By default, the page orientation is in Landscape mode (l). To translate the page - orientation to portrait mode (p), set the orientation = 'p'. - - The GIF command is used to create or append to a gif file. There are two modes - for saving a gif file: `Append' mode (a) appends gif output to an existing gif - file; `Replace' (r) mode overwrites an existing gif file with new gif output. - The default mode is to overwrite an existing gif file (i.e. mode (r)). - - :Example: - a=vcs.init() - a.plot(array) - a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') - a.gif('example') # overwrite existing gif file (default is merge='r') - a.gif('example',merge='r') # overwrite existing gif file - a.gif('example',merge='a') # merge gif image into existing gif file - a.gif('example',orientation='l') # merge gif image into existing gif file with landscape orientation - a.gif('example',orientation='p') # merge gif image into existing gif file with portrait orientation - a.gif('example',geometry='600x500') # merge gif image into existing gif file and set the gif geometry -""" % (self._dotdir) + In some cases, the user may want to save the plot out as a gif image. This + routine allows the user to save the VCS canvas output as a SUN gif file. + This file can be converted to other gif formats with the aid of xv and other + such imaging tools found freely on the web. + + By default, the page orientation is in Landscape mode (l). To translate the page + orientation to portrait mode (p), set the orientation = 'p'. + + The GIF command is used to create or append to a gif file. There are two modes + for saving a gif file: 'Append' mode (a) appends gif output to an existing gif + file; 'Replace' (r) mode overwrites an existing gif file with new gif output. + The default mode is to overwrite an existing gif file (i.e. mode (r)). + + :Example: + + :: + + a=vcs.init() + a.plot(array) + a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') + # overwrite existing gif file (default is merge='r') + a.gif('example') + # overwrite existing gif file + a.gif('example',merge='r') + # merge gif image into existing gif file + a.gif('example',merge='a') + # merge gif image into existing gif file with landscape orientation + a.gif('example',orientation='l') + # merge gif image into existing gif file with portrait orientation + a.gif('example',orientation='p') + # merge gif image into existing gif file and set the gif geometry + a.gif('example',geometry='600x500') + """ if orientation is None: orientation = self.orientation()[0] g = geometry.split('x') @@ -5225,45 +5202,41 @@ def eps(self, file, mode='r', orientation=None, width=None, height=None, units=' :: - a=vcs.init() - a.plot(array) - # Overwrite a postscript file - a.postscript('example') - # Append postscript to an existing file - a.postscript('example', 'a') - # Overwrite an existing file - a.postscript('example', 'r') - # Append postscript to an existing file - a.postscript('example', mode='a') - # US Legal (default) - a.postscript('example', width=11.5, height= 8.5) - # A4 - a.postscript('example', width=21, height=29.7, units='cm') - a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) - # US Legal output and control of margins (for printer friendly output), default units 'inches' - - -:param file: String name of the desired output file -:type file: str + a=vcs.init() + a.plot(array) + # Overwrite a postscript file + a.postscript('example') + # Append postscript to an existing file + a.postscript('example', 'a') + # Overwrite an existing file + a.postscript('example', 'r') + # Append postscript to an existing file + a.postscript('example', mode='a') + # US Legal (default) + a.postscript('example', width=11.5, height= 8.5) + # A4 + a.postscript('example', width=21, height=29.7, units='cm') + a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) + # US Legal output and control of margins (for printer friendly output), default units 'inches' -:param mode: The mode in which to open the file. One of 'r' or 'a'. -:type mode: str + :param file: String name of the desired output file + :type file: str -:param orientation: Deprecated. -:type orientation: None + :param mode: The mode in which to open the file. One of 'r' or 'a'. + :type mode: str -:param width: Width of the output image, in the unit of measurement specified -:type width: float + :param orientation: Deprecated. + :type orientation: None -:param height: Height of the output image, in the unit of measurement specified -:type height: float + :param width: Width of the output image, in the unit of measurement specified + :type width: float -:param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Defaults to 'inches'. -:type units: str + :param height: Height of the output image, in the unit of measurement specified + :type height: float -:returns: ??? -:rtype: ??? -""" + :param units: One of ['inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']. Defaults to 'inches'. + :type units: str + """ ext = file.split(".")[-1] if ext.lower() != 'eps': file = file + '.eps' @@ -5292,15 +5265,14 @@ def isinfile(self, GM, file=None): Checks if a graphic method is stored in a file if no file name is passed then looks into the initial.attributes file -:param GM: The graphics method to search for -:type GM: str + :param GM: The graphics method to search for + :type GM: str -:param file: String name of the file to search -:type file: str - -:returns: ??? -:rtype: ??? + :param file: String name of the file to search + :type file: str + :returns: ??? + :rtype: ??? """ nm = GM.name gm = GM.g_name @@ -5319,34 +5291,31 @@ def isinfile(self, GM, file=None): def saveinitialfile(self): """ - Function: saveinitialfile # Save initial.attribute file + At start-up, VCS reads a script file named initial.attributes that + defines the initial appearance of the VCS Interface. Although not + required to run VCS, this initial.attributes file contains many + predefined settings to aid the beginning user of VCS. - Description of Function: - At start-up, VCS reads a script file named initial.attributes that - defines the initial appearance of the VCS Interface. Although not - required to run VCS, this initial.attributes file contains many - predefined settings to aid the beginning user of VCS. The path to - the file must be: + :Example: - /$HOME/%s/initial.attributes + :: - The contents of the initial.attributes file can be customized by - the user. + a=vcs.init() + ... - :Example: - a=vcs.init() - ... + a.saveinitialfile() - a.saveinitialfile() + .. warning:: + This removes first ALL object generated automatically + (i.e. whose name starts with '__') in order to preserve this, rename objects first + e.g: - WARNING: This removes first ALL object generated automatically - (i.e. whose name starts with '__') in order to preserve this, rename objects first - e.g: - b=a.createboxfill() - b.name='MyBoxfill' + .. codeblock:: python - # graphic method is now preserved -""" % (self._dotdir) + b=a.createboxfill() + b.name='MyBoxfill' + # graphic method is now preserved + """ self.clean_auto_generated_objects() return vcs.saveinitialfile() @@ -5358,24 +5327,24 @@ def raisecanvas(self, *args): def islandscape(self): """ - Indicates if VCS's orientation is landscape. + Indicates if VCS's orientation is landscape. - Returns a 1 if orientation is landscape. - Otherwise, it will return a 0, indicating false (not in landscape mode). + Returns a 1 if orientation is landscape. + Otherwise, it will return a 0, indicating false (not in landscape mode). - :Example: + :Example: :: - a=vcs.init() - # ... - if a.islandscape(): - # Set VCS's orientation to portrait mode - a.portrait() + a=vcs.init() + # ... + if a.islandscape(): + # Set VCS's orientation to portrait mode + a.portrait() -:returns: Integer indicating VCS is in landscape mode (1), or not (0) -:rtype: int -""" + :returns: Integer indicating VCS is in landscape mode (1), or not (0) + :rtype: int + """ if (self.orientation() == 'landscape'): return 1 else: @@ -5383,23 +5352,22 @@ def islandscape(self): def isportrait(self): """ - Indicates if VCS's orientation is portrait. + Indicates if VCS's orientation is portrait. - :Example: + :Example: :: - a=vcs.init() - #... - if a.isportrait(): - # Set VCS's orientation to landscape mode - a.landscape() - -:returns: Returns a 1 if orientation is portrait, or 0 if not in portrait mode -:rtype: bool + a=vcs.init() + #... + if a.isportrait(): + # Set VCS's orientation to landscape mode + a.landscape() -""" + :returns: Returns a 1 if orientation is portrait, or 0 if not in portrait mode + :rtype: bool + """ if (self.orientation() == 'portrait'): return 1 else: @@ -5407,32 +5375,33 @@ def isportrait(self): def getplot(self, Dp_name_src='default', template=None): """ - .. deprecated:: 1.0 - The geplot function is dperecated + .. deprecated:: 2.0 + + The getplot function is deprecated - This function will create a display plot object from an existing display - plot object from an existing VCS plot. If no display plot name - is given, then None is returned. + This function will create a display plot object from an existing display + plot object from an existing VCS plot. If no display plot name + is given, then None is returned. - :Example: + :Example: :: - a=vcs.init() - # Show all the existing templates - a.show('template') - # plot1 instance of 'dpy_plot_1' display plot - plot1=a.getplot('dpy_plot_1') + a=vcs.init() + # Show all the existing templates + a.show('template') + # plot1 instance of 'dpy_plot_1' display plot + plot1=a.getplot('dpy_plot_1') -:param Dp_name_src: String name of an existing display plot object -:type Dp_name_src: str + :param Dp_name_src: String name of an existing display plot object + :type Dp_name_src: str -:param template: ??? -:type template: ??? + :param template: The displayplot template to inherit from + :type template: -:returns: ??? -:rtype: ??? -""" + :returns: A VCS displayplot object + :rtype: vcs.displayplot.Dp + """ if not isinstance(Dp_name_src, str): raise ValueError('Error - The argument must be a string.') @@ -5443,8 +5412,6 @@ def getplot(self, Dp_name_src='default', template=None): return display def createcolormap(self, Cp_name=None, Cp_name_src='default'): - """ - """ return vcs.createcolormap(Cp_name, Cp_name_src) createcolormap.__doc__ = vcs.manageElements.createcolormap.__doc__ @@ -5456,12 +5423,12 @@ def addfont(self, path, name=""): """ Add a font to VCS. - :param path: Path to the font file you wish to add (must be .ttf) - :type path: str + :param path: Path to the font file you wish to add (must be .ttf) + :type path: str - :param name: Name to use to represent the font. - :type name: str -""" + :param name: Name to use to represent the font. + :type name: str + """ if not os.path.exists(path): raise ValueError('Error - The font path does not exists') if os.path.isdir(path): @@ -5506,12 +5473,12 @@ def getfont(self, font): """ Get the font name/number associated with a font number/name -:param font: The font name/number -:type font: int or str + :param font: The font name/number + :type font: int or str -:returns: If font parameter was a string, will return the integer associated with that string. - If font parameter was an integer, will return the string associated with that integer. -:rtype: int or str + :returns: If font parameter was a string, will return the integer associated with that string. + If font parameter was an integer, will return the string associated with that integer. + :rtype: int or str """ if isinstance(font, int): return self.getfontname(font) @@ -5524,12 +5491,12 @@ def switchfonts(self, font1, font2): """ Switch the font numbers of two fonts. -:param font1: The first font -:type font1: int or str + :param font1: The first font + :type font1: int or str -:param font2: The second font -:type font2: int or str -""" + :param font2: The second font + :type font2: int or str + """ if isinstance(font1, str): index1 = self.getfont(font1) elif isinstance(font1, (int, float)): @@ -5554,14 +5521,14 @@ def switchfonts(self, font1, font2): def copyfontto(self, font1, font2): """ - Copy `font1` into `font2`. + Copy 'font1' into 'font2'. -:param font1: Name/number of font to copy -:type font1: str or int + :param font1: Name/number of font to copy + :type font1: str or int -:param font2: Name/number of destination -:type font2: str or int -""" + :param font2: Name/number of destination + :type font2: str or int + """ if isinstance(font1, str): index1 = self.getfont(font1) elif isinstance(font1, (int, float)): @@ -5586,8 +5553,8 @@ def setdefaultfont(self, font): """ Sets the passed/def show font as the default font for vcs -:param font: Font name or index to use as default -:type font: str or int + :param font: Font name or index to use as default + :type font: str or int """ if isinstance(font, str): font = self.getfont(font) @@ -5607,8 +5574,8 @@ def orientation(self, *args, **kargs): # Show current orientation of the canvas a.orientation() -:returns: A string indicating the orientation of the canvas, i.e. 'landscape' or 'portrait' -:rtype: str + :returns: A string indicating the orientation of the canvas, i.e. 'landscape' or 'portrait' + :rtype: str """ return self.backend.orientation(*args, **kargs) From de1d359317c0a0044579137755a1ec43d7b8bab0 Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Wed, 24 Aug 2016 15:26:07 -0700 Subject: [PATCH 2/8] Doctests added to queries.py. All :Example: converted to doctest. Minor formatting of Canvas.py. Updated lots of xmldocs to facilitate docstring tests. --- vcs/Canvas.py | 8 +- vcs/queries.py | 262 ++++++++++++++------------ vcs/xmldocs.py | 484 +++++++++++++++++++++++++++---------------------- 3 files changed, 423 insertions(+), 331 deletions(-) diff --git a/vcs/Canvas.py b/vcs/Canvas.py index 5cf1d267c..b6ba6e9c6 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -1073,7 +1073,7 @@ def scriptobject(self, obj, script_filename=None, mode=None): def removeobject(self, obj): return vcs.removeobject(obj) - removeobject.__doc__ = vcs.removeobject.__doc__ # noqa + removeobject.__doc__ = vcs.manageElements.removeobject.__doc__ # noqa def removeP(self, *args): return vcs.removeP(*args) @@ -5570,9 +5570,9 @@ def orientation(self, *args, **kargs): :: - a = vcs.init() - # Show current orientation of the canvas - a.orientation() + a = vcs.init() + # Show current orientation of the canvas + a.orientation() :returns: A string indicating the orientation of the canvas, i.e. 'landscape' or 'portrait' :rtype: str diff --git a/vcs/queries.py b/vcs/queries.py index 6618227c9..caef60f7d 100644 --- a/vcs/queries.py +++ b/vcs/queries.py @@ -57,21 +57,25 @@ def isgraphicsmethod(gobj): :Example: -:: + .. doctest:: queries_isgraphicsmethod - a=vcs.init() - # To Modify an existing boxfill use: - box=a.getboxfill('quick') - #... - if vcs.isgraphicsmethod(box): - box.list() + >>> a=vcs.init() + ... -:param gobj: A graphics object -:type gobj: A VCS graphics object + # To Modify an existing boxfill use: + >>> box=a.getboxfill('quick') + ... -:returns: Integer reperesenting whether gobj is one of the above graphics methods. 1 indicates true, 0 indicates false. -:rtype: -""" + >>> vcs.isgraphicsmethod(box) + 1 + + :param gobj: A graphics object + :type gobj: A VCS graphics object + + :returns: Integer reperesenting whether gobj is one of the above graphics methods. + 1 indicates true, 0 indicates false. + :rtype: + """ import vcsaddons if (isinstance(gobj, boxfill.Gfb)): return 1 @@ -105,16 +109,18 @@ def graphicsmethodlist(): :Example: -:: + .. doctest:: queries_gmlist - a=vcs.init() - # Return graphics method list - gm_list=a.graphicsmethodlist() + >>> a=vcs.init() + ... -:returns: A list of available grapics methods (i.e., boxfill, isofill, isoline, outfill, - scatter, vector, xvsy, xyvsy, yxvsx, taylordiagram ). -:rtype: list -""" + >>> vcs.graphicsmethodlist() # Return graphics method list + ['boxfill', 'isofill', 'isoline', 'meshfill', 'scatter', 'vector', 'xvsy', 'xyvsy', 'yxvsx', ...] + + :returns: A list of available grapics methods (i.e., boxfill, isofill, isoline, outfill, + scatter, vector, xvsy, xyvsy, yxvsx, taylordiagram ). + :rtype: list + """ return ['boxfill', 'isofill', 'isoline', 'meshfill', 'scatter', 'vector', 'xvsy', 'xyvsy', 'yxvsx', 'taylordiagram', '1d', '3d_scalar', '3d_dual_scalar', '3d_vector'] @@ -123,31 +129,42 @@ def graphicsmethodtype(gobj): """ Check the type of a graphics object. - Returns a None if the object is not a graphics method. + Returns None if the object is not a graphics method. :Example: -:: - - a=vcs.init() - # Get an existing boxfill graphics method in VCS - box=a.getboxfill('quick') - # Get an existing isofill graphics method in VCS - iso=a.getisofill('quick') - # Get an existing line element in VCS - ln=a.getline('quick') - #... - # Will print 'boxfill' - print vcs.graphicsmethodtype(box) - # Will print 'isofill' - print vcs.graphicsmethodtype(iso) - # Will print None, because ln is not a graphics method - print vcs.graphicsmethodtype(ln) - -:returns: If gobj is a graphics method object, returns its type: 'boxfill', 'isofill', 'isoline', - 'scatter', 'vector', 'xvsy', 'xyvsy', or 'yxvsx', 'taylordiagram'. - If gobj is not a graphics method object, returns None. -:rtype: str or None + .. doctest:: queries_gmtype + + >>> a=vcs.init() + ... + + >>> # Get an existing boxfill graphics method in VCS: + >>> box=a.getboxfill('quick') + ... + + >>> # Get an existing isofill graphics method in VCS + >>> iso=a.getisofill('quick') + ... + + >>> # Get an existing line element in VCS + >>> ln=a.getline('red') + ... + + >>> print vcs.graphicsmethodtype(box) + boxfill + + >>> print vcs.graphicsmethodtype(iso) + isofill + + >>> print vcs.graphicsmethodtype(ln) + Traceback (most recent call last): + ... + vcsError: The object passed is not a graphics method object. + + :returns: If gobj is a graphics method object, returns its type: 'boxfill', 'isofill', 'isoline', + 'scatter', 'vector', 'xvsy', 'xyvsy', or 'yxvsx', 'taylordiagram'. + If gobj is not a graphics method object, raises an exception and prints a vcsError message. + :rtype: str or None """ import vcsaddons if (isinstance(gobj, boxfill.Gfb)): @@ -180,25 +197,29 @@ def isplot(pobj): """ Check to see if this object is a VCS secondary display plot. - :Example: + :Example: -:: + .. doctest:: queries_isplot - a=vcs.init() - # Show all available display - a.show('display') - # To test an existing display object - test_obj = a.getdisplay('default') - # ... - if queries.isdisplay(test_obj): - test_obj.list() + >>> a=vcs.init() -:param obj: A VCS object -:type obj: VCS Object + >>> a.show('display') # Show all available displays + *******************Display Names List********************** + ... + *******************End Display Names List********************** -:returns: An integer indicating whether the object is a display plot (1), or not (0). -:rtype: int -""" + >>> ex = a.getplot('default') # To test an existing display object + ... + + >>> vcs.queries.isplot(ex) + 1 + + :param obj: A VCS object + :type obj: VCS Object + + :returns: An integer indicating whether the object is a display plot (1), or not (0). + :rtype: int + """ if (isinstance(pobj, displayplot.Dp)): return 1 else: @@ -209,24 +230,28 @@ def iscolormap(obj): """ Check to see if this object is a VCS secondary colormap. - :Example: + :Example: -:: + .. doctest:: queries_iscolormap - a=vcs.init() - # Show all available colormap - a.show('colormap') - # To test an existing colormap object - test_obj = a.getcolormap('default') - # ... - if queries.iscolormap(test_obj): - test_obj.list() + >>> a=vcs.init() + ... -:param obj: A VCS object -:type obj: VCS Object + >>> a.show('colormap') # Show all available colormap objects + *******************Colormap Names List********************** + ... + *******************End Colormap Names List********************** + >>> ex = a.getcolormap('default') # To test an existing colormap object + ... -:returns: An integer indicating whether the object is a colormap (1), or not (0). -:rtype: int + >>> vcs.iscolormap(ex) + 1 + + :param obj: A VCS object + :type obj: VCS Object + + :returns: An integer indicating whether the object is a colormap (1), or not (0). + :rtype: int """ if (isinstance(obj, vcs.colormap.Cp)): return 1 @@ -240,16 +265,20 @@ def istemplate(gobj): :Example: -:: + .. doctest:: queries_istemplate + + >>> a=vcs.init() - a=vcs.init() - # Show all available template - a.show('template') - # To test an existing template object - test_obj = a.gettemplate('default') - # ... - if queries.istemplate(test_obj): - test_obj.list() + >>> a.show('template') # Show all available template + *******************Template Names List********************** + ... + *******************End Template Names List********************** + + >>> ex = a.gettemplate('default') # To test an existing template object + ... + + >>> vcs.istemplate(ex) + 1 :param obj: A VCS object :type obj: VCS Object @@ -265,9 +294,10 @@ def istemplate(gobj): def issecondaryobject(sobj): """ - Check to see if this object is a VCS secondary object + Check to see if this object is a VCS secondary object .. note:: + Secondary objects will be one of the following: 1.) colormap: specification of combinations of 256 available colors @@ -283,25 +313,30 @@ def issecondaryobject(sobj): horizontal/vertical alignment 9.) projections - :Example: + :Example: -:: + .. doctest:: queries_issecondary - a=vcs.init() - # Show all available lines - a.show('line') - # To test an existing line object - test_obj = a.getprojection('default') - # ... - if queries.issecondaryobject(test_obj): - test_obj.list() + >>> a=vcs.init() + ... -:param obj: A VCS object -:type obj: VCS Object + >>> a.show('line') # Show all available lines + *******************Line Names List********************** + ... + *******************End Line Names List********************** -:returns: An integer indicating whether the object is a projection graphics object (1), or not (0). -:rtype: int -""" + >>> ex = a.getprojection('default') # To test an existing line object + ... + + >>> vcs.issecondaryobject(ex) + 1 + + :param obj: A VCS object + :type obj: VCS Object + + :returns: An integer indicating whether the object is a projection graphics object (1), or not (0). + :rtype: int + """ if (isinstance(sobj, line.Tl)): return 1 elif (isinstance(sobj, marker.Tm)): @@ -328,25 +363,30 @@ def isprojection(obj): """ Check to see if this object is a VCS secondary projection graphics object. - :Example: + :Example: -:: + .. doctest:: queries_isprojection - a=vcs.init() - # Show all available projection - a.show('projection') - # To test an existing projection object - test_obj = a.getprojection('default') - # ... - if queries.isprojection(test_obj): - test_obj.list() + >>> a=vcs.init() + ... -:param obj: A VCS object -:type obj: VCS Object + >>> a.show('projection') # Show all available projection + *******************Projection Names List********************** + ... + *******************End Projection Names List********************** -:returns: An integer indicating whether the object is a projection graphics object (1), or not (0). -:rtype: int -""" + >>> ex = a.getprojection('default') # To test an existing projection object + ... + + >>> vcs.isprojection(ex) + 1 + + :param obj: A VCS object + :type obj: VCS Object + + :returns: An integer indicating whether the object is a projection graphics object (1), or not (0). + :rtype: int + """ if (isinstance(obj, projection.Proj)): return 1 else: diff --git a/vcs/xmldocs.py b/vcs/xmldocs.py index 2613395cd..3765fc5d4 100644 --- a/vcs/xmldocs.py +++ b/vcs/xmldocs.py @@ -1,86 +1,86 @@ plot_keywords_doc = """ -:param xaxis: Axis object to replace the slab -1 dim axis -:param yaxis: Axis object to replace the slab -2 dim axis, only if slab has more than 1D -:param zaxis: Axis object to replace the slab -3 dim axis, only if slab has more than 2D -:param taxis: Axis object to replace the slab -4 dim axis, only if slab has more than 3D -:param waxis: Axis object to replace the slab -5 dim axis, only if slab has more than 4D -:param xrev: reverse x axis -:param yrev: reverse y axis, only if slab has more than 1D -:param xarray: Values to use instead of x axis -:param yarray: Values to use instead of y axis, only if var has more than 1D -:param zarray: Values to use instead of z axis, only if var has more than 2D -:param tarray: Values to use instead of t axis, only if var has more than 3D -:param warray: Values to use instead of w axis, only if var has more than 4D -:param continents: continents type number -:param name: replaces variable name on plot -:param time: replaces time name on plot -:param units: replaces units value on plot -:param ymd: replaces year/month/day on plot -:param hms: replaces hh/mm/ss on plot -:param file_comment: replaces file_comment on plot -:param xbounds: Values to use instead of x axis bounds values -:param ybounds: Values to use instead of y axis bounds values (if exist) -:param xname: replace xaxis name on plot -:param yname: replace yaxis name on plot (if exists) -:param zname: replace zaxis name on plot (if exists) -:param tname: replace taxis name on plot (if exists) -:param wname: replace waxis name on plot (if exists) -:param xunits: replace xaxis units on plot -:param yunits: replace yaxis units on plot (if exists) -:param zunits: replace zaxis units on plot (if exists) -:param tunits: replace taxis units on plot (if exists) -:param wunits: replace waxis units on plot (if exists) -:param xweights: replace xaxis weights used for computing mean -:param yweights: replace xaxis weights used for computing mean -:param comment1: replaces comment1 on plot -:param comment2: replaces comment2 on plot -:param comment3: replaces comment3 on plot -:param comment4: replaces comment4 on plot -:param long_name: replaces long_name on plot -:param grid: replaces array grid (if exists) -:param bg: plots in background mode -:param ratio: sets the y/x ratio ,if passed as a string with 't' at the end, will aslo moves the ticks -:type xaxis: cdms2.axis.TransientAxis -:type yaxis: cdms2.axis.TransientAxis -:type zaxis: cdms2.axis.TransientAxis -:type taxis: cdms2.axis.TransientAxis -:type waxis: cdms2.axis.TransientAxis -:type xrev: bool -:type yrev: bool -:type xarray: array -:type yarray: array -:type zarray: array -:type tarray: array -:type warray: array -:type continents: int -:type name: str -:type time: A cdtime object -:type units: str -:type ymd: str -:type hms: str -:type file_comment: str -:type xbounds: array -:type ybounds: array -:type xname: str -:type yname: str -:type zname: str -:type tname: str -:type wname: str -:type xunits: str -:type yunits: str -:type zunits: str -:type tunits: str -:type wunits: str -:type xweights: array -:type yweights: array -:type comment1: str -:type comment2: str -:type comment3: str -:type comment4: str -:type long_name: str -:type grid: cdms2.grid.TransientRectGrid -:type bg: bool/int -:type ratio: int/str + :param xaxis: Axis object to replace the slab -1 dim axis + :param yaxis: Axis object to replace the slab -2 dim axis, only if slab has more than 1D + :param zaxis: Axis object to replace the slab -3 dim axis, only if slab has more than 2D + :param taxis: Axis object to replace the slab -4 dim axis, only if slab has more than 3D + :param waxis: Axis object to replace the slab -5 dim axis, only if slab has more than 4D + :param xrev: reverse x axis + :param yrev: reverse y axis, only if slab has more than 1D + :param xarray: Values to use instead of x axis + :param yarray: Values to use instead of y axis, only if var has more than 1D + :param zarray: Values to use instead of z axis, only if var has more than 2D + :param tarray: Values to use instead of t axis, only if var has more than 3D + :param warray: Values to use instead of w axis, only if var has more than 4D + :param continents: continents type number + :param name: replaces variable name on plot + :param time: replaces time name on plot + :param units: replaces units value on plot + :param ymd: replaces year/month/day on plot + :param hms: replaces hh/mm/ss on plot + :param file_comment: replaces file_comment on plot + :param xbounds: Values to use instead of x axis bounds values + :param ybounds: Values to use instead of y axis bounds values (if exist) + :param xname: replace xaxis name on plot + :param yname: replace yaxis name on plot (if exists) + :param zname: replace zaxis name on plot (if exists) + :param tname: replace taxis name on plot (if exists) + :param wname: replace waxis name on plot (if exists) + :param xunits: replace xaxis units on plot + :param yunits: replace yaxis units on plot (if exists) + :param zunits: replace zaxis units on plot (if exists) + :param tunits: replace taxis units on plot (if exists) + :param wunits: replace waxis units on plot (if exists) + :param xweights: replace xaxis weights used for computing mean + :param yweights: replace xaxis weights used for computing mean + :param comment1: replaces comment1 on plot + :param comment2: replaces comment2 on plot + :param comment3: replaces comment3 on plot + :param comment4: replaces comment4 on plot + :param long_name: replaces long_name on plot + :param grid: replaces array grid (if exists) + :param bg: plots in background mode + :param ratio: sets the y/x ratio ,if passed as a string with 't' at the end, will aslo moves the ticks + :type xaxis: cdms2.axis.TransientAxis + :type yaxis: cdms2.axis.TransientAxis + :type zaxis: cdms2.axis.TransientAxis + :type taxis: cdms2.axis.TransientAxis + :type waxis: cdms2.axis.TransientAxis + :type xrev: bool + :type yrev: bool + :type xarray: array + :type yarray: array + :type zarray: array + :type tarray: array + :type warray: array + :type continents: int + :type name: str + :type time: A cdtime object + :type units: str + :type ymd: str + :type hms: str + :type file_comment: str + :type xbounds: array + :type ybounds: array + :type xname: str + :type yname: str + :type zname: str + :type tname: str + :type wname: str + :type xunits: str + :type yunits: str + :type zunits: str + :type tunits: str + :type wunits: str + :type xweights: array + :type yweights: array + :type comment1: str + :type comment2: str + :type comment3: str + :type comment4: str + :type long_name: str + :type grid: cdms2.grid.TransientRectGrid + :type bg: bool/int + :type ratio: int/str """ # noqa data_time = """ @@ -146,8 +146,10 @@ (Ex: 1.E20) second value of yaxis on plot """ # noqa -graphics_method_core = """%s -%s""" % (graphics_method_core_notime, data_time) +graphics_method_core = """ + %s + %s + """ % (graphics_method_core_notime, data_time) axisconvert = """ :param {axis}axisconvert: (Ex: 'linear') converting {axis}axis linear/log/log10/ln/exp/area_wt :type {axis}axisconvert: str\n""" @@ -165,37 +167,35 @@ """ extsdoc = """ - Sets the ext_1 and ext_2 values on the object. + Sets the ext_1 and ext_2 values on the object. -:param ext1: Sets the :py:attr:`ext_1` value on the object. 'y' sets it to True, 'n' sets it to False. -:type ext1: str + :param ext1: Sets the :py:attr:`ext_1` value on the object. 'y' sets it to True, 'n' sets it to False. + :type ext1: str -:param ext2: Sets the :py:attr:`ext_2` value on the object. 'y' sets it to True, 'n' sets it to False. -:type ext2: str + :param ext2: Sets the :py:attr:`ext_2` value on the object. 'y' sets it to True, 'n' sets it to False. + :type ext2: str """ -ticlabeldoc = """ - Sets the %sticlabels1 and %sticlabels2 values on the object +ticlabelsdoc = """ + Sets the %sticlabels1 and %sticlabels2 values on the object -:param %stl1: Sets the object's value for :py:attr:`%sticlabels1`. - Must be a str, or a dictionary object with float:str mappings. -:type %stl1: {float:str} or str + :param %stl1: Sets the object's value for :py:attr:`%sticlabels1`. Must be a str, or a dictionary object with float:str mappings. + :type %stl1: {float:str} or str -:param %stl2: Sets the object's value for :py:attr:`%sticlabels2`. - Must be a str, or a dictionary object with float:str mappings. -:type %stl2: {float:str} or str + :param %stl2: Sets the object's value for :py:attr:`%sticlabels2`. Must be a str, or a dictionary object with float:str mappings. + :type %stl2: {float:str} or str """ -xticlabelsdoc = ticlabeldoc % (('x',) * 8) -yticlabelsdoc = ticlabeldoc % (('y',) * 8) +xticlabelsdoc = ticlabelsdoc % (('x',) * 8) +yticlabelsdoc = ticlabelsdoc % (('y',) * 8) mticsdoc = """ - Sets the %smtics1 and %smtics2 values on the object + Sets the %smtics1 and %smtics2 values on the object -:param %smt1: Value for :py:attr:`%smtics1`. Must be a str, or a dictionary object with float:str mappings. -:type %smt1: {float:str} or str + :param %smt1: Value for :py:attr:`%smtics1`. Must be a str, or a dictionary object with float:str mappings. + :type %smt1: {float:str} or str -:param %smt2: Value for :py:attr:`%smtics2`. Must be a str, or a dictionary object with float:str mappings. -:type %smt2: {float:str} or str -""" + :param %smt2: Value for :py:attr:`%smtics2`. Must be a str, or a dictionary object with float:str mappings. + :type %smt2: {float:str} or str + """ xmticsdoc = mticsdoc % (('x',) * 8) ymticsdoc = mticsdoc % (('y',) * 8) @@ -213,14 +213,13 @@ :param dsp4: Sets the :py:attr:`datawc_x2` property of the object. :type dsp4: float - """ xyscaledoc = """ - Sets xaxisconvert and yaxisconvert values for the object. + Sets xaxisconvert and yaxisconvert values for the object. - :Example: + :Example: -:: + :: a=vcs.init() #create a boxfill to work with @@ -233,7 +232,7 @@ :param yat: Set value for y axis conversion. :type yat: str - """ + """ listdoc = """ Lists the current values of object attributes""" # Scriptdocs section @@ -343,91 +342,121 @@ # dict['parent'] is for rare cases where there is no 'default' object to inherit from. dict['parent'] = 'REPLACE_ME' -queries_is_doc = """ - Check to see if this object is a VCS %(type)s %(name)s graphics method. +dict['tc_example'] = dict['to'] = '' +queries_is_doc= """ + Check to see if this object is a VCS %(type)s %(name)s %(method_type)s. :Example: - .. doctest:: queries_is + .. doctest:: queries_is - # Make a VCS Canvas object to work with: - >>> a=vcs.init() - ... - - # Show all available %(name)s - >>> a.show('%(name)s') - *... + # Make a VCS Canvas object to work with: + >>> a=vcs.init() + ... + %(tc_example)s + # Show all available %(name)s + >>> a.show('%(name)s') + *******************%(cap)s Names List********************** + ... + *******************End %(cap)s Names List********************** - # To test an existing %(name)s object - >>> ex = a.get%(name)s(%(parent)s) - ... + # To test an existing %(name)s object + >>> ex = a.get%(name)s('%(parent)s'%(to)s) + ... - >>> print(vcs.queries.is%(name)s(ex)) - 1 + >>> vcs.queries.is%(name)s(ex) + 1 -:param obj: A VCS object -:type obj: VCS Object + :param obj: A VCS object + :type obj: VCS Object -:returns: An integer indicating whether the object is a %(name)s graphics method (1), or not (0). -:rtype: int -""" + :returns: An integer indicating whether the object is a %(name)s %(method_type)s (1), or not (0). + :rtype: int + """ # queries.is[PRIMARY_OBJECT] dict['type'] = 'primary' -dict['parent'] = "'default'" +dict['parent'] = 'default' +dict['method_type'] = 'graphics method' dict['name'] = 'vector' +dict['cap'] = dict['name'].title() isvector_doc = queries_is_doc % dict dict['name'] = 'taylordiagram' +dict['cap'] = dict['name'].title() +dict['cap'] = dict['name'].title() istaylordiagram_doc = queries_is_doc % dict dict['name'] = 'meshfill' +dict['cap'] = dict['name'].title() ismeshfill_doc = queries_is_doc % dict dict['name'] = 'boxfill' -isboxfill_doc = queries_is_doc % dict +dict['cap'] = dict['name'].title() +isboxfill_doc= queries_is_doc % dict dict['name'] = 'isofill' -isisofill_doc = queries_is_doc % dict +dict['cap'] = dict['name'].title() +isisofill_doc= queries_is_doc % dict dict['name'] = 'isoline' -isisoline_doc = queries_is_doc % dict -dict['name'] = '3d_scalar' -is3d_scalar_doc = queries_is_doc % dict -dict['name'] = '3d_dual_scalar' -is3d_dual_scalar_doc = queries_is_doc % dict -dict['name'] = '3d_vector' -is3d_vector_doc = queries_is_doc % dict +dict['cap'] = dict['name'].title() +isisoline_doc= queries_is_doc % dict +dict['name'] = dict['cap'] = '3d_scalar' +is3d_scalar_doc= queries_is_doc % dict +dict['name'] = dict['cap'] = '3d_dual_scalar' +is3d_dual_scalar_doc= queries_is_doc % dict +dict['name'] = dict['cap'] = '3d_vector' +is3d_vector_doc= queries_is_doc % dict dict['name'] = 'xvsy' +dict['cap'] = dict['name'].title() isxvsy_doc = queries_is_doc % dict dict['name'] = 'yxvsx' +dict['cap'] = dict['name'].title() isyxvsx_doc = queries_is_doc % dict -dict['name'] = '1d' +dict['name'] = dict['cap'] = '1d' is1d_doc = queries_is_doc % dict # special inheritance cases dict['name'] = 'scatter' -dict['parent'] = "'default_scatter_'" +dict['cap'] = dict['name'].title() +dict['parent'] = 'default_scatter_' isscatter_doc = queries_is_doc % dict dict['name'] = 'xyvsy' -dict['parent'] = "'default_xyvsy_'" +dict['cap'] = dict['name'].title() +dict['parent'] = 'default_xyvsy_' isxyvsy_doc = queries_is_doc % dict # queries.is[SECONDARY_OBJECT] dict['type'] = 'secondary' -dict['parent'] = "'default'" +dict['parent'] = 'default' dict['name'] = 'line' +dict['cap'] = dict['name'].title() isline_doc = queries_is_doc % dict dict['name'] = 'marker' +dict['cap'] = dict['name'].title() ismarker_doc = queries_is_doc % dict dict['name'] = 'fillarea' +dict['cap'] = dict['name'].title() isfillarea_doc = queries_is_doc % dict dict['name'] = 'texttable' +dict['cap'] = dict['name'].title() istexttable_doc = queries_is_doc % dict dict['name'] = 'textorientation' +dict['cap'] = dict['name'].title() istextorientation_doc = queries_is_doc % dict + +# queries.is[SPECIAL_CASES] dict['name'] = 'textcombined' +dict['cap'] = dict['name'].title() +dict['tc_example'] =""" + + >>> vcs.createtext('new_tt', 'std', 'new_to', '7left') + >> vcs.show('%(name)s') # Show all the existing %(name)s %(type)s + *******************%(cap)s Names List********************** + ... + *******************End %(cap)s Names List********************** + + # instance of '%(parent)s' %(name)s %(type)s + ex=vcs.get%(call)s() + # instance of existing 'quick' %(name)s %(type)s + ex2=vcs.get%(call)s('quick') + # Create instance of %(name)s object 'red' + ex3=vcs.create%(call)s(name='new', name='red',style=1, index=1, + color=242, priority=1, viewport=[0, 2.0, 0, 2.0], + worldcoordinate=[0,100, 0,50] + x=[0,20,40,60,80,100], + y=[0,10,20,30,40,50] ) + # Plot using specified %(call)s object + vcs.%(name)s(ex3) """ # Get for secondary methods with a 'default' available dict['parent'] = 'default' dict['type'] = 'secondary method' dict['name'] = dict['call'] = 'fillarea' +dict['cap'] = dict['name'].title() get_fillarea_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_texttable_doc = get_methods_doc % dict -dict['name'] = dict['call'] = 'texttable' +dict['name'] = dict['call'] = 'template' +dict['cap'] = dict['name'].title() get_template_doc = get_methods_doc % dict -dict['name'] = dict['call'] = 'texttable' +dict['name'] = dict['call'] = 'projection' +dict['cap'] = dict['name'].title() get_projection_doc = get_methods_doc % dict -dict['name'] = dict['call'] = 'texttable' +dict['name'] = dict['call'] = 'boxfill' +dict['cap'] = dict['name'].title() get_boxfill_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_taylor_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_meshfill_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_isofill_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_isoline_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_1d_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_xyvsy_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_yxvsx_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_xvsy_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_vector_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_scatter_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_line_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_marker_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_textorientation_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_textcombined_doc = get_methods_doc % dict -dict['name'] = dict['call'] = 'texttable' +dict['name'] = dict['call'] = dict['cap'] = '3d_scalar' get_3d_scalar_doc = get_methods_doc % dict -dict['name'] = dict['call'] = 'texttable' +dict['name'] = dict['call'] = dict['cap'] = '3d_dual_scalar' get_3d_dual_scalar_doc = get_methods_doc % dict -dict['name'] = dict['call'] = 'texttable' +dict['name'] = dict['call'] = dict['cap'] = '3d_vector' get_3d_vector_doc = get_methods_doc % dict dict['name'] = dict['call'] = 'texttable' +dict['cap'] = dict['name'].title() get_colormap_doc = get_methods_doc % dict -exts_attrs = """ +exts_attrs= """ .. py:attribute:: ext_1 (str) Draws an extension arrow on right side (values less than first range value) @@ -523,7 +576,7 @@ .. py:attribute:: fillareacolors ([int,...]) Colors to use for each level -""" + """ fillarea_attrs = """ .. py:attribute:: fillareastyle (str) @@ -533,13 +586,13 @@ .. py:attribute:: fillareaindices ([int,...]) List of patterns to use when filling a level and using pattern/hatch -""" + """ legend_attr = """ .. py:attribute:: legend (None/{float:str}) Replaces the legend values in the dictionary keys with their associated string -""" + """ level_attrs = """ .. py:attribute:: level_1 (float) @@ -549,20 +602,20 @@ .. py:attribute:: level_2 (float) Sets the value of the legend's end level -""" + """ levels_attr = """ .. py:attribute:: levels ([float,...]/[[float,float],...]) Sets the levels range to use, can be either a list of contiguous levels, or list of tuples indicating first and last value of the range. -""" + """ missing_attr = """ .. py:attribute:: missing (int) Color to use for missing value or values not in defined ranges -""" + """ meshfill_doc = """ %s @@ -571,8 +624,7 @@ %s %s %s -""" % (levels_attr, fillarea_colors_attr, fillarea_attrs, legend_attr, exts_attrs, missing_attr) - + """ % (levels_attr,fillarea_colors_attr, fillarea_attrs, legend_attr, exts_attrs, missing_attr) isofill_doc = meshfill_doc @@ -580,7 +632,7 @@ fillareacolor :: (int) (None) color to use for outfilling fillareastyle :: (str) ('solid') style to use for levels filling: solid/pattenr/hatch fillareaindex :: (int) (None) pattern to use when filling a level and using pattern/hatch -""" # noqa + """ # noqa linesdoc = """ line :: ([str,...]/[vcs.line.Tl,...]/[int,...]) (['solid',]) line type to use for each isoline, can also pass a line object or line object name linecolors :: ([int,...]) ([241]) colors to use for each isoline @@ -594,13 +646,13 @@ textsdoc = """ text :: (None/[vcs.textcombined.Tc,...]) (None) text objects or text objects names to use for each countour labels textcolors :: (None/[int,...]) (None) colors to use for each countour labels -""" # noqa + """ # noqa markerdoc = """ marker :: (None/int/str/vcs.marker.Tm) (None) markers type to use markercolor :: (None/int) (None) color to use for markers markersize :: (None/int) (None) size of markers -""" + """ ############################################################################# # # @@ -609,81 +661,81 @@ ############################################################################# create_GM_input = """ -:param new_GM_name: (Ex: 'my_awesome_gm') name of the new graphics method object. If no name is given, then one will be created for use. -:type new_GM_name: str -:param source_GM_name: (Ex: 'default') copy the contents of the source object to the newly created one. If no name is given, then the 'default' graphics methond contents is copied over to the new object. -:type source_GM_name: str -""" # noqa + :param new_GM_name: (Ex: 'my_awesome_gm') name of the new graphics method object. If no name is given, then one will be created for use. + :type new_GM_name: str + :param source_GM_name: (Ex: 'default') copy the contents of the source object to the newly created one. If no name is given, then the 'default' graphics methond contents is copied over to the new object. + :type source_GM_name: str + """ # noqa get_GM_input = """ -:param GM_name: (Ex: 'default') retrieve the graphics method object of the given name. If no name is given, then retrieve the 'default' graphics method. -:type GM_name: str -""" # noqa + :param GM_name: (Ex: 'default') retrieve the graphics method object of the given name. If no name is given, then retrieve the 'default' graphics method. + :type GM_name: str + """ # noqa plot_1D_input = """ -:param slab: (Ex: [1, 2]) Data at least 1D, last dimension will be plotted -:type slab: array -""" # noqa + :param slab: (Ex: [1, 2]) Data at least 1D, last dimension will be plotted + :type slab: array + """ # noqa plot_2D_input = """ -:param slab: (Ex: [[0, 1]]) Data at least 2D, last 2 dimensions will be plotted -:type slab: array -""" # noqa + :param slab: (Ex: [[0, 1]]) Data at least 2D, last 2 dimensions will be plotted + :type slab: array + """ # noqa plot_2_1D_input = """ -:param slab_or_primary_object: Data at least 1D, last dimension(s) will be plotted, or secondary vcs object -:type slab_or_primary_object: array -""" # noqa + :param slab_or_primary_object: Data at least 1D, last dimension(s) will be plotted, or secondary vcs object + :type slab_or_primary_object: array + """ # noqa plot_2_1D_options = """ -:param slab2: Data at least 1D, last dimension(s) will be plotted -:param template: ('default') vcs template to use -:param gm: (Ex: 'default') graphic method to use -:type slab2: array -:type template: str/vcs.template.P -:type gm: VCS graphics method object -""" # noqa + :param slab2: Data at least 1D, last dimension(s) will be plotted + :param template: ('default') vcs template to use + :param gm: (Ex: 'default') graphic method to use + :type slab2: array + :type template: str/vcs.template.P + :type gm: VCS graphics method object + """ # noqa ############################################################################# # # # Graphics Method output section. # # # ############################################################################# plot_output = """ -:return: Display Plot object representing the plot. -:rtype: vcs.displayplot.Dp -""" + :return: Display Plot object representing the plot. + :rtype: vcs.displayplot.Dp + """ boxfill_output = """ boxfill :: (Ex: 0) no default -""" + """ isofill_output = """ isofill :: (Ex: 0) no default -""" + """ isoline_output = """ isoline :: (Ex: 0) no default -""" + """ yxvsx_output = """ yxvsx :: (Ex: 0) no default -""" + """ xyvsy_output = """ xyvsy :: (Ex: 0) no default -""" + """ xvsy_output = """ xvsy :: (Ex: 0) no default -""" + """ scatter_output = """ scatter :: (Ex: 0) no default -""" + """ outfill_output = """ outfill :: (Ex: 0) no default -""" + """ outline_output = """ outline :: (Ex: 0) no default -""" + """ From abd64feeb9fe9ba9796199a5ea01c87f9f297666 Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Wed, 24 Aug 2016 18:28:57 -0700 Subject: [PATCH 3/8] Adding doctests to Canvas examples --- vcs/Canvas.py | 614 ++++++++++++++++++++++++++------------------------ 1 file changed, 323 insertions(+), 291 deletions(-) diff --git a/vcs/Canvas.py b/vcs/Canvas.py index b6ba6e9c6..fece48f51 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -788,13 +788,13 @@ def objecthelp(self, *arg): :Example: - :: + .. doctest:: a=vcs.init() # Get a VCS line object ln=a.getline('red') # This will print out information on how to use ln - a.objecthelp(ln) + >>> a.objecthelp(ln) """ for x in arg: print getattr(x, "__doc__", "") @@ -943,6 +943,14 @@ def getdrawlogo(self): """ Returns value of draw logo + :Example: + + .. doctest:: canvas_getdrawlogo + + >>> a=vcs.init() + >>> a.getdrawlogo() + True + :returns: Boolean value of system variable which indicates whether log will be drawn :rtype: bool """ @@ -959,20 +967,19 @@ def update(self, *args, **kargs): :Example: - :: + .. doctest:: canvas_update - a=vcs.init() - a.plot(s,'default','boxfill','quick') - # Go to manual mode - a.mode = 0 - box=x.getboxfill('quick') - box.color_1=100 - box.xticlabels('lon30','lon30') - box.xticlabels('','') - box.datawc(1e20,1e20,1e20,1e20) - box.datawc(-45.0, 45.0, -90.0, 90.0) - # Update the changes manually - a.update() + >>> a=vcs.init() + >>> s=None + >>> a.plot(s,'default','boxfill','quick') # TODO: add a bit creating a slab + >>> a.mode = 0 # Go to manual mode + >>> box=x.getboxfill('quick') + >>> box.color_1=100 + >>> box.xticlabels('lon30','lon30') + >>> box.xticlabels('','') + >>> box.datawc(1e20,1e20,1e20,1e20) + >>> box.datawc(-45.0, 45.0, -90.0, 90.0) + >>> a.update() # Update the changes manually """ return self.backend.update(*args, **kargs) @@ -1004,18 +1011,13 @@ def scriptobject(self, obj, script_filename=None, mode=None): :Example: - :: + .. doctest:: canvas_scriptobject - a=vcs.init() - # To Modify an existing line object - l=a.getline('red') - # Create an instance of default isoline object - i=a.createisoline('dean') - #... - # Save isoline object as a Python file 'isoline.py' - a.scriptobject(i,'ex_isoline.py') - # Save isoline object as a JSON object 'isoline2.json' - a.scriptobject(i,'ex_isoline2') + >>> a=vcs.init() + >>> l=a.getline('red') # To Modify an existing line object + >>> i=a.createisoline('dean') # Create an instance of default isoline object + >>> a.scriptobject(i,'ex_isoline.py') # Save isoline object as a Python file 'isoline.py' + >>> a.scriptobject(i,'ex_isoline2') # Save isoline object as a JSON object 'isoline2.json' :param script_filename: Name of the output script file. :type script_filename: str @@ -1142,17 +1144,6 @@ def getprojection(self, Proj_name_src='default'): getprojection.__doc__ = vcs.manageElements.getprojection.__doc__ def createboxfill(self, name=None, source='default'): - """ - Create a Boxfill Graphics Method - - :param name: The name of the created object - :type name: str - - :param source: The object to inherit from - :type source: a boxfill, or a string name of a boxfill - - :return: A boxfill graphics method - """ return vcs.createboxfill(name, source) createboxfill.__doc__ = vcs.manageElements.createboxfill.__doc__ @@ -1171,33 +1162,33 @@ def boxfill(self, *args, **parms): :Example: - :: + .. doctest:: canvas_boxfill - a=vcs.init() - # Show all the existing boxfill graphics methods - a.show('boxfill') - # Create instance of 'quick' - box=a.getboxfill('quick') - # Plot array using specified box and default template - a.boxfill(array,box) - # Create an instance of template 'AMIP' - template=a.gettemplate('AMIP') - # Clear VCS canvas - a.clear() - # Plot array using specified box and template - a.boxfill(array,box,template) - # Plot array using specified box and template - a.boxfill(box,array,template) - # Plot array using specified box and template - a.boxfill(template,array,box) - # Plot array using specified box and template - a.boxfill(template,array,box) - # Use 'AMIP' template and 'quick' boxfill - a.boxfill(array,'AMIP','quick') - # Use 'AMIP' template and 'quick' boxfill - a.boxfill('AMIP',array,'quick') - # Use 'AMIP' template and 'quick' boxfill - a.boxfill('AMIP','quick',array) + >>> a=vcs.init() + + >>> a.show('boxfill') # Show all the existing boxfill graphics methods + + >>> box=a.getboxfill('quick') # Create instance of 'quick' + + >>> a.boxfill(array,box) # Plot array using specified box and default template + + >>> template=a.gettemplate('AMIP') # Create an instance of template 'AMIP' + + >>> a.clear() # Clear VCS canvas + + >>> a.boxfill(array,box,template) # Plot array using specified box and template + + >>> a.boxfill(box,array,template) # Plot array using specified box and template + + >>> a.boxfill(template,array,box) # Plot array using specified box and template + + >>> a.boxfill(template,array,box) # Plot array using specified box and template + + >>> a.boxfill(array,'AMIP','quick') # Use 'AMIP' template and 'quick' boxfill + + >>> a.boxfill('AMIP',array,'quick') # Use 'AMIP' template and 'quick' boxfill + + >>> a.boxfill('AMIP','quick',array) # Use 'AMIP' template and 'quick' boxfill %s %s @@ -1227,19 +1218,23 @@ def taylordiagram(self, *args, **parms): :Example: - :: + .. doctest:: canvas_taylordiagram - a=vcs.init() - # Show all the existing taylordiagram graphics methods - a.show('taylordiagram') - # Create instance of 'default' - td=a.gettaylordiagram() - # Plot array using specified iso and default template - a.taylordiagram(array,td) - # Clear VCS canvas - a.clear() - # Plot array using specified iso and template - a.taylordiagram(array,td,template) + >>> a=vcs.init() + + >>> a.show('taylordiagram') # Show all the existing taylordiagram graphics methods + + >>> td= a.gettaylordiagram() # Create instance of 'default' + + >>> array=None # TODO: put a legitimate array here + + >>> a.taylordiagram(array,td) # Plot array using specified iso and default template + + >>> a.clear() # Clear VCS canvas + + >>> template=None # TODO: put a legitimate template here + + >>> a.taylordiagram(array,td,template) # Plot array using specified iso and template """ arglist = _determine_arg_list('taylordiagram', args) return self.__plot(arglist, parms) @@ -1275,19 +1270,19 @@ def meshfill(self, *args, **parms): # noqa :Example: - :: + .. doctest:: canvas_meshfill - a=vcs.init() - # Show all the existing meshfill graphics methods - a.show('meshfill') - # Create instance of 'default' - mesh=a.getmeshfill() - # Plot array using specified mesh and default template - a.meshfill(array,mesh) - # Clear VCS canvas - a.clear() - # Plot array using specified mesh mesh graphic method and template - a.meshfill(array,mesh,mesh_graphic_method,template) + >>> a=vcs.init() + + >>> a.show('meshfill') # Show all the existing meshfill graphics methods + # Create instance of 'default' + mesh=a.getmeshfill() + # Plot array using specified mesh and default template + >>> a.meshfill(array,mesh) + # Clear VCS canvas + >>> a.clear() + # Plot array using specified mesh mesh graphic method and template + >>> a.meshfill(array,mesh,mesh_graphic_method,template) :returns: ??? :rtype: ??? @@ -1351,19 +1346,19 @@ def isofill(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing isofill graphics methods - a.show('isofill') + >>> a.show('isofill') # Create instance of 'quick' iso=a.getisofill('quick') # Plot array using specified iso and default template - a.isofill(array,iso) + >>> a.isofill(array,iso) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified iso and template - a.isofill(array,iso,template) + >>> a.isofill(array,iso,template) %s %s @@ -1393,19 +1388,19 @@ def isoline(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing isoline graphics methods - a.show('isoline') + >>> a.show('isoline') # Create instance of 'quick' iso=a.getisoline('quick') # Plot array using specified iso and default template - a.isoline(array,iso) + >>> a.isoline(array,iso) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified iso and template - a.isoline(array,iso,template) + >>> a.isoline(array,iso,template) %s %s @@ -1443,19 +1438,19 @@ def xyvsy(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing Xyvsy graphics methods - a.show('xyvsy') + >>> a.show('xyvsy') # Create instance of 'quick' xyy=a.getxyvsy('quick') # Plot array using specified xyy and default template - a.xyvsy(array,xyy) + >>> a.xyvsy(array,xyy) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified xyy and template - a.xyvsy(array,xyy,template) + >>> a.xyvsy(array,xyy,template) %s %s @@ -1485,19 +1480,19 @@ def yxvsx(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing Yxvsx graphics methods - a.show('yxvsx') + >>> a.show('yxvsx') # Create instance of 'quick' yxx=a.getyxvsx('quick') # Plot array using specified yxx and default template - a.yxvsx(array,yxx) + >>> a.yxvsx(array,yxx) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified yxx and template - a.yxvsx(array,yxx,template) + >>> a.yxvsx(array,yxx,template) %s %s @@ -1527,19 +1522,19 @@ def xvsy(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing XvsY graphics methods - a.show('xvsy') + >>> a.show('xvsy') # Create instance of 'quick' xy=a.getxvsy('quick') # Plot array using specified xy and default template - a.xvsy(array,xy) + >>> a.xvsy(array,xy) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified xy and template - a.xvsy(array,xy,template) + >>> a.xvsy(array,xy,template) %s %s @@ -1572,19 +1567,19 @@ def vector(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing vector graphics methods - a.show('vector') + >>> a.show('vector') # Create instance of 'quick' vec=a.getvector('quick') # Plot array using specified vec and default template - a.vector(array,vec) + >>> a.vector(array,vec) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified vec and template - a.vector(array,vec,template) + >>> a.vector(array,vec,template) """ arglist = _determine_arg_list('vector', args) return self.__plot(arglist, parms) @@ -1606,19 +1601,19 @@ def scatter(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing scatter graphics methods - a.show('scatter') + >>> a.show('scatter') # Create instance of 'quick' sct=a.getscatter('quick') # Plot array using specified sct and default template - a.scatter(array,sct) + >>> a.scatter(array,sct) # Clear VCS canvas - a.clear() + >>> a.clear() # Plot array using specified sct and template - a.scatter(array,sct,template) + >>> a.scatter(array,sct,template) %s %s @@ -1655,11 +1650,11 @@ def line(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing line objects - a.show('line') + >>> a.show('line') # Create instance of 'red' ln=a.getline('red') # Set the line width @@ -1673,7 +1668,7 @@ def line(self, *args, **parms): # Set the y value points ln.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Plot using specified line object - a.line(ln) + >>> a.line(ln) """ arglist = _determine_arg_list('line', args) return self.__plot(arglist, parms) @@ -1687,11 +1682,11 @@ def drawline(self, name=None, ltype='solid', width=1, color=241, # noqa :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing line objects - a.show('line') + >>> a.show('line') # Create instance of line object 'red' ln=a.drawline(name='red', ltype='dash', width=2, color=242, priority=1, viewport=[0, 1.0, 0, 1.0], @@ -1699,7 +1694,7 @@ def drawline(self, name=None, ltype='solid', width=1, color=241, # noqa x=[0,20,40,60,80,100], y=[0,10,20,30,40,50] ) # Plot using specified line object - a.line(ln) + >>> a.line(ln) :param name: Name of created object :type name: str @@ -1781,11 +1776,11 @@ def marker(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing marker objects - a.show('marker') + >>> a.show('marker') # Create instance of 'red' mrk=a.getmarker('red') # Set the marker size @@ -1799,7 +1794,7 @@ def marker(self, *args, **parms): # Set the y value points mrk.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Plot using specified marker object - a.marker(mrk) + >>> a.marker(mrk) :returns: a VCS displayplot object :rtype: vcs.displayplot.Dp @@ -1816,11 +1811,11 @@ def drawmarker(self, name=None, mtype='solid', size=1, color=241, :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing marker objects - a.show('marker') + >>> a.show('marker') # Create instance of marker object 'red' mrk=a.drawmarker(name='red', mtype='dot', size=2, color=242, priority=1, viewport=[0, 1.0, 0, 1.0], @@ -1828,7 +1823,7 @@ def drawmarker(self, name=None, mtype='solid', size=1, color=241, x=[0,20,40,60,80,100], y=[0,10,20,30,40,50] ) # Plot using specified marker object - a.marker(mrk) + >>> a.marker(mrk) :param name: Name of created object :type name: str @@ -1908,11 +1903,11 @@ def fillarea(self, *args, **parms): :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing fillarea objects - a.show('fillarea') + >>> a.show('fillarea') # Create instance of 'red' fa=a.createfillarea('red') # Set the fillarea style @@ -1928,7 +1923,7 @@ def fillarea(self, *args, **parms): # Set the y value points fa.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Plot using specified fillarea object - a.fillarea(fa) + >>> a.fillarea(fa) :returns: A fillarea object :rtype: vcs.displayplot.Dp @@ -1945,11 +1940,11 @@ def drawfillarea(self, name=None, style=1, index=1, color=241, :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing fillarea objects - a.show('fillarea') + >>> a.show('fillarea') # Create instance of fillarea object 'red' fa=a.drawfillarea(name='red', style=1, color=242, priority=1, viewport=[0, 1.0, 0, 1.0], @@ -1957,7 +1952,7 @@ def drawfillarea(self, name=None, style=1, index=1, color=241, x=[0,20,40,60,80,100], y=[0,10,20,30,40,50], bg=0 ) # Plot using specified fillarea object - a.fillarea(fa) + >>> a.fillarea(fa) :param name: Name of created object :type name: str @@ -2080,31 +2075,40 @@ def textcombined(self, *args, **parms): :Example: - :: + .. doctest:: canvas_textcombined - a=vcs.init() - # Show all the existing texttable objects - a.show('texttable') - # Show all the existing textorientation objects - a.show('textorientation') - # Create instance of 'std' and '7left' - tt=a.gettext('std','7left') - # Show the string "Text1" on the VCS Canvas - tt.string = 'Text1' - # Set the text size - tt.font=2 - # Set the text color - tt.color = 242 - # Set the text angle - tt.angle = 45 - # Set the x value points - tt.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - tt.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified text object - a.text(tt) - #Optionally you can pass a string, the coordinates, and any keyword - a.plot('Hi',.5,.5,color=241,angle=45) + >>> a=vcs.init() + + >>> a.show('texttable') # Show all the existing texttable objects + *******************Texttable Names List********************** + ... + *******************End Texttable Names List********************** + + >>> a.show('textorientation') # Show all the existing textorientation objects + *******************Textorientation Names List********************** + ... + *******************End Textorientation Names List********************** + + >>> vcs.createtext('std_tt', 'std', '7left_to', '7left') # Create instance of 'std_tt' and '7left_to' + >> tc=a.gettext('std_tt','7left_to') + + >>> tc.string = 'Text1' # Show the string "Text1" on the VCS Canvas + + >>> tc.font=2 # Set the text size + + >>> tc.color = 242 # Set the text color + + >>> tc.angle = 45 # Set the text angle + + >>> tc.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] # Set the x value points + + >>> tc.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Set the y value points + + >>> a.textcombined(tc) # Plot using specified text object + + >>> a.plot('Hi',.5,.5,color=241,angle=45) # You can also pass a string, the coordinates, and any keyword :returns: A plot object :rtype: @@ -2146,7 +2150,7 @@ def gettextextent(self, textobject): :Example: - :: + .. doctest:: a=vcs.init() t=a.createtext() @@ -2183,11 +2187,11 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None, :Example: - :: + .. doctest:: a=vcs.init() # Show all the existing texttable objects - a.show('texttable') + >>> a.show('texttable') # Create instance of texttable object 'red' tt=a.drawtexttable(Tt_name = 'red', To_name='7left', mtype='dash', size=2, color=242, priority=1, viewport=[0, 1.0, 0, 1.0], @@ -2195,7 +2199,7 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None, x=[0,20,40,60,80,100], y=[0,10,20,30,40,50] ) # Plot using specified texttable object - a.texttable(tt) + >>> a.texttable(tt) :param name: Name of created object :type name: str @@ -2442,7 +2446,7 @@ def plot(self, *actual_args, **keyargs): :Example: - :: + .. doctest:: # x is an instance of the VCS class object (constructor) x=vcs.init() @@ -3931,12 +3935,12 @@ def clear(self, *args, **kargs): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') + >>> a.plot(array,'default','isofill','quick') #clear VCS displays from the page - a.clear() + >>> a.clear() """ if self.animate.created(): @@ -3975,12 +3979,12 @@ def close(self, *args, **kargs): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') + >>> a.plot(array,'default','isofill','quick') #close the vcs canvas - a.close() + >>> a.close() """ if self.configurator: @@ -3996,11 +4000,11 @@ def destroy(self): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') - a.destroy() + >>> a.plot(array,'default','isofill','quick') + >>> a.destroy() """ import gc @@ -4044,11 +4048,11 @@ def flush(self, *args): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') - a.flush() + >>> a.plot(array,'default','isofill','quick') + >>> a.flush() """ return self.backend.flush(*args) @@ -4058,11 +4062,11 @@ def geometry(self, *args): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') - a.geometry(450,337) + >>> a.plot(array,'default','isofill','quick') + >>> a.geometry(450,337) """ if len(args) == 0: return self.backend.geometry() @@ -4091,7 +4095,7 @@ def getcontinentstype(self, *args): :Example: - :: + .. doctest:: a=vcs.init() # Get the continents type @@ -4112,16 +4116,16 @@ def pstogif(self, filename, *opt): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # convert the postscript file to a gif file (l=landscape) - a.pstogif('filename.ps') + >>> a.pstogif('filename.ps') # convert the postscript file to a gif file (l=landscape) - a.pstogif('filename.ps','l') + >>> a.pstogif('filename.ps','l') # convert the postscript file to a gif file (p=portrait) - a.pstogif('filename.ps','p') + >>> a.pstogif('filename.ps','p') :param filename: String name of the desired output file :type filename: str @@ -4169,10 +4173,10 @@ def grid(self, *args): :Example: - :: + .. doctest:: a=vcs.init() - a.grid(12,12,0,71,0,45) + >>> a.grid(12,12,0,71,0,45) """ p = self.canvas.grid(*args) @@ -4200,20 +4204,20 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Change the VCS Canvas orientation and set object flag to landscape - a.landscape() + >>> a.landscape() # Change the VCS Canvas to landscape and clear the page - a.landscape(clear=1) + >>> a.landscape(clear=1) # Change to landscape and set the window size - a.landscape(width = 400, height = 337) + >>> a.landscape(width = 400, height = 337) # Change to landscape and set the x and y screen position - a.landscape(x=100, y = 200) + >>> a.landscape(x=100, y = 200) # Change to landscape and give specifications - a.landscape(width = 400, height = 337, x=100, y = 200, clear=1) + >>> a.landscape(width = 400, height = 337, x=100, y = 200, clear=1) :param width: Width of the canvas, in pixels :type width: int @@ -4273,10 +4277,10 @@ def listelements(self, *args): :Example: - :: + .. doctest:: a=vcs.init() - a.listelements() + >>> a.listelements() :returns: A list of string names of all VCS class objects :rtype: list @@ -4303,11 +4307,11 @@ def open(self, width=None, height=None, **kargs): :Example: - :: + .. doctest:: a=vcs.init() - a.open() - a.open(800,600) + >>> a.open() + >>> a.open(800,600) :param width: Integer representing the desire width of the opened window in pixels :type width: int @@ -4338,20 +4342,20 @@ def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Change the VCS Canvas orientation and set object flag to portrait - a.portrait() + >>> a.portrait() # Change the VCS Canvas to portrait and clear the page - a.portrait(clear=1) + >>> a.portrait(clear=1) # Change to portrait and set the window size - a.portrait(width = 337, height = 400) + >>> a.portrait(width = 337, height = 400) # Change to portrait and set the x and y screen position - a.portrait(x=100, y = 200) + >>> a.portrait(x=100, y = 200) # Change to portrait and give specifications - a.portrait(width = 337, height = 400, x=100, y = 200, clear=1) + >>> a.portrait(width = 337, height = 400, x=100, y = 200, clear=1) :param width: Width to set the canvas to (in pixels) :type width: int @@ -4414,7 +4418,7 @@ def ffmpeg(self, movie, files, bitrate=1024, rate=None, options=None): :Example: - :: + .. doctest:: a=vcs.init() #... code to generate png files ... @@ -4424,15 +4428,15 @@ def ffmpeg(self, movie, files, bitrate=1024, rate=None, options=None): a.png('my_png__%i' % i) files.append('my_png__%i.png' % i) # generates mpeg from pattern - a.ffmpeg('mymovie.mpeg','my_png_%d.png') + >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png') # generates from list of files - a.ffmpeg('mymovie.mpeg',files) + >>> a.ffmpeg('mymovie.mpeg',files) # generates mpeg at 512kbit - a.ffmpeg('mymovie.mpeg','my_png_%d.png',bitrate=512) + >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png',bitrate=512) # generates movie with 50 frame per second - a.ffmpeg('mymovie.mpeg','my_png_%d.png',rate=50) + >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png',rate=50) # generates movie at 50 frame per sec and 1024k bitrate - a.ffmpeg('mymovie.mpeg','my_png_%d.png',options='-r 50 -b 1024k') + >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png',options='-r 50 -b 1024k') :param movie: Output video file name :type movie: str @@ -4546,13 +4550,13 @@ def setbgoutputdimensions(self, width=None, height=None, units='inches'): :Example: - :: + .. doctest:: a=vcs.init() # US Legal - a.setbgoutputdimensions(width=11.5, height= 8.5) + >>> a.setbgoutputdimensions(width=11.5, height= 8.5) # A4 - a.setbgoutputdimensions(width=21, height=29.7, units='cm') + >>> a.setbgoutputdimensions(width=21, height=29.7, units='cm') :param width: Float representing the desired width of the output, using the specified unit of measurement :type width: float @@ -4594,12 +4598,12 @@ def png(self, file, width=None, height=None, :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Overwrite a png file - a.png('example') + >>> a.png('example') :param file: Output image filename :type file: str @@ -4641,16 +4645,16 @@ def pdf(self, file, width=None, height=None, units='inches', :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Overwrite a postscript file - a.pdf('example') + >>> a.pdf('example') # US Legal - a.pdf('example', width=11.5, height= 8.5) + >>> a.pdf('example', width=11.5, height= 8.5) # A4 - a.pdf('example', width=21, height=29.7, units='cm') + >>> a.pdf('example', width=21, height=29.7, units='cm') :param file: Desired string name of the output file :type file: str @@ -4693,16 +4697,16 @@ def svg(self, file, width=None, height=None, units='inches', :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Overwrite a postscript file - a.svg('example') + >>> a.svg('example') # US Legal - a.svg('example', width=11.5, height= 8.5) + >>> a.svg('example', width=11.5, height= 8.5) # A4 - a.svg('example', width=21, height=29.7, units='cm') + >>> a.svg('example', width=21, height=29.7, units='cm') :param file: :type file: @@ -4926,24 +4930,24 @@ def postscript(self, file, mode='r', orientation=None, width=None, height=None, :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Overwrite a postscript file - a.postscript('example') + >>> a.postscript('example') # Append postscript to an existing file - a.postscript('example', 'a') + >>> a.postscript('example', 'a') # Overwrite an existing file - a.postscript('example', 'r') + >>> a.postscript('example', 'r') # Append postscript to an existing file - a.postscript('example', mode='a') + >>> a.postscript('example', mode='a') # US Legal (default) - a.postscript('example', width=11.5, height= 8.5) + >>> a.postscript('example', width=11.5, height= 8.5) # A4 - a.postscript('example', width=21, height=29.7, units='cm') + >>> a.postscript('example', width=21, height=29.7, units='cm') # US Legal output and control of margins (for printer friendly output), default units 'inches' - a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) + >>> a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) :param file: String name of the desired output file :type file: str @@ -5009,11 +5013,11 @@ def setcolormap(self, name): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') - a.setcolormap("AMIP") + >>> a.plot(array,'default','isofill','quick') + >>> a.setcolormap("AMIP") :param name: Name of the colormap to use :type name: str @@ -5044,17 +5048,17 @@ def setcolorcell(self, *args): :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array,'default','isofill','quick') - a.setcolormap("AMIP") - a.setcolorcell(11,0,0,0) - a.setcolorcell(21,100,0,0) - a.setcolorcell(31,0,100,0) - a.setcolorcell(41,0,0,100) - a.setcolorcell(51,100,100,100) - a.setcolorcell(61,70,70,70) + >>> a.plot(array,'default','isofill','quick') + >>> a.setcolormap("AMIP") + >>> a.setcolorcell(11,0,0,0) + >>> a.setcolorcell(21,100,0,0) + >>> a.setcolorcell(31,0,100,0) + >>> a.setcolorcell(41,0,0,100) + >>> a.setcolorcell(51,100,100,100) + >>> a.setcolorcell(61,70,70,70) """ a = vcs.setcolorcell(self.colormap, *args) @@ -5067,15 +5071,15 @@ def setcontinentsline(self, line="default"): :Example: - :: + .. doctest:: a = vcs.init() line = vcs.createline() line.width = 5 # Use custom continents line - a.setcontinentsline(line) + >>> a.setcontinentsline(line) # Use default line - a.setcontinentsline("default") + >>> a.setcontinentsline("default") :param line: Line to use for drawing continents. Can be a string name of a line, or a VCS line object :type line: str or :py:class:`vcs.line.Tl` @@ -5111,11 +5115,11 @@ def setcontinentstype(self, value): :Example: - :: + .. doctest:: a=vcs.init() - a.setcontinentstype(3) - a.plot(array,'default','isofill','quick') + >>> a.setcontinentstype(3) + >>> a.plot(array,'default','isofill','quick') :param value: Integer representing continent type, as specified in function description :type value: int @@ -5158,23 +5162,23 @@ def gif(self, filename='noname.gif', merge='r', orientation=None, :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) - a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') + >>> a.plot(array) + >>> a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') # overwrite existing gif file (default is merge='r') - a.gif('example') + >>> a.gif('example') # overwrite existing gif file - a.gif('example',merge='r') + >>> a.gif('example',merge='r') # merge gif image into existing gif file - a.gif('example',merge='a') + >>> a.gif('example',merge='a') # merge gif image into existing gif file with landscape orientation - a.gif('example',orientation='l') + >>> a.gif('example',orientation='l') # merge gif image into existing gif file with portrait orientation - a.gif('example',orientation='p') + >>> a.gif('example',orientation='p') # merge gif image into existing gif file and set the gif geometry - a.gif('example',geometry='600x500') + >>> a.gif('example',geometry='600x500') """ if orientation is None: orientation = self.orientation()[0] @@ -5200,23 +5204,23 @@ def eps(self, file, mode='r', orientation=None, width=None, height=None, units=' :Example: - :: + .. doctest:: a=vcs.init() - a.plot(array) + >>> a.plot(array) # Overwrite a postscript file - a.postscript('example') + >>> a.postscript('example') # Append postscript to an existing file - a.postscript('example', 'a') + >>> a.postscript('example', 'a') # Overwrite an existing file - a.postscript('example', 'r') + >>> a.postscript('example', 'r') # Append postscript to an existing file - a.postscript('example', mode='a') + >>> a.postscript('example', mode='a') # US Legal (default) - a.postscript('example', width=11.5, height= 8.5) + >>> a.postscript('example', width=11.5, height= 8.5) # A4 - a.postscript('example', width=21, height=29.7, units='cm') - a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) + >>> a.postscript('example', width=21, height=29.7, units='cm') + >>> a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) # US Legal output and control of margins (for printer friendly output), default units 'inches' :param file: String name of the desired output file @@ -5298,12 +5302,12 @@ def saveinitialfile(self): :Example: - :: + .. doctest:: a=vcs.init() ... - a.saveinitialfile() + >>> a.saveinitialfile() .. warning:: This removes first ALL object generated automatically @@ -5334,13 +5338,13 @@ def islandscape(self): :Example: - :: + .. doctest:: a=vcs.init() # ... if a.islandscape(): # Set VCS's orientation to portrait mode - a.portrait() + >>> a.portrait() :returns: Integer indicating VCS is in landscape mode (1), or not (0) :rtype: int @@ -5357,7 +5361,7 @@ def isportrait(self): :Example: - :: + .. doctest:: a=vcs.init() #... @@ -5385,13 +5389,13 @@ def getplot(self, Dp_name_src='default', template=None): :Example: - :: + .. doctest:: canvas_getplot - a=vcs.init() - # Show all the existing templates - a.show('template') - # plot1 instance of 'dpy_plot_1' display plot - plot1=a.getplot('dpy_plot_1') + >>> a=vcs.init() + + >>> a.show('template') # Show all the existing templates + + >>> plot1=a.getplot('dpy_plot_1') # plot1 instance of 'dpy_plot_1' display plot :param Dp_name_src: String name of an existing display plot object :type Dp_name_src: str @@ -5473,6 +5477,34 @@ def getfont(self, font): """ Get the font name/number associated with a font number/name + :Example: + + .. doctest:: canvas_getfont + + >>> a=vcs.init() + + >>> fonts=[] + + >>> for i in range(1,17): + ... fonts.append(str(a.getfont(i))) + + >>> print(fonts[0:8]) + ['default', 'Clarendon', 'Courier', 'Helvetica', 'Adelon', 'Times', 'Arabic', 'Chinese'] + >>> print(fonts[8:16]) + ['Greek', 'Hebrew', 'Russian', 'Maths1', 'Maths2', 'Maths3', 'Maths4', 'AvantGarde'] + + >>> fontmap = {} + + >>> for font in fonts: + ... fontmap[font] = a.getfont(font) + + >>> print(fontmap.items()[0:6]) + [('Maths1', 12), ('Maths3', 14), ('Maths2', 13), ('Chinese', 8), ('Courier', 3), ('Greek', 9)] + >>> print(fontmap.items()[6:12]) + [('default', 1), ('Helvetica', 4), ('AvantGarde', 16), ('Times', 6), ('Clarendon', 2), ('Hebrew', 10)] + >>> print(fontmap.items()[12:16]) + [('Russian', 11), ('Adelon', 5), ('Arabic', 7), ('Maths4', 15)] + :param font: The font name/number :type font: int or str @@ -5568,11 +5600,11 @@ def orientation(self, *args, **kargs): :Example: - :: + .. doctest:: a = vcs.init() # Show current orientation of the canvas - a.orientation() + >>> a.orientation() :returns: A string indicating the orientation of the canvas, i.e. 'landscape' or 'portrait' :rtype: str From aa79b1b31aedb55d39230e2a768977d47c3b3594 Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Tue, 30 Aug 2016 17:50:36 -0700 Subject: [PATCH 4/8] Converting Canvas.py examples to doctests. --- vcs/Canvas.py | 594 +++++++++++++++++++++++++--------------------- vcs/projection.py | 263 +++++++++++--------- 2 files changed, 478 insertions(+), 379 deletions(-) diff --git a/vcs/Canvas.py b/vcs/Canvas.py index fece48f51..01de9d275 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -788,13 +788,11 @@ def objecthelp(self, *arg): :Example: - .. doctest:: + .. doctest:: canvas_objecthelp - a=vcs.init() - # Get a VCS line object - ln=a.getline('red') - # This will print out information on how to use ln - >>> a.objecthelp(ln) + >>> a=vcs.init() + >>> ln=a.getline('red') # Get a VCS line object + >>> a.objecthelp(ln) # This will print out information on how to use ln """ for x in arg: print getattr(x, "__doc__", "") @@ -932,16 +930,38 @@ def processParameterChange(self, args): # Functions to set/querie drawing of UV-CDAT logo def drawlogoon(self): - """Show UV-CDAT logo on the canvas""" + """ + Show UV-CDAT logo on the canvas + + :Example: + + .. doctest:: canvas_drawlogoon + + >>> a=vcs.init() + >>> a.drawlogoon() + >>> a.getdrawlogo() + True + """ self.enableLogo = True def drawlogooff(self): - """Hide UV-CDAT logo on the canvas""" + """ + Hide UV-CDAT logo on the canvas + + :Example: + + .. doctest:: canvas_drawlogooff + + >>> a=vcs.init() + >>> a.drawlogooff() + >>> a.getdrawlogo() + False + """ self.enableLogo = False def getdrawlogo(self): """ - Returns value of draw logo + Returns value of draw logo. By default, draw logo is set to True. :Example: @@ -950,8 +970,11 @@ def getdrawlogo(self): >>> a=vcs.init() >>> a.getdrawlogo() True + >>> a.drawlogooff() + >>> a.getdrawlogo() + False - :returns: Boolean value of system variable which indicates whether log will be drawn + :returns: Boolean value of system variable which indicates whether logo will be drawn :rtype: bool """ return self.enableLogo @@ -970,10 +993,13 @@ def update(self, *args, **kargs): .. doctest:: canvas_update >>> a=vcs.init() - >>> s=None - >>> a.plot(s,'default','boxfill','quick') # TODO: add a bit creating a slab + >>> import cdms2 # We need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> s = f('clt') # use the data file to create a slab + >>> a.plot(s,'default','boxfill','quick') + >>> a.mode = 0 # Go to manual mode - >>> box=x.getboxfill('quick') + >>> box=a.getboxfill('quick') >>> box.color_1=100 >>> box.xticlabels('lon30','lon30') >>> box.xticlabels('','') @@ -1019,15 +1045,15 @@ def scriptobject(self, obj, script_filename=None, mode=None): >>> a.scriptobject(i,'ex_isoline.py') # Save isoline object as a Python file 'isoline.py' >>> a.scriptobject(i,'ex_isoline2') # Save isoline object as a JSON object 'isoline2.json' - :param script_filename: Name of the output script file. - :type script_filename: str + :param script_filename: Name of the output script file. + :type script_filename: str - :param mode: Mode is either "w" for replace or "a" for append. - :type mode: str + :param mode: Mode is either "w" for replace or "a" for append. + :type mode: str - :param obj: Any VCS primary class or secondary class object. - :type obj: VCS object - """ + :param obj: Any VCS primary class or secondary class object. + :type obj: VCS object + """ if istemplate(obj): template.P.script(obj, script_filename, mode) elif isgraphicsmethod(obj): @@ -1153,13 +1179,13 @@ def getboxfill(self, Gfb_name_src='default'): def boxfill(self, *args, **parms): """ - Plot a boxfill. - Generate a boxfill plot given the data, boxfill graphics method, and template. If no boxfill class object is given, then the 'default' boxfill graphics method is used. Similarly, if no template class object is given, then the 'default' template is used. + + :Example: .. doctest:: canvas_boxfill @@ -1167,29 +1193,38 @@ def boxfill(self, *args, **parms): >>> a=vcs.init() >>> a.show('boxfill') # Show all the existing boxfill graphics methods + *******************Boxfill Names List********************** + ... + *******************End Boxfill Names List********************** >>> box=a.getboxfill('quick') # Create instance of 'quick' - >>> a.boxfill(array,box) # Plot array using specified box and default template - - >>> template=a.gettemplate('AMIP') # Create an instance of template 'AMIP' + >>> array=[range(10) for _ in range(10)] + >>> a.boxfill(array, box) # Plot array using specified box and default template + + >>> template = a.gettemplate('quick') # get quick template >>> a.clear() # Clear VCS canvas + >>> a.boxfill(array, box, template) # Plot array using specified box and template + + >>> a.boxfill(box, array, template) # Plot array using specified box and template + + >>> a.boxfill(template, array, box) # Plot array using specified box and template + + >>> a.boxfill(template, box, array) # Plot array using specified box and template + + >>> a.boxfill(array, 'hovmuller', 'quick') # Use 'hovmuller' template and 'quick' boxfill + + >>> a.boxfill('hovmuller', array, 'quick') # Use 'hovmuller' template and 'quick' boxfill + + >>> a.boxfill('hovmuller', 'quick', array) # Use 'hovmuller template and 'quick' boxfill + - >>> a.boxfill(array,box,template) # Plot array using specified box and template - - >>> a.boxfill(box,array,template) # Plot array using specified box and template - - >>> a.boxfill(template,array,box) # Plot array using specified box and template - - >>> a.boxfill(template,array,box) # Plot array using specified box and template - - >>> a.boxfill(array,'AMIP','quick') # Use 'AMIP' template and 'quick' boxfill - - >>> a.boxfill('AMIP',array,'quick') # Use 'AMIP' template and 'quick' boxfill - - >>> a.boxfill('AMIP','quick',array) # Use 'AMIP' template and 'quick' boxfill + .. note:: + As shown above, the array, 'template', and 'box' parameters can be provided in any order. + The 'template' and 'box' parameters can either be VCS template and boxfill objects, + or string names of template and boxfill objects. %s %s %s @@ -1223,18 +1258,20 @@ def taylordiagram(self, *args, **parms): >>> a=vcs.init() >>> a.show('taylordiagram') # Show all the existing taylordiagram graphics methods - + *******************Taylordiagram Names List********************** + ... + *******************End Taylordiagram Names List********************** >>> td= a.gettaylordiagram() # Create instance of 'default' - - >>> array=None # TODO: put a legitimate array here - + >>> array=[range(1, 11) for _ in range(1, 11)] >>> a.taylordiagram(array,td) # Plot array using specified iso and default template - + >>> a.clear() # Clear VCS canvas - - >>> template=None # TODO: put a legitimate template here - + >>> template=a.gettemplate('hovmuller') >>> a.taylordiagram(array,td,template) # Plot array using specified iso and template + + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('taylordiagram', args) return self.__plot(arglist, parms) @@ -1273,19 +1310,22 @@ def meshfill(self, *args, **parms): # noqa .. doctest:: canvas_meshfill >>> a=vcs.init() - >>> a.show('meshfill') # Show all the existing meshfill graphics methods - # Create instance of 'default' - mesh=a.getmeshfill() - # Plot array using specified mesh and default template - >>> a.meshfill(array,mesh) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified mesh mesh graphic method and template - >>> a.meshfill(array,mesh,mesh_graphic_method,template) + *******************Meshfill Names List********************** + ... + *******************End Meshfill Names List********************** + >>> import cdms2 # Need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> slab = f('clt') # use the data file to create a cdms2 slab + >>> mesh=a.getmeshfill() # Create instance of 'default' + >>> a.meshfill(slab,mesh) # Plot array using specified mesh and default template + + >>> a.clear() # Clear VCS canvas + >>> a.meshfill(slab,mesh,'quick','a_polar_meshfill') # Plot slab with polar mesh, quick template + - :returns: ??? - :rtype: ??? + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('meshfill', args) return self.__plot(arglist, parms) @@ -1346,25 +1386,32 @@ def isofill(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_isofill - a=vcs.init() - # Show all the existing isofill graphics methods - >>> a.show('isofill') - # Create instance of 'quick' - iso=a.getisofill('quick') - # Plot array using specified iso and default template - >>> a.isofill(array,iso) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified iso and template - >>> a.isofill(array,iso,template) + >>> a=vcs.init() + >>> a.show('isofill') # Show all the existing isofill graphics methods + *******************Isofill Names List********************** + ... + *******************End Isofill Names List********************** + >>> iso=a.getisofill('quick') # Create instance of 'quick' + >>> import cdms2 # Need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> slab = f('clt') # use the data file to create a cdms2 slab + >>> a.isofill(slab,iso) # Plot array using specified iso and default template + + >>> a.clear() # Clear VCS canvas + >>> template = a.gettemplate('hovmuller') + >>> a.isofill(slab,iso,template) # Plot array using specified iso and template + %s %s %s %s %s + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('isofill', args) return self.__plot(arglist, parms) @@ -1388,26 +1435,31 @@ def isoline(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_isoline - a=vcs.init() - # Show all the existing isoline graphics methods - >>> a.show('isoline') - # Create instance of 'quick' - iso=a.getisoline('quick') - # Plot array using specified iso and default template - >>> a.isoline(array,iso) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified iso and template - >>> a.isoline(array,iso,template) + >>> a=vcs.init() + >>> a.show('isoline') # Show all the existing isoline graphics methods + *******************Isoline Names List********************** + ... + *******************End Isoline Names List********************** + >>> iso=a.getisoline('quick') # Create instance of 'quick' + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.isoline(array,iso) # Plot array using specified iso and default template + + >>> a.clear() # Clear VCS canvas + >>> template = a.gettemplate('hovmuller') + >>> a.isoline(array,iso,template) # Plot array using specified iso and template + %s %s %s %s %s -""" + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp + """ arglist = _determine_arg_list('isoline', args) return self.__plot(arglist, parms) isoline.__doc__ = isoline.__doc__ % ( @@ -1438,25 +1490,30 @@ def xyvsy(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_xyvsy - a=vcs.init() - # Show all the existing Xyvsy graphics methods - >>> a.show('xyvsy') - # Create instance of 'quick' - xyy=a.getxyvsy('quick') - # Plot array using specified xyy and default template - >>> a.xyvsy(array,xyy) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified xyy and template - >>> a.xyvsy(array,xyy,template) + >>> a=vcs.init() + >>> a.show('xyvsy') # Show all the existing Xyvsy graphics methods + *******************Xyvsy Names List********************** + ... + *******************End Xyvsy Names List********************** + >>> xyy=a.getxyvsy('default_xyvsy_') # Create instance of default xyvsy + >>> array=[range(1, 11) for _ in range(1, 11)] + >>> a.xyvsy(array,xyy) # Plot array using specified xyy and default template + + >>> a.clear() # Clear VCS canvas + >>> template=a.gettemplate('hovmuller') + >>> a.xyvsy(array,xyy,template) # Plot array using specified xyy and template + %s %s %s %s %s + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('xyvsy', args) return self.__plot(arglist, parms) @@ -1480,25 +1537,30 @@ def yxvsx(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_yxvsx - a=vcs.init() - # Show all the existing Yxvsx graphics methods - >>> a.show('yxvsx') - # Create instance of 'quick' - yxx=a.getyxvsx('quick') - # Plot array using specified yxx and default template - >>> a.yxvsx(array,yxx) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified yxx and template - >>> a.yxvsx(array,yxx,template) + >>> a=vcs.init() + >>> a.show('yxvsx') # Show all the existing Yxvsx graphics methods + *******************Yxvsx Names List********************** + ... + *******************End Yxvsx Names List********************** + >>> yxx=a.getyxvsx('default_yxvsx_') # Create instance of default yxvsx + >>> array=[range(1, 11) for _ in range(1, 11)] + >>> a.yxvsx(array,yxx) # Plot array using specified yxx and default template + + >>> a.clear() # Clear VCS canvas + >>> template=a.gettemplate('hovmuller') + >>> a.yxvsx(array,yxx,template) # Plot array using specified yxx and template + %s %s %s %s %s + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('yxvsx', args) return self.__plot(arglist, parms) @@ -1522,25 +1584,30 @@ def xvsy(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_xvsy - a=vcs.init() - # Show all the existing XvsY graphics methods - >>> a.show('xvsy') - # Create instance of 'quick' - xy=a.getxvsy('quick') - # Plot array using specified xy and default template - >>> a.xvsy(array,xy) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified xy and template - >>> a.xvsy(array,xy,template) + >>> a=vcs.init() + >>> a.show('xvsy') # Show all the existing XvsY graphics methods + *******************Xvsy Names List********************** + ... + *******************End Xvsy Names List********************** + >>> xy=a.getxvsy('default_xvsy_') # Create instance of 'quick' + >>> array=[range(1, 11) for _ in range(1, 11)] + >>> a.xvsy(array,xy) # Plot array using specified xy and default template + + >>> a.clear() # Clear VCS canvas + >>> template=a.gettemplate('hovmuller') + >>> a.xvsy(array,xy,template) # Plot array using specified xy and template + %s %s %s %s %s + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('xvsy', args) return self.__plot(arglist, parms) @@ -1567,19 +1634,26 @@ def vector(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_vector - a=vcs.init() - # Show all the existing vector graphics methods - >>> a.show('vector') - # Create instance of 'quick' - vec=a.getvector('quick') - # Plot array using specified vec and default template - >>> a.vector(array,vec) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified vec and template - >>> a.vector(array,vec,template) + >>> a=vcs.init() + >>> a.show('vector') # Show all the existing vector graphics methods + *******************Vector Names List********************** + ... + *******************End Vector Names List********************** + >>> import cdms2 # Need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> slab1 = f('u') # use the data file to create a cdms2 slab + >>> slab2 = f('v') # vector needs 2 slabs, so get another + >>> a.vector(slab1, slab2) # plot vector using slab and default vector + + >>> a.clear() # Clear VCS canvas + >>> template=a.gettemplate('hovmuller') + >>> a.vector(slab1, slab2, template) # Plot array using default vector and specified template + + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('vector', args) return self.__plot(arglist, parms) @@ -1601,25 +1675,32 @@ def scatter(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_scatter - a=vcs.init() - # Show all the existing scatter graphics methods - >>> a.show('scatter') - # Create instance of 'quick' - sct=a.getscatter('quick') - # Plot array using specified sct and default template - >>> a.scatter(array,sct) - # Clear VCS canvas - >>> a.clear() - # Plot array using specified sct and template - >>> a.scatter(array,sct,template) + >>> a=vcs.init() + >>> a.show('scatter') # Show all the existing scatter graphics methods + *******************Scatter Names List********************** + ... + *******************End Scatter Names List********************** + >>> import cdms2 # Need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> slab1 = f('u') # use the data file to create a cdms2 slab + >>> slab2 = f('v') # need 2 slabs, so get another + >>> a.scatter(slab1, slab2) # Plot array using specified sct and default template + + >>> a.clear() # Clear VCS canvas + >>> template=a.gettemplate('hovmuller') + >>> a.scatter(slab1, slab2, template) # Plot array using specified sct and template + %s %s %s %s %s + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('scatter', args) @@ -1650,25 +1731,24 @@ def line(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_line - a=vcs.init() - # Show all the existing line objects - >>> a.show('line') - # Create instance of 'red' - ln=a.getline('red') - # Set the line width - ln.width=4 - # Set the line color - ln.color = 242 - # Set the line type - ln.type = 4 - # Set the x value points - ln.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - ln.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified line object - >>> a.line(ln) + >>> a=vcs.init() + >>> a.show('line') # Show all the existing line objects + *******************Line Names List********************** + ... + *******************End Line Names List********************** + >>> ln=a.getline('red') # Create instance of 'red' + >>> ln.width=4 # Set the line width + >>> ln.color = 242 # Set the line color + >>> ln.type = 4 # Set the line type + >>> ln.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] # Set the x value points + >>> ln.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Set the y value points + >>> a.line(ln) # Plot using specified line object + + + :returns: A VCS displayplot object. + :rtype: vcs.displayplot.Dp """ arglist = _determine_arg_list('line', args) return self.__plot(arglist, parms) @@ -1682,19 +1762,17 @@ def drawline(self, name=None, ltype='solid', width=1, color=241, # noqa :Example: - .. doctest:: + .. doctest:: canvas_drawline - a=vcs.init() - # Show all the existing line objects - >>> a.show('line') - # Create instance of line object 'red' - ln=a.drawline(name='red', ltype='dash', width=2, - color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50], - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified line object - >>> a.line(ln) + >>> a=vcs.init() + >>> a.show('line') # Show all the existing line objects + >>> ln=a.drawline(name='red', ltype='dash', width=2, + ... color=242, priority=1, viewport=[0, 1.0, 0, 1.0], + ... worldcoordinate=[0,100, 0,50], + ... x=[0,20,40,60,80,100], + ... y=[0,10,20,30,40,50] ) + >>> a.line(ln) # Plot using specified line object + :param name: Name of created object :type name: str @@ -1776,25 +1854,21 @@ def marker(self, *args, **parms): :Example: - .. doctest:: + .. doctest:: canvas_marker - a=vcs.init() - # Show all the existing marker objects - >>> a.show('marker') - # Create instance of 'red' - mrk=a.getmarker('red') - # Set the marker size - mrk.size=4 - # Set the marker color - mrk.color = 242 - # Set the marker type - mrk.type = 4 - # Set the x value points - mrk.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - mrk.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified marker object - >>> a.marker(mrk) + >>> a=vcs.init() + >>> a.show('marker') # Show all the existing marker objects + *******************Marker Names List********************** + ... + *******************End Marker Names List********************** + >>> mrk=a.getmarker('red') # Create instance of 'red' + >>> mrk.size=4 # Set the marker size + >>> mrk.color = 242 # Set the marker color + >>> mrk.type = 4 # Set the marker type + >>> mrk.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] # Set the x value points + >>> mrk.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Set the y value points + >>> a.marker(mrk) # Plot using specified marker object + :returns: a VCS displayplot object :rtype: vcs.displayplot.Dp @@ -1811,19 +1885,20 @@ def drawmarker(self, name=None, mtype='solid', size=1, color=241, :Example: - .. doctest:: + .. doctest:: canvas_drawmarker - a=vcs.init() - # Show all the existing marker objects - >>> a.show('marker') - # Create instance of marker object 'red' - mrk=a.drawmarker(name='red', mtype='dot', size=2, - color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified marker object - >>> a.marker(mrk) + >>> a=vcs.init() + >>> a.show('marker') # Show all the existing marker objects + *******************Marker Names List********************** + ... + *******************End Marker Names List********************** + >>> mrk=a.drawmarker(name='red', mtype='dot', size=2, + ... color=242, priority=1, viewport=[0, 1.0, 0, 1.0], + ... worldcoordinate=[0,100, 0,50] + ... x=[0,20,40,60,80,100], + ... y=[0,10,20,30,40,50] ) # Create instance of marker object 'red' + >>> a.marker(mrk) # Plot using specified marker object + :param name: Name of created object :type name: str @@ -1905,25 +1980,21 @@ def fillarea(self, *args, **parms): .. doctest:: - a=vcs.init() - # Show all the existing fillarea objects - >>> a.show('fillarea') - # Create instance of 'red' - fa=a.createfillarea('red') - # Set the fillarea style - fa.style=1 - # Set the fillarea index - fa.index=4 - # Set the fillarea color - fa.color = 242 - # Set the fillarea type - fa.type = 4 - # Set the x value points - fa.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] - # Set the y value points - fa.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] - # Plot using specified fillarea object - >>> a.fillarea(fa) + a=vcs.init() + + >>> a.show('fillarea') # Show all the existing fillarea objects + *******************Fillarea Names List********************** + ... + *******************End Fillarea Names List********************** + >>> fa=a.createfillarea() # Create instance of default fillarea + >>> fa.style=1 # Set the fillarea style + >>> fa.index=4 # Set the fillarea index + >>> fa.color = 242 # Set the fillarea color + >>> fa.type = 4 # Set the fillarea type + >>> fa.x=[[1.0,2.0,2.0,1.0,1.0], [0.5,1.5]] # Set the x value points + >>> fa.y=[[1.0,1.0,2.0,2.0,1.0], [1.0,1.0]] # Set the y value points + >>> a.fillarea(fa) # Plot using specified fillarea object + :returns: A fillarea object :rtype: vcs.displayplot.Dp @@ -2089,7 +2160,7 @@ def textcombined(self, *args, **parms): ... *******************End Textorientation Names List********************** - >>> vcs.createtext('std_tt', 'std', '7left_to', '7left') # Create instance of 'std_tt' and '7left_to' + >>> vcs.createtext('qa_tt', 'qa', '7left_to', '7left') # Create instance of 'std_tt' and '7left_to' >> tc=a.gettext('std_tt','7left_to') @@ -5206,22 +5277,16 @@ def eps(self, file, mode='r', orientation=None, width=None, height=None, units=' .. doctest:: - a=vcs.init() - >>> a.plot(array) - # Overwrite a postscript file - >>> a.postscript('example') - # Append postscript to an existing file - >>> a.postscript('example', 'a') - # Overwrite an existing file - >>> a.postscript('example', 'r') - # Append postscript to an existing file - >>> a.postscript('example', mode='a') - # US Legal (default) - >>> a.postscript('example', width=11.5, height= 8.5) - # A4 - >>> a.postscript('example', width=21, height=29.7, units='cm') - >>> a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) - # US Legal output and control of margins (for printer friendly output), default units 'inches' + >>> a=vcs.init() + >>> array = [range(10) for _ in range(10)] + >>> a.plot(array) + + >>> a.postscript('example') # Overwrite a postscript file + >>> a.postscript('example', 'a') # Append postscript to an existing file + >>> a.postscript('example', 'r') # Overwrite an existing file + >>> a.postscript('example', mode='a') # Append postscript to an existing file + >>> a.postscript('example', width=11.5, height= 8.5) # US Legal (default) + >>> a.postscript('example', width=21, height=29.7, units='cm') # A4 :param file: String name of the desired output file :type file: str @@ -5302,23 +5367,21 @@ def saveinitialfile(self): :Example: - .. doctest:: - - a=vcs.init() - ... + .. doctest:: canvas_saveinitial - >>> a.saveinitialfile() + >>> a=vcs.init() + >>> a.saveinitialfile() .. warning:: - This removes first ALL object generated automatically + + This removes first ALL objects generated automatically (i.e. whose name starts with '__') in order to preserve this, rename objects first e.g: - .. codeblock:: python + .. doctest:: canvas_saveinitial_warning - b=a.createboxfill() - b.name='MyBoxfill' - # graphic method is now preserved + >>> b=vcs.createboxfill() + >>> b.name='MyBoxfill' # graphic method is now preserved """ self.clean_auto_generated_objects() return vcs.saveinitialfile() @@ -5394,8 +5457,11 @@ def getplot(self, Dp_name_src='default', template=None): >>> a=vcs.init() >>> a.show('template') # Show all the existing templates + *******************Template Names List********************** + ... + *******************End Template Names List********************** - >>> plot1=a.getplot('dpy_plot_1') # plot1 instance of 'dpy_plot_1' display plot + >>> plot1=a.getplot() # plot1 instance of 'dpy_plot_1' display plot :param Dp_name_src: String name of an existing display plot object :type Dp_name_src: str @@ -5482,28 +5548,16 @@ def getfont(self, font): .. doctest:: canvas_getfont >>> a=vcs.init() - - >>> fonts=[] - + >>> font_names=[] >>> for i in range(1,17): - ... fonts.append(str(a.getfont(i))) - - >>> print(fonts[0:8]) - ['default', 'Clarendon', 'Courier', 'Helvetica', 'Adelon', 'Times', 'Arabic', 'Chinese'] - >>> print(fonts[8:16]) - ['Greek', 'Hebrew', 'Russian', 'Maths1', 'Maths2', 'Maths3', 'Maths4', 'AvantGarde'] - - >>> fontmap = {} - - >>> for font in fonts: - ... fontmap[font] = a.getfont(font) - - >>> print(fontmap.items()[0:6]) - [('Maths1', 12), ('Maths3', 14), ('Maths2', 13), ('Chinese', 8), ('Courier', 3), ('Greek', 9)] - >>> print(fontmap.items()[6:12]) - [('default', 1), ('Helvetica', 4), ('AvantGarde', 16), ('Times', 6), ('Clarendon', 2), ('Hebrew', 10)] - >>> print(fontmap.items()[12:16]) - [('Russian', 11), ('Adelon', 5), ('Arabic', 7), ('Maths4', 15)] + ... font_names.append(str(a.getfont(i))) # font_names is now filled with all font names + >>> font_names + ['default', ...] + >>> font_numbers = [] + >>> for name in font_names: + ... font_numbers.append(a.getfont(name)) # font_numbers is now filled with all font numbers + >>> font_numbers + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] :param font: The font name/number :type font: int or str diff --git a/vcs/projection.py b/vcs/projection.py index b04589eb2..a8f95ada0 100644 --- a/vcs/projection.py +++ b/vcs/projection.py @@ -53,237 +53,291 @@ class Proj(object): can be used to change some or all of the attributes in an existing projection table entry. -.. describe:: Projection Transformation Package Projection Parameters - - +-----------------------+---------------------------------------------------------------------------------+ - | | Array Element | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - | Code & Projection Id | 1 | 2 | 3 | 4 | 5 | 6 |7 | 8| 9 | 10 | 11 | 12 | 13 | - +=======================+======+======+======+======+=======+=========+==+==+=====+=====+=====+=====+=====+ - |0 Geographic | | | | | | | | | | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |1 U T M |Lon/Z |Lat/Z | | | | | | | | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |2 State Plane | | | | | | | | | | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |3 Albers Equal Area |SMajor|SMinor|STDPR1|STDPR2|CentMer|OriginLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |4 Lambert Conformal C |SMajor|SMinor|STDPR1|STDPR2|CentMer|OriginLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |5 Mercator |SMajor|SMinor| | |CentMer|TrueScale|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |6 Polar Stereographic |SMajor|SMinor| | |LongPol|TrueScale|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |7 Polyconic |SMajor|SMinor| | |CentMer|OriginLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |8 Equid. Conic A |SMajor|SMinor|STDPAR| |CentMer|OriginLat|FE|FN| zero| | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - | Equid. Conic B |SMajor|SMinor|STDPR1|STDPR2|CentMer|OriginLat|FE|FN| one | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |9 Transverse Mercator |SMajor|SMinor|Factor| |CentMer|OriginLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |10 Stereographic |Sphere| | | |CentLon|CenterLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |11 Lambert Azimuthal |Sphere| | | |CentLon|CenterLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |12 Azimuthal |Sphere| | | |CentLon|CenterLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |13 Gnomonic |Sphere| | | |CentLon|CenterLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |14 Orthographic |Sphere| | | |CentLon|CenterLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |15 Gen. Vert. Near Per |Sphere| |Height| |CentLon|CenterLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |16 Sinusoidal |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |17 Equirectangular |Sphere| | | |CentMer|TrueScale|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |18 Miller Cylindrical |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |19 Van der Grinten |Sphere| | | |CentMer|OriginLat|FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |20 Hotin Oblique Merc A|SMajor|SMinor|Factor| | |OriginLat|FE|FN|Long1|Lat1 |Long2|Lat2 |zero | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - | Hotin Oblique Merc B|SMajor|SMinor|Factor|AziAng|AzmthPt|OriginLat|FE|FN| | | | | one | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |21 Robinson |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |22 Space Oblique Merc A|SMajor|SMinor| |IncAng|AscLong| |FE|FN|PSRev|LRat |PFlag| |zero | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - | Space Oblique Merc B|SMajor|SMinor|Satnum|Path | | |FE|FN| | | | | one | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |23 Alaska Conformal |SMajor|SMinor| | | | |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |24 Interrupted Goode |Sphere| | | | | | | | | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |25 Mollweide |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |26 Interrupt Mollweide |Sphere| | | | | | | | | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |27 Hammer |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |28 Wagner IV |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |29 Wagner VII |Sphere| | | |CentMer| |FE|FN| | | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ - |30 Oblated Equal Area |Sphere| |Shapem|Shapen|CentLon|CenterLat|FE|FN|Angle| | | | | - +-----------------------+------+------+------+------+-------+---------+--+--+-----+-----+-----+-----+-----+ + .. describe:: Projection Transformation Package Projection Parameters + + +-----------------------+---------------------------------------------------------+ + | | Array Element | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |*Code & Projection Id* | 1 | 2 | 3 | 4 | 5 | 6 |7 | 8| 9 | + +=======================+======+======+======+======+=======+=========+==+==+=====+ + |0 Geographic | | | | | | | | | | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |1 U T M |Lon/Z |Lat/Z | | | | | | | | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |2 State Plane | | | | | | | | | | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |3 Albers Equal Area |SMajor|SMinor|STDPR1|STDPR2|CentMer|OriginLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |4 Lambert Conformal C |SMajor|SMinor|STDPR1|STDPR2|CentMer|OriginLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |5 Mercator |SMajor|SMinor| | |CentMer|TrueScale|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |6 Polar Stereographic |SMajor|SMinor| | |LongPol|TrueScale|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |7 Polyconic |SMajor|SMinor| | |CentMer|OriginLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |8 Equid. Conic A |SMajor|SMinor|STDPAR| |CentMer|OriginLat|FE|FN| zero| + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + | Equid. Conic B |SMajor|SMinor|STDPR1|STDPR2|CentMer|OriginLat|FE|FN| one | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |9 Transverse Mercator |SMajor|SMinor|Factor| |CentMer|OriginLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |10 Stereographic |Sphere| | | |CentLon|CenterLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |11 Lambert Azimuthal |Sphere| | | |CentLon|CenterLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |12 Azimuthal |Sphere| | | |CentLon|CenterLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |13 Gnomonic |Sphere| | | |CentLon|CenterLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |14 Orthographic |Sphere| | | |CentLon|CenterLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |15 Gen. Vert. Near Per |Sphere| |Height| |CentLon|CenterLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |16 Sinusoidal |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |17 Equirectangular |Sphere| | | |CentMer|TrueScale|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |18 Miller Cylindrical |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |19 Van der Grinten |Sphere| | | |CentMer|OriginLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |20 Hotin Oblique Merc A|SMajor|SMinor|Factor| | |OriginLat|FE|FN|Long1| + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + | Hotin Oblique Merc B|SMajor|SMinor|Factor|AziAng|AzmthPt|OriginLat|FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |21 Robinson |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |22 Space Oblique Merc A|SMajor|SMinor| |IncAng|AscLong| |FE|FN|PSRev| + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + | Space Oblique Merc B|SMajor|SMinor|Satnum|Path | | |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |23 Alaska Conformal |SMajor|SMinor| | | | |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |24 Interrupted Goode |Sphere| | | | | | | | | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |25 Mollweide |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |26 Interrupt Mollweide |Sphere| | | | | | | | | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |27 Hammer |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |28 Wagner IV |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |29 Wagner VII |Sphere| | | |CentMer| |FE|FN| | + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + |30 Oblated Equal Area |Sphere| |Shapem|Shapen|CentLon|CenterLat|FE|FN|Angle| + +-----------------------+------+------+------+------+-------+---------+--+--+-----+ + + +-----------------------+-----------------------+ + | | Array Element | + +-----------------------+-----+-----+-----+-----+ + | Code & Projection Id | 10 | 11 | 12 | 13 | + +=======================+=====+=====+=====+=====+ + |20 Hotin Oblique Merc A|Lat1 |Long2|Lat2 |zero | + +-----------------------+-----+-----+-----+-----+ + | Hotin Oblique Merc B| | | | one | + +-----------------------+-----+-----+-----+-----+ + |22 Space Oblique Merc A|LRat |PFlag| |zero | + +-----------------------+-----+-----+-----+-----+ + | Space Oblique Merc B| | | | one | + +-----------------------+-----+-----+-----+-----+ + + .. note:: + + All other projections are blank (containing 0) for elements 10-13 + + .. glossary:: Lon/Z + Longitude of any point in the UTM zone or zero. If zero, a zone code must be specified. Lat/Z + Latitude of any point in the UTM zone or zero. If zero, a zone code must be specified. SMajor + Semi-major axis of ellipsoid. If zero, Clarke 1866 in meters is assumed. SMinor + Eccentricity squared of the ellipsoid if less than zero, if zero, a spherical form is assumed, or if greater than zero, the semi-minor axis of ellipsoid. Sphere + Radius of reference sphere. If zero, 6370997 meters is used. STDPAR + Latitude of the standard parallel STDPR1 + Latitude of the first standard parallel STDPR2 + Latitude of the second standard parallel CentMer + Longitude of the central meridian OriginLat + Latitude of the projection origin FE + False easting in the same units as the semi-major axis FN + False northing in the same units as the semi-major axis TrueScale + Latitude of true scale LongPol + Longitude down below pole of map Factor + Scale factor at central meridian (Transverse Mercator) or center of projection (Hotine Oblique Mercator) CentLon + Longitude of center of projection CenterLat + Latitude of center of projection Height + Height of perspective point Long1 + Longitude of first point on center line (Hotine Oblique Mercator, format A) Long2 + Longitude of second point on center line (Hotine Oblique Mercator, format A) Lat1 + Latitude of first point on center line (Hotine Oblique Mercator, format A) Lat2 + Latitude of second point on center line (Hotine Oblique Mercator, format A) AziAng + Azimuth angle east of north of center line (Hotine Oblique Mercator, format B) AzmthPt + Longitude of point on central meridian where azimuth occurs (Hotine Oblique Mercator, format B) IncAng + Inclination of orbit at ascending node, counter-clockwise from equator (SOM, format A) AscLong + Longitude of ascending orbit at equator (SOM, format A) PSRev + Period of satellite revolution in minutes (SOM, format A) LRat + Landsat ratio to compensate for confusion at northern end of orbit (SOM, format A -- use 0.5201613) PFlag + End of path flag for Landsat: 0 = start of path, 1 = end of path (SOM, format A) Satnum + Landsat Satellite Number (SOM, format B) Path + Landsat Path Number (Use WRS-1 for Landsat 1, 2 and 3 and WRS-2 for Landsat 4, 5 and 6.) (SOM, format B) Shapem + Oblated Equal Area oval shape parameter m Shapen + Oblated Equal Area oval shape parameter n Angle + Oblated Equal Area oval rotation angle - .. describe:: Array Elements: + .. describe:: Array Elements: - * Array elements 14 and 15 are set to zero + * Array elements 14 and 15 are set to zero - * All array elements with blank fields are set to zero + * All array elements with blank fields are set to zero - * All angles (latitudes, longitudes, azimuths, etc.) are entered in packed - degrees/ minutes/ seconds (DDDMMMSSS.SS) format + * All angles (latitudes, longitudes, azimuths, etc.) are entered in packed + degrees/ minutes/ seconds (DDDMMMSSS.SS) format - .. describe:: Space Oblique Mercator A projection: + .. describe:: Space Oblique Mercator A projection: - * A portion of Landsat rows 1 and 2 may also be seen as parts of rows - 246 or 247. To place these locations at rows 246 or 247, set the end of - path flag (parameter 11) to 1--end of path. This flag defaults to zero. + * A portion of Landsat rows 1 and 2 may also be seen as parts of rows + 246 or 247. To place these locations at rows 246 or 247, set the end of + path flag (parameter 11) to 1--end of path. This flag defaults to zero. - * When Landsat-1,2,3 orbits are being used, use the following values - for the specified parameters: + * When Landsat-1,2,3 orbits are being used, use the following values + for the specified parameters: - * Parameter 4 099005031.2 - * Parameter 5 128.87 degrees - (360/251 * path number) in packed DMS format + * Parameter 4 099005031.2 + * Parameter 5 128.87 degrees - (360/251 * path number) in packed DMS format - * Parameter 9 103.2669323 - * Parameter 10 0.5201613 + * Parameter 9 103.2669323 + * Parameter 10 0.5201613 - * When Landsat-4,5 orbits are being used, use the following values - for the specified parameters: + * When Landsat-4,5 orbits are being used, use the following values + for the specified parameters: - * Parameter 4 098012000.0 - * Parameter 5 129.30 degrees - (360/233 * path number) in packed DMS format - * Parameter 9 98.884119 - * Parameter 10 0.5201613 + * Parameter 4 098012000.0 + * Parameter 5 129.30 degrees - (360/233 * path number) in packed DMS format + * Parameter 9 98.884119 + * Parameter 10 0.5201613 - .. note:: - In vcs angles can be entered either in DDDMMMSSS or regular angle format. + .. note:: + In vcs angles can be entered either in DDDMMMSSS or regular angle format. .. describe:: Useful Functions: @@ -328,12 +382,7 @@ class Proj(object): #or iso.projection='lambert' -""" - ########################################################################## - # # - # Initialize the projection attributes. # - # # - ########################################################################## + """ def __init__(self, Proj_name=None, Proj_name_src='default'): @@ -951,8 +1000,4 @@ def _setparameters(self, value): 'parameters', value) self._parameters = value - parameters = property(_getparameters, _setparameters) - -########################################################################## -# END OF FILE # -########################################################################## + parameters = property(_getparameters, _setparameters) \ No newline at end of file From 3c5c82ac7e02b7683f9d96e8e26e6ae2aad22823 Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Wed, 31 Aug 2016 17:37:18 -0700 Subject: [PATCH 5/8] Updating Canvas examples to doctests. --- vcs/Canvas.py | 528 +++++++++++++++++++++++++------------------------- 1 file changed, 262 insertions(+), 266 deletions(-) diff --git a/vcs/Canvas.py b/vcs/Canvas.py index 01de9d275..bd6d19547 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -1591,13 +1591,16 @@ def xvsy(self, *args, **parms): *******************Xvsy Names List********************** ... *******************End Xvsy Names List********************** - >>> xy=a.getxvsy('default_xvsy_') # Create instance of 'quick' - >>> array=[range(1, 11) for _ in range(1, 11)] - >>> a.xvsy(array,xy) # Plot array using specified xy and default template + >>> xy=a.getxvsy('default_xvsy_') # Create instance of default xvsy + >>> import cdms2 # Need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> slab1 = f('u') # use the data file to create a cdms2 slab + >>> slab2 = f('v') # use the data file to create a cdms2 slab + >>> a.xvsy(slab1,slab2,xy) # Plot array using specified xy and default template >>> a.clear() # Clear VCS canvas >>> template=a.gettemplate('hovmuller') - >>> a.xvsy(array,xy,template) # Plot array using specified xy and template + >>> a.xvsy(slab1,slab2,xy,template) # Plot array using specified xy and template %s @@ -1766,6 +1769,9 @@ def drawline(self, name=None, ltype='solid', width=1, color=241, # noqa >>> a=vcs.init() >>> a.show('line') # Show all the existing line objects + *******************Line Names List********************** + ... + *******************End Line Names List********************** >>> ln=a.drawline(name='red', ltype='dash', width=2, ... color=242, priority=1, viewport=[0, 1.0, 0, 1.0], ... worldcoordinate=[0,100, 0,50], @@ -1894,7 +1900,7 @@ def drawmarker(self, name=None, mtype='solid', size=1, color=241, *******************End Marker Names List********************** >>> mrk=a.drawmarker(name='red', mtype='dot', size=2, ... color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - ... worldcoordinate=[0,100, 0,50] + ... worldcoordinate=[0,100, 0,50], ... x=[0,20,40,60,80,100], ... y=[0,10,20,30,40,50] ) # Create instance of marker object 'red' >>> a.marker(mrk) # Plot using specified marker object @@ -1978,10 +1984,9 @@ def fillarea(self, *args, **parms): :Example: - .. doctest:: - - a=vcs.init() + .. doctest:: canvas_fillarea + >>> a=vcs.init() >>> a.show('fillarea') # Show all the existing fillarea objects *******************Fillarea Names List********************** ... @@ -2011,19 +2016,16 @@ def drawfillarea(self, name=None, style=1, index=1, color=241, :Example: - .. doctest:: + .. doctest:: canvas_drawfillarea - a=vcs.init() - # Show all the existing fillarea objects - >>> a.show('fillarea') - # Create instance of fillarea object 'red' - fa=a.drawfillarea(name='red', style=1, color=242, - priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50], bg=0 ) - # Plot using specified fillarea object - >>> a.fillarea(fa) + >>> a=vcs.init() + >>> a.show('fillarea') # Show all the existing fillarea objects + >>> fa=a.drawfillarea(name='red', style=1, color=242, + ... priority=1, viewport=[0, 1.0, 0, 1.0], + ... worldcoordinate=[0,100, 0,50], + ... x=[0,20,40,60,80,100], + ... y=[0,10,20,30,40,50], bg=0 ) # Create instance of fillarea object 'red' + >>> a.fillarea(fa) # Plot using specified fillarea object :param name: Name of created object :type name: str @@ -2149,40 +2151,29 @@ def textcombined(self, *args, **parms): .. doctest:: canvas_textcombined >>> a=vcs.init() - + >>> a.clean_auto_generated_objects() >>> a.show('texttable') # Show all the existing texttable objects *******************Texttable Names List********************** ... *******************End Texttable Names List********************** - >>> a.show('textorientation') # Show all the existing textorientation objects *******************Textorientation Names List********************** ... *******************End Textorientation Names List********************** - - >>> vcs.createtext('qa_tt', 'qa', '7left_to', '7left') # Create instance of 'std_tt' and '7left_to' + >>> vcs.createtext('qa_txta', 'qa', '7left_txto', '7left') # Create instance of 'std_tt' and '7left_to' >> tc=a.gettext('std_tt','7left_to') - - >>> tc.string = 'Text1' # Show the string "Text1" on the VCS Canvas - + >>> tc=a.gettext('qa_txta', '7left_txto') + >>> tc.string='Text1' # Show the string "Text1" on the VCS Canvas >>> tc.font=2 # Set the text size - - >>> tc.color = 242 # Set the text color - - >>> tc.angle = 45 # Set the text angle - - >>> tc.x=[[0.0,2.0,2.0,0.0,0.0], [0.5,1.5]] # Set the x value points - - >>> tc.y=[[0.0,0.0,2.0,2.0,0.0], [1.0,1.0]] # Set the y value points - + >>> tc.color=242 # Set the text color + >>> tc.angle=45 # Set the text angle + >>> tc.x=[0.5] + >>> tc.y=[0.5] >>> a.textcombined(tc) # Plot using specified text object + - >>> a.plot('Hi',.5,.5,color=241,angle=45) # You can also pass a string, the coordinates, and any keyword - - :returns: A plot object - :rtype: + :returns: A fillarea object + :rtype: vcs.displayplot.Dp """ # First check if color is a string if 'color' in parms.keys(): @@ -2221,21 +2212,21 @@ def gettextextent(self, textobject): :Example: - .. doctest:: + .. doctest:: canvas_gettextextent - a=vcs.init() - t=a.createtext() - t.x=[.5] - t.y=[.5] - t.string=['Hello World'] - extent = a.gettextextent(t) - print extent + >>> a=vcs.init() + >>> t=a.createtext() + >>> t.x=[.5] + >>> t.y=[.5] + >>> t.string=['Hello World'] + >>> a.gettextextent(t) + [[0.5, 0.578125, 0.5, 0.5177065767284992]] :param textobject: A VCS text object :type textobject: textcombined - :returns: ??? - :rtype: ??? + :returns: list of floats containing the coordinates of the text object's bounding box. + :rtype: list """ if not vcs.istext(textobject): raise vcsError('You must pass a text object') @@ -2258,19 +2249,19 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None, :Example: - .. doctest:: + .. doctest:: canvas_drawtextcombined - a=vcs.init() - # Show all the existing texttable objects - >>> a.show('texttable') - # Create instance of texttable object 'red' - tt=a.drawtexttable(Tt_name = 'red', To_name='7left', mtype='dash', size=2, - color=242, priority=1, viewport=[0, 1.0, 0, 1.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified texttable object - >>> a.texttable(tt) + >>> a=vcs.init() + >>> a.show('texttable') # Show all the existing texttable objects + *******************Texttable Names List********************** + ... + *******************End Texttable Names List********************** + >>> tt=a.drawtexttable(Tt_name = 'red', To_name='7left', mtype='dash', size=2, + ... color=242, priority=1, viewport=[0, 1.0, 0, 1.0], + ... worldcoordinate=[0,100, 0,50], + ... x=[0,20,40,60,80,100], + ... y=[0,10,20,30,40,50] ) # Create instance of texttable object 'red' + >>> a.texttable(tt) # Plot using specified texttable object :param name: Name of created object :type name: str @@ -2377,6 +2368,7 @@ def plot(self, *actual_args, **keyargs): [key=value [, key=value [, ...]]]) .. note:: + array1 and array2 are NumPy arrays. .. describe:: Plot attribute keywords: @@ -2444,6 +2436,7 @@ def plot(self, *actual_args, **keyargs): [x|y]rev = 0|1 .. note:: + For example, xrev = 1 would reverse the direction of the x-axis @@ -2456,6 +2449,7 @@ def plot(self, *actual_args, **keyargs): continents_line = vcs.getline("default") .. note:: + If continents >=1, plot continental outlines. By default: plot of xaxis is longitude, yaxis is latitude -OR- xname is 'longitude' and yname is 'latitude' @@ -2504,6 +2498,7 @@ def plot(self, *actual_args, **keyargs): plot_based_dual_grid = True | False .. note:: + This is based on what is needed by the plot: isofill, isoline, vector need point attributes, boxfill and meshfill need cell attributes the default is True (if the parameter is not specified). @@ -2517,26 +2512,25 @@ def plot(self, *actual_args, **keyargs): :Example: - .. doctest:: + .. doctest:: canvas_plot - # x is an instance of the VCS class object (constructor) - x=vcs.init() - # this call will use default settings for template and boxfill - x.plot(array) - # this is specifying the template and graphics method - x.plot(array, 'AMIP', 'isofill','AMIP_psl') - # get a predefined the template 'AMIP' - t=x.gettemplate('AMIP') - # get a predefined the vector graphics method 'quick' - vec=x.getvector('quick') - # plot the data as a vector using the 'AMIP' template - x.plot(array1, array2, t, vec) - # clear the VCS Canvas of all plots - x.clear() - # create boxfill graphics method 'new' - box=x.createboxfill('new') - # plot array data using box 'new' and template 't' - x.plot(box,t,array) + >>> x=vcs.init() + >>> import cdms2 # Need cdms2 to create a slab + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file + >>> slab1 = f('u') # use the data file to create a cdms2 slab + >>> slab2 = f('v') # need 2 slabs, so get another + >>> x.plot(slab1) # this call will use default settings for template and boxfill + + >>> x.plot(slab1, 'polar', 'isofill', 'polar') # this is specifying the template and graphics method + + >>> t=x.gettemplate('polar') # get the polar template + >>> vec=x.getvector() # get default vector + >>> x.plot(slab1, slab2, t, vec) # plot the data as a vector using the 'AMIP' template + + >>> x.clear() # clear the VCS Canvas of all plots + >>> box=x.createboxfill('new') # create boxfill graphics method 'new' + >>> x.plot(box,t,slab2) # plot array data using box 'new' and template 't' + %s %s @@ -2544,6 +2538,9 @@ def plot(self, *actual_args, **keyargs): %s %s %s + + :returns: A VCS display plot object + :rtype: vcs.displayplot.Dp """ self.__last_plot_actual_args = actual_args self.__last_plot_keyargs = keyargs @@ -4006,12 +4003,13 @@ def clear(self, *args, **kargs): :Example: - .. doctest:: + .. doctest:: canvas_clear - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - #clear VCS displays from the page - >>> a.clear() + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.clear() # clear VCS displays from the page """ if self.animate.created(): @@ -4050,12 +4048,13 @@ def close(self, *args, **kargs): :Example: - .. doctest:: + .. doctest:: canvas_close - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - #close the vcs canvas - >>> a.close() + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.close() #close the vcs canvas """ if self.configurator: @@ -4071,11 +4070,13 @@ def destroy(self): :Example: - .. doctest:: + .. doctest:: canvas_destroy - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - >>> a.destroy() + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.destroy() """ import gc @@ -4119,11 +4120,13 @@ def flush(self, *args): :Example: - .. doctest:: + .. doctest:: canvas_flush - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - >>> a.flush() + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.flush() """ return self.backend.flush(*args) @@ -4133,11 +4136,13 @@ def geometry(self, *args): :Example: - .. doctest:: + .. doctest:: canvas_geometry - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - >>> a.geometry(450,337) + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.geometry(450,337) """ if len(args) == 0: return self.backend.geometry() @@ -4156,6 +4161,7 @@ def canvasinfo(self, *args, **kargs): Obtain the current attributes of the VCS Canvas window. :returns: Dictionary with keys: "mapstate" (whether the canvas is opened), "height", "width", "depth", "x", "y" + :rtype: dict """ return self.backend.canvasinfo(*args, **kargs) @@ -4166,11 +4172,10 @@ def getcontinentstype(self, *args): :Example: - .. doctest:: + .. doctest:: canvas_getcontinentstype - a=vcs.init() - # Get the continents type - cont_type = a.getcontinentstype() + >>> a=vcs.init() + >>> cont_type = a.getcontinentstype() # Get the continents type :returns: An int between 1 and 0, or the path to a custom continentstype :rtype: int or system filepath @@ -4187,16 +4192,15 @@ def pstogif(self, filename, *opt): :Example: - .. doctest:: + .. doctest:: canvas_pstogif - a=vcs.init() - >>> a.plot(array) - # convert the postscript file to a gif file (l=landscape) - >>> a.pstogif('filename.ps') - # convert the postscript file to a gif file (l=landscape) - >>> a.pstogif('filename.ps','l') - # convert the postscript file to a gif file (p=portrait) - >>> a.pstogif('filename.ps','p') + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.pstogif('filename.ps') # convert the postscript file to a gif file (l=landscape) + >>> a.pstogif('filename.ps','l') # convert the postscript file to a gif file (l=landscape) + >>> a.pstogif('filename.ps','p') # convert the postscript file to a gif file (p=portrait) :param filename: String name of the desired output file :type filename: str @@ -4244,10 +4248,10 @@ def grid(self, *args): :Example: - .. doctest:: + .. doctest:: canvas_grid - a=vcs.init() - >>> a.grid(12,12,0,71,0,45) + >>> a=vcs.init() + >>> a.grid(12,12,0,71,0,45) """ p = self.canvas.grid(*args) @@ -4275,20 +4279,17 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0): :Example: - .. doctest:: + .. doctest:: canvas_landscape - a=vcs.init() - >>> a.plot(array) - # Change the VCS Canvas orientation and set object flag to landscape - >>> a.landscape() - # Change the VCS Canvas to landscape and clear the page - >>> a.landscape(clear=1) - # Change to landscape and set the window size - >>> a.landscape(width = 400, height = 337) - # Change to landscape and set the x and y screen position - >>> a.landscape(x=100, y = 200) - # Change to landscape and give specifications - >>> a.landscape(width = 400, height = 337, x=100, y = 200, clear=1) + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.landscape() # Change the VCS Canvas orientation and set object flag to landscape + >>> a.landscape(clear=1) # Change the VCS Canvas to landscape and clear the page + >>> a.landscape(width = 400, height = 337) # Change to landscape and set the window size + >>> a.landscape(x=100, y = 200) # Change to landscape and set the x and y screen position + >>> a.landscape(width = 400, height = 337, x=100, y = 200, clear=1) # landscape with more settings :param width: Width of the canvas, in pixels :type width: int @@ -4348,10 +4349,11 @@ def listelements(self, *args): :Example: - .. doctest:: + .. doctest:: canvas_listelements - a=vcs.init() - >>> a.listelements() + >>> a=vcs.init() + >>> a.listelements() + ['1d', '3d_dual_scalar', '3d_scalar', ...] :returns: A list of string names of all VCS class objects :rtype: list @@ -4378,11 +4380,11 @@ def open(self, width=None, height=None, **kargs): :Example: - .. doctest:: + .. doctest:: canvas_open - a=vcs.init() - >>> a.open() - >>> a.open(800,600) + >>> a=vcs.init() + >>> a.open() + >>> a.open(800,600) :param width: Integer representing the desire width of the opened window in pixels :type width: int @@ -4413,20 +4415,17 @@ def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0): :Example: - .. doctest:: + .. doctest:: canvas_portrait - a=vcs.init() - >>> a.plot(array) - # Change the VCS Canvas orientation and set object flag to portrait - >>> a.portrait() - # Change the VCS Canvas to portrait and clear the page - >>> a.portrait(clear=1) - # Change to portrait and set the window size - >>> a.portrait(width = 337, height = 400) - # Change to portrait and set the x and y screen position - >>> a.portrait(x=100, y = 200) - # Change to portrait and give specifications - >>> a.portrait(width = 337, height = 400, x=100, y = 200, clear=1) + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.portrait() # Change the VCS Canvas orientation and set object flag to portrait + >>> a.portrait(clear=1) # Change the VCS Canvas to portrait and clear the page + >>> a.portrait(width = 337, height = 400) # Change to portrait and set the window size + >>> a.portrait(x=100, y = 200) # Change to portrait and set the x and y screen position + >>> a.portrait(width = 337, height = 400, x=100, y = 200, clear=1) # portrait, with more specifications :param width: Width to set the canvas to (in pixels) :type width: int @@ -4489,25 +4488,26 @@ def ffmpeg(self, movie, files, bitrate=1024, rate=None, options=None): :Example: - .. doctest:: + .. doctest:: canvas_ffmpeg - a=vcs.init() - #... code to generate png files ... - # here is a dummy example - files =[] - for i in range(10): - a.png('my_png__%i' % i) - files.append('my_png__%i.png' % i) - # generates mpeg from pattern - >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png') - # generates from list of files - >>> a.ffmpeg('mymovie.mpeg',files) - # generates mpeg at 512kbit - >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png',bitrate=512) - # generates movie with 50 frame per second - >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png',rate=50) - # generates movie at 50 frame per sec and 1024k bitrate - >>> a.ffmpeg('mymovie.mpeg','my_png_%d.png',options='-r 50 -b 1024k') + >>> a=vcs.init() + >>> import cdms2 + >>> f = cdms2.open(vcs.sample_data+'/clt.nc') + >>> v = f('v') # use the data file to create a cdms2 slab + >>> u = f('u') # use the data file to create a cdms2 slab + >>> files = [] + >>> for i in range(10): # create a number of pngs to use for an mpeg + ... a.clear() + ... if (i%2): + ... a.plot(u,v) + ... else: + ... a.plot(v,u) + ... a.png('my_png__%i' % i) + ... files.append('my_png__%i.png' % i) + >>> a.ffmpeg('mymovie.mpeg',files) # generates from list of files + >>> a.ffmpeg('mymovie.mpeg',files,bitrate=512) # generates mpeg at 512kbit + >>> a.ffmpeg('mymovie.mpeg',files,rate=50) # generates movie with 50 frame per second + >>> a.ffmpeg('mymovie.mpeg',files,options='-r 50 -b 1024k') # 50 fps and 1024k bitrate :param movie: Output video file name :type movie: str @@ -4621,13 +4621,11 @@ def setbgoutputdimensions(self, width=None, height=None, units='inches'): :Example: - .. doctest:: + .. doctest:: canvas_setbgoutputdimensions - a=vcs.init() - # US Legal - >>> a.setbgoutputdimensions(width=11.5, height= 8.5) - # A4 - >>> a.setbgoutputdimensions(width=21, height=29.7, units='cm') + >>> a=vcs.init() + >>> a.setbgoutputdimensions(width=11.5, height= 8.5) # US Legal + >>> a.setbgoutputdimensions(width=21, height=29.7, units='cm') # A4 :param width: Float representing the desired width of the output, using the specified unit of measurement :type width: float @@ -4669,12 +4667,13 @@ def png(self, file, width=None, height=None, :Example: - .. doctest:: + .. doctest:: canvas_png - a=vcs.init() - >>> a.plot(array) - # Overwrite a png file - >>> a.png('example') + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.png('example') # Overwrite a png file :param file: Output image filename :type file: str @@ -4716,16 +4715,15 @@ def pdf(self, file, width=None, height=None, units='inches', :Example: - .. doctest:: + .. doctest:: canvas_pdf - a=vcs.init() - >>> a.plot(array) - # Overwrite a postscript file - >>> a.pdf('example') - # US Legal - >>> a.pdf('example', width=11.5, height= 8.5) - # A4 - >>> a.pdf('example', width=21, height=29.7, units='cm') + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.pdf('example') # Overwrite a postscript file + >>> a.pdf('example', width=11.5, height= 8.5) # US Legal + >>> a.pdf('example', width=21, height=29.7, units='cm') # A4 :param file: Desired string name of the output file :type file: str @@ -4741,9 +4739,6 @@ def pdf(self, file, width=None, height=None, units='inches', :param textAsPaths: Specifies whether to render text objects as paths. :type textAsPaths: bool - - :returns: ??? - :rtype: ??? """ if units not in [ 'inches', 'in', 'cm', 'mm', 'pixel', 'pixels', 'dot', 'dots']: @@ -4768,16 +4763,15 @@ def svg(self, file, width=None, height=None, units='inches', :Example: - .. doctest:: + .. doctest:: canvas_svg - a=vcs.init() - >>> a.plot(array) - # Overwrite a postscript file - >>> a.svg('example') - # US Legal - >>> a.svg('example', width=11.5, height= 8.5) - # A4 - >>> a.svg('example', width=21, height=29.7, units='cm') + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.svg('example') # Overwrite a postscript file + >>> a.svg('example', width=11.5, height= 8.5) # US Legal + >>> a.svg('example', width=21, height=29.7, units='cm') # A4 :param file: :type file: @@ -5001,24 +4995,19 @@ def postscript(self, file, mode='r', orientation=None, width=None, height=None, :Example: - .. doctest:: + .. doctest:: canvas_postscript - a=vcs.init() - >>> a.plot(array) - # Overwrite a postscript file - >>> a.postscript('example') - # Append postscript to an existing file - >>> a.postscript('example', 'a') - # Overwrite an existing file - >>> a.postscript('example', 'r') - # Append postscript to an existing file - >>> a.postscript('example', mode='a') - # US Legal (default) - >>> a.postscript('example', width=11.5, height= 8.5) - # A4 - >>> a.postscript('example', width=21, height=29.7, units='cm') - # US Legal output and control of margins (for printer friendly output), default units 'inches' - >>> a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array) + + >>> a.postscript('example') # Overwrite a postscript file + >>> a.postscript('example', 'a') # Append postscript to an existing file + >>> a.postscript('example', 'r') # Overwrite an existing file + >>> a.postscript('example', mode='a') # Append postscript to an existing file + >>> a.postscript('example', width=11.5, height= 8.5) # US Legal (default) + >>> a.postscript('example', width=21, height=29.7, units='cm') # A4 + >>> a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) :param file: String name of the desired output file :type file: str @@ -5084,11 +5073,15 @@ def setcolormap(self, name): :Example: - .. doctest:: + .. doctest:: canvas_setcolormap - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - >>> a.setcolormap("AMIP") + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.setcolormap("AMIP") + >>> a.plot(array,'default','isofill','quick') + :param name: Name of the colormap to use :type name: str @@ -5119,19 +5112,22 @@ def setcolorcell(self, *args): :Example: - .. doctest:: - - a=vcs.init() - >>> a.plot(array,'default','isofill','quick') - >>> a.setcolormap("AMIP") - >>> a.setcolorcell(11,0,0,0) - >>> a.setcolorcell(21,100,0,0) - >>> a.setcolorcell(31,0,100,0) - >>> a.setcolorcell(41,0,0,100) - >>> a.setcolorcell(51,100,100,100) - >>> a.setcolorcell(61,70,70,70) - """ + .. doctest:: canvas_setcolorcell + >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + + >>> a.setcolormap("AMIP") + >>> a.setcolorcell(11,0,0,0) + >>> a.setcolorcell(21,100,0,0) + >>> a.setcolorcell(31,0,100,0) + >>> a.setcolorcell(41,0,0,100) + >>> a.setcolorcell(51,100,100,100) + >>> a.setcolorcell(61,70,70,70) + >>> a.plot(array,'default','isofill','quick') + + """ a = vcs.setcolorcell(self.colormap, *args) return a @@ -5142,15 +5138,13 @@ def setcontinentsline(self, line="default"): :Example: - .. doctest:: + .. doctest:: canvas_setcontinentsline - a = vcs.init() - line = vcs.createline() - line.width = 5 - # Use custom continents line - >>> a.setcontinentsline(line) - # Use default line - >>> a.setcontinentsline("default") + >>> a = vcs.init() + >>> line = vcs.createline() + >>> line.width = 5 + >>> a.setcontinentsline(line) # Use custom continents line + >>> a.setcontinentsline("default") # Use default line :param line: Line to use for drawing continents. Can be a string name of a line, or a VCS line object :type line: str or :py:class:`vcs.line.Tl` @@ -5186,11 +5180,13 @@ def setcontinentstype(self, value): :Example: - .. doctest:: + .. doctest:: canvas_setcontinentstype - a=vcs.init() - >>> a.setcontinentstype(3) - >>> a.plot(array,'default','isofill','quick') + >>> a=vcs.init() + >>> a.setcontinentstype(3) + >>> array = [range(1, 11) for _ in range(1, 11)] + >>> a.plot(array,'default','isofill','quick') + :param value: Integer representing continent type, as specified in function description :type value: int @@ -5233,23 +5229,23 @@ def gif(self, filename='noname.gif', merge='r', orientation=None, :Example: - .. doctest:: + .. doctest:: canvas_gif - a=vcs.init() - >>> a.plot(array) - >>> a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') - # overwrite existing gif file (default is merge='r') - >>> a.gif('example') - # overwrite existing gif file - >>> a.gif('example',merge='r') - # merge gif image into existing gif file - >>> a.gif('example',merge='a') - # merge gif image into existing gif file with landscape orientation - >>> a.gif('example',orientation='l') - # merge gif image into existing gif file with portrait orientation - >>> a.gif('example',orientation='p') - # merge gif image into existing gif file and set the gif geometry - >>> a.gif('example',geometry='600x500') + >>> a=vcs.init() + >>> a.plot(array) + >>> a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') + + >>> a.gif('example') # overwrite existing gif file (default is merge='r') + + >>> a.gif('example',merge='r') # overwrite existing gif file + # merge gif image into existing gif file + >>> a.gif('example',merge='a') + # merge gif image into existing gif file with landscape orientation + >>> a.gif('example',orientation='l') + # merge gif image into existing gif file with portrait orientation + >>> a.gif('example',orientation='p') + # merge gif image into existing gif file and set the gif geometry + >>> a.gif('example',geometry='600x500') """ if orientation is None: orientation = self.orientation()[0] @@ -5381,7 +5377,7 @@ def saveinitialfile(self): .. doctest:: canvas_saveinitial_warning >>> b=vcs.createboxfill() - >>> b.name='MyBoxfill' # graphic method is now preserved + >>> b.rename('MyBoxfill') # graphic method is now preserved """ self.clean_auto_generated_objects() return vcs.saveinitialfile() From 32d006510076cfb500139566eb8011d5efc97bfd Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Tue, 6 Sep 2016 15:52:26 -0700 Subject: [PATCH 6/8] All :Example: in Canvas.py replaced with doctests. Most doctests passing. Some fail due to implementation errorsi/bugs. --- vcs/Canvas.py | 135 +++++++++++++++++++++--------------------- vcs/manageElements.py | 3 +- 2 files changed, 70 insertions(+), 68 deletions(-) diff --git a/vcs/Canvas.py b/vcs/Canvas.py index bd6d19547..2e6ae0483 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -1191,16 +1191,12 @@ def boxfill(self, *args, **parms): .. doctest:: canvas_boxfill >>> a=vcs.init() - >>> a.show('boxfill') # Show all the existing boxfill graphics methods *******************Boxfill Names List********************** ... *******************End Boxfill Names List********************** - >>> box=a.getboxfill('quick') # Create instance of 'quick' - >>> array=[range(10) for _ in range(10)] - >>> a.boxfill(array, box) # Plot array using specified box and default template >>> template = a.gettemplate('quick') # get quick template @@ -1995,9 +1991,8 @@ def fillarea(self, *args, **parms): >>> fa.style=1 # Set the fillarea style >>> fa.index=4 # Set the fillarea index >>> fa.color = 242 # Set the fillarea color - >>> fa.type = 4 # Set the fillarea type - >>> fa.x=[[1.0,2.0,2.0,1.0,1.0], [0.5,1.5]] # Set the x value points - >>> fa.y=[[1.0,1.0,2.0,2.0,1.0], [1.0,1.0]] # Set the y value points + >>> fa.x=[0.25,0.75] # Set the x value points + >>> fa.y=[0.2,0.5] # Set the y value points >>> a.fillarea(fa) # Plot using specified fillarea object @@ -2020,12 +2015,16 @@ def drawfillarea(self, name=None, style=1, index=1, color=241, >>> a=vcs.init() >>> a.show('fillarea') # Show all the existing fillarea objects + *******************Fillarea Names List********************** + ... + *******************End Fillarea Names List********************** >>> fa=a.drawfillarea(name='red', style=1, color=242, ... priority=1, viewport=[0, 1.0, 0, 1.0], ... worldcoordinate=[0,100, 0,50], ... x=[0,20,40,60,80,100], ... y=[0,10,20,30,40,50], bg=0 ) # Create instance of fillarea object 'red' >>> a.fillarea(fa) # Plot using specified fillarea object + :param name: Name of created object :type name: str @@ -2160,9 +2159,9 @@ def textcombined(self, *args, **parms): *******************Textorientation Names List********************** ... *******************End Textorientation Names List********************** - >>> vcs.createtext('qa_txta', 'qa', '7left_txto', '7left') # Create instance of 'std_tt' and '7left_to' + >>> vcs.createtext('qa_tta', 'qa', '7left_tto', '7left') # Create instance of 'std_tt' and '7left_to' >> tc=a.gettext('qa_txta', '7left_txto') + >>> tc=a.gettext('qa_tta', '7left_tto') >>> tc.string='Text1' # Show the string "Text1" on the VCS Canvas >>> tc.font=2 # Set the text size >>> tc.color=242 # Set the text color @@ -2256,12 +2255,12 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None, *******************Texttable Names List********************** ... *******************End Texttable Names List********************** - >>> tt=a.drawtexttable(Tt_name = 'red', To_name='7left', mtype='dash', size=2, + >>> tc=a.drawtextcombined(Tt_name = 'std_example', To_name='7left_example', string='Hello example!', spacing=5, ... color=242, priority=1, viewport=[0, 1.0, 0, 1.0], ... worldcoordinate=[0,100, 0,50], ... x=[0,20,40,60,80,100], - ... y=[0,10,20,30,40,50] ) # Create instance of texttable object 'red' - >>> a.texttable(tt) # Plot using specified texttable object + ... y=[0,10,20,30,40,50]) # Create instance of texttable object 'red' + >>> a.textcombined(tc) # Plot using specified texttable object :param name: Name of created object :type name: str @@ -2514,22 +2513,22 @@ def plot(self, *actual_args, **keyargs): .. doctest:: canvas_plot - >>> x=vcs.init() + >>> a=vcs.init() >>> import cdms2 # Need cdms2 to create a slab >>> f = cdms2.open(vcs.sample_data+'/clt.nc') # use cdms2 to open a data file >>> slab1 = f('u') # use the data file to create a cdms2 slab >>> slab2 = f('v') # need 2 slabs, so get another - >>> x.plot(slab1) # this call will use default settings for template and boxfill + >>> a.plot(slab1) # this call will use default settings for template and boxfill - >>> x.plot(slab1, 'polar', 'isofill', 'polar') # this is specifying the template and graphics method + >>> a.plot(slab1, 'polar', 'isofill', 'polar') # this is specifying the template and graphics method - >>> t=x.gettemplate('polar') # get the polar template - >>> vec=x.getvector() # get default vector - >>> x.plot(slab1, slab2, t, vec) # plot the data as a vector using the 'AMIP' template + >>> t=a.gettemplate('polar') # get the polar template + >>> vec=a.getvector() # get default vector + >>> a.plot(slab1, slab2, t, vec) # plot the data as a vector using the 'AMIP' template - >>> x.clear() # clear the VCS Canvas of all plots - >>> box=x.createboxfill('new') # create boxfill graphics method 'new' - >>> x.plot(box,t,slab2) # plot array data using box 'new' and template 't' + >>> a.clear() # clear the VCS Canvas of all plots + >>> box=a.getboxfill() # get default boxfill graphics method + >>> a.plot(box,t,slab2) # plot array data using box 'new' and template 't' %s @@ -4252,6 +4251,10 @@ def grid(self, *args): >>> a=vcs.init() >>> a.grid(12,12,0,71,0,45) + + .. admonition:: Not Yet Implemented + + :py:func`vcs.Canvas.grid`_ does not work. """ p = self.canvas.grid(*args) @@ -4495,19 +4498,24 @@ def ffmpeg(self, movie, files, bitrate=1024, rate=None, options=None): >>> f = cdms2.open(vcs.sample_data+'/clt.nc') >>> v = f('v') # use the data file to create a cdms2 slab >>> u = f('u') # use the data file to create a cdms2 slab - >>> files = [] + >>> png_files = [] # for saving file names to make the mpeg + >>> plots = [] # for saving plots for later reference >>> for i in range(10): # create a number of pngs to use for an mpeg ... a.clear() ... if (i%2): - ... a.plot(u,v) + ... plots.append(a.plot(u,v)) ... else: - ... a.plot(v,u) + ... plots.append(a.plot(v,u)) ... a.png('my_png__%i' % i) - ... files.append('my_png__%i.png' % i) - >>> a.ffmpeg('mymovie.mpeg',files) # generates from list of files - >>> a.ffmpeg('mymovie.mpeg',files,bitrate=512) # generates mpeg at 512kbit - >>> a.ffmpeg('mymovie.mpeg',files,rate=50) # generates movie with 50 frame per second - >>> a.ffmpeg('mymovie.mpeg',files,options='-r 50 -b 1024k') # 50 fps and 1024k bitrate + ... png_files.append('my_png__%i.png' % i) + >>> a.ffmpeg('mymovie.mpeg',png_files) # generates from list of files + True + >>> a.ffmpeg('mymovie.mpeg',files="my_png__[0-9]*\.png") # generate from files with name matching regex + True + >>> a.ffmpeg('mymovie.mpeg',png_files,bitrate=512) # generates mpeg at 512kbit + True + >>> a.ffmpeg('mymovie.mpeg',png_files,rate=50) # generates movie with 50 frame per second + True :param movie: Output video file name :type movie: str @@ -5007,7 +5015,6 @@ def postscript(self, file, mode='r', orientation=None, width=None, height=None, >>> a.postscript('example', mode='a') # Append postscript to an existing file >>> a.postscript('example', width=11.5, height= 8.5) # US Legal (default) >>> a.postscript('example', width=21, height=29.7, units='cm') # A4 - >>> a.postscript('example', right_margin=.2,left_margin=.2,top_margin=.2,bottom_margin=.2) :param file: String name of the desired output file :type file: str @@ -5232,20 +5239,16 @@ def gif(self, filename='noname.gif', merge='r', orientation=None, .. doctest:: canvas_gif >>> a=vcs.init() + >>> array = [range(1, 11) for _ in range(1, 11)] >>> a.plot(array) + >>> a.gif(filename='example.gif', merge='a', orientation='l', geometry='800x600') - >>> a.gif('example') # overwrite existing gif file (default is merge='r') - >>> a.gif('example',merge='r') # overwrite existing gif file - # merge gif image into existing gif file - >>> a.gif('example',merge='a') - # merge gif image into existing gif file with landscape orientation - >>> a.gif('example',orientation='l') - # merge gif image into existing gif file with portrait orientation - >>> a.gif('example',orientation='p') - # merge gif image into existing gif file and set the gif geometry - >>> a.gif('example',geometry='600x500') + >>> a.gif('example',merge='a') # merge gif image into existing gif file + >>> a.gif('example',orientation='l') # merge gif image into existing gif file with landscape orientation + >>> a.gif('example',orientation='p') # merge gif image into existing gif file with portrait orientation + >>> a.gif('example',geometry='600x500') # merge gif image into existing gif file and set gif geometry """ if orientation is None: orientation = self.orientation()[0] @@ -5271,7 +5274,7 @@ def eps(self, file, mode='r', orientation=None, width=None, height=None, units=' :Example: - .. doctest:: + .. doctest:: canvas_eps >>> a=vcs.init() >>> array = [range(10) for _ in range(10)] @@ -5397,13 +5400,14 @@ def islandscape(self): :Example: - .. doctest:: + .. doctest:: canvas_islandscape - a=vcs.init() - # ... - if a.islandscape(): - # Set VCS's orientation to portrait mode - >>> a.portrait() + >>> a=vcs.init() + >>> array = [range(10) for _ in range(10)] + >>> a.plot(array) + + >>> if a.islandscape(): + ... a.portrait() # Set VCS's orientation to portrait mode :returns: Integer indicating VCS is in landscape mode (1), or not (0) :rtype: int @@ -5420,13 +5424,14 @@ def isportrait(self): :Example: - .. doctest:: + .. doctest:: canvas_isportrait - a=vcs.init() - #... - if a.isportrait(): - # Set VCS's orientation to landscape mode - a.landscape() + >>> a=vcs.init() + >>> array = [range(10) for _ in range(10)] + >>> a.plot(array) + + >>> if a.isportrait(): + ... a.landscape() # Set VCS's orientation to landscape mode :returns: Returns a 1 if orientation is portrait, or 0 if not in portrait mode :rtype: bool @@ -5451,23 +5456,21 @@ def getplot(self, Dp_name_src='default', template=None): .. doctest:: canvas_getplot >>> a=vcs.init() - >>> a.show('template') # Show all the existing templates *******************Template Names List********************** ... *******************End Template Names List********************** - >>> plot1=a.getplot() # plot1 instance of 'dpy_plot_1' display plot - :param Dp_name_src: String name of an existing display plot object - :type Dp_name_src: str + :param Dp_name_src: String name of an existing display plot object + :type Dp_name_src: str - :param template: The displayplot template to inherit from - :type template: + :param template: The displayplot template to inherit from + :type template: - :returns: A VCS displayplot object - :rtype: vcs.displayplot.Dp - """ + :returns: A VCS displayplot object + :rtype: vcs.displayplot.Dp + """ if not isinstance(Dp_name_src, str): raise ValueError('Error - The argument must be a string.') @@ -5650,11 +5653,11 @@ def orientation(self, *args, **kargs): :Example: - .. doctest:: + .. doctest:: canvas_orientation - a = vcs.init() - # Show current orientation of the canvas - >>> a.orientation() + >>> a=vcs.init() + >>> a.orientation() # Show current orientation of the canvas + 'landscape' :returns: A string indicating the orientation of the canvas, i.e. 'landscape' or 'portrait' :rtype: str diff --git a/vcs/manageElements.py b/vcs/manageElements.py index 9b774b3e8..bb65e1cd7 100644 --- a/vcs/manageElements.py +++ b/vcs/manageElements.py @@ -2507,8 +2507,7 @@ def getcolormap(Cp_name_src='default'): :returns: A pre-existing VCS colormap object :rtype: vcs.colormap.Cp - -""" + """ # Check to make sure the argument passed in is a STRING if not isinstance(Cp_name_src, str): raise ValueError('Error - The argument must be a string.') From db9d3ebc1977d5b9212f6631713a71ea1a6131db Mon Sep 17 00:00:00 2001 From: Ed Brown Date: Wed, 7 Sep 2016 11:22:32 -0700 Subject: [PATCH 7/8] Fixing doctest errors --- vcs/boxfill.py | 2 +- vcs/isofill.py | 2 +- vcs/isoline.py | 2 +- vcs/queries.py | 5 ---- vcs/xmldocs.py | 72 ++++++++++++++------------------------------------ 5 files changed, 23 insertions(+), 60 deletions(-) diff --git a/vcs/boxfill.py b/vcs/boxfill.py index 1239ea145..989151e72 100755 --- a/vcs/boxfill.py +++ b/vcs/boxfill.py @@ -825,7 +825,7 @@ def datawc(self, dsp1=1e20, dsp2=1e20, dsp3=1e20, dsp4=1e20): def xyscale(self, xat='linear', yat='linear'): self.xaxisconvert = xat self.yaxisconvert = yat - xyscale.__doc__ = xmldocs.xyscaledoc + xyscale.__doc__ = xmldocs.xyscaledoc % (('boxfill',) * 2) def getlevels(self, varmin, varmax): if self.boxfill_type == "custom": diff --git a/vcs/isofill.py b/vcs/isofill.py index 95b780b1e..9aca81d9e 100755 --- a/vcs/isofill.py +++ b/vcs/isofill.py @@ -709,7 +709,7 @@ def datawc(self, dsp1=1e20, dsp2=1e20, dsp3=1e20, dsp4=1e20): def xyscale(self, xat='', yat=''): self.xaxisconvert = xat self.yaxisconvert = yat - xyscale.__doc__ = xmldocs.xyscaledoc + xyscale.__doc__ = xmldocs.xyscaledoc % (('isofill',) * 2) def list(self): print "", "----------Isofill (Gfi) member (attribute) listings ----------" diff --git a/vcs/isoline.py b/vcs/isoline.py index 13da152b0..c487b06e2 100755 --- a/vcs/isoline.py +++ b/vcs/isoline.py @@ -1008,7 +1008,7 @@ def datawc(self, dsp1=1e20, dsp2=1e20, dsp3=1e20, dsp4=1e20): def xyscale(self, xat='', yat=''): self.xaxisconvert = xat self.yaxisconvert = yat - xyscale.__doc__ = xmldocs.xyscaledoc + xyscale.__doc__ = xmldocs.xyscaledoc % (('isoline',) * 2) def list(self): if (self.name == '__removed_from_VCS__'): diff --git a/vcs/queries.py b/vcs/queries.py index caef60f7d..672975925 100644 --- a/vcs/queries.py +++ b/vcs/queries.py @@ -20,11 +20,6 @@ ########################################################################## """ -########################################################################################### -# # -# Functions which get information about vcs graphics objects such as graphics methods. # -# # -########################################################################################### """ import boxfill import isofill diff --git a/vcs/xmldocs.py b/vcs/xmldocs.py index 3765fc5d4..3b8ba8dc7 100644 --- a/vcs/xmldocs.py +++ b/vcs/xmldocs.py @@ -219,13 +219,11 @@ :Example: - :: + .. doctest:: xyscale_%s - a=vcs.init() - #create a boxfill to work with - box=a.createboxfill('temp') - # set xaxisconvert and yaxisconvert to 'linear' - box.xyscale(xat='linear', yat='linear') + >>> a=vcs.init() + >>> ex=a.create%s('xyscale_ex') # create a boxfill to work with + >>> ex.xyscale(xat='linear', yat='linear') # set xaxisconvert and yaxisconvert to 'linear' :param xat: Set value for x axis conversion. :type xat: str @@ -258,27 +256,16 @@ .. warning:: VCS Scripts Deprecated. - SCR scripts are no longer generated by this function. + SCR script files are no longer generated by this function. :Example: .. doctest:: script_examples - # Make a Canvas object to work with: - >>> a=vcs.init() - ... - - # Create %(call)s 'temp' that inherits from 'default' - >>> ex=a.create%(call)s('temp') - ... - - # Append to a Python script named 'filename.py' - >>> ex.script('filename.py') - ... - - # Create or overwrite a JSON file 'filename.json'. - >>> ex.script('filename','w') - ... + >>> a=vcs.init() # Make a Canvas object to work with: + >>> ex=a.get%(call)s() # Get default %(call)s + >>> ex.script('filename.py') # Append to a Python script named 'filename.py' + >>> ex.script('filename','w') # Create or overwrite a JSON file 'filename.json'. :param script_filename: Output name of the script file. If no extension is specified, a .json object is created. :type script_filename: str @@ -350,20 +337,13 @@ .. doctest:: queries_is - # Make a VCS Canvas object to work with: - >>> a=vcs.init() - ... + >>> a=vcs.init() # Make a VCS Canvas object to work with: %(tc_example)s - # Show all available %(name)s - >>> a.show('%(name)s') + >>> a.show('%(name)s') # Show all available %(name)s *******************%(cap)s Names List********************** ... *******************End %(cap)s Names List********************** - - # To test an existing %(name)s object - >>> ex = a.get%(name)s('%(parent)s'%(to)s) - ... - + >>> ex = a.get%(name)s('%(parent)s'%(to)s) # To test an existing %(name)s object >>> vcs.queries.is%(name)s(ex) 1 @@ -446,13 +426,11 @@ dict['name'] = 'textcombined' dict['cap'] = dict['name'].title() dict['tc_example'] =""" - - >>> vcs.createtext('new_tt', 'std', 'new_to', '7left') - >> vcs.createtext('example_tt', 'std', 'example_to', '7left') + """ -dict['parent'] = 'new_tt' -dict['to'] = ", 'new_to'" +dict['parent'] = 'example_tt' +dict['to'] = ", 'example_to'" istextcombined_doc = queries_is_doc % dict dict['tc_example'] = dict['to'] = '' @@ -472,24 +450,14 @@ .. doctest:: get_methods - + >>> a=vcs.init() >>> vcs.show('%(name)s') # Show all the existing %(name)s %(type)s *******************%(cap)s Names List********************** ... *******************End %(cap)s Names List********************** - - # instance of '%(parent)s' %(name)s %(type)s - ex=vcs.get%(call)s() - # instance of existing 'quick' %(name)s %(type)s - ex2=vcs.get%(call)s('quick') - # Create instance of %(name)s object 'red' - ex3=vcs.create%(call)s(name='new', name='red',style=1, index=1, - color=242, priority=1, viewport=[0, 2.0, 0, 2.0], - worldcoordinate=[0,100, 0,50] - x=[0,20,40,60,80,100], - y=[0,10,20,30,40,50] ) - # Plot using specified %(call)s object - vcs.%(name)s(ex3) + >>> ex=vcs.get%(call)s() # instance of '%(parent)s' %(name)s %(type)s + >>> a.%(name)s(ex) # Plot using specified %(call)s object + """ # Get for secondary methods with a 'default' available dict['parent'] = 'default' From bb7233c38e82efb37cf54843593906360d66fb8a Mon Sep 17 00:00:00 2001 From: embrown Date: Wed, 21 Sep 2016 10:17:51 -0700 Subject: [PATCH 8/8] Fixed queries.py examples --- vcs/queries.py | 82 +++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/vcs/queries.py b/vcs/queries.py index 672975925..84f235f38 100644 --- a/vcs/queries.py +++ b/vcs/queries.py @@ -55,12 +55,7 @@ def isgraphicsmethod(gobj): .. doctest:: queries_isgraphicsmethod >>> a=vcs.init() - ... - - # To Modify an existing boxfill use: - >>> box=a.getboxfill('quick') - ... - + >>> box=a.getboxfill('quick') # To Modify an existing boxfill >>> vcs.isgraphicsmethod(box) 1 @@ -107,13 +102,11 @@ def graphicsmethodlist(): .. doctest:: queries_gmlist >>> a=vcs.init() - ... - >>> vcs.graphicsmethodlist() # Return graphics method list ['boxfill', 'isofill', 'isoline', 'meshfill', 'scatter', 'vector', 'xvsy', 'xyvsy', 'yxvsx', ...] - :returns: A list of available grapics methods (i.e., boxfill, isofill, isoline, outfill, - scatter, vector, xvsy, xyvsy, yxvsx, taylordiagram ). + :returns: A list of available grapics methods (i.e., 'boxfill', 'isofill', 'isoline', 'meshfill', 'scatter', + 'vector', 'xvsy', 'xyvsy', 'yxvsx', 'taylordiagram', '1d', '3d_scalar', '3d_dual_scalar', '3d_vector'). :rtype: list """ return ['boxfill', 'isofill', 'isoline', 'meshfill', 'scatter', @@ -131,35 +124,24 @@ def graphicsmethodtype(gobj): .. doctest:: queries_gmtype >>> a=vcs.init() - ... - - >>> # Get an existing boxfill graphics method in VCS: - >>> box=a.getboxfill('quick') - ... - - >>> # Get an existing isofill graphics method in VCS - >>> iso=a.getisofill('quick') - ... - - >>> # Get an existing line element in VCS - >>> ln=a.getline('red') - ... - + >>> box=a.getboxfill('quick') # Get an existing boxfill graphics method in VCS: + >>> + >>> iso=a.getisofill('quick') # Get an existing isofill graphics method in VCS + >>> ln=a.getline('red') # Get an existing line element in VCS >>> print vcs.graphicsmethodtype(box) boxfill - >>> print vcs.graphicsmethodtype(iso) isofill - >>> print vcs.graphicsmethodtype(ln) Traceback (most recent call last): ... vcsError: The object passed is not a graphics method object. - :returns: If gobj is a graphics method object, returns its type: 'boxfill', 'isofill', 'isoline', - 'scatter', 'vector', 'xvsy', 'xyvsy', or 'yxvsx', 'taylordiagram'. - If gobj is not a graphics method object, raises an exception and prints a vcsError message. - :rtype: str or None + :returns: If gobj is a graphics method object, returns its type: 'boxfill', 'isofill', 'isoline', 'meshfill', + 'scatter', 'vector', 'xvsy', 'xyvsy', 'yxvsx', 'taylordiagram', '1d', '3d_scalar', '3d_dual_scalar', + '3d_vector'. + If gobj is not a graphics method object, raises an exception and prints a vcsError message. + :rtype: str or None """ import vcsaddons if (isinstance(gobj, boxfill.Gfb)): @@ -197,15 +179,11 @@ def isplot(pobj): .. doctest:: queries_isplot >>> a=vcs.init() - >>> a.show('display') # Show all available displays *******************Display Names List********************** ... *******************End Display Names List********************** - >>> ex = a.getplot('default') # To test an existing display object - ... - >>> vcs.queries.isplot(ex) 1 @@ -230,15 +208,11 @@ def iscolormap(obj): .. doctest:: queries_iscolormap >>> a=vcs.init() - ... - >>> a.show('colormap') # Show all available colormap objects *******************Colormap Names List********************** ... *******************End Colormap Names List********************** >>> ex = a.getcolormap('default') # To test an existing colormap object - ... - >>> vcs.iscolormap(ex) 1 @@ -247,7 +221,7 @@ def iscolormap(obj): :returns: An integer indicating whether the object is a colormap (1), or not (0). :rtype: int -""" + """ if (isinstance(obj, vcs.colormap.Cp)): return 1 else: @@ -258,29 +232,25 @@ def istemplate(gobj): """ Check to see if this object is a template. - :Example: + :Example: .. doctest:: queries_istemplate >>> a=vcs.init() - >>> a.show('template') # Show all available template *******************Template Names List********************** - ... + ... *******************End Template Names List********************** - >>> ex = a.gettemplate('default') # To test an existing template object - ... - >>> vcs.istemplate(ex) 1 -:param obj: A VCS object -:type obj: VCS Object + :param obj: A VCS object + :type obj: VCS Object -:returns: An integer indicating whether the object is a template (1), or not (0) -:rtype: int -""" + :returns: An integer indicating whether the object is a template (1), or not (0) + :rtype: int + """ if (isinstance(gobj, template.P)): return 1 else: @@ -313,16 +283,11 @@ def issecondaryobject(sobj): .. doctest:: queries_issecondary >>> a=vcs.init() - ... - - >>> a.show('line') # Show all available lines + >>> a.show('projection') # Show all available projections *******************Line Names List********************** ... *******************End Line Names List********************** - >>> ex = a.getprojection('default') # To test an existing line object - ... - >>> vcs.issecondaryobject(ex) 1 @@ -363,16 +328,11 @@ def isprojection(obj): .. doctest:: queries_isprojection >>> a=vcs.init() - ... - >>> a.show('projection') # Show all available projection *******************Projection Names List********************** ... *******************End Projection Names List********************** - >>> ex = a.getprojection('default') # To test an existing projection object - ... - >>> vcs.isprojection(ex) 1