API

This is the User Reference for the metroscore package. If you are looking for an introduction to metroscore, read the Tutorial guide. This guide describes the usage of metroscore’s public API.

metroscore.metroscore module

class metroscore.metroscore.Metroscore(name, C)

Main object that creates Metroscore analyses.

Parameters:
  • name (str) – The name of the place for analysis.

  • C (float) – Scaling factor used in metroscore calculation.

Returns:

Metroscore – Instance of Metroscore object. Note that this object is not able to run analyses until the drive and transit networks are built by running build_drive and build_transit.

build_drive(traffic_damper=0.3)

Build the drive network.

Parameters:

traffic_damper (float) – Dampening factor for traffic speeds. Defaults to 0.3.

Returns:

Metroscore – Instance of Metroscore object with configured m._drive_graph object.

build_transit(**kwargs)

Build the transit network.

Parameters:

**kwargs – Path to the GTFS feed for each transit mode specified by the user.

Returns:

Metroscore – Instance of Metroscore object with configured m._transit_graph object.

compute(locations, time_of_days, cutoffs, overwrite=False)

Compute the metroscores.

Parameters:
  • locations (list) – List of (lat, lon) coordinates to use as test locations.

  • time_of_days (list) – List of times (in seconds after midnight) to use as departure times.

  • cutoffs (list) – List of times (in seconds) to use as travel times.

  • overwrite (bool) – Boolean used to determine if results should overwrite existing ones.

Returns:

pandas.DataFrame – DataFrame with 4 columns: location, time_of_day, cutoff, and metroscore.

get_score(location, time_of_day, cutoff)

Get a single metroscore.

Parameters:
  • location – Location coordinate (lat, lon).

  • time_of_day – Time of day (in seconds after midnight).

  • cutoff – Travel duration (in seconds).

Returns:

float – Single metroscore value.

list_scores(locations=None, time_of_days=None, cutoffs=None)

Get all metroscores with matching locations, time_of_days, and cutoffs.

Parameters:
  • locations (list, optional) – List of (lat, lon) coordinates. Defaults to None.

  • time_of_days (list, optional) – List of times (in seconds after midnight). Defaults to None.

  • cutoffs (list, optional) – List of times (in seconds). Defaults to None.

Returns:

pandas.DataFrame – DataFrame with metroscores matching the specified criteria.

slice_results(by, agg)

Slice and aggregate metroscores across a given dimension.

Parameters:
  • by (str) – Dimension to slice by. Supports “location”, “time_of_day”, “cutoff”, or “all”.

  • agg (str) – Aggregation function to use. Supports “mean”, “max”, “min”, and “median”.

Returns:

pandas.Series or float – Aggregated metroscores across the specified dimension.