<jupyter_start><jupyter_text>Areal interpolation: Tracts to Voting PrecinctsThis 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.<jupyter_code>import tobler
import matplotlib.pyplot as plt
%matplotlib inline

import geopandas
tracts = geopandas.read_file("https://ndownloader.figshare.com/files/20460645") 
tracts.shape<jupyter_output><empty_output><jupyter_text>There are 822 tracts in the two counties.<jupyter_code>tracts.head()
tracts.plot(facecolor='none', edgecolor='g')<jupyter_output><empty_output><jupyter_text>Precincts<jupyter_code>precincts = geopandas.read_file("https://ndownloader.figshare.com/files/20460549") 

precincts.shape<jupyter_output><empty_output><jupyter_text>For the 3780 precincts in the two counties, we wish to obtain estimates of the percentage of the  population that is youth.<jupyter_code>precincts.plot(facecolor='none', edgecolor='r')<jupyter_output><empty_output><jupyter_text>Interpolation<jupyter_code>estimates = tobler.area_weighted.area_interpolate(tracts, precincts, intensive_variables=['pct Youth'])<jupyter_output>Source and target dataframes have different crs. Please correct.<jupyter_text>Notice the warning about different crs.<jupyter_code>estimates<jupyter_output><empty_output><jupyter_text>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<jupyter_code>tracts = tracts.to_crs(precincts.crs) 
estimates = tobler.area_weighted.area_interpolate(tracts, precincts, intensive_variables=['pct Youth'])
estimates
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()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10586011342155009, 'fraction_numerical': 0.017958412098298678, 'mean_word_length': 8.325991189427313, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '223290', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 758, 'n_tokens_neox': 711, 'n_words': 169, 'path': 'notebooks/precincts.ipynb', 'repo_name': 'pattyf/tobler', 'size': '2116'}