vcs
vcs copied to clipboard
Projections and Secondaries don't get along
I'm playing with a technique to do a polar 1D plot in VCS, and I ran into some issues along the way. The biggest issue is that attempting to use a projection on a secondary object (which is something the API supports) doesn't really work, at all.
A simple test case:
import vcs
line = vcs.createline()
line.projection = "polar"
line.worldcoordinate = [-180, 180, -90, 90]
line.viewport = [.25, .75, .25, .75]
line.x = [-180, 180]
line.y = [90, 90]
canvas = vcs.init()
canvas.plot(line)
which gives you a blank canvas.
This seemed odd to me, since we do essentially that exact line when plotting a polar plot of a 2D variable (via the template.box1 attribute).
import vcs, cdms2
f = cdms2.open(vcs.sample_data + '/clt.nc')
s = f('clt')
canvas = vcs.init()
boxfill = vcs.getboxfill("polar")
empty_template = vcs.createtemplate()
empty_template.blank()
empty_template.box1.priority = 1
canvas.plot(s, empty_template, boxfill)
I inserted some code to dump the attributes of the line object being generated for that template, and got this:
----------Line (Tl) member (attribute) listings ----------
secondary method = Tl
name = __line_591065525709696
type = ['solid']
width = [1.0]
color = [1]
priority = 1
viewport = [0.2766584621956789, 0.7233415266284211, 0.259999990463, 0.860000014305]
worldcoordinate = [-180.3333333325, 179.6666666625, -90.0, 90.0]
x = [[-180.3333333325, 179.6666666625], [-180.3333333325, 179.6666666625]]
y = [[90.0, 90.0], [-90.0, -90.0]]
projection = polar
colormap = None
I tried assigning those exact values to a line and plotting it, but it still failed to produce any output.
I dug into the VTK objects actually being assembled, iterated across all of the points created, and still, everything was the same for both ways. After a bunch of spelunking through misc. VTK objects, I discovered the the bounds on the actors were set differently.
It turns out that the plot
function will try and grab a "vtk_backend_grid" and pass it to this code in fitToViewport
; when we plot the template, vtk_backend_grid
is passed as a kwarg, but when we plot the line straight-up, we use the Xrg
and Yrg
values derived from the worldcoordinate
attribute on the line
object.
We definitely need to be able to correctly project stuff without plotting a variable as part of the process, so this is in the "bug" category.
Migrated from: https://github.com/UV-CDAT/uvcdat/issues/1965