Neighbors

find_neighbors(locations, radius, n_neighbor, bits, minx=-180, maxx=180, miny=-90, maxy=90, grid='longlat', search_ids=None, search_target_ids=None)[source]

Finds neighbouring agents for given agents.

Parameters:
  • locations (ndarray) – Either a 2-dimensional array of x and y locations for agents, or a 1-dimensional array of geohashes.

  • radius (Union[float, int]) – Search radius. Specified in meters for grid=longlat, specified in map units for orthogonal grids.

  • n_neighbors – Maxiumum number of neighbors to find for each agent.

  • bits (int) – Number of bits to use for geohashes.

  • minx (Union[float, int]) – Minimum x-value of the entire relevant space.

  • maxx (Union[float, int]) – Maximum x-value of the entire relevant space.

  • miny (Union[float, int]) – Minimum y-value of the entire relevant space.

  • miny – Maximum y-value of the entire relevant space.

  • grid (str) – Type of grid. Can be ‘longlat’ or ‘orthogonal’.

  • search_ids (Optional[ndarray]) – Only search for neighbors of agent with search_ids.

  • search_target_ids (Optional[ndarray]) – Only search neighbors with search_target_ids.

Returns:

neighbors – 2-dimensional NumPy array. The first dimension represents the results for each of the agents, the second dimension the indices of the neighbors for each of those agents. -1 represents no neighbor (possible only if less than the requested number of neighbors are available in the search radius.)

Return type:

ndarray

process_hashcodes(location_hashcodes, search_ids, search_target_ids, dtype)[source]
Parameters:
  • location_hashcodes (ndarray) – Geohashes of all agents.

  • search_ids (Optional[ndarray]) – Ids of the agents to find neighbors for. If None, search all agents.

  • dtype (type) – Datatype to use to hold indices.

Returns:
  • search_target_unique_hashcodes – Array of unique geohashes of agents.

  • search_source_unique_hashcodes – Array of unique geohashes of agents to find neighbors for.

  • search_target_hashcodes_sort_indices – Indices that can be used to sort the location_hashcodes.

  • cumulative_count_per_search_hashcode – Cumulative count of the unique search hashcodes.

  • map_search_source_to_target

  • search_source_hashcodes_sort_indices – Indices that can be used to sort the location_hashcodes.

Return type:

tuple[ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray]