H_masked = DENSITY.transform_h(H=H) grad = DENSITY.transform_grad(grad=grad) search = np.where(H < 0.1 * np.average(H)) Hmaxx, Hmaxy = search[1], search[0] Hmaxx = (lonmax - lonmin) / (nbins) * Hmaxx + lonmin Hmaxy = (latmax - latmin) / (nbins) * Hmaxy + latmin # Make sure all low density coordinates ARE within shapefile! low_density_coords = ps.paths_in_shape(np.column_stack((Hmaxx, Hmaxy))) #N_cluster_points = kmeans(low_density_coords, N)[0] density_coords = DENSITY.select_points() # make sure that your density coords are within the boundary shape density_coords = INPOLY.points_in(density_coords) #cluster = True if counter == 0: grad_ideal = 1e6 avg_ideal = 0 if grad_check1 < grad_ideal and avg_ideal < H_avg1: with open(u'ideal_coordinates.pickle', 'wb') as f: print "\nExporting new ideal coordinates." pickle.dump(coords, f, protocol=2) DENSITY.plot_field() #nodes=POLY_NODES)#SHAPE=UNIQUE_SHAPE) grad_ideal = grad_check1
INPOLY = InPoly(shape_path) # Create matplotlib Path object from imported shapefile outer_shape = UNIQUE_SHAPE.buffer(1.,resolution=1) inner_shape = UNIQUE_SHAPE.buffer(-8,resolution=1) outer_poly = INPOLY.poly_from_shape(shape=outer_shape) inner_poly = INPOLY.poly_from_shape(shape=inner_shape) many_points = INPOLY.rand_poly(poly=outer_poly, N=1e4) # Scale smaller shape to fit inside larger shape. #SMALL_SHAPE = scale(UNIQUE_SHAPE, xfact=0.3, yfact=0.3) #points_in_small_shape = INPOLY.rand_shape(shape=SMALL_SHAPE, IN=False) # Generate matplotlib Path object for the small scalled polygon #small_poly = INPOLY.node_poly(SHAPE.external_coords(shape=SMALL_SHAPE)) # Remove points that are outside the buffered_poly outer_poly_points = INPOLY.points_in(many_points, poly=outer_poly) # Remove points that are inside the small_poly inner_poly_points = np.asarray(INPOLY.points_in(outer_poly_points, poly=inner_poly, IN=False)) cluster_points = np.asarray(kmeans(inner_poly_points, 130)[0]) #plt.figure() #plt.scatter(inner_poly_points[:,0], inner_poly_points[:,1], c='b') #plt.scatter(cluster_points[:,0], cluster_points[:,1], c='orange', s=35) #plt.show()
H_masked = DENSITY.transform_h(H=H) grad = DENSITY.transform_grad(grad=grad) search = np.where(H < 0.1 * np.average(H)) Hmaxx, Hmaxy = search[1], search[0] Hmaxx = (lonmax - lonmin) / (nbins) * Hmaxx + lonmin Hmaxy = (latmax - latmin) / (nbins) * Hmaxy + latmin # Make sure all low density coordinates ARE within shapefile! low_density_coords = ps.paths_in_shape(np.column_stack((Hmaxx, Hmaxy))) # N_cluster_points = kmeans(low_density_coords, N)[0] density_coords = DENSITY.select_points() # make sure that your density coords are within the boundary shape density_coords = INPOLY.points_in(density_coords) # cluster = True if counter == 0: grad_ideal = 1e6 avg_ideal = 0 if grad_check1 < grad_ideal and avg_ideal < H_avg1: with open(u"ideal_coordinates.pickle", "wb") as f: print "\nExporting new ideal coordinates." pickle.dump(coords, f, protocol=2) DENSITY.plot_field() # nodes=POLY_NODES)#SHAPE=UNIQUE_SHAPE) grad_ideal = grad_check1
poly = INPOLY.poly_from_shape(shape=UNIQUE_SHAPE) many_points = INPOLY.rand_poly(poly=poly, N=1e5) # Scale smaller shape to fit inside larger shape. #SMALL_SHAPE = scale(UNIQUE_SHAPE, xfact=0.3, yfact=0.3) #points_in_small_shape = INPOLY.rand_shape(shape=SMALL_SHAPE, IN=False) # Generate matplotlib Path object for the small scalled polygon #small_poly = INPOLY.node_poly(SHAPE.external_coords(shape=SMALL_SHAPE)) # Remove points that are outside the buffered_poly #outer_poly_points = INPOLY.points_in(many_points, poly=outer_poly) # Remove points that are inside the small_poly poly_points = np.asarray(INPOLY.points_in(many_points, poly=poly, IN=True)) cluster_points = np.asarray(kmeans(poly_points, n_stations)[0]) #plt.figure() #plt.scatter(poly_points[:,0], poly_points[:,1], c='b') #plt.scatter(cluster_points[:,0], cluster_points[:,1], c='orange', s=35) #plt.show() #----------------------------------------------------------------------------- # GENERATE SECOND SET OF VARIABLES AND STATES #----------------------------------------------------------------------------- ideal_path = 'ideal_coordinates.pickle' #if no paths have been done before, start afresh!
#inner_poly = INPOLY.poly_from_shape(shape=inner_shape) poly = INPOLY.poly_from_shape(shape=UNIQUE_SHAPE) many_points = INPOLY.rand_poly(poly=poly, N=1e5) # Scale smaller shape to fit inside larger shape. #SMALL_SHAPE = scale(UNIQUE_SHAPE, xfact=0.3, yfact=0.3) #points_in_small_shape = INPOLY.rand_shape(shape=SMALL_SHAPE, IN=False) # Generate matplotlib Path object for the small scalled polygon #small_poly = INPOLY.node_poly(SHAPE.external_coords(shape=SMALL_SHAPE)) # Remove points that are outside the buffered_poly #outer_poly_points = INPOLY.points_in(many_points, poly=outer_poly) # Remove points that are inside the small_poly poly_points = np.asarray(INPOLY.points_in(many_points, poly=poly, IN=True)) cluster_points = np.asarray(kmeans(poly_points, n_stations)[0]) #plt.figure() #plt.scatter(poly_points[:,0], poly_points[:,1], c='b') #plt.scatter(cluster_points[:,0], cluster_points[:,1], c='orange', s=35) #plt.show() #----------------------------------------------------------------------------- # GENERATE SECOND SET OF VARIABLES AND STATES #----------------------------------------------------------------------------- ideal_path = 'ideal_coordinates.pickle' #if no paths have been done before, start afresh! #if dataless: # coords = Dataless.locs_from_dataless(dataless_path)