-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
304 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator_Auxiliary_Sphere"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],PARAMETER["Auxiliary_Sphere_Type",0.0],UNIT["Meter",1.0]] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import fiona\n", | ||
"import geopandas as gpd\n", | ||
"import pysal as ps\n", | ||
"#from pysal.contrib.viz import mapping as maps\n", | ||
"import shapefile\n", | ||
"import pandas as pd\n", | ||
"from shapely.geometry import shape\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"myshp = open(\"../data/CA_2020_Census_Tracts/tl_2020_06_tract.shp\",\"rb\")\n", | ||
"mydbf = open(\"../data/CA_2020_Census_Tracts/tl_2020_06_tract.dbf\", \"rb\")\n", | ||
"myprj = open(\"../data/CA_2020_Census_Tracts/tl_2020_06_tract.prj\", \"rb\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"r = shapefile.Reader(shp=myshp, dbf=mydbf, prj=myprj)\n", | ||
"attributes, geometry = [], []\n", | ||
"field_names = [field[0] for field in r.fields[1:]] \n", | ||
"for row in r.shapeRecords(): \n", | ||
" geometry.append(shape(row.shape.__geo_interface__)) \n", | ||
" attributes.append(dict(zip(field_names, row.record))) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf = gpd.GeoDataFrame(data = attributes, geometry = geometry)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf['fips'] = gdf['STATEFP'] + gdf['COUNTYFP'] + gdf['TRACTCE']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf['fips'] = gdf['fips'].astype(int)\n", | ||
"gdf['GEOID'] = gdf['GEOID'].astype(int)\n", | ||
"gdf['tot'] = 0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df000 = pd.read_csv(\"CA.csv\", header=None, names=[\"fips\", \"tot\"], dtype={'fips':int, 'tot':float})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf000 = gdf.merge(df000, left_on='fips', right_on='fips', how='left')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf['COUNTYFP']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig, ax = plt.subplots(figsize=(10,10))\n", | ||
"ax.set(aspect='equal', xticks=[], yticks=[])\n", | ||
"gdf000.plot(column= 'tot_x', ax = ax, cmap='Purples', edgecolor=\"black\", linewidth=0.2, legend=False, vmin=0, vmax=50000)\n", | ||
"gdf000.plot(column= 'tot_y', ax = ax, cmap='Purples', legend=True, vmin=0, vmax=0.0001)\n", | ||
"#gdf000.plot(column= 'tot_x', ax = ax, cmap='Purples')\n", | ||
"fig.savefig(\"CA\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plt.savefig(\"bay_area\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\"{:06d}\".format(400)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"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": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import fiona\n", | ||
"import geopandas as gpd\n", | ||
"import pysal as ps\n", | ||
"#from pysal.contrib.viz import mapping as maps\n", | ||
"import shapefile\n", | ||
"import pandas as pd\n", | ||
"from shapely.geometry import shape\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"myshp = open(\"../data/CA_2020_Counties/CA_Counties_TIGER2016.shp\", \"rb\")\n", | ||
"mydbf = open(\"../data/CA_2020_Counties/CA_Counties_TIGER2016.dbf\", \"rb\")\n", | ||
"myprj = open(\"../data/CA_2020_Counties/CA_Counties/CA_Counties_TIGER2016.prj\", \"rb\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"r = shapefile.Reader(shp=myshp, dbf=mydbf, prj=myprj)\n", | ||
"attributes, geometry = [], []\n", | ||
"field_names = [field[0] for field in r.fields[1:]] \n", | ||
"for row in r.shapeRecords(): \n", | ||
" geometry.append(shape(row.shape.__geo_interface__)) \n", | ||
" attributes.append(dict(zip(field_names, row.record))) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf = gpd.GeoDataFrame(data = attributes, geometry = geometry)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf['GEOID'] = gdf['GEOID'].astype(int)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df000 = pd.read_csv(\"CA.csv\", header=None, names=[\"GEOID\", \"tot\"], dtype={'fips':int, 'tot':float})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gdf000 = gdf.merge(df000, left_on='GEOID', right_on='GEOID', how='inner')\n", | ||
"gdf000['logtot'] = np.log10(gdf000['tot'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig, ax = plt.subplots(figsize=(8,8))\n", | ||
"ax.set(aspect='equal', xticks=[], yticks=[])\n", | ||
"gdf000.plot(column= 'logtot', ax = ax, cmap='Purples', edgecolor=\"black\", linewidth=0.2, legend=False, vmin=4, vmax=8)\n", | ||
"#gdf000.plot(column= 'tot_y', ax = ax, cmap='Purples', legend=True, vmin=0, vmax=0.0001)\n", | ||
"#gdf000.plot(column= 'tot_x', ax = ax, cmap='Purples')\n", | ||
"fig.savefig(\"CA\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plt.savefig(\"CA\")" | ||
] | ||
} | ||
], | ||
"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": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters