Density and public transportation¶
Sufficient population and job density are important for a public transportation system. Therefore plotting densities and public transportation systems on the same map can reveal opportuntities to build more public transportation lines (where density is high, but there are no existing lines) and to build more housing/jobs (where public transportation lines exist, but densities are low).
Let’s create a map of population density. In the United States, we can get this geo-tagged population data from the United States Census Bureau. dpd.modeling has a class Zones to store this data and a method to automatically pull this data from the United States Census Bureau.
First, we’ll define the state that we are interested in mapping. States seems to be the best level to get data for. If we get data by county, there are lots of requests so it takes too long. However, data for the whole country is unnecessary.
[1]:
import us
from ipywidgets import Select
from IPython.display import display
YEAR = "2017"
state = Select(
options=list(map(lambda x: x.name, us.STATES)),
description="State",
value="California",
)
display(state)
Now we can get the census data for California. The government assigns a number to each state so California is 06. B01003_001E is the population in each census tract. This is renamed to Total Population. Also, ALAND is the land area of the zone. We use these two values to compute a density as population per area. Also, we simplify the geometry column to speed up any geometric computations.
[2]:
from dpd.modeling import Zones
zones = Zones.from_uscensus(str(us.states.lookup(state.value).fips), YEAR)
zones["geometry"] = zones["geometry"].apply(lambda x: x.simplify(0.001))
zones.head(1)
/home/docs/checkouts/readthedocs.org/user_builds/dpd/envs/latest/lib/python3.9/site-packages/dpd/modeling/zones.py:58: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
zones["Worker Population"] = zones["Worker Population"].fillna(0).apply(int)
[2]:
Name | Total Population | Worker Population | state | county | tract | STATEFP | COUNTYFP | TRACTCE | NAME_y | ... | FUNCSTAT | ALAND | AWATER | INTPTLAT | INTPTLON | geometry | Total Population + Worker Population | Total Population Density | Worker Population Density | Total Population + Worker Population Density | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GEOID | |||||||||||||||||||||
6037503502 | Census Tract 5035.02, Los Angeles County, Cali... | 4359 | 0 | 06 | 037 | 503502 | 06 | 037 | 503502 | 5035.02 | ... | S | 1244436 | 0 | +33.9320286 | -118.0031960 | POLYGON ((-118.01180 33.92688, -118.01169 33.9... | 4359 | 0.003503 | 0.0 | 0.003503 |
1 rows × 22 columns
Here we can plot the population density of California.
[3]:
zones.explore(
column="Total Population + Worker Population Density", scheme="JenksCaspall", k=20
)
[3]: