def haus_dist(net1, net2, kx, ky, x0=0, y0=0): # Get the limits and data LEFT, RIGHT, BOTTOM, TOP = get_limits(net1) gridlist = partitions((LEFT, RIGHT, BOTTOM, TOP), kx, ky, x0=x0, y0=y0) edges1 = [net1.edges[e]['geometry'] for e in net1.edges()] edges2 = [net2.edges[e]['geometry'] for e in net2.edges()] # Compute Hausdorff distance C = compute_hausdorff(gridlist, edges1, edges2) C_vals = np.array([C[bound] for bound in gridlist]) C_masked = np.ma.array(C_vals, mask=np.isnan(C_vals)) # Plot the deviation DPI = 72 fig = plt.figure(figsize=(700 / DPI, 500 / DPI), dpi=DPI) ax = plt.subplot() plot_network_pair(ax, net1, net2) plot_deviation(ax, gridlist, C_masked, colormap=cm.Greens) add_colorbar(fig, ax, colormap=cm.Greens, vmin=0.0, vmax=max(C_masked), devname="Hausdorff distance") fig.savefig("{}{}.png".format( figpath, str(sub) + '-haus-comp-' + str(kx) + '-' + str(ky) + suffix), bbox_inches='tight') return C
leg_data = [Line2D([0], [0], color=c_actual, markerfacecolor=c_actual, marker='o',markersize=40, label='Actual distribution network'), Line2D([0], [0], color=c_synth, markerfacecolor=c_synth, marker='o',markersize=40, label='Synthetic distribution network'), Patch(facecolor='white', edgecolor='black', hatch="./", label='Grid cells with no actual network data')] #%% Hausdorff distance between networks kx = 7 ky = 7 x0 = 0.05 y0 = 0 LEFT,RIGHT,BOTTOM,TOP = get_limits(area_data) gridlist = partitions((LEFT,RIGHT,BOTTOM,TOP),kx,ky,x0=x0,y0=y0) act_edges,syn_edges = get_edges(area_data) C = compute_hausdorff(gridlist,act_edges,syn_edges) C_vals = np.array([C[bound] for bound in gridlist]) C_masked = np.ma.array(C_vals, mask=np.isnan(C_vals)) # Plot the Hausdorff deviation fig = plt.figure(figsize=(30,25)) ax = fig.add_subplot(1,1,1) for area in area_data: plot_gdf(ax,area_data[area]['df_lines'],area_data[area]['df_buses'], c_actual) plot_gdf(ax,area_data[area]['df_synth'],area_data[area]['df_cords'], c_synth)
return def get_polygon(boundary): """Gets the vertices for the boundary polygon""" vert1 = [boundary.west_edge, boundary.north_edge] vert2 = [boundary.east_edge, boundary.north_edge] vert3 = [boundary.east_edge, boundary.south_edge] vert4 = [boundary.west_edge, boundary.south_edge] return np.array([vert1, vert2, vert3, vert4]) cords = np.array([list(synth_net.nodes[n]['cord']) for n in synth_net]) LEFT, BOTTOM = np.min(cords, 0) RIGHT, TOP = np.max(cords, 0) gridlist = partitions((LEFT, RIGHT, BOTTOM, TOP), 5, 5) DPI = 72 fig = plt.figure(figsize=(700 / DPI, 500 / DPI), dpi=DPI) ax = plt.subplot() ax.set_xlim(LEFT, RIGHT) ax.set_ylim(BOTTOM, TOP) # Get the boxes for the valid comparisons verts_valid = [get_polygon(bound) for i, bound in enumerate(gridlist)] c = PolyCollection(verts_valid, edgecolor='black', facecolor='white') ax.add_collection(c) i = 4 suffix = str(sub) + '-' + str(i) tree = nx.read_gpickle(outpath + str(sub) + '-ensemble-' + str(i) + '.gpickle')