Ez Templates

This tutorial shows how to easily create templates for CDAT's VCS

© 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.

Download the Jupyter Notebook

Introduction

Back to Top

More often than not one would like to have mutliple plots on a single page (or vcs canvas in our case).

This can be achieved via VCS's templates objects. Tweaking the templates can be tidious, this is where the EzTemplate comes handy, it helps creating vcs template object for most common plot copnfigurations.

Setting up the notebook

Back to Top

In [1]:
from __future__ import print_function, division
from vcsaddons import EzTemplate
from IPython.display import Image
import vcs
import cdms2

vcs.download_sample_data_files()
canvas = vcs.init(bg=True)
f = cdms2.open(vcs.sample_data+"/clt.nc")
clt = f("clt")
gm = vcs.createisofill()
levels = range(0,110,25)
gm.levels = levels
gm.fillareacolors = vcs.getcolors(levels)

box = vcs.createline()
box.x = [0.001, .999, .999, .001, .001]
box.y = [0.001, .001, .999, .999, .001]

def plot_all(M):
    canvas.clear()
    for i in range(M.rows * M.columns):
        template = M.get(column = i % M.columns, row = i // M.columns)  # This is vcs template object you could further edit
        display = canvas.plot(clt[i*2], template, gm)
    return canvas.plot(box)
Downloading: 'th_yr.nc' from 'https://uvcdat.llnl.gov/cdat/sample_data/' in: /export/reshel3/anaconda52/envs/cdms2/share/uvcdat/sample_data/th_yr.nc
Downloading: 'th_yr.nc' from 'https://uvcdat.llnl.gov/cdat/sample_data/' in: /export/reshel3/anaconda52/envs/cdms2/share/uvcdat/sample_data/th_yr.nc
Downloading: 'th_yr.nc' from 'https://uvcdat.llnl.gov/cdat/sample_data/' in: /export/reshel3/anaconda52/envs/cdms2/share/uvcdat/sample_data/th_yr.nc

Creating Templates for 2x3 plots

Back to Top

Let's say we want have 6 plots, split on 3 rows of 2. Notice the canvas automatically switch to portrait orientation.

In [2]:
Multiple = EzTemplate.Multi(rows=3, columns=2, x=canvas)
for i in range(6):
    template = Multiple.get()  # This is vcs template object you could further edit
    display = canvas.plot(clt[i*2], template, gm)
display  # for notebook to render final picture
Out[2]:

Accessing a specific template

Back to Top

Rather than accessing templates in order, you can retrieve directly a specific object

In [3]:
canvas.clear()
template = Multiple.get(row=0, column=0)  # This is vcs template object you could further edit
canvas.plot(clt[0], template, gm)
template = Multiple.get(row=1, column=1)  # This is vcs template object you could further edit
canvas.plot(clt[6], template, gm)
template = Multiple.get(row=2, column=0)  # This is vcs template object you could further edit
canvas.plot(clt[12], template, gm)
Out[3]:

Local legend

Back to Top

You probably noticed that only one legend is plotted, sometimes you might want a separate legend for a specific subplot. This can be achieved when you get the template

In [4]:
canvas.clear()
canvas.clear()
template = Multiple.get(row=0, column=0)  # This is vcs template object you could further edit
canvas.plot(clt[0], template, gm)
template = Multiple.get(row=1, column=1, legend="local")  # This is vcs template object you could further edit
canvas.plot(clt[6], template, gm)
template = Multiple.get(row=2, column=0)  # This is vcs template object you could further edit
canvas.plot(clt[12], template, gm)
Out[4]:

Controling the subplots aspects

Back to Top

Many general aspect of the plot cna be controlled via the Multi object. Al ist of controllable aspect and their current values can be accessed vi the list() function

In [5]:
Multiple.list()
----------Template (P) member (attribute) listings ----------
rows = 3
columns = 2
template = default
member = margins
top = 0.05
bottom = 0.075
right = 0.05
left = 0.033
member = spacing
horizontal = 0.05
vertical = 0.035
member = legend
direction = horizontal
stretch = 0.8
thickness = 0.2
fat = 0.05

Base template

Back to Top

By default each individual template is generated based on the default vcs template. But you can pass it the base template you would like to be used.

In [6]:
base_template = vcs.createtemplate()
base_template.blank(["title","crtime","crdate",
                     "source","dataname", "units",
                     "tname", "tvalue", "zvalue",
                     "min", "max",
                     "xname", "xlabel1"])
canvas.clear()
canvas.plot(clt,base_template, gm)
Out[6]: