New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Python Scripting in VisIt for analysis and visualization" by Alex Razoumov #142

Closed
brunogrande opened this Issue Oct 24, 2016 · 0 comments

Comments

2 participants
@brunogrande
Member

brunogrande commented Oct 24, 2016

Description

VisIt is one of the leading open-source multi-platform 3D scientific visualization packages. In this one-hour workshop we'll take a look at building VisIt visualizations with Python scripting. No prior experience with either VisIt or Python is required. Attendees need to bring their laptops with the latest version of VisIt installed.

Time and Place

Where: Room 7010, Library Research Commons, SFU Burnaby Campus

When: April 11th, 2017 @ 3:00 PM

Registration

REGISTER HERE

Notes

I normally teach full-day VisIt workshops -- for reference you can download the slides and data files as a ZIP archive (26 MB). Today we'll take a look at only the scripting part, so there is no need to download anything besides the VisIt package itself. The data file noise.silo comes with VisIt.

OpenDatabase("/path/to/noise.silo")  
AddPlot("Pseudocolor", "hardyglobal")
DrawPlots()
p = PseudocolorAttributes()
p
p.min, p.max = 1, 3
p.minFlag, p.maxFlag = 1, 1   # turn it on
SetPlotOptions(p)
help(SetPlotOptions)
p.minFlag, p.maxFlag = 0, 0
SetPlotOptions(p)
p.colorTableName = "Greens"
SetPlotOptions(p)
os.getcwd()
os.chdir('/Users/razoumov/teaching/visitWorkshop/scripts')
Source('scriptName.py')
# this is orange.py
DeleteAllPlots()
AddPlot("Pseudocolor", "hardyglobal")
p = PseudocolorAttributes()
p.colorTableName = "Oranges"
SetPlotOptions(p)
DrawPlots()
# this is addOperator.py
DeleteAllPlots()
AddPlot("Pseudocolor", "hardyglobal")
AddOperator("Isosurface")
isoAtts = IsosurfaceAttributes() # create an operator attributes object
isoAtts.contourMethod = isoAtts.Level  # contour by level(s)
isoAtts.variable = "hardyglobal"
SetOperatorOptions(isoAtts) # set operator attributes to above values
DrawPlots()
print isoAtts   # default is 10 isosurface levels
# this is threeSurfaces.py
isoAtts.contourMethod = isoAtts.Value  # contour by value(s)
for i in range(3):
    isoAtts.contourValue = 2. + i*1.5
    SetOperatorOptions(isoAtts)
# this is saveSurfaces.py
s = SaveWindowAttributes()
s.format, s.fileName, s.outputToCurrentDirectory = s.PNG, 'iso', 0
s.outputDirectory = "/Users/razoumov/Documents/teaching/visitWorkshop"
SetSaveWindowAttributes(s)
for i in range(3):
    isoAtts.contourValue = 2. + i*1.5
    SetOperatorOptions(isoAtts)
    name = SaveWindow()
# this is oneSurface.py
DeleteAllPlots()
AddPlot('Contour', 'hardyglobal')
contAtt = ContourAttributes()
contAtt.contourMethod = contAtt.Value
contAtt.contourValue = (3.8)
contAtt.colorType = contAtt.ColorBySingleColor
contAtt.singleColor = (0, 255, 0, 255)
SetPlotOptions(contAtt)
DrawPlots()
# this is printView.py
print GetView3D()   # print all its attributes of the current view
# GetView3D().viewNormal   # can also print a single attribute
# this is setControlPoint.py
from math import *
c0 = View3DAttributes()
phi = 0   # 0 <= phi <= 2*pi
theta = 0   # -pi/2 <= theta <= pi/2
c0.viewNormal = (cos(theta)*cos(phi),cos(theta)*sin(phi),sin(theta))
c0.focus, c0.viewUp = (0, 0, 0), (0, 0, 1)
c0.viewAngle, c0.parallelScale, c0.imageZoom = 30, 17.3205, 1
c0.nearPlane, c0.farPlane, c0.perspective = -34.641, 34.641, 1
SetView3D(c0)
# this is rotateAroundVertical.py
nsteps = 300
for i in range(nsteps):
    phi = float(i)/float(nsteps-1)*2.*pi
    c0.viewNormal = (cos(theta)*cos(phi), cos(theta)*sin(phi),
                     sin(theta))
    SetView3D(c0)
