def get_buildings_by_address_nodes(self): out = C() for i in list(self.nodes.values()): #print(i.tags) if "addr:housenumber" in i.tags: out.coords.append(list(i.geom.coords)[0]) return out
def get_buildings_data_obj(self): out = C() for i in list(self.ways.values()): #print(i.tags) if "building" in i.tags and i.tags["building"] == "yes": out.coords.append(list(i.geom.centroid.coords)[0]) #print("a building!") return out
def gauss_circle_in_other(outer_radius,p_in_central,p_in_outer,sigma_in,sigma_out): data_obj = C() data_obj.c_number = 2 data_obj.coords = data_obj.coords + gauss_blob((0.0,0.0),sigma_in,p_in_central) data_obj.labels = data_obj.labels + [0]*p_in_central data_obj.coords = data_obj.coords + gauss_arc((0.0,0.0),outer_radius,0.0,2*math.pi,sigma_out,p_in_outer) data_obj.labels = data_obj.labels + [1]*p_in_outer return data_obj
def multiple_weighted_gauss_blobs(field_size,n_in_blob,n_of_blobs,sigmas): data_obj =C() data_obj.c_number = n_of_blobs for i in range(n_of_blobs): data_obj.c_positions.append([random.uniform(0.0,field_size) for i in range(2)]) for num,val in enumerate(data_obj.c_positions): gb = weighted_gauss_blob(val,sigmas,n_in_blob) data_obj.coords = data_obj.coords + gb data_obj.labels = data_obj.labels + [num for j in range(n_in_blob)] return data_obj
def croissants(number_in_c,radius_distance,sigma): data_obj = C() data_obj.c_number = 2 data_obj.coords = data_obj.coords + gauss_arc((0.0,0.0),radius_distance,0.0,1*math.pi,sigma,number_in_c) data_obj.labels = data_obj.labels + [0]*number_in_c data_obj.c_positions.append((radius_distance,0.0)) data_obj.coords = data_obj.coords + gauss_arc((0.0,radius_distance),radius_distance,math.pi,2*math.pi,sigma,number_in_c) data_obj.labels = data_obj.labels + [1]*number_in_c data_obj.c_positions.append((-radius_distance,radius_distance)) return data_obj
def _balanced_centers(field_size,dist_function,dist_function_params,num_of_clusters): data_obj = C() data_obj.c_number = num_of_clusters counter = 0 passes = False while not passes: print("trying") data_obj.c_positions = [linear_square_point([field_size/2.0 for x in [0,1]],field_size)] while (not passes) and counter < 100*data_obj.c_number: newobj = linear_square_point([field_size/2.0 for x in [0,1]],field_size) temp_passes = True for i in data_obj.c_positions: if not dist_function(i,newobj,dist_function_params) and geom.distance(i,newobj) > 0 : temp_passes = False break if temp_passes: data_obj.c_positions.append(newobj) counter += 1 passes = (len(data_obj.c_positions)==data_obj.c_number) return data_obj
from copy import deepcopy from py_osm_cluster.eval import comparative as Comp import py_osm_cluster.visualisation.visualisation as visu import matplotlib.pyplot as plt def save(data_obj, name): visu.plot_coords_label_color(data_obj) plt.xlim((-0.5, 2.5)) plt.ylim((-0.5, 2.5)) plt.savefig(name + ".png") data_obj = C() for i in range(3): for j in range(3): data_obj.coords.append((float(i), float(j))) data_obj.labels.append(i) data_obj.c_number = 3 print("data_obj") print(Comp.scikit_all_scores_dict(data_obj, data_obj)) save(data_obj, "data_obj") one_cluster = deepcopy(data_obj) one_cluster.labels = [0, 0, 0, 0, 0, 0, 0, 0, 0] print("one_cluster") print(Comp.scikit_all_scores_dict(one_cluster, data_obj)) save(one_cluster, "one_cluster")