iduedu.aggregate_objects

iduedu.aggregate_objects(urban_graph, cutoff, *, gdf_origins=None, gdf_objects=None, origins_nodes=None, object_nodes=None, columns=None, weight='time_min', decay=None, beta=None, direction='from', graph_node_column='graph_node_id', max_workers=None)[source]

Count objects and sum their values within a travel cost of every origin.

With decay every object counts with a weight that falls with its travel cost d: "linear" is 1 - d / cutoff, "exp" is exp(-beta * d) and "inverse" is 1 / d (objects at cost 0 are left out). Sums and counts are then weighted, and means are weighted means.

Parameters:
  • urban_graph (UrbanGraph) – Graph to search.

  • cutoff (Union[float, Iterable[float]]) – Largest travel cost, inclusive, or several of them; every cutoff gives its own columns.

  • gdf_origins (DataFrame | None) – Origin objects, with graph_node_column or matched to their nearest nodes, or

  • origins_nodes (Optional[Iterable[Any]]) – origin node ids.

  • gdf_objects (DataFrame | None) – Objects to aggregate, with the same conventions, or

  • object_nodes (Optional[Iterable[Any]]) – their node ids (counts only).

  • columns (Optional[Iterable[str]]) – Numeric columns of gdf_objects to sum and average. Missing values are left out.

  • weight (Literal['length_meter', 'time_min']) – Edge cost column: time_min (minutes) or length_meter (metres).

  • decay (Optional[Literal['linear', 'exp', 'inverse']]) – Distance decay of the weights, or None for none.

  • beta (Union[float, Iterable[float], None]) – Rate of the exponential decay, one value or one per cutoff. By default 4 / cutoff, which leaves a weight of 0.018 at the cutoff.

  • direction (Literal['from', 'to']) – "from" measures the way from the origin to the object, "to" from the object to the origin. They differ on directed graphs.

  • graph_node_column (str) – Column of object tables that holds graph node ids.

  • max_workers (int | None) – Number of threads; None uses all cores.

Returns:

count_c and, for each of columns, <column>_sum_c and <column>_mean_c (NaN where nothing is in reach).

Return type:

DataFrame indexed like the origins. For every cutoff c

Raises:
  • ValueError – If cutoff, decay or direction is invalid, or columns is passed without gdf_objects.

  • KeyError – If a column is absent from gdf_objects.