This tutorial provides an example, from start to finish, of downloading some data and plotting it.
The CDAT software was developed by LLNL. This tutorial was written by Charles Doutriaux. This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.
import vcs
import cdms2
Download some sample data.
vcs.download_sample_data_files()
Open the clt.nc NetCDF file which contains total cloudiness data and assign that open file to the variable f
. The file contains three types of data:
f=cdms2.open(vcs.sample_data+"/clt.nc")
We'll load the total cloudiness data, clt
, into the s
variable (for sample data).
s=f("clt")
Next we'll create a vcs canvas called x
which is basically a window in which to display the data.
Setting bg=True
means the data will be plotted in the background (bg) meaning the data will plot in this notebook and not in a separate window on your computer.
x=vcs.init(bg=True)
First we'll plot the data just as it is using the default settings in VCS, which in this case creates a boxfill plot (the default plotting style if two dimensional or higher data is present).
x.plot(s)
First we'll list all the graphic methods available.
vcs.listelements()
Let's create an isofill object called gm
(for graphic method) using the createisofill
method.
gm = vcs.createisofill()
Let's see what options available for manipulating the gm
object that uses the isofill graphics method.
gm.list()
The graphic method controls how things are drawn:
datawc
stands for dataworldcoordinates.x/yticlabels
are the labels to use on the x/y axes (python dictionaries {location_value:"string"}.x/ymtics
are the ticks that do not have strings/labels attached.missing
is color to use for misssing values (index in colormap, (r,g,b,o) or "string").fillarea
are the contour properties.gm.datawc_x1 = -10
gm.datawc_x2 = 60
gm.datawc_y1= 15
gm.datawc_y2 = 65
gm.xticlabels1 = {0:"Greenwich", 20:"20E"}
gm.yticlabels2 = {0:"Equator",60:"Arctic Circle", 45:"45N"}
levels = list(range(0,101,5)) # specify the iso contours to use
colors = vcs.getcolors(levels) # automatically picks colors that will be spread across the range of your data.
gm.levels = levels
gm.fillareacolors = colors
x.clear()
x.plot(s,gm,bg=True)
To control the location of elements, like the plot title, we use a template.
t = vcs.createtemplate()
t.list()
lists all the properties that can be set.
t.list()
The most commonly used elements/members are: dataname, title, mean, max, min, units, data, and legend.
data
controls the area where to plot the data.legend
is the area used by the legend/colorbar.The values come from the data plotted.
Most common attributes are:
priority
is the order of drawing with 2 drawing above 1 and 3 drawing above 2. A value of 0 turns the priority value off.See below for more information on text objects, but they are basically controlled via textorientation
and texttable
objects properties.
t.min.priority =0 # turn off min
s.id = "I AM LEARNING" # change dataname
s.title = "THIS IS MY TITLE"
s.units= "SOME WEIRD UNIT"
t.reset('x',.2,.5,t.data.x1,t.data.x2) # reset template to go from 20% to %0% of page (left essentially)
x.clear()
x.plot(s,gm,t)
Let's preserve the aspect ratio.
x.clear()
x.plot(s,gm,t,ratio="autot")