当前位置: 首页>>代码示例>>Python>>正文


Python Delaunay.area方法代码示例

本文整理汇总了Python中scipy.spatial.Delaunay.area方法的典型用法代码示例。如果您正苦于以下问题:Python Delaunay.area方法的具体用法?Python Delaunay.area怎么用?Python Delaunay.area使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.spatial.Delaunay的用法示例。


在下文中一共展示了Delaunay.area方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DTFE

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import area [as 别名]
 def DTFE(self):
   """Because it's so awesomely optimized now, calculate the area at all particles."""
   from scipy.spatial import Delaunay
   self.subsetTmp([(0,None)])
   tmp=self.fetch(['x','y'])
   d=Delaunay(tmp)
   tmp=np.zeros(self.n)
   flat=d.vertices.flatten()
   widgets = [progressbar.Percentage(), progressbar.Bar(),' ',progressbar.FormatLabel('Time elapsed: %(elapsed)s'),' ',progressbar.ETA()]
   pbar = progressbar.ProgressBar(widgets=widgets, maxval=self.n).start()
   #Replace each point in d.vertices with its (x,y) coordinate in a flat way
   d.vertPts=np.reshape(d.points[flat].flatten(),(d.vertices.shape[0],6))
   #Calculate the area of all the triangles at once...
   d.area=np.abs((d.vertPts[:,0]-d.vertPts[:,4])*(d.vertPts[:,3]-d.vertPts[:,1])-(d.vertPts[:,0]-d.vertPts[:,2])*(d.vertPts[:,5]-d.vertPts[:,1]))/2.
   #Basic idea is that each triangle is represented 3 times, with the coordinates permuted.
   #The resulting big array can be sorted by its first column and we can efficiently pull out 
   fast=np.column_stack([d.vertices,d.area])
   fast2=deepcopy(fast)
   #Permute cols
   fast2[:,0]=fast[:,1]
   fast2[:,1]=fast[:,2]
   fast2[:,2]=fast[:,0]
   fast3=deepcopy(fast)
   fast3[:,0]=fast2[:,1]
   fast3[:,1]=fast2[:,2]
   fast3[:,2]=fast2[:,0]
   #Stack them all up
   bigfast=np.row_stack([fast,fast2,fast3])
   #Sort
   bigfast=bigfast[np.argsort(bigfast[:,0]),]
   counts=np.bincount(np.intp(bigfast[:,0]))
   boundaries=np.append(0,np.cumsum(counts))
   for i in xrange(self.n):
     pbar.update(i)
     #Fetch the area of each cell...
     tmp[i]=(3.*self.m)/np.sum(bigfast[boundaries[i]:boundaries[i+1],3])
   self.DTCD_=tmp
   self.subsetRestore()
开发者ID:jakebarnwell,项目名称:PythonGenerator,代码行数:40,代码来源:data.py


注:本文中的scipy.spatial.Delaunay.area方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。