diff --git a/data/CA_2020_Census_Tracts/tl_2020_06_tract.dbf b/data/CA_2020_Census_Tracts/tl_2020_06_tract.dbf new file mode 100755 index 0000000..0d6bf2b Binary files /dev/null and b/data/CA_2020_Census_Tracts/tl_2020_06_tract.dbf differ diff --git a/data/CA_2020_Census_Tracts/tl_2020_06_tract.prj b/data/CA_2020_Census_Tracts/tl_2020_06_tract.prj new file mode 100755 index 0000000..747df58 --- /dev/null +++ b/data/CA_2020_Census_Tracts/tl_2020_06_tract.prj @@ -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]] \ No newline at end of file diff --git a/data/CA_2020_Census_Tracts/tl_2020_06_tract.shp b/data/CA_2020_Census_Tracts/tl_2020_06_tract.shp new file mode 100755 index 0000000..5f180da Binary files /dev/null and b/data/CA_2020_Census_Tracts/tl_2020_06_tract.shp differ diff --git a/data/CA_2020_Counties/CA_Counties_TIGER2016.dbf b/data/CA_2020_Counties/CA_Counties_TIGER2016.dbf new file mode 100644 index 0000000..0f47818 Binary files /dev/null and b/data/CA_2020_Counties/CA_Counties_TIGER2016.dbf differ diff --git a/data/CA_2020_Counties/CA_Counties_TIGER2016.prj b/data/CA_2020_Counties/CA_Counties_TIGER2016.prj new file mode 100644 index 0000000..5c6f76d --- /dev/null +++ b/data/CA_2020_Counties/CA_Counties_TIGER2016.prj @@ -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]] \ No newline at end of file diff --git a/data/CA_2020_Counties/CA_Counties_TIGER2016.shp b/data/CA_2020_Counties/CA_Counties_TIGER2016.shp new file mode 100644 index 0000000..7682cb2 Binary files /dev/null and b/data/CA_2020_Counties/CA_Counties_TIGER2016.shp differ diff --git a/etc/California.ipynb b/etc/California.ipynb new file mode 100644 index 0000000..ac0e49b --- /dev/null +++ b/etc/California.ipynb @@ -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 +} diff --git a/etc/California_Counties.ipynb b/etc/California_Counties.ipynb new file mode 100644 index 0000000..ef0b51b --- /dev/null +++ b/etc/California_Counties.ipynb @@ -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 +} diff --git a/etc/plot.py b/etc/plot.py index 09e2fc5..509627a 100644 --- a/etc/plot.py +++ b/etc/plot.py @@ -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)