j40-cejst-2/data/data-pipeline/data_pipeline/ipython/TractArea.ipynb
Vim eb3004c0d5
Fix on large AK tracts that are off screen (#1740)
* Change low to high transition and global zoom

- change the low to high transition from 7 to 5. This can not go any lower as high tiles on AWS only go to zoom level 5
- reduce the zoom level globally on all census tracts

* Remove geolocation from feature flag

- geolocation is now available to all

* Add python notebook that sorts all tracts by area

- add a column of the required zoom level for the tract to be fully contained in the viewport

* Place geolocation back to behind a feature flag

* Differentiate zoom levels b/w shortcuts and tracts
2022-07-13 19:01:43 -07:00

418 lines
14 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 54,
"id": "df048f08",
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"import pathlib"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "62366f7d",
"metadata": {},
"outputs": [],
"source": [
"lowJson = pathlib.Path() / 'usa-low.json'\n",
"assert lowJson.exists()\n",
"highJson = pathlib.Path() / 'usa-high.json'\n",
"assert highJson.exists()"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "4077ed78",
"metadata": {},
"outputs": [],
"source": [
"gdf = gpd.read_file(highJson)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "d4abfc64",
"metadata": {},
"outputs": [],
"source": [
"gdf['area'] = gdf.apply(lambda row : gpd.GeoSeries(row['geometry']).area, axis = 1)"
]
},
{
"cell_type": "markdown",
"id": "5077d9ef",
"metadata": {},
"source": [
"Add `zlfc` = *zoom level full containment*, This field will indicate the maximum zoom level the user can go up to while still keeping the entire tract in view. Below, we sample a few tracts to get an idea of the relationship between zoom level and area"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "a1234574",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>GEOID10</th>\n",
" <th>SF</th>\n",
" <th>CF</th>\n",
" <th>area</th>\n",
" <th>zlfc</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>9846</th>\n",
" <td>02185000200</td>\n",
" <td>Alaska</td>\n",
" <td>North Slope Borough</td>\n",
" <td>53.323702</td>\n",
" <td>4.45</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9937</th>\n",
" <td>02290000100</td>\n",
" <td>Alaska</td>\n",
" <td>Yukon-Koyukuk Census Area</td>\n",
" <td>21.653154</td>\n",
" <td>5.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9857</th>\n",
" <td>02188000100</td>\n",
" <td>Alaska</td>\n",
" <td>Northwest Arctic Borough</td>\n",
" <td>21.188159</td>\n",
" <td>5.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9935</th>\n",
" <td>02290000200</td>\n",
" <td>Alaska</td>\n",
" <td>Yukon-Koyukuk Census Area</td>\n",
" <td>20.744770</td>\n",
" <td>5.38</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9934</th>\n",
" <td>02290000300</td>\n",
" <td>Alaska</td>\n",
" <td>Yukon-Koyukuk Census Area</td>\n",
" <td>17.140826</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9936</th>\n",
" <td>02290000400</td>\n",
" <td>Alaska</td>\n",
" <td>Yukon-Koyukuk Census Area</td>\n",
" <td>14.687448</td>\n",
" <td>5.77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9893</th>\n",
" <td>02180000100</td>\n",
" <td>Alaska</td>\n",
" <td>Nome Census Area</td>\n",
" <td>13.377817</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9847</th>\n",
" <td>02164000100</td>\n",
" <td>Alaska</td>\n",
" <td>Lake and Peninsula Borough</td>\n",
" <td>13.061644</td>\n",
" <td>5.33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9918</th>\n",
" <td>02261000100</td>\n",
" <td>Alaska</td>\n",
" <td>Valdez-Cordova Census Area</td>\n",
" <td>11.118835</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9945</th>\n",
" <td>02050000100</td>\n",
" <td>Alaska</td>\n",
" <td>Bethel Census Area</td>\n",
" <td>10.951888</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9841</th>\n",
" <td>02270000100</td>\n",
" <td>Alaska</td>\n",
" <td>Wade Hampton Census Area</td>\n",
" <td>8.771806</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9839</th>\n",
" <td>02240000100</td>\n",
" <td>Alaska</td>\n",
" <td>Southeast Fairbanks Census Area</td>\n",
" <td>8.613690</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9843</th>\n",
" <td>02070000100</td>\n",
" <td>Alaska</td>\n",
" <td>Dillingham Census Area</td>\n",
" <td>8.575307</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9947</th>\n",
" <td>02050000300</td>\n",
" <td>Alaska</td>\n",
" <td>Bethel Census Area</td>\n",
" <td>8.408040</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9899</th>\n",
" <td>02170000101</td>\n",
" <td>Alaska</td>\n",
" <td>Matanuska-Susitna Borough</td>\n",
" <td>6.480444</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9944</th>\n",
" <td>02068000100</td>\n",
" <td>Alaska</td>\n",
" <td>Denali Borough</td>\n",
" <td>5.997236</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9836</th>\n",
" <td>02013000100</td>\n",
" <td>Alaska</td>\n",
" <td>Aleutians East Borough</td>\n",
" <td>5.487726</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9921</th>\n",
" <td>02122000100</td>\n",
" <td>Alaska</td>\n",
" <td>Kenai Peninsula Borough</td>\n",
" <td>4.831831</td>\n",
" <td>6.10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9851</th>\n",
" <td>02150000100</td>\n",
" <td>Alaska</td>\n",
" <td>Kodiak Island Borough</td>\n",
" <td>4.664009</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9850</th>\n",
" <td>02105000300</td>\n",
" <td>Alaska</td>\n",
" <td>Hoonah-Angoon Census Area</td>\n",
" <td>4.305716</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9838</th>\n",
" <td>02016000100</td>\n",
" <td>Alaska</td>\n",
" <td>Aleutians West Census Area</td>\n",
" <td>4.053520</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9917</th>\n",
" <td>02282000100</td>\n",
" <td>Alaska</td>\n",
" <td>Yakutat City and Borough</td>\n",
" <td>3.926182</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9920</th>\n",
" <td>02261000300</td>\n",
" <td>Alaska</td>\n",
" <td>Valdez-Cordova Census Area</td>\n",
" <td>3.285482</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9840</th>\n",
" <td>02240000400</td>\n",
" <td>Alaska</td>\n",
" <td>Southeast Fairbanks Census Area</td>\n",
" <td>3.233961</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9919</th>\n",
" <td>02261000200</td>\n",
" <td>Alaska</td>\n",
" <td>Valdez-Cordova Census Area</td>\n",
" <td>3.156317</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10354</th>\n",
" <td>41045970900</td>\n",
" <td>Oregon</td>\n",
" <td>Malheur County</td>\n",
" <td>2.731719</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9888</th>\n",
" <td>02198000100</td>\n",
" <td>Alaska</td>\n",
" <td>Prince of Wales-Hyder Census Area</td>\n",
" <td>2.606286</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10212</th>\n",
" <td>41025960200</td>\n",
" <td>Oregon</td>\n",
" <td>Harney County</td>\n",
" <td>2.568943</td>\n",
" <td>7.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9844</th>\n",
" <td>02185000300</td>\n",
" <td>Alaska</td>\n",
" <td>North Slope Borough</td>\n",
" <td>2.463165</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9858</th>\n",
" <td>02130000100</td>\n",
" <td>Alaska</td>\n",
" <td>Ketchikan Gateway Borough</td>\n",
" <td>2.440051</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" GEOID10 SF CF area zlfc\n",
"9846 02185000200 Alaska North Slope Borough 53.323702 4.45\n",
"9937 02290000100 Alaska Yukon-Koyukuk Census Area 21.653154 5.50\n",
"9857 02188000100 Alaska Northwest Arctic Borough 21.188159 5.50\n",
"9935 02290000200 Alaska Yukon-Koyukuk Census Area 20.744770 5.38\n",
"9934 02290000300 Alaska Yukon-Koyukuk Census Area 17.140826 0.00\n",
"9936 02290000400 Alaska Yukon-Koyukuk Census Area 14.687448 5.77\n",
"9893 02180000100 Alaska Nome Census Area 13.377817 0.00\n",
"9847 02164000100 Alaska Lake and Peninsula Borough 13.061644 5.33\n",
"9918 02261000100 Alaska Valdez-Cordova Census Area 11.118835 0.00\n",
"9945 02050000100 Alaska Bethel Census Area 10.951888 0.00\n",
"9841 02270000100 Alaska Wade Hampton Census Area 8.771806 0.00\n",
"9839 02240000100 Alaska Southeast Fairbanks Census Area 8.613690 0.00\n",
"9843 02070000100 Alaska Dillingham Census Area 8.575307 0.00\n",
"9947 02050000300 Alaska Bethel Census Area 8.408040 0.00\n",
"9899 02170000101 Alaska Matanuska-Susitna Borough 6.480444 0.00\n",
"9944 02068000100 Alaska Denali Borough 5.997236 0.00\n",
"9836 02013000100 Alaska Aleutians East Borough 5.487726 0.00\n",
"9921 02122000100 Alaska Kenai Peninsula Borough 4.831831 6.10\n",
"9851 02150000100 Alaska Kodiak Island Borough 4.664009 0.00\n",
"9850 02105000300 Alaska Hoonah-Angoon Census Area 4.305716 0.00\n",
"9838 02016000100 Alaska Aleutians West Census Area 4.053520 0.00\n",
"9917 02282000100 Alaska Yakutat City and Borough 3.926182 0.00\n",
"9920 02261000300 Alaska Valdez-Cordova Census Area 3.285482 0.00\n",
"9840 02240000400 Alaska Southeast Fairbanks Census Area 3.233961 0.00\n",
"9919 02261000200 Alaska Valdez-Cordova Census Area 3.156317 0.00\n",
"10354 41045970900 Oregon Malheur County 2.731719 0.00\n",
"9888 02198000100 Alaska Prince of Wales-Hyder Census Area 2.606286 0.00\n",
"10212 41025960200 Oregon Harney County 2.568943 7.08\n",
"9844 02185000300 Alaska North Slope Borough 2.463165 0.00\n",
"9858 02130000100 Alaska Ketchikan Gateway Borough 2.440051 0.00"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdf['zlfc'] = 0\n",
"gdf.at[9846, 'zlfc'] = 4.45\n",
"gdf.at[10212, 'zlfc'] = 7.08\n",
"gdf.at[9937, 'zlfc'] = 5.5\n",
"gdf.at[9857, 'zlfc'] = 5.5\n",
"gdf.at[9935, 'zlfc'] = 5.38\n",
"gdf.at[9936, 'zlfc'] = 5.77\n",
"gdf.at[9921, 'zlfc'] = 6.1\n",
"gdf.at[9847, 'zlfc'] = 5.33\n",
"gdf_short = gdf[[\"GEOID10\", \"SF\", \"CF\", \"area\", \"zlfc\"]]\n",
"gdf_short_sorted = gdf_short.sort_values(by='area', ascending=False);\n",
"gdf_short_sorted.head(30)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5930de0e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}