Search
precincts

Areal interpolation: Tracts to Voting Precincts

This notebook demonstrates the interpolation of an intensive variable (Pct Youth) measured for the census tracts tracts in Riverside and San Bernardino counties in California to the voting precincts in the respective counties.

import tobler
import matplotlib.pyplot as plt
%matplotlib inline
import geopandas
tracts = geopandas.read_file("https://ndownloader.figshare.com/files/20460645") 
tracts.shape
(822, 8)

There are 822 tracts in the two counties.

tracts.head()
STATEFP COUNTYFP TRACTCE GEOID IE_NAME IE_pct_you pct Youth geometry
0 06 071 004201 06071004201 Census Tract 42.01, San Bernardino County, Cal... 0.214690 0.21 POLYGON ((-117.34794 34.13602, -117.34725 34.1...
1 06 071 004202 06071004202 Census Tract 42.02, San Bernardino County, Cal... 0.204101 0.20 POLYGON ((-117.32259 34.11639, -117.32259 34.1...
2 06 071 004401 06071004401 Census Tract 44.01, San Bernardino County, Cal... 0.237707 0.24 POLYGON ((-117.35944 34.09045, -117.35944 34.0...
3 06 065 041912 06065041912 Census Tract 419.12, Riverside County, California 0.198622 0.20 POLYGON ((-117.65093 33.87887, -117.65086 33.8...
4 06 065 043822 06065043822 Census Tract 438.22, Riverside County, California 0.127917 0.13 POLYGON ((-117.21237 34.00421, -117.20705 34.0...
tracts.plot(facecolor='none', edgecolor='g')
<matplotlib.axes._subplots.AxesSubplot at 0x7fa40853ac88>

Precincts

precincts = geopandas.read_file("https://ndownloader.figshare.com/files/20460549") 
precincts.shape
(3780, 11)

For the 3780 precincts in the two counties, we wish to obtain estimates of the percentage of the population that is youth.

precincts.plot(facecolor='none', edgecolor='r')
<matplotlib.axes._subplots.AxesSubplot at 0x7fa407b4c128>

Interpolation

estimates = tobler.area_weighted.area_interpolate(tracts, precincts, intensive_variables=['pct Youth'])
Source and target dataframes have different crs. Please correct.

Notice the warning about different crs.

estimates

As a result of the different crs, tobler will not carry out the interpolation. We need to fix the crs issue first by setting the tract geometries to use the precincts crs

tracts = tracts.to_crs(precincts.crs) 
/home/serge/anaconda3/envs/tobler/lib/python3.7/site-packages/pyproj/crs.py:77: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method.
  return _prepare_from_string(" ".join(pjargs))
estimates = tobler.area_weighted.area_interpolate(tracts, precincts, intensive_variables=['pct Youth'])
nan values in variable: pct Youth, replacing with 0.0
estimates
(array([], dtype=float64), array([[0.42896819],
        [0.23996352],
        [0.70018814],
        ...,
        [0.18013979],
        [0.11000376],
        [0.22      ]]))
f, ax = plt.subplots(1, figsize=(8, 8))
ax = tracts.plot(column='pct Youth', ax=ax, legend=True, alpha=0.5, scheme='Quantiles', k=10)
plt.show()
precincts['pct Youth'] = estimates[-1]
f, ax = plt.subplots(1, figsize=(8, 8))
ax = precincts.plot(column='pct Youth', ax=ax, legend=True, alpha=0.5, scheme='Quantiles', k=10)
plt.show()