Divvy (Chicago)¶

Fetches trip data straight from the public S3 bucket via bike_network_traffic.get_bike_data and links a Celldega clustergram to the deck.gl flow map.

In [1]:
from bike_network_traffic import silence_warnings
silence_warnings()

import celldega as dega
from ipywidgets import HBox, Layout

from bike_network_traffic import (
    get_bike_data,
    link_flow_to_clustergram,
    make_flow_widget,
    make_station_clustergram,
)

1. Download trips and build station + transition tables¶

First call downloads (and caches under ~/.cache/bike_network_traffic) the monthly zip from S3 and returns a station table plus a destination-probability matrix ready for Celldega.

In [2]:
ds = get_bike_data('chicago', year=2026, return_trips=True)
stations, transition_prob, trips = ds.stations, ds.transition_prob, ds.trips
print('stations:', stations.shape, ' transition_prob:', transition_prob.shape, ' trips:', trips.shape)
stations.head()
stations: (1477, 4)  transition_prob: (1395, 1365)  trips: (656274, 8)
Out[2]:
station_id station_name lat lng
0 CHI00611 2112 W Peterson Ave 41.991178 -87.683593
1 CHI01823 21st St & Pulaski Rd 41.853908 -87.724794
2 CHI00315 63rd St Beach 41.780911 -87.576323
3 CHI01748 900 W Harrison St 41.874754 -87.649807
4 CHI01976 Aberdeen St & 103rd St 41.707040 -87.650220

2. Cluster the transition matrix¶

In [3]:
mat, cgm, cluster_map = make_station_clustergram(transition_prob, n_clusters=100)

3. Build the flow map and link it to the clustergram¶

In [4]:
flow = make_flow_widget(stations, transition_prob, cluster_map, trips=trips, height=700, debug=True)
link_flow_to_clustergram(flow, cgm)

flow.layout = Layout(width='560px', height='700px')
cgm.layout  = Layout(width='720px', height='700px')
HBox([flow, cgm])
Out[4]: