Nearest Allocation
Code for allocating renewable generation resources to NY Grid buses.
The nearest neighbor algorithm is originally from:
https://autogis-site.readthedocs.io/en/2019/notebooks/L3/nearest-neighbor-faster.html
- nygrid.allocate.get_nearest(src_points: array, candidates: array, k_neighbors: int = 1, metric: str = 'minkowski', leaf_size: int = 20) Tuple[array, array][source]
Find nearest neighbors for all source points from a set of candidate points
- Parameters:
src_points (np.ndarray) – A numpy array of shape (n, 2) representing the source points.
candidates (np.ndarray) – A numpy array of shape (m, 2) representing the candidate points.
k_neighbors (int) – Number of nearest neighbors to return.
metric (str) – The distance metric to use. Default is ‘minkowski’.
leaf_size (int) – Leaf size passed to BallTree. Default is 20.
- Returns:
The indices of the k-nearest neighbors in the candidates array and the corresponding distances.
- Return type:
Tuple[np.ndarray, np.ndarray]
- nygrid.allocate.nearest_neighbor_lat_lon(left_gdf: GeoDataFrame, right_gdf: GeoDataFrame, return_dist: bool = False, leaf_size: int = 20) Dict | Tuple[source]
For each point in left_gdf, find closest point in right GeoDataFrame and return them.
NOTICE: Assumes that the input Points are in WGS84 projection (lat/lon).
- Parameters:
left_gdf (gpd.GeoDataFrame) – A GeoDataFrame containing the origin points.
right_gdf (gpd.GeoDataFrame) – A GeoDataFrame containing the candidate destination points.
return_dist (bool) – If True, the distance between the nearest neighbors is returned.
leaf_size (int) – Leaf size passed to BallTree. Default is 20.
- Returns:
closest_points – A dictionary or tuple containing the closest points and distances (if requested).
- Return type:
Union[Dict, Tuple]
- nygrid.allocate.nearest_neighbor_meters(left_gdf: GeoDataFrame, right_gdf: GeoDataFrame, return_dist: bool = False, leaf_size: int = 20) Dict | Tuple[source]
For each point in left_gdf, find the closest point in right GeoDataFrame and return them.
NOTICE: Assumes that the input Points are in WGS84 projection (meters).
- Parameters:
left_gdf (gpd.GeoDataFrame) – A GeoDataFrame containing the origin points.
right_gdf (gpd.GeoDataFrame) – A GeoDataFrame containing the candidate destination points.
return_dist (bool) – If True, the distance between the nearest neighbors is returned.
leaf_size (int) – Leaf size passed to BallTree. Default is 20.
- Returns:
closest_points – A dictionary or tuple containing the closest points and distances (if requested).
- Return type:
Union[Dict, Tuple]