Bluebikes (Boston)¶
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('boston', 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: (562, 4) transition_prob: (561, 561) trips: (253780, 8)
Out[2]:
| station_id | station_name | lat | lng | |
|---|---|---|---|---|
| 0 | M32093 | 101 Smith Place | 42.392568 | -71.150761 |
| 1 | K32015 | 1200 Beacon St | 42.344144 | -71.114696 |
| 2 | C32117 | 135 Morrissey Blvd | 42.315569 | -71.048416 |
| 3 | W32006 | 160 Arsenal St | 42.364665 | -71.175687 |
| 4 | A32019 | 175 N Harvard St | 42.364475 | -71.128410 |
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]: