Color maps of UV-CDAT

Grep all available color maps and visualize them using EzTemplate

The CDAT software was developed by LLNL. This tutorial was written by Charles Doutriaux and Jiwoo Lee (2017). 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

Import modules

Back to Top

In [1]:
import vcs, EzTemplate
import MV2
import numpy as np

Prepare a dummy array

Back to Top

  • We need a 2-D dummy array that will contain monotonically increasing numbers each of two rows, to be used for the visualization
In [2]:
a=[]
num_levels = 224

for i in range(0,num_levels):
  a.append(i/float(num_levels))

for i in range(0,num_levels):
  a.append(i/float(num_levels))

a = MV2.array(a)
a = MV2.reshape(a, (-1,num_levels))

Colormap visualizing function

Back to Top

  • Below function will visualize given colormaps to provide a selection guidance.
In [3]:
import math

def visualize(cmlst, v, loadcmap):
 
    T = vcs.createtemplate()
    T.blank(['title','mean','min','max','dataname','crdate','crtime',
         'units','zvalue','tvalue','xunits','yunits','xname','yname', 'legend'])

    cmlst_num = len(cmlst)
    nrows = int(math.ceil(cmlst_num/2.))
    
    M = EzTemplate.Multi(template=T, rows=nrows, columns=2)
    M.margins.top = 0.05
    M.margins.bottom = 0.05
    M.margins.left = 0.2
    M.margins.right = 0.2
    M.spacing.vertical= 0.005
    
    for i in range(0, cmlst_num):
        box = v.createboxfill()
        box.color_1 = 16
        box.color_2 = 240
        box.xticlabels('','') # Hide x-axis tick labels
        box.yticlabels('','') # Hide y-axis tick labels
        box.colormap = loadcmap(cmlst[i])
    
        if i >= nrows: #right column
            jj=1
            ii=i-nrows
            x = 0.81 # text starting x position
        else: # left column
            jj=0
            ii=i
            x = 0.01 # text starting x position

        t = M.get(row=ii, column=jj, legend='none')
        t.blank(['legend'])

        v.plot(a, t, box, bg=1)

        subplot_title = vcs.createtext()
        subplot_title.string = box.colormap
        subplot_title.x = x
        subplot_title.y = (t.box1.y1 + t.box1.y2) / 2.
        subplot_title.height = 8
        subplot_title.halign = 'left'
        subplot_title.valign = 'half'
        subplot_title.color = 'black'
        v.plot(subplot_title, t)
        v.removeobject(box)
        v.removeobject(subplot_title)
        
        #print box.colormap  ## List available color maps
    return(v)

Open a VCS canvas

Back to Top

  • Let's open a VCS canvas to play with!
In [4]:
v = vcs.init(geometry={"width":600,"height":1200}, bg=1)
vcs.utils.defaultColorsRange = range(16,240)

VCS colormaps

Back to Top

  • VCS is default module that is being used for the UV-CDAT. You can use VCS color maps which is loaded at the beginning.
In [5]:
cmlst = v.listelements('colormap')
loadcmap = str
v = visualize(cmlst, v, loadcmap)

plot_title = v.createtext()
plot_title.string = 'VCS Colormaps'
plot_title.height = 15
plot_title.halign = 'center'
plot_title.valign = 'bottom'
plot_title.x = 0.5
plot_title.y = 0.96
v.plot(plot_title)
Out[5]:
<vcs.displayplot.Dp at 0x1171c4a08>

Matplotlib colormaps in VCS

Back to Top

  • You can load and visualize Matplotlib colormaps in the VCS canvas.
  • Use vcs.colors.matplotlib2vcs to convert
  • For now if same name is already being used in VCS, new name with tail _000 is assigned, as showing below as "warning messages".
  • You can also use vcs.utils.loadmatplotlibcolormaps() to bring all Matplotlib colormaps to VCS
In [6]:
v.clear()

import matplotlib.pyplot as plt

# Get list of all available colormaps from matplotlib (except '_r' which is reversed one)
cmlst = [x for x in plt.colormaps() if not '_r' in x]
cmlst = sorted(cmlst, key=lambda s: s.lower()) # Sort as case-insensitive alphabet order

loadcmap = vcs.colors.matplotlib2vcs
v = visualize(cmlst, v, loadcmap)

plot_title.string = 'Matplotlib Colormaps for VCS'
v.plot(plot_title)
Out[6]:
<vcs.displayplot.Dp at 0x127283868>
In [ ]: