Lesson4 VCS_XmGrace_CDAT_Graphics

Embed Size (px)

Citation preview

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    1/31

    Lesson4

    Visualization vcs andxmgrace

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    2/31

    Preview

    VisualizationandControlSystem(VCS)

    Xmgrace

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    3/31

    VCSConceptsandTerminology

    Basicconcepts:

    VCSCanvas where

    the

    plots

    are

    drawn GraphicMethods howthedataisrendered(the

    plottype).E.g.boxfill,isofill,isoline,

    vector,

    etc,.

    Multiple

    projectionsmay

    be

    availableforagivenGraphicMethod.

    Templates definethelocationwherethingsare

    drawn

    on

    the

    canvas

    (data,

    legend,

    title,

    comments,units,etc..)

    Primitives additionalsecondaryitemssuchaslines,polygons,text,markers,etc.,

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    4/31

    TheVCSCanvas

    VCScanvasneedstobeinitialized(created)

    >>> x=vcs.init() # without any arguments

    Upto8Canvasesatonce.

    Canvasasmagicboard,cancleanordestroyit:>>> x.clear()

    >>> x.close()

    CanhavemultipleplotsonasingleCanvas(notcoveredhere)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    5/31

    VCSHelp

    BasichelponVCScanbeobtaininlinevia:>>>vcs.help()

    Thiswilllistavailablefunctionin VCS,notablyfunctionstocreate/get/query VCSobjects

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    6/31

    VCSFirstHelp

    Thisalsocanbeusedtogethelponaspecific

    command:>>> vcs.help(createboxfill)

    Function: createboxfill# Construct a new boxfill graphics method

    Description of Function:Createanewboxfill graphicsmethodgiventhenameandtheexistingboxfill

    graphicsmethodtocopythe attributesfrom.Ifnoexistingboxfill graphicsmethodnameisgiven,thenthedefaultboxfill graphicsmethodwillbeusedasthegraphicsmethodtowhichtheattributeswillbecopiedfrom.

    Ifthenameprovidedalreadyexists,thenaerrorwillbereturned.Graphics

    methodnamesmustbeunique.

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    7/31

    GraphicMethodsConcepts(1)

    EssentiallyagraphicmethodrepresentsHOWdataaregoingtobeplotted(theWHEREwillbedeterminedviatemplates,seelater)

    Thereare13typeofgraphicmethodsinVCS: 2DGraphicMethods

    Boxfill,Isofill,Isoline,Meshfill,Vector,Outfill,

    Outline,

    Continents

    , (Taylordiagrams)

    1DGraphicMethods

    Yxvsx,

    Xyvsy,

    XvsY,

    Scatter

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    8/31

    SpecifyingaGraphicMethod

    Tospecifyagraphicmethoduseacreatefunction,thenuseplot:

    Forexample,foraboxfill:

    >>> gm = x.createboxfill(name)

    >>> x.plot(data, gm)

    Ifagraphicmethodalreadyexists,usegetfunctions:

    >>> gm = x.getboxfill(name)

    >>> x.plot(data, gm)

    Replaceboxfillintheaboveforothermethods.

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    9/31

    2D boxfill

    Theboxfill graphicmethodtakesa2Darrayandrepresentsit

    byfillingabox(determinedbytheboundsoneachaxis

    values)withacolor linkedtothearraysvalueatthislocation:

    >>> box=x.createboxfill(new)

    >>> x.plot(data,box)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    10/31

    2D isofill

    Isofill graphicmethodsdrawsfilledisocontour

    Theyareextremelysimilartoboxfill customtype

    KnownLimitation:

    Nocontrolonlabelsposition

    Nocontrolonisolines Smoothness

    >>> iso=x.createisofill(new)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    11/31

    2D isoline

    Isoline,drawsisocontours,color,style,canbe

    controlled. Limitation:

    No

    control

    on

    the

    labels

    location Nocontrolofsmoothness

    >>> iso=x.createisoline(new)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    12/31

    2D vector

    TheVectorgraphicmethodrepresentsthe

    combinationof2arrays,viavectorthefirst

    arrayrepresentingtheXaxiscomponent

    andthesecondarrayrepresentingtheY

    axiscomponent.>>> f=cdms.open(sample_data/clt.bc)

    >>> u=f(u)

    >>> v=f(v)

    >>> vec=x.createvector(new)

    >>> x.plot(u,v,vec)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    13/31

    1D Y(x)vs x

    All1DplotsinVCSbasicallyworkthesameway.Thereare4typesof1Dgraphicmethod,wellstartwiththebasic:Yxvsx,whichstandsforY(x)vsx

    Thisgraphicmethoddrawsa1Darray(Y)asafunctionofits1Daxis(x)

    Examplezonalmeanofthefirsttimepointofourdataarray>>> zm=MV.average(data[0],1) # Zm.shape is (46,)

    >>> x.plot(zm) # knows to plot 1D with yxvsx

    >>> yx=x.createyxvsx(new)

    >>> x.plot(zm,yx) # same

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    14/31

    1D VCSYxvsxattributes

    Asinisoline,orvector,line,linecolor,

    linewidth,determinetheline. marker,markercolor,markersize,determine

    the

    markers

    to

    be

    drawn:>>> yx.line='dot'>>> yx.linecolor=242

    >>> yx.linewidth=2

    >>> yx.marker='star

    >>> yx.markercolor=244

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    15/31

    GraphicMethodsAttributes

    >>> b=x.createboxfill(new_one)

    >>> b.list()

    Boxfill (Gfb)member(attribute)listings

    CanvasMode=1

    graphicsmethod=Gfb #indicatesthegraphicmethodtype:GraphicFilledBoxes(Gfb)

    name=new #Nameofthespecificgraphicmethod

    projection=linear#projectiontouse(seeprojectionsection)

    xticlabels1=* #1stsetofticlabels,* meansautomatic

    xticlabels2=*#2ndsetoflabels(posdeterminedbytemplate)

    xmtics1= #1stsetofsubti fordetails)xmtics2=

    yticlabels1=*

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    16/31

    2D WorldCoordinates example

    attributes worldcoordinate attributesarepresentonall

    graphic

    methods. canselectasubsetarea.

    forexampletovisualiseAfrica:

    >>> b.datawc_x1 = -45.

    >>> b.datawc_x2 = 70.

    >>> b.datawc_y1 = -38.

    >>> b.datawc_y2 = 38.

    >>> x.plot(s,b)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    17/31

    Projections

    P=x.createprojection()

    Graphicmethod.projection=P

    P.type=n

    Ncanbeoneof28possible

    printP.__doc__

    Eachtypehasspecificparameters

    P.list()

    importvcs,cdms2,sys

    f=cdms2.open(sys.prefix+\

    /sample_data/clt.nc)

    s=f(clt,time=slice(0,1),\

    longitude=(210,50))

    x=vcs.init()

    iso=x.createisofill()

    p=x.createprojection()

    p.type=orthographic

    iso.projection=p

    x.plot(s,iso,ratio=1t)

    x.clear()

    p.type=lambert

    x.plot(s(latitude=(20,70),\

    longitude=(150,50)),iso)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    18/31

    ProjectionattributesofGraphic

    MethodsEachgraphicmethodmayhaveanumberof

    projections,thefulllistisavailablefrom:>>> v.show('projection')************************Projection Names List*************************

    ( 1): default linear mollweide

    ( 4): robinson polyconic polar( 7): lambert orthographic mercator

    ************************End Projection Names List*********************

    mollweide polar robinson

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    19/31

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    20/31

    VCS:templatemanipulation

    TemplateratioX.ratio=2 : y is twice as big as x

    X.ratio=autoX.ratio=2t : also moves tick marks

    Templatescaling(lowerleftdataareaunchanged)T.scale(.5) # half size

    T.scale(.5, axis=x) #half size in X, fontunchanged

    T.scale(.5, axis=x, font=1) # also alterfonts

    TemplatemovingT.move(.2, .4) # move by 20% in x, 40% in yPositive values means up/right

    T.moveto(x,y) # move lower left corner ofdata to x,y

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    21/31

    VCS:templatemanipulation

    UsingEzTemplate

    Alsoavailable:EzTemplate.oneD,

    for1Dplots,usestheprovidedbasetemplateandmovethelegendaccordingtothenumberofdataset

    fromvcsaddons importEzTemplate

    importvcs

    x=vcs.init()

    M=EzTemplate.Multi(rows=4,columns=3)

    fori inrange(12):

    t=M.get()x.plot(s,t,iso)

    OD=EzTemplate.oneD(n=n,template=t)

    fori inrange(n):

    y =MV2.sin((i+1)*x)y.setAxis(0,ax)

    yx =X.createyxvsx()

    yx.linecolor=241+i

    yx.datawc_y1=1.

    yx.datawc_y2=1.t =OD.get()

    X.plot(y,t,yx,bg=bg)

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    22/31

    vcs:textprimitives

    text=x.createtext()TextTable(Tt)member(attribute)listings

    Tt_name =newfont=1spacing=2

    expansion=100color=1priority=1string=Noneviewport=[0,1,0,1]worldcoordinate =[0,1,0,1]x =Noney =None

    projection=defaultTextOrientation(To)member(attribute)listings

    To_name =newheight=14angle=0path=righthalign =leftvalign =half

    Font_name =x.addfont(path_to_ttf_font)

    Font=x.getfont(Font_name)#usableintemplate

    Availablefontsbydefault:['Adelon','Arabic','AvantGarde','Chinese','Clarendon','Courier','Greek','Hebrew','Helvetica','Maths1','Maths2','Maths3','Maths4','Russian','Times','default']

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    23/31

    vcs:otherprimitives

    fa=x.createfillarea(new)

    l=x.createline(new)

    m=x.createmarker(new)

    Eachprimitivehasthe2followingattributes: Prim.viewport=[xv1,xv2,yv1,yv2]#default:[0,1,0,1]

    In%ofpage,areaoftheprimitiveextends

    Prim.worldcoordinates =[x1,x2,y1,y2]#defalut [0,1,0,1] Coordinatescorrespondingtoxv1,xv2,yv1,yv2

    Primitiveunitsareintheworldcoordinate system

    Example text.viewport=[.25,.75,.25,.75]#definesmallerzoneonpage

    text.worldcoordinate=[180, 90,180,90]#Definethecoordinatesystem

    text.x=[122.4428]

    text.y=[37.7709]

    text.string=[SanFrancisco,CA,94117]

    Foroverlaywithanexistinggraphicmethod Prim.viewport #settoyourtemplate.data

    Prim.worldcoordinates #settoyourgraphicmethod.data.wc

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    24/31

    Animating throughtheGUI

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    25/31

    Animatingatthecommandline

    Justkeepwriteaframetoacanvas,togifand

    clear,thendoalloveragain>>> x=vcs.init()

    >>> templ=canvas.gettemplate('BADC_ERA40')

    >>> plot_type=canvas.getisofill(ASD)

    >>> for i in range(loop_num):

    ... x.clear()

    ... x.plot( data( time=slice(i,i+1) ), templ, \plot_type)

    ... x.gif(outfile) # Second arg of merge="a"

    # needed on some versions

    OrcallupGUIwithx.animate.gui()

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    26/31

    Example:VCS

    Lookatthesampleprogramtest_vcs.pyand

    runitthroughstepbystep.

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    27/31

    vcsaddons

    GIScapability.Youcanreadandplotgis/shapefiles.

    importvcs,vcsaddons

    importcdms2,sysx=vcs.init()

    importvcs.test.support

    bg=0

    c=vcsaddons.createusercontinents(x=x)

    lon1=

    125lon2=75.

    lat1=20.

    lat2=55.

    c.types =['shapefile','shapefile']

    c.sources =['../Data/co1990p020','../Data/fe_2007_06_county',]

    c.colors =[246,241,244,241]c.widths=[1,1,1]

    c.lines=['solid','solid','solid','dot']

    f=cdms2.open(sys.prefix+/sample_data/clt.nc)

    s=f("clt",latitude=(lat1,lat2),longitude=(lon1,lon2),time=slice(0,1

    ))

    t=x.createtemplate()

    iso=x.createisofill()

    x.plot(s,t,iso,continents=0,ratio='autot',bg=bg)

    x.plot(s,c,t,ratio='autot',bg=bg)

    x.png('uscounties')

    importvcsaddons._gis

    sources=

    ['../Data/fe_2007_06_county.dbf','../Dat

    a/co1990p020.dbf]

    fors insources:

    D=vcsaddons._gis.readdbffile(s)

    printD.keys()

    try:

    printD['NAME']

    except:

    printD['COUNTY']

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    28/31

    Xmgrace

    Xmgrace isaveryniceplottingpackage for

    1ddata. Ifyouhavexmgrace installedonyour

    computer,

    you

    can

    script

    it

    via

    CDAT.

    Its

    interfacehasbeenmappedtobeascloseas

    possiblefromtheparameterfilesfrom

    xmgrace.

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    29/31

    Example:Xmgrace

    Lookatthesampleprogram

    test_xmgrace.pyandrunitthroughstepbystep.

  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    30/31

    Otherpackages

    Matplotlib:http://matplotlib.sourceforge.net

    Visus

    IaGraphics

    http://matplotlib.sourceforge.net/http://matplotlib.sourceforge.net/
  • 8/6/2019 Lesson4 VCS_XmGrace_CDAT_Graphics

    31/31

    Acknowledgements

    DeanWilliams,CharlesDoutriaux (PCMDI,

    LLNL) Dr.JohnnyLin