meshfill

# Meshfill (Gfm) module

class vcs.meshfill.Gfm(Gfm_name, Gfm_name_src='default')[source]

The meshfill graphics method (Gfm) displays a two-dimensional data array by surrounding each data value by a colored grid mesh.

This class is used to define a meshfill table entry used in VCS, or it can be used to change some or all of the attributes in an existing meshfill table entry.

Useful Functions:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# VCS Canvas Constructor
a=vcs.init()
# Show predefined meshfill graphics methods
a.show('meshfill')
# Change the VCS color map
a.setcolormap("AMIP")
# Plot data 's' with meshfill 'b' and 'default' template
a.meshfill(s,b,'default')
# Updates the VCS Canvas at user's request
a.update()
Create a new instance of meshfill:
1
2
3
4
# Copies content of 'quick' to 'new'
mesh=a.createmeshfill('new','quick')
# Copies content of 'default' to 'new'
mesh=a.createmeshfill('new')
Modify an existing meshfill:
mesh=a.getmeshfill('AMIP_psl')
Overview of meshfill object attributes:
  • List all the meshfill attribute values

    mesh.list()
    
  • Setting attributes:

    • Setting general attributes:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      mesh.projection='linear'
      lon30={-180:'180W',-150:'150W',0:'Eq'}
      mesh.xticlabels1=lon30
      mesh.xticlabels2=lon30
      # Will set them both
      mesh.xticlabels(lon30, lon30)
      mesh.xmtics1=''
      mesh.xmtics2=''
      # Will set them both
      mesh.xmtics(lon30, lon30)
      mesh.yticlabels1=lat10
      mesh.yticlabels2=lat10
      # Will set them both
      mesh.yticlabels(lat10, lat10)
      mesh.ymtics1=''
      mesh.ymtics2=''
      # Will set them both
      mesh.ymtics(lat10, lat10)
      mesh.datawc_y1=-90.0
      mesh.datawc_y2=90.0
      mesh.datawc_x1=-180.0
      mesh.datawc_x2=180.0
      # Will set them all
      mesh.datawc(-90, 90, -180, 180)
      mesh.ext_1='n'
      mesh.ext_2='y'
      # Will set them both
      mesh.exts('n', 'y' )
      # Color index value range 0 to 255
      mesh.missing=241
      
    • There are two possibilities for setting meshfill levels:

      1. Levels are all contiguous:

        1
        2
        3
        4
        mesh.levels=([0,20,25,30,35,40],)
        mesh.levels=([0,20,25,30,35,40,45,50])
        mesh.levels=[0,20,25,30,35,40]
        mesh.levels=(0.0,20.0,25.0,30.0,35.0,40.0,50.0)
        
      2. Levels are not contiguous (Examples):

        mesh.levels=([0,20],[30,40],[50,60])
        mesh.levels=([0,20,25,30,35,40],[30,40],[50,60])
        
    • There are three ways to set fillarea color indices:

      mesh.fillareacolors=([22,33,44,55,66,77])
      mesh.fillareacolors=(16,19,33,44)
      mesh.fillareacolors=None
      
    • There are three ways to set fillarea style:

      mesh.fillareastyle = 'solid'
      mesh.fillareastyle = 'hatch'
      mesh.fillareastyle = 'pattern'
      
    • There are two ways to set fillarea hatch or pattern indices:

      mesh.fillareaindices=([1,3,5,6,9,20])
      mesh.fillareaindices=(7,1,4,9,6,15)
      
Using the fillarea secondary object:
  • Create a new instance of fillarea:

    1
    2
    3
    4
    # Copies 'quick' to 'new'
    fill=a.createfillarea('new','quick')
    # Copies 'default' to 'new'
    fill=a.createfillarea('new')
    
  • Modify an existing fillarea:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    fill=a.getmfillarea('def37')
    # Set index using fillarea
    mesh.fillareaindices=(7,fill,4,9,fill,15)
    # list fillarea attributes
    fill.list()
    # change style
    fill.style='hatch'
    # change color
    fill.color=241
    # change style index
    fill.index=3
    
    xmtics1(str/{float:str})

    (Ex: ‘’) dictionary with location of intermediate tics as keys for 1st side of y axis

    xmtics2(str/{float:str})

    (Ex: ‘’) dictionary with location of intermediate tics as keys for 2nd side of y axis

    ymtics1(str/{float:str})

    (Ex: ‘’) dictionary with location of intermediate tics as keys for 1st side of y axis

    ymtics2(str/{float:str})

    (Ex: ‘’) dictionary with location of intermediate tics as keys for 2nd side of y axis

    xticlabels1(str/{float:str})

    (Ex: ‘*’) values for labels on 1st side of x axis

    xticlabels2(str/{float:str})

    (Ex: ‘*’) values for labels on 2nd side of x axis

    yticlabels1(str/{float:str})

    (Ex: ‘*’) values for labels on 1st side of y axis

    yticlabels2(str/{float:str})

    (Ex: ‘*’) values for labels on 2nd side of y axis

    projection(str/vcs.projection.Proj)

    (Ex: ‘default’) projection to use, name or object

    datawc_x1(float)

    (Ex: 1.E20) first value of xaxis on plot

    datawc_x2(float)

    (Ex: 1.E20) second value of xaxis on plot

    datawc_y1(float)

    (Ex: 1.E20) first value of yaxis on plot

    datawc_y2(float)

    (Ex: 1.E20) second value of yaxis on plot

    datawc_timeunits(str)

    (Ex: ‘days since 2000’) units to use when displaying time dimension auto tick

    datawc_calendar(int)

    (Ex: 135441) calendar to use when displaying time dimension auto tick, default is proleptic gregorian calendar

    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.

    fillareacolors([int, ...])

    Colors to use for each level

    fillareastyle(str)

    Style to use for levels filling: solid/pattern/hatch

    fillareaindices([int, ...])

    List of patterns to use when filling a level and using pattern/hatch

    legend(None/{float:str})

    Replaces the legend values in the dictionary keys with their associated string

    ext_1(str)

    Draws an extension arrow on right side (values less than first range value)

    ext_2(str)

    Draws an extension arrow on left side (values greater than last range value)

    missing(int)

    Color to use for missing value or values not in defined ranges

mesh :: (str/int) (0) Draws the mesh wrap :: ([float,float]) ([0.,0.]) Modulo to wrap around on either axis (automatically set to 360 for longitude axes)

colors(color1=16, color2=239)[source]

Sets the color_1 and color_2 properties of the object.

Note

color_1 and color_2 control which parts of the colormap to use for the plot. It defaults to the full range of the colormap (0-255), but if you use fewer colors, it will break up your data into precisely that many discrete colors.

Example
1
2
3
4
5
6
>>> a=vcs.init()
>>> array=[range(10) for _ in range(10)]
>>> ex=a.createmeshfill()
>>> ex.colors(0, 64) # use colorcells 0-64 of colormap
>>> a.plot(ex, array, array)
<vcs.displayplot.Dp object at 0x...>
Parameters
  • color1 (int) – Sets the color_1 value on the object.

  • color2 (int) – Sets the color_2 value on the object.

datawc(dsp1=1e+20, dsp2=1e+20, dsp3=1e+20, dsp4=1e+20)[source]

Sets the data world coordinates for object

Example
1
2
3
4
5
>>> a=vcs.init()
>>> ex=a.createmeshfill('meshfill_dwc')
>>> ex.datawc(0.0, 0.1, 1.0, 1.1) # sets datawc y1, y2, x1, x2
>>> ex.datawc_y1, ex.datawc_y2, ex.datawc_x1, ex.datawc_x2
(0.0, 0.1, 1.0, 1.1)
Parameters
  • dsp1 (float) – Sets the datawc_y1 property of the object.

  • dsp2 (float) – Sets the datawc_y2 property of the object.

  • dsp3 (float) – Sets the datawc_x1 property of the object.

  • dsp4 (float) – Sets the datawc_x2 property of the object.

ext_1

Turns on extensions arrows for values before the first level

ext_2

Turns on extensions arrows for values after the last level

exts(ext1='n', ext2='y')[source]

Sets the ext_1 and ext_2 values on the object.

Example
Parameters
  • ext1 (str or bool) – Sets the ext_1 value on the object. ‘y’ sets it to True, ‘n’ sets it to False. True or False can be used in lieu of ‘y’ and ‘n’.

  • ext2 (str or bool) – Sets the ext_2 value on the object. ‘y’ sets it to True, ‘n’ sets it to False. True or False can be used in lieu of ‘y’ and ‘n’.

levels

Sets the levels on a graphic method, optionally turns on/off extensions arrows

list()[source]

Lists the current values of object attributes

Example
1
2
3
4
5
>>> a=vcs.init()
>>> obj=a.getmeshfill() # default
>>> obj.list() # print meshfill attributes
---------- ... ----------
...
script(script_filename, mode='a')[source]

Saves out a copy of the meshfill graphics method, in JSON or Python format to a designated file.

Note

If the the filename has a ‘.py’ at the end, it will produce a Python script. If no extension is given, then by default a .json file containing a JSON serialization of the object’s data will be produced.

Warning

VCS Scripts Deprecated. SCR script files are no longer generated by this function.

Example
1
2
3
4
>>> a=vcs.init()
>>> ex=a.getmeshfill()
>>> ex.script('filename.py') # append to 'filename.py'
>>> ex.script('filename','w') # make/overwrite 'filename.json'
Parameters
  • script_filename (str) – Output name of the script file. If no extension is specified, a .json object is created.

  • mode (str) – Either ‘w’ for replace, or ‘a’ for append. Defaults to ‘a’, if not specified.

xmtics(xmt1='', xmt2='')[source]

Sets the xmtics1 and xmtics2 values on the object.

Note

The mtics attributes are not inherently plotted by the default template. The example below shows how to apply a custom template and enable it to plot mtics. To plot a the meshfill after setting the mtics and template, refer to vcs.Canvas.plot() or vcs.Canvas.meshfill().

Example
1
2
3
4
5
>>> a=vcs.init()
>>> ex=vcs.createmeshfill()
>>> ex.xmtics("lon5") # minitick every 5 degrees
>>> tmp=vcs.createtemplate() # custom template to plot minitics
>>> tmp.xmintic1.priority = 1 # plotting shows xmtics
Parameters
  • xmt1 (dict or str) – Value for xmtics1. Must be a str, or a dictionary object with float:str mappings.

  • xmt2 (dict or str) – Value for xmtics2. Must be a str, or a dictionary object with float:str mappings.

xticlabels(xtl1='', xtl2='')[source]

Sets the xticlabels1 and xticlabels2 values on the object

Example
1
2
3
4
5
6
7
>>> a = vcs.init()
>>> import cdms2 # Need cdms2 to create a slab
>>> f = cdms2.open(vcs.sample_data+'/clt.nc') # open data file
>>> ex = a.createmeshfill()
>>> ex.xticlabels({0: "Prime Meridian", -121.7680: "Livermore", 37.6173: "Moscow"})
>>> a.plot(ex, f('u')) # plot shows labels
<vcs.displayplot.Dp object at 0x...>
Parameters
  • xtl1 (dict or str) – Sets the object’s value for xticlabels1. Must be a str, or a dictionary object with float:str mappings.

  • xtl2 (dict or str) – Sets the object’s value for xticlabels2. Must be a str, or a dictionary object with float:str mappings.

xyscale(xat='', yat='')[source]

Sets xaxisconvert and yaxisconvert values for the object.

Example
>>> a=vcs.init()
>>> ex=a.createmeshfill('meshfill_xys') # make a meshfill
>>> ex.xyscale(xat='linear', yat='linear')
Parameters
  • xat (str) – Set value for x axis conversion.

  • yat (str) – Set value for y axis conversion.

ymtics(ymt1='', ymt2='')[source]

Sets the xmtics1 and xmtics2 values on the object.

Note

The mtics attributes are not inherently plotted by the default template. The example below shows how to apply a custom template and enable it to plot mtics. To plot a the meshfill after setting the mtics and template, refer to vcs.Canvas.plot() or vcs.Canvas.meshfill().

Example
1
2
3
4
5
>>> a=vcs.init()
>>> ex=vcs.createmeshfill()
>>> ex.xmtics("lon5") # minitick every 5 degrees
>>> tmp=vcs.createtemplate() # custom template to plot minitics
>>> tmp.xmintic1.priority = 1 # plotting shows xmtics
Parameters
  • xmt1 (dict or str) – Value for xmtics1. Must be a str, or a dictionary object with float:str mappings.

  • xmt2 (dict or str) – Value for xmtics2. Must be a str, or a dictionary object with float:str mappings.

yticlabels(ytl1='', ytl2='')[source]

Sets the yticlabels1 and yticlabels2 values on the object

Example
1
2
3
4
5
6
7
>>> a = vcs.init()
>>> import cdms2 # Need cdms2 to create a slab
>>> f = cdms2.open(vcs.sample_data+'/clt.nc') # open data file
>>> ex = a.createmeshfill()
>>> ex.yticlabels({0: "Eq.", 37.6819: "L", 55.7558: "M"})
>>> a.plot(ex, f('u')) # plot shows labels
<vcs.displayplot.Dp object at 0x...>
Parameters
  • ytl1 (dict or str) – Sets the object’s value for yticlabels1. Must be a str, or a dictionary object with float:str mappings.

  • ytl2 (dict or str) – Sets the object’s value for yticlabels2. Must be a str, or a dictionary object with float:str mappings.