Python code for constructing commuter networks from Census data.
These scripts all produce commuter networks as GraphML objects. There are various relevant node and edge attributes; not all are present in each graph:
Node:
name
: the node names correspond to FIPS codes for a particular level of granularitystate
,county
: straightforward descriptivestown
: in states where available, the name of the relevant minor civil divisionsblock
,tract
: Census administrative unitsPopulation
: The total population of the region in the 2016 5-year ACS. The population data is downloaded using thecollect_population_data.py
script.<18
,18-24
, ...,65+
: Distribution of ages in the region, also drawn from the 2016 5-year ACS.latitude
,longitude
: coordinates for the relevant spatial unit, drawn from 2019 Census gazetteer files
Edge:
weight
: the amount of commuting traffic between the edgesmargin
: the uncertainty around this magnitude, where available (ACS only)
construct_county_network.py
creates a weighted edgelist of commuting flows
between counties, drawn from Table 1 of the 2011-2015 5-Year ACS Commuting Flows
dataset.
construct_town_network.py
creates a weighted edgelist of commuting flows
between minor civil divisions (where available; counties where not available),
drawn from Table 3 of the 2011-2015 5-Year ACS Commuting Flows
dataset.
construct_tract_network.py
creates a weighted edgelist of commuting flows
between Census tracts, drawn from LODES. Before
running it, download the LODES data using the collect_lodes_data.sh
script,
and then aggregate from block level to tract level using the
aggregate_lodes_tract_level.py
script.
construct_block_level.py
creates a weighted edgelist of commuting flows
between Census tracts, drawn from LODES. Before
running it, download the LODES data using the collect_lodes_data.sh
script.
All four scripts are used in the same way.
python construct_block_network.py -s ma,me,vt,ct,ri,nh -o new_england -m 1
The -s
flag takes a comma-separated list of USPS state codes; if it is absent,
it runs the script across all 50 states plus DC. The output data files are in
data/derived
; the -o
flag adds an additional subdirectory (e.g.,
data/derived/new_england
). The -m
flag specifies a minimum weight necessary
for an edge to be included, effectively thresholding the network.