Skip to content

Commit

Permalink
update viz tools with latest stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
atmyers committed Nov 21, 2023
1 parent 6837f96 commit c81e09c
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 1 deletion.
Binary file added data/CA_2020_Census_Tracts/tl_2020_06_tract.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions data/CA_2020_Census_Tracts/tl_2020_06_tract.prj
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 added data/CA_2020_Census_Tracts/tl_2020_06_tract.shp
Binary file not shown.
Binary file added data/CA_2020_Counties/CA_Counties_TIGER2016.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions data/CA_2020_Counties/CA_Counties_TIGER2016.prj
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 added data/CA_2020_Counties/CA_Counties_TIGER2016.shp
Binary file not shown.
163 changes: 163 additions & 0 deletions etc/California.ipynb
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
}
137 changes: 137 additions & 0 deletions etc/California_Counties.ipynb
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
}
3 changes: 2 additions & 1 deletion etc/plot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import yt
from yt.frontends.boxlib.data_structures import AMReXDataset
import pylab as plt
import sys

fn = "plt00168"
fn = sys.argv[1]

ds = AMReXDataset(fn)

Expand Down

0 comments on commit c81e09c

Please sign in to comment.