def whittle(cloud, polygons): """ Parameters ---------- cloud : ndarray Mx3 array containing the point cloud. Columns are x, y, and z Should be centered about the origin polygons : list of ndarray Each array is Mx2 and represents a series of x, y points defining a polygon. Returns ------- cloud : ndarray Mx3 array representing the points from the original cloud that are contained inside the 3d volume defined by the series of polygons """ # Divide half the circle evenly among the polygons angle = np.pi / len(polygons) rotation_matrix = get_rotation_matrix(angle) for polygon in polygons: # Find and remove the points that fall outside the current projection mask = mlab.inside_poly(cloud[:, 1:], polygon) cloud = cloud[mask] 1/0 # Rotate the cloud and go to the next projection cloud = cloud.dot(rotation_matrix) return cloud
def polygon_average(self, pvert, bluered='blue'): """Averages within a polygon""" self.show_lines([ numpy.array(pvert[0]).T, ], edgecolor=bluered, linewidth=2) avgfigure = mpl.figure() avgax = avgfigure.add_subplot(111) for i, hdu in enumerate(self.extra_hdus): points = self._get_points(hdu) vel = getaxes(hdu.header, 1) #mask = points_inside_poly(points, pvert[0]) mask = inside_poly(points, pvert[0]) navg = len(numpy.where(mask)[0]) hdunew = hdu.data.copy() ny, nx, nv = hdunew.shape hdunew = hdunew.reshape((ny * nx), nv) poly_avg = hdunew[mask, :].mean(axis=0) avgax.plot(vel, poly_avg, linestyle='steps-mid', label='%s %s polygon' % (self._get_hdu_title(i), bluered)) avgax.set_title("Average made from %s qualifying points" % navg) avgax.legend(loc='best') avgfigure.canvas.draw() self.refresh()
def getdataInRect(self): # Get the data from the Graphicsitem self.getDataItem() x = self.dataxy[0] y = self.dataxy[1] # Rect Edges Xbl = (self.Coords[0], self.Coords[1]) # bottom left Xbr = (self.Coords[2], self.Coords[1]) # bottom right Xtr = (self.Coords[2], self.Coords[3]) # top right Xtl = (self.Coords[0], self.Coords[3]) # top left #Make a list of [(x0,y0),(x1,y1) ...] self.xy = list() for i in x: tmp = (x[i], y[i]) self.xy.append(tmp) # exemple = inside_poly([(x0,y0),(x1,y1),...],[Xbl, Xbr, Xtr, Xtl]) self.insideIndex = inside_poly(self.xy, [Xbl, Xbr, Xtr, Xtl])
def getIntensity(self, lat, long): # TODO: Test long += 5.0 lat += 10.0 wind_kt = 0.0 # wind speed in knots for i in xrange(self.data.numRecords): if len(inside_poly([[long, lat]], self.data.shape(i).points)) > 0: # Find the wind corresponding to the bus latutude and longitude wind_kt = max(wind_kt, float(self.data.record(i)[1])) # Converting from knott to mph (1 kt = 1.15077945 miles per hour) wind_mph = wind_kt * 1.15077945 # Converting from mph wind to mph gust (1 mph wind = 1.3 mph gust) gust_mph = wind_mph * 1.3 return gust_mph
def getdataInRect(self): # Get the data from the Graphicsitem self.getDataItem() x = self.dataxy[0] y = self.dataxy[1] # Rect Edges Xbl = (self.Coords[0], self.Coords[1]) # bottom left Xbr = (self.Coords[2], self.Coords[1]) # bottom right Xtr = (self.Coords[2], self.Coords[3]) # top right Xtl = (self.Coords[0], self.Coords[3]) # top left #Make a list of [(x0,y0),(x1,y1) ...] self.xy = list() for i in range(len(x)): tmp = (x[i], y[i]) self.xy.append(tmp) # matplotlib inside_poly function gets # datapoints that are within polygon self.insideIndex = inside_poly(self.xy, [Xbl, Xbr, Xtr, Xtl])
def checkPointsInPolygon(polygon_list, points_list): inside = mlab.inside_poly(points_list, polygon_list); return inside;
def checkPointsInPolygon(polygon_list, points_list): inside = mlab.inside_poly(points_list, polygon_list) return inside