# this is flyInOut.py
nsteps = 100
xfirst = 0
xlast = -40
for i in range(nsteps):
    x = xfirst + float(i)/float(nsteps-1)*(xlast-xfirst)
    c0.focus = (x, 0, 0)
    SetView3D(c0)
for i in range(nsteps):
    x = xlast + float(i)/float(nsteps-1)*(xfirst-xlast)
    c0.focus = (x, 0, 0)
    SetView3D(c0)
# this is perspective.py
nsteps = 100
a1 = 30
a2 = 60
for i in range(nsteps):
    c0.viewAngle = a1 + float(i)/float(nsteps-1)*(a2-a1)
    SetView3D(c0)
for i in range(nsteps):
    c0.viewAngle = a2 + float(i)/float(nsteps-1)*(a1-a2)
    SetView3D(c0)
# this is copyView.py
def copyView(a,b):
    b.viewNormal = a.viewNormal
    b.focus = a.focus
    b.viewUp = a.viewUp
    b.viewAngle = a.viewAngle
    b.parallelScale = a.parallelScale
    b.nearPlane = a.nearPlane
    b.farPlane = a.farPlane
    b.perspective = a.perspective
    b.imageZoom = a.imageZoom
# this is threeControlPoints.py
c1 = View3DAttributes()
copyView(c0,c1)
phi = pi/2
c1.viewNormal = (cos(theta)*cos(phi), cos(theta)*sin(phi),
                 sin(theta))
c2 = View3DAttributes()
copyView(c1,c2)
theta = pi/6
c2.viewNormal = (cos(theta)*cos(phi), cos(theta)*sin(phi),
                 sin(theta))
c3 = View3DAttributes()
copyView(c2,c3)
c3.focus = (0, -30, -20)
# this is interpolate.py
# define a tuple of control points
cpts = (c0, c1, c2, c3)
# define a corresponding tuple of their positions in time
# from 0 to 1, in this case (0, 1/3, 2/3, 1)
x, n = [], len(cpts)
for i in range(n):
    x = x + [float(i) / float(n-1)]
# interpolate between control points to cover [0,1]
# time interval with a much smaller step
nsteps = 200
for i in range(nsteps):
    t = float(i) / float(nsteps - 1)
    c = EvalCubicSpline(t, x, cpts)
    SetView3D(c)
