Citi Bike (NYC)¶
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('nyc', year=2026, month=3, 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: (2314, 4) transition_prob: (2269, 2230) trips: (2945753, 8)
Out[2]:
| station_id | station_name | lat | lng | |
|---|---|---|---|---|
| 0 | 7522.02 | 1 Ave & E 110 St | 40.792327 | -73.938300 |
| 1 | 7596.11 | 1 Ave & E 118 St | 40.797459 | -73.934499 |
| 2 | 5779.08 | 1 Ave & E 16 St | 40.732219 | -73.981656 |
| 3 | 5854.09 | 1 Ave & E 18 St | 40.733812 | -73.980544 |
| 4 | 6079.03 | 1 Ave & E 30 St | 40.741444 | -73.975361 |
2. Cluster the transition matrix¶
In [3]:
mat, cgm, cluster_map = make_station_clustergram(transition_prob, n_clusters=150)
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]: