Skip to content

transitlos.flex.catchment

Who does each stop serve? Counts (population, jobs, any additive census column) of the H3 cells each stop WINS.

A stop wins a cell when it is the station that gives the cell its level of service (the station of the winning slot, core.recompute_cells*). Which stop wins depends on the scoring, so the catchment is recomputed together with the scores.

counts = block_counts_to_cells(blocks_gdf, cells, ["population", "lodes_wac_jobsTotal"])    # [nc, ncol] counts per served cell
los, slot, prof = core.recompute_cells_fast(res.station, res.dist, prof, params)
winner = winner_station(res.station, slot)                                                      # station index per cell, -1 none
totals = stop_catchment(winner, counts.to_numpy(), n_stations)                                  # [S, ncol]

block_counts_to_cells spreads a polygon layer's counts over the cells (uniform density inside each polygon): a polygon larger than ~2 cells gives each served cell whose centre lies inside it cell_area / polygon_area of its count; a smaller polygon gives its whole count to the cell of its representative point. Counts of people in cells that no stop reaches are simply not attributed to any stop.

winner_station(cell_station, slot)

Station index that wins each cell (-1 when the cell has no station): cell_station[c, slot[c]].

Parameters:

Name Type Description Default
cell_station ndarray

[cells, K] station index per slot.

required
slot ndarray

Winning slot per cell (-1: none).

required

Returns:

Type Description
ndarray

Station index per cell.

stop_catchment(winner, counts, n_stations)

[S, ncol] sum of counts [nc, ncol] over the cells each station wins; also returns nothing for cells without a winner.

Parameters:

Name Type Description Default
winner ndarray

Winning station per cell (-1: none).

required
counts ndarray

[cells, columns] counts (population, jobs...).

required
n_stations int

Number of stations.

required

Returns:

Type Description
ndarray

[stations, columns] sums.

cells_won(winner, n_stations)

Number of cells each station wins.

Parameters:

Name Type Description Default
winner ndarray

Winning station per cell (-1: none).

required
n_stations int

Number of stations.

required

Returns:

Type Description
ndarray

Cells per station.

cell_centres(cells)

(lat, lon) arrays of H3 cell centres (vectorised).

Parameters:

Name Type Description Default
cells ndarray

uint64 H3 cell ids.

required

Returns:

Type Description

(lat, lon) arrays.

block_counts_to_cells(blocks, cells, columns, resolution=10)

Counts per served cell from a polygon layer (GeoDataFrame, EPSG:4326) with additive columns. Returns a DataFrame indexed like cells.

Parameters:

Name Type Description Default
blocks

Polygons (EPSG:4326) with additive columns.

required
cells ndarray

Sorted unique uint64 H3 ids.

required
columns Sequence[str]

Additive columns to move onto the cells.

required
resolution int

H3 resolution of the cells.

10

Raises:

Type Description
ValueError

If cells is not sorted and unique.