# this is clipStatic.py
DeleteAllPlots()
AddPlot("Pseudocolor", "hardyglobal")
c0 = View3DAttributes()
c0.viewNormal = (0.9, 0., 0.4358898943540673)
c0.focus, c0.viewUp = (0, 0, 0), (0, 0, 1)
c0.viewAngle, c0.parallelScale = 30, 17.3205
c0.nearPlane, c0.farPlane, c0.perspective = -171.473, 171.473, 1
SetView3D(c0)
light0 = LightAttributes()
light0.enabledFlag, light0.type = 1, light0.Camera
light0.direction = (0., -0.6, -0.8)
light0.color, light0.brightness = (255, 255, 255, 255), 1
SetLight(0, light0)
AddOperator("Clip")
clipAtts = ClipAttributes()
clipAtts.funcType, clipAtts.plane1Status = clipAtts.Plane, 1
clipAtts.plane1Origin, clipAtts.plane1Normal = (0, 0, 0), (0, 0, 1)
SetOperatorOptions(clipAtts)
DrawPlots()
# this is queryPseudocolor.py
DeleteAllPlots()
AddPlot("Pseudocolor","hardyglobal")
DrawPlots()
print Query("MinMax")
val = GetQueryOutputValue()
print val
# this is queryContour.py
DeleteAllPlots()
AddPlot("Contour","hardyglobal")
contAtts = ContourAttributes()
contAtts.contourMethod = contAtts.Value
contAtts.contourValue = (3.8)
SetPlotOptions(contAtts)
DrawPlots()
print Query("MinMax")
val = GetQueryOutputValue()
print val
# this is querySlice.py
DeleteAllPlots()
AddPlot("Pseudocolor", "hardyglobal")
AddOperator("Slice")
DrawPlots()
for i in range(10):
    position = i*2 - 9
    print 'position =', position
    s = SliceAttributes()
    s.axisType = s.XAxis
    s.originType = s.Intercept
    s.originIntercept = position
    SetOperatorOptions(s)
    Query("MinMax")   # queries the 3D volume!
    print '  minMax =', GetQueryOutputValue()
    Query("Weighted Variable Sum")   # queries the 2D slice!
    print '  sum =', GetQueryOutputValue()
OpenDatabase("~/teaching/visitWorkshop/datasets/092g06.dem")
AddPlot("Pseudocolor", "height")
DrawPlots()
# this is terrain3d.py
DeleteAllPlots()
OpenDatabase("~/teaching/visitWorkshop/datasets/092g06.dem")
AddPlot("Pseudocolor", "height")
AddOperator("Elevate")
e = ElevateAttributes()
e.useXYLimits = 1 # if X/Y are longitude/latitude, z-height would be off
SetOperatorOptions(e) #   => simply rescale all 3 axes to a cube
AddOperator("Transform")
t = TransformAttributes()
t.doScale = 1     # turn on scaling
t.scaleX, t.scaleY, t.scaleZ = 1, 1, 0.05   # and make z-heights smaller
SetOperatorOptions(t)
DrawPlots()
# this is drawMolecule.py
OpenDatabase("~/teaching/visitWorkshop/datasets/molecules/1l5q.pdb", 0)
AddPlot("Molecule", "element", 1, 1)
DrawPlots()
m = MoleculeAttributes()
m.drawAtomsAs = m.SphereAtoms # NoAtoms, SphereAtoms, ImposterAtoms
m.scaleRadiusBy = m.Fixed  # Fixed, Covalent, Atomic, Variable
m.atomSphereQuality = m.Medium  # Low, Medium, High, Super
m.radiusFixed = 0.5
m.drawBondsAs = m.CylinderBonds # NoBonds, LineBonds, CylinderBonds
m.colorBonds = m.ColorByAtom  # ColorByAtom, SingleColor
m.bondCylinderQuality = m.Medium  # Low, Medium, High, Super
m.bondRadius = 0.08
m.elementColorTable = "cpk_jmol"
m.legendFlag = 1
SetPlotOptions(m)
ffmpeg -r 10 -i clip%04d.png -c:v libx264 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" movie.mp4

Assumed Knowledge

No prior experience with either VisIt or Python is required.

Software Dependencies

Attendees need to bring their laptops with the latest version of VisIt [installed(http://goo.gl/KcGWHa).

Data

TBA.

Links

Lessons Notes: TBA

@razoumov razoumov changed the title from Python Scripting in VisIt for analysis and visualization to "Python Scripting in VisIt for analysis and visualization" by Alex Razoumov Dec 8, 2016

@dfornika dfornika added this to Workshop Ideas in Workshop Planning Feb 6, 2017

@brunogrande brunogrande added workshop and removed workshop-idea labels Mar 31, 2017

@brunogrande brunogrande moved this from Workshop Ideas to Scheduled Workshops in Workshop Planning Mar 31, 2017

@brunogrande brunogrande closed this Jun 1, 2017

@brunogrande brunogrande removed the workshop label Jun 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment