def areaxy(self, lowerbound=-np.inf, upperbound=np.inf, spacing=0.1):
mask = (self.coord[:,2] > lowerbound) & (self.coord[:,2] < upperbound)
points = self.coord[mask, :2]
# The magic number factor 1.1 is not critical at all
# Just a number to set a margin to the bounding box and
# have all points fall within the boundaries
bbmin, bbmax = 1.1*points.min(axis=0), 1.1*points.max(axis=0)
size = bbmax - bbmin
cells = (size / spacing + 0.5).astype('int')
# Grid points over bounding box with specified spacing
grid = np.mgrid[bbmin[0]:bbmax[0]:(cells[0]*1j),
bbmin[1]:bbmax[1]:(cells[1]*1j)].reshape((2,-1)).T
# Occupied cells is approximately equal to grid points within
# gridspacing distance of points
occupied = occupancy(grid, points, spacing)
# The occupied area follows from the fraction of occupied
# cells times the area spanned by the bounding box
return size[0]*size[1]*sum(occupied > 0)/occupied.size
评论列表
文章目录