Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def apply_points_cluster_mam_on_gdf_multiprocess(
- network,
- network_element_dict,
- ign_parcel,
- tigre_parcel,
- size_of_range=config.MAM_GRID_SIZE,
- step_of_range=config.MAM_GRID_STEP,
- nb_evals=config.MAM_NB_EVALS,
- how=config.MAM_OBJECTIVE_METHOD,
- max_distance_for_clusters=config.MAM_MAX_DIST_CLUST,
- point_buffer=config.MAM_POINT_BUFFER,
- save_translation_file=False,
- parcel_buffer=config.MERGE_PARCEL_BUFFER,
- mam_buffer_aug_rate=config.MAM_BUFFER_AUG_RATE,
- mam_aug_buffer_min_threshold=config.MAM_PARCEL_AREA_THRESOLD,
- ):
- """ Apply the points cluster mam on a whole gdf with multiprocess
- Arguments:
- network {GeoDataFrame} -- network gdf to move
- chambers {GeoDataFrame} -- chambers gdf to move
- size_of_range {float} -- size of the grid in each direction. The length of the
- grid = size_of_range*2
- step_of_range {float} -- step for moving on the grid.
- nb_evals {int} -- number of evaluations for hyperopt
- how {string} -- method used to evaluate the best move how. sum if how == 'sum',
- ratio if anything else
- save_translation_file {boolean} -- if True, will save the and X,Y delta for each
- point clustered
- parcel_buffer - in meter : the buffer used to merge parcels that are close together
- Returns:
- moved_gdf {GeoDataFrame} -- moved GeoDataFrame
- """
- to_move_gdf = network.copy()
- to_move_gdf = to_move_gdf[to_move_gdf.id.isin([882714,
- 4766449,
- 4766450,
- 4766451,
- 810344
- ])]
- assert len(to_move_gdf) > 0
- to_move_gdf = explode_multilines(to_move_gdf)
- logger.info("Create list of unique points and their affected clusters")
- clustered_points = create_unique_points_clusters(to_move_gdf, max_distance_for_clusters)
- nb_clusters = len(clustered_points.cluster.unique())
- nb_points = len(clustered_points)
- stats_nb_points = {"nb_clusters": nb_clusters, "nb_points": nb_points}
- logger.info("There are {nb_clusters} clusters, from {nb_points} points".format(**stats_nb_points))
- unary_parcel = ign_parcel.buffer(parcel_buffer).unary_union
- logger.info("Launch multi-process mam for network")
- executor = concurrent.futures.ProcessPoolExecutor(config.MAM_MULTIPROCESS_NB_EXEC)
- futures = [
- executor.submit(
- apply_points_cluster_mam,
- ign_parcel,
- tigre_parcel,
- unary_parcel,
- nb_cluster,
- clustered_points,
- size_of_range,
- step_of_range,
- nb_evals,
- how,
- point_buffer,
- mam_buffer_aug_rate,
- mam_aug_buffer_min_threshold,
- )
- for nb_cluster in range(nb_clusters)
- ]
- concurrent.futures.wait(futures),
- futures_df = _get_futures_df(futures, save_translation_file=save_translation_file)
- # we check that all the clusters has been computed
- assert len(futures_df.index) == nb_clusters
- logger.info("Moving network elements...")
- assignement_element_points_dict = {}
- rejection_element_dict = {}
- rejected_element_nearest_neighbor_dict = {}
- for key, value in network_element_dict.items():
- assignement_element_points, rejection_element_list = assign_points_to_cluster(
- value, clustered_points
- )
- assignement_element_points_dict[key] = assignement_element_points
- rejection_element_dict[key] = rejection_element_list
- rejected_element_nearest_neighbor_dict[key] = handle_rejected_cases(
- rejection_element_list, clustered_points
- )
- moved_network = _move_network(
- to_move_gdf, clustered_points, futures_df, nb_clusters,
- )
- moved_network_dict = {}
- for key in assignement_element_points_dict.keys():
- moved_network_dict[key] = _move_network_element(
- network_element_dict[key],
- assignement_element_points_dict[key],
- futures_df,
- nb_clusters,
- )
- return rejection_element_dict, moved_network, moved_network_dict, stats_nb_points
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement