Skip to content
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

[WIP] painfully trying to plot isofill with gengrid #322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vcs/Canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,7 @@ def __plot(self, arglist, keyargs):
if inGrid is not None and arglist[0] is not None and\
isinstance(arglist[0], cdms2.avariable.AbstractVariable) and\
not isinstance(arglist[0].getGrid(), cdms2.grid.AbstractRectGrid) and\
arglist[3] not in ["meshfill", ]:
arglist[3] not in ["meshfill", "isofill" ]:
raise RuntimeError("You are attempting to plot unstructured grid" +
"with a method that is not meshfill")
# preprocessing for extra keyword (at-plotting-time options)
Expand Down Expand Up @@ -3812,7 +3812,7 @@ def __plot(self, arglist, keyargs):
arglist[1].setAxis(i, axes_changed2[i])
# Check to make sure that you have at least 2 dimensions for the follow graphics methods
# Flipping the order to avoid the tv not exist problem
if (arglist[3] in ['boxfill', 'isofill', 'isoline', 'vector']) and (
if (arglist[3] in ['boxfill', 'isoline', 'vector']) and (
len(arglist[0].shape) < 2):
raise vcsError(
'Invalid number of dimensions for %s' %
Expand Down
9 changes: 6 additions & 3 deletions vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,13 @@ def trimData2D(self, data):
g = data.getGrid()
gaxes = list(g.getAxisList())
daxes = list(data.getAxisList())
if daxes[len(daxes) - len(gaxes):] == gaxes:
if numpy.allclose(daxes[len(daxes) - len(gaxes):], gaxes):
# Ok it is gridded and the grid axes are last
return self.cleanupData(
data(*(slice(0, 1),) * (len(daxes) - len(gaxes)), squeeze=1))
if len(daxes) != len(gaxes):
return self.cleanupData(
data(*(slice(0, 1),) * (len(daxes) - len(gaxes)), squeeze=1))
else:
return data
else:
# Ok just return the last two dims
return self.cleanupData(
Expand Down
59 changes: 44 additions & 15 deletions vcs/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,50 @@ def genGrid(data1, data2, gm, deep=True, grid=None, geo=None, genVectors=False,
continents = True
wrap = [0., 360.]
if grid is None:
m = g.getMesh()
xm = m[:, 1].min()
xM = m[:, 1].max()
ym = m[:, 0].min()
yM = m[:, 0].max()
numberOfCells = m.shape[0]
# For vtk we need to reorder things
m2 = numpy.ascontiguousarray(numpy.transpose(m, (0, 2, 1)))
m2.resize((m2.shape[0] * m2.shape[1], m2.shape[2]))
m2 = m2[..., ::-1]
# here we add dummy levels, might want to reconsider converting
# "trimData" to "reOrderData" and use actual levels?
m3 = numpy.concatenate(
(m2, numpy.zeros(
(m2.shape[0], 1))), axis=1)
try:
m = g.getMesh()
xm = m[:, 1].min()
xM = m[:, 1].max()
ym = m[:, 0].min()
yM = m[:, 0].max()
numberOfCells = m.shape[0]
# For vtk we need to reorder things
m2 = numpy.ascontiguousarray(numpy.transpose(m, (0, 2, 1)))
m2.resize((m2.shape[0] * m2.shape[1], m2.shape[2]))
m2 = m2[..., ::-1]
# here we add dummy levels, might want to reconsider converting
# "trimData" to "reOrderData" and use actual levels?
m3 = numpy.concatenate(
(m2, numpy.zeros(
(m2.shape[0], 1))), axis=1)
except Exception: # ok no mesh, so unstructured grid point data
vg = vtk.vtkUnstructuredGrid()
lat = g.getLatitude().asma()
lon = g.getLongitude().asma()
pts = vtk.vtkPoints()
for i in range(len(lat)):
pts.InsertNextPoint(float(lon[i]),float(lat[i]),0.)
vg.SetPoints(pts)



xm, xM, ym, yM = lon.min(),lon.max(),lat.min(),lat.max()
wc = [gm.datawc_x1, gm.datawc_x2, gm.datawc_y1, gm.datawc_y2]
geo, geopts = project(pts, projection, getWrappedBounds(wc, [xm, xM, ym, yM], wrap))
out = {"vtk_backend_grid": vg,
"xm": xm,
"xM": xM,
"ym": ym,
"yM": yM,
"continents": continents,
"wrap": wrap,
"geo": geo,
"cellData": False,
"data": data1,
"data2": data2
}
return out

# Could still be meshfill with mesh data
# Ok probably should do a test for hgrid before sending data2
if isinstance(gm, meshfill.Gfm) and data2 is not None:
Expand Down
15 changes: 13 additions & 2 deletions vcs/vcsvtk/pipeline2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def plot(self, data1, data2, tmpl, grid, transform, **kargs):
self._updateScalarData()
self._min = self._data1.min()
self._max = self._data1.max()
self._scalarRange = vcs.minmax(self._data1)
self._scalarRange = (self._min, self._max)

# Create/update the VTK dataset.
plotBasedDualGrid = kargs.get('plot_based_dual_grid', True)
Expand Down Expand Up @@ -357,7 +357,18 @@ def _updateVTKDataSet(self, plotBasedDualGrid):
def _createPolyDataFilter(self):
"""This is only used when we use the grid stored in the file for all plots."""
self._vtkPolyDataFilter = vtk.vtkDataSetSurfaceFilter()
if self._hasCellData == self._needsCellData:
import ipdb
ipdb.set_trace()
if self._vtkDataSet.IsA("vtkUnstructuredGrid"):
print("UNSADFRRTVXDFGFDGDHRFDCGDRFDSGDSFGREDSCFDGRDFSG")
delny = vtk.vtkDelaunay2D()
profile = vtk.vtkPolyData()
profile.SetPoints(self._vtkDataSet.GetPoints())
delny.SetInputData(profile)
delny.SetTolerance(0.001)
self._vtkPolyDataFilter.SetInputConnection(delny.GetOutputPort())

elif self._hasCellData == self._needsCellData:
self._vtkPolyDataFilter.SetInputData(self._vtkDataSet)
elif self._hasCellData:
# use cells but needs points
Expand Down