def merge_tube_curvature_arrays(tube_graph_a, tube_graph_b, graph_interpolator, resolution): boundary_arc_lengths_a = tube_graph_a.arc_lengths_partitions[-1] boundary_arc_lengths_b = tube_graph_b.arc_lengths_partitions[0] boundary_a_length = boundary_arc_lengths_a.shape[0] boundary_b_length = boundary_arc_lengths_b.shape[0] boundary_arc_lengths = np.concatenate((boundary_arc_lengths_a[:-1], boundary_arc_lengths_b)) boundary_tube_elevations_a = tube_graph_a.tube_elevations_partitions[-1] boundary_tube_elevations_b = tube_graph_b.tube_elevations_partitions[0] boundary_tube_elevations = np.concatenate( (boundary_tube_elevations_a[:-1], boundary_tube_elevations_b)) boundary_points = zip(boundary_arc_lengths, boundary_tube_elevations) _, boundary_tube_curvature_array = graph_interpolator(boundary_points, resolution) boundary_tube_curvature_array_a = boundary_tube_curvature_array[ :boundary_a_length] boundary_tube_curvature_array_b = boundary_tube_curvature_array[ -boundary_b_length:] graph_a_tube_curvature_array = tube_graph_a.tube_curvature_array graph_b_tube_curvature_array = tube_graph_b.tube_curvature_array if (graph_a_tube_curvature_array == None and graph_b_tube_curvature_array == None): merged_curvature_array = boundary_tube_curvature_array elif (graph_a_tube_curvature_array != None and graph_b_tube_curvature_array != None): graph_a_tube_curvature_array[-boundary_a_length:] = \ np.maximum(graph_a_tube_curvature_array[-boundary_a_length:], boundary_tube_curvature_array_a) graph_b_tube_curvature_array[:boundary_b_length] = \ np.maximum(graph_b_tube_curvature_array[:boundary_b_length], boundary_tube_curvature_array_b) merged_curvature_array = util.glue_array_pair( graph_a_tube_curvature_array, graph_b_tube_curvature_array) elif (graph_a_tube_curvature_array != None and graph_b_tube_curvature_array == None): graph_a_tube_curvature_array[-boundary_a_length:] = \ np.maximum(graph_a_tube_curvature_array[-boundary_a_length:], boundary_tube_curvature_array_a) merged_curvature_array = util.glue_array_pair( graph_a_tube_curvature_array, boundary_tube_curvature_array_b) elif (graph_a_tube_curvature_array == None and graph_b_tube_curvature_array != None): graph_b_tube_curvature_array[:boundary_b_length] = \ np.maximum(graph_b_tube_curvature_array[:boundary_b_length], boundary_tube_curvature_array_b) merged_curvature_array = util.glue_array_pair( boundary_tube_curvature_array_a, graph_b_tube_curvature_array) return merged_curvature_array
def merge_two_spatial_graphs(cls, spatial_graph_a, spatial_graph_b, graph_interpolator, resolution): abstract_graph_a = spatial_graph_a.to_abstract_graph() abstract_graph_b = spatial_graph_b.to_abstract_graph() merged_abstract_graph = \ abstract_graphs.AbstractGraph.merge_abstract_graphs( abstract_graph_a, abstract_graph_b) land_cost = spatial_graph_a.land_cost + spatial_graph_b.land_cost pylon_cost = spatial_graph_a.pylon_cost + spatial_graph_b.pylon_cost tube_cost = spatial_graph_a.tube_cost + spatial_graph_b.tube_cost tunneling_cost = (spatial_graph_a.tunneling_cost + spatial_graph_b.tunneling_cost) latlngs = util.glue_list_pair(spatial_graph_a.latlngs, spatial_graph_b.latlngs) elevation_profile = elevation.ElevationProfile.merge_elevation_profiles( spatial_graph_a.elevation_profile, spatial_graph_b.elevation_profile) tube_curvature_array = util.glue_array_pair( spatial_graph_a.tube_curvature_array, spatial_graph_b.tube_curvature_array) spatial_curvature_array = SpatialGraph.merge_spatial_curvature_arrays( spatial_graph_a, spatial_graph_b, graph_interpolator, resolution) merged_spatial_graph = cls(merged_abstract_graph, land_cost, pylon_cost, tube_cost, tunneling_cost, latlngs, elevation_profile, spatial_curvature_array, tube_curvature_array) return merged_spatial_graph
def merge_spatial_curvature_arrays(spatial_graph_a, spatial_graph_b, graph_interpolator, resolution): boundary_geospatials_a = \ spatial_graph_a.elevation_profile.geospatials_partitions[-1] boundary_geospatials_b = \ spatial_graph_b.elevation_profile.geospatials_partitions[0] boundary_a_length = len(boundary_geospatials_a) boundary_b_length = len(boundary_geospatials_b) merged_boundary_geospatials = util.glue_array_pair( boundary_geospatials_a, boundary_geospatials_b) interpolated_boundary_geospatials, boundary_spatial_curvature_array = \ graph_interpolator(merged_boundary_geospatials) spatial_curvature_array_a = spatial_graph_a.spatial_curvature_array spatial_curvature_array_b = spatial_graph_b.spatial_curvature_array boundary_curvatures_a = boundary_spatial_curvature_array[: boundary_a_length] boundary_curvatures_b = boundary_spatial_curvature_array[ -boundary_b_length:] if (spatial_curvature_array_a == None and spatial_curvature_array_b == None): merged_curvature_array = boundary_spatial_curvature_array elif (spatial_curvature_array_a != None and spatial_curvature_array_b != None): spatial_curvature_array_a[-boundary_a_length:] = \ np.maximum(spatial_curvature_array_a[-boundary_a_length:], boundary_curvatures_a) spatial_curvature_array_b[:boundary_b_length] = \ np.maximum(spatial_curvature_array_b[:boundary_b_length], boundary_curvatures_b) merged_curvature_array = util.glue_array_pair( spatial_curvature_array_a, spatial_curvature_array_b) elif (spatial_curvature_array_a != None and spatial_curvature_array_b == None): merged_curvature_array = util.glue_array_pair( spatial_curvature_array_a, boundary_curvatures_b) elif (spatial_curvature_array_a == None and spatial_curvature_array_b != None): merged_curvature_array = util.glue_array_pair( boundary_curvatures_a, spatial_curvature_array_b) return merged_curvature_array
def merge_elevation_profiles(cls, elevation_profile_a, elevation_profile_b): if (elevation_profile_a.geospatials_partitions != None and elevation_profile_b.geospatials_partitions != None): merged_geospatials_partitions = ( elevation_profile_a.geospatials_partitions + elevation_profile_b.geospatials_partitions) else: merged_geospatials_partitions = None merged_geospatials = np.vstack((elevation_profile_a.geospatials, elevation_profile_b.geospatials[1:])) merged_latlngs = np.vstack((elevation_profile_a.latlngs, elevation_profile_b.latlngs[1:])) merged_land_elevations = util.glue_array_pair( elevation_profile_a.land_elevations, elevation_profile_b.land_elevations) merged_arc_lengths = util.shift_and_glue_array_pair( elevation_profile_a.arc_lengths, elevation_profile_b.arc_lengths) data = cls(merged_geospatials, merged_latlngs, merged_arc_lengths, land_elevations=merged_land_elevations, geospatials_partitions=merged_geospatials_partitions) return data