def _sort(self, expfact):
# keep unique vertices only by creating a set and sort first on x then on y coordinate
# using rather slow python sort but couldn;t wrap my head around np.lexsort
verts = sorted(list({ tuple(t) for t in self.center[::] }))
x = set(c[0] for c in verts)
y = set(c[1] for c in verts)
nx = len(x)
ny = len(y)
self.minx = min(x)
self.maxx = max(x)
self.miny = min(y)
self.maxy = max(y)
xscale = (self.maxx-self.minx)/(nx-1)
yscale = (self.maxy-self.miny)/(ny-1)
# note: a purely flat plane cannot be scaled
if (yscale != 0.0) and (abs(xscale/yscale) - 1.0 > 1e-3):
raise ValueError("Mesh spacing not square %d x %d %.4f x %4.f"%(nx,ny,xscale,yscale))
self.zscale = 1.0
if abs(yscale) > 1e-6 :
self.zscale = 1.0/yscale
# keep just the z-values and null any ofsset
# we might catch a reshape error that will occur if nx*ny != # of vertices (if we are not dealing with a heightfield but with a mesh with duplicate x,y coords, like an axis aligned cube
self.center = np.array([c[2] for c in verts],dtype=np.single).reshape(nx,ny)
self.center = (self.center-np.amin(self.center))*self.zscale
if self.rainmap is not None:
rmscale = np.max(self.center)
self.rainmap = expfact + (1-expfact)*(self.center/rmscale)
评论列表
文章目录