Capital Bikeshare (DC)¶
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('dc', 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: (823, 4) transition_prob: (822, 821) trips: (501941, 8)
Out[2]:
| station_id | station_name | lat | lng | |
|---|---|---|---|---|
| 0 | 31949.0 | S Scott St & 12th St | 38.863531 | -77.077209 |
| 1 | 32324.0 | Scotts Crossing Rd & Spring Gate Dr | 38.927018 | -77.211094 |
| 2 | 31256.0 | 10th & E St NW | 38.895915 | -77.026063 |
| 3 | 31274.0 | 10th & G St NW | 38.898244 | -77.026235 |
| 4 | 31672.0 | 10th & H St NE | 38.899983 | -76.992723 |
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]: