iduedu.apply_grade_speed

iduedu.apply_grade_speed(urban_graph, model='tobler', *, edge_types=None)[source]

Rescale the travel times of a graph with elevation by a speed model that depends on the grade.

The time of an edge is divided by the relative speed the model gives for its grade. An edge that goes up and down is taken as a climb of ascent followed by a drop of descent, both at the mean absolute grade (ascent + descent) / length. A row that serves both directions (an edge of an undirected graph, or a two-way edge of a directed one) gets the mean of the two directions.

The times before the change are kept in time_min_flat, and a repeated call starts from them.

Parameters:
  • urban_graph (UrbanGraph) – Graph with ascent and descent on its edges (see add_elevation()).

  • model (Union[Literal['tobler', 'cycling'], Callable[[ndarray], ndarray]]) – "tobler" (tobler(), walking), "cycling" (cycling()) or a function that maps an array of signed grades to speeds relative to flat ground.

  • edge_types (Optional[Iterable[str]]) – Change only edges whose type is one of these, for example ["walk"] in an intermodal graph.

Return type:

UrbanGraph

Returns:

A new UrbanGraph with changed time_min.

Raises:
  • KeyError – If the edges have no ascent and descent.

  • ValueError – If the model is unknown or returns speeds that are not positive.