diff --git a/vcs/Canvas.py b/vcs/Canvas.py index 4af549363..3c9505891 100644 --- a/vcs/Canvas.py +++ b/vcs/Canvas.py @@ -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) @@ -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' % diff --git a/vcs/VTKPlots.py b/vcs/VTKPlots.py index fa5c55d30..00711bb99 100644 --- a/vcs/VTKPlots.py +++ b/vcs/VTKPlots.py @@ -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( diff --git a/vcs/vcs2vtk.py b/vcs/vcs2vtk.py index 287057e71..4a672f271 100644 --- a/vcs/vcs2vtk.py +++ b/vcs/vcs2vtk.py @@ -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: diff --git a/vcs/vcsvtk/pipeline2d.py b/vcs/vcsvtk/pipeline2d.py index 54f1a9ed1..37d06dc74 100644 --- a/vcs/vcsvtk/pipeline2d.py +++ b/vcs/vcsvtk/pipeline2d.py @@ -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) @@ -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