access.weights.step_fn

access.weights.step_fn(step_dict)[source]

Create a step function from a dictionary.

Parameters:
step_dictdict

Dictionary of cut-offs and weight values.

Returns:
weight_functionfunction

Function returning weight, for input distance or time, x. Values beyond the largest threshold will return 0.

Examples

Import the weights:

>>> from access import weights

Create a step function with thresholds at 20, 40, and 60. Travel costs are in minutes here, but the code cannot tell if you mix units!

>>> fn = weights.step_fn({20 : 1, 40 : 0.68, 60 : 0.22})
>>> {v : fn(v) for v in range(0, 71, 10)}
{0: 1, 10: 1, 20: 1, 30: 0.68, 40: 0.68, 50: 0.22, 60: 0.22, 70: 0}