From 8fe33511c61c1e8a8e4efcf73774653aa95a5a68 Mon Sep 17 00:00:00 2001 From: Joshua Croff Date: Mon, 11 Dec 2023 18:52:01 -0800 Subject: [PATCH] Update equity_priority_communities_build.ipynb --- .../equity_priority_communities_build.ipynb | 2617 ++--------------- 1 file changed, 251 insertions(+), 2366 deletions(-) diff --git a/Project-Documentation/Equity-Priority-Communities/equity_priority_communities_build.ipynb b/Project-Documentation/Equity-Priority-Communities/equity_priority_communities_build.ipynb index a1910a1..ef03d95 100644 --- a/Project-Documentation/Equity-Priority-Communities/equity_priority_communities_build.ipynb +++ b/Project-Documentation/Equity-Priority-Communities/equity_priority_communities_build.ipynb @@ -21,12 +21,13 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# get census api key\n", - "api_key = getpass.getpass(prompt=\"Enter your Census API key: \")" + "api_key = os.environ.get(\"CENSUS_API_KEY\")\n", + "agol_password = os.environ.get(\"AGOL_CONTENT_PASSWORD\")" ] }, { @@ -36,7 +37,7 @@ "outputs": [], "source": [ "# authenticate to agol\n", - "gis = GIS(url=\"https://mtc.maps.arcgis.com/home\", username=\"content_MTC\")" + "gis = GIS(url=\"https://mtc.maps.arcgis.com/home\", username=\"content_MTC\", password=agol_password)" ] }, { @@ -263,7 +264,7 @@ " import geopandas as gpd\n", " import requests\n", "\n", - " valid_years = [2012, 2015, 2016, 2017, 2018, 2019, 2020, 2021]\n", + " valid_years = [2012, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]\n", " pre_2020 = [2012, 2015, 2016, 2017, 2018, 2019]\n", " if year not in valid_years:\n", " print(\"Error- vintage not available. Please see docstring for valid years\")\n", @@ -327,20 +328,39 @@ " return geog_gdf" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Read selected ACS varibles from csv" - ] - }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "acs_epc_selected_vars = pd.read_csv(\"Data/acs_table_variables_epc_factors.csv\")" + "# create a function to overwrite a feature layer\n", + "def overwrite_published_feature_layer(f_layer_id, geojson_path, client):\n", + " \"\"\"Overwrite a published feature layer\n", + "\n", + " Parameters:\n", + " -----------\n", + " f_layer_id : str\n", + " id of the feature layer to overwrite\n", + " geojson_path : str\n", + " path to the geojson file\n", + " client : authenticated arcgis client\n", + " authentication example below:\n", + " from arcgis.gis import GIS\n", + " password = os.environ.get(\"AGOL_CONTENT_PASSWORD\")\n", + " gis = GIS(url=\"https://mtc.maps.arcgis.com/home/\", username=\"content_MTC\", password=password)\n", + " \"\"\"\n", + " from arcgis.features import FeatureLayerCollection\n", + " \n", + " # get the feature layer\n", + " host_flayer = client.content.get(f_layer_id)\n", + "\n", + " # create feature layer collection object\n", + " f_layer = FeatureLayerCollection.fromitem(host_flayer)\n", + " # overwrite the feature layer\n", + " f_layer.manager.overwrite(geojson_path)\n", + "\n", + " print(f\"Overwrote hosted feature layer with id: {f_layer_id}\")" ] }, { @@ -349,67 +369,91 @@ "metadata": {}, "outputs": [], "source": [ - "acs_vars_lst = acs_epc_selected_vars[\"ACS_Table_Variable\"].tolist()" + "# create a function that publishes a geojson to agol\n", + "def publish_geojson_to_agol(\n", + " geojson_path,\n", + " layer_name,\n", + " layer_snippet,\n", + " tags,\n", + " client,\n", + " folder=None,\n", + " overwrite=False,\n", + " f_layer_id=None,\n", + "):\n", + " \"\"\"Publish a geojson to ArcGIS Online\n", + "\n", + " Parameters:\n", + " -----------\n", + " geojson_path : str\n", + " path to the geojson file\n", + " layer_name : str\n", + " name of the layer\n", + " layer_snippet : str\n", + " layer snippet\n", + " tags : list\n", + " tags as a comma separated string (e.g. \"tag1, tag2, tag3\")\n", + " client : authenticated arcgis client\n", + " authentication example below:\n", + " from arcgis.gis import GIS\n", + " password = os.environ.get(\"AGOL_CONTENT_PASSWORD\")\n", + " gis = GIS(url=\"https://mtc.maps.arcgis.com/home/\", username=\"content_MTC\", password=password)\n", + " folder : str\n", + " name of the folder to publish to (optional)\n", + " overwrite : bool\n", + " if True, overwrite existing layer\n", + " f_layer_id : str\n", + " if overwrite is True, provide the id of the feature layer to overwrite\n", + " \"\"\"\n", + " if overwrite:\n", + " overwrite_published_feature_layer(f_layer_id, geojson_path, client)\n", + " else:\n", + " # publish the geojson\n", + " item_prop = {\n", + " \"type\": \"GeoJson\",\n", + " \"title\": layer_name,\n", + " \"tags\": tags,\n", + " \"snippet\": layer_snippet,\n", + " \"overwrite\": True,\n", + " }\n", + " item = client.content.add(item_properties=item_prop, data=geojson_path, folder=folder)\n", + "\n", + " # publish the item\n", + " published_item = item.publish(file_type=\"geojson\")\n", + "\n", + " print(f\"Published {layer_name} to ArcGIS Online as {published_item.id}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Query ACS API\n", - "#### [Census American Community Survey 5-Year Data API Documentation](https://www.census.gov/data/developers/data-sets/acs-5year.html)" + "### Read selected ACS varibles from csv" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "# pull american community survey tabular data\n", - "acs_df = pull_acs_5_year_est_data(\n", - " census_api_key=api_key, acs_year=2021, tbl_prof_type=\"Detailed\", select_table_vars=acs_vars_lst\n", - ")" + "acs_epc_selected_vars = pd.read_csv(\"Data/acs_table_variables_epc_factors.csv\")" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "# pull american community survey geographic data\n", - "acs_gdf = pull_census_tracts_geodata(year=2021, cartographic=True)" + "acs_vars_lst = acs_epc_selected_vars[\"ACS_Table_Variable\"].tolist()" ] }, { - "cell_type": "code", - "execution_count": 17, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\n", - "Name: WGS 84\n", - "Axis Info [ellipsoidal]:\n", - "- Lat[north]: Geodetic latitude (degree)\n", - "- Lon[east]: Geodetic longitude (degree)\n", - "Area of Use:\n", - "- name: World.\n", - "- bounds: (-180.0, -90.0, 180.0, 90.0)\n", - "Datum: World Geodetic System 1984 ensemble\n", - "- Ellipsoid: WGS 84\n", - "- Prime Meridian: Greenwich" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "acs_gdf.crs" + "### Query ACS API\n", + "#### [Census American Community Survey 5-Year Data API Documentation](https://www.census.gov/data/developers/data-sets/acs-5year.html)" ] }, { @@ -418,12 +462,22 @@ "metadata": {}, "outputs": [], "source": [ - "water_area = gpd.read_file(\n", - " \"https://services3.arcgis.com/i2dkYWmb4wHvYPda/arcgis/rest/services/region_water_area/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson\",\n", - " driver=\"GeoJSON\",\n", + "# pull american community survey tabular data\n", + "acs_df = pull_acs_5_year_est_data(\n", + " census_api_key=api_key, acs_year=2022, tbl_prof_type=\"Detailed\", select_table_vars=acs_vars_lst\n", ")" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "# pull american community survey geographic data\n", + "acs_gdf = pull_census_tracts_geodata(year=2022, cartographic=True)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -433,7 +487,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -461,12 +515,12 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ - "# calculate minority population\n", - "acs_df[\"pop_minori\"] = acs_df[\"tot_pop_mi\"] - acs_df[\"B03002_003E\"]\n", + "# calculate pocty population\n", + "acs_df[\"pop_poc\"] = acs_df[\"tot_pop_mi\"] - acs_df[\"B03002_003E\"]\n", "\n", "# calculate senior population\n", "acs_df[\"pop_over75\"] = (\n", @@ -519,12 +573,12 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ - "acs_df[\"pct_minori\"] = np.where(\n", - " acs_df[\"tot_pop_mi\"] == 0, 0, (acs_df[\"pop_minori\"] / acs_df[\"tot_pop_mi\"])\n", + "acs_df[\"pct_poc\"] = np.where(\n", + " acs_df[\"tot_pop_mi\"] == 0, 0, (acs_df[\"pop_poc\"] / acs_df[\"tot_pop_mi\"])\n", ")\n", "acs_df[\"pct_over75\"] = np.where(\n", " acs_df[\"tot_pop_se\"] == 0, 0, (acs_df[\"pop_over75\"] / acs_df[\"tot_pop_se\"])\n", @@ -559,13 +613,13 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "cols_dict_halfsd = {\n", " \"pct_over75\": \"over75_1_2\",\n", - " \"pct_minori\": \"minori_1_2\",\n", + " \"pct_poc\": \"poc_1_2\",\n", " \"pct_spfam\": \"spfam_1_2\",\n", " \"pct_disab\": \"disab_1_2\",\n", " \"pct_lep\": \"lep_1_2\",\n", @@ -579,13 +633,13 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "halfsd_cols_list = [\n", " \"below2_1_2\",\n", - " \"minori_1_2\",\n", + " \"poc_1_2\",\n", " \"spfam_1_2\",\n", " \"disab_1_2\",\n", " \"lep_1_2\",\n", @@ -605,12 +659,12 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "halfsd_remain = [\"spfam_1_2\", \"disab_1_2\", \"lep_1_2\", \"over75_1_2\", \"zvhh_1_2\", \"hus_re_1_2\"]\n", - "halfsd_cond = ((acs_df[\"minori_1_2\"] == 1) & (acs_df[\"below2_1_2\"] == 1)) | (\n", + "halfsd_cond = ((acs_df[\"poc_1_2\"] == 1) & (acs_df[\"below2_1_2\"] == 1)) | (\n", " (acs_df[\"below2_1_2\"] == 1) & (acs_df[halfsd_remain].sum(axis=1) >= 3)\n", ")\n", "acs_df[\"epc50p_1_2\"] = np.where(halfsd_cond, 1, 0)" @@ -625,13 +679,13 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "cols_dict_onesd = {\n", " \"pct_over75\": \"over75_1\",\n", - " \"pct_minori\": \"minori_1\",\n", + " \"pct_poc\": \"poc_1\",\n", " \"pct_spfam\": \"spfam_1\",\n", " \"pct_disab\": \"disab_1\",\n", " \"pct_lep\": \"lep_1\",\n", @@ -645,13 +699,13 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "onesd_cols_list = [\n", " \"below2_1\",\n", - " \"minori_1\",\n", + " \"poc_1\",\n", " \"spfam_1\",\n", " \"disab_1\",\n", " \"lep_1\",\n", @@ -671,12 +725,12 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "onesd_remain = [\"spfam_1\", \"disab_1\", \"lep_1\", \"over75_1\", \"zvhh_1\", \"hus_re_1\"]\n", - "onesd_cond = ((acs_df[\"minori_1\"] == 1) & (acs_df[\"below2_1\"] == 1)) | (\n", + "onesd_cond = ((acs_df[\"poc_1\"] == 1) & (acs_df[\"below2_1\"] == 1)) | (\n", " (acs_df[\"below2_1\"] == 1) & (acs_df[onesd_remain].sum(axis=1) >= 3)\n", ")\n", "acs_df[\"epc50p_1\"] = np.where(onesd_cond, 1, 0)" @@ -691,13 +745,13 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "cols_dict_onehalfsd = {\n", " \"pct_over75\": \"over75_1ha\",\n", - " \"pct_minori\": \"minori_1ha\",\n", + " \"pct_poc\": \"poc_1ha\",\n", " \"pct_spfam\": \"spfam_1ha\",\n", " \"pct_disab\": \"disab_1ha\",\n", " \"pct_lep\": \"lep_1ha\",\n", @@ -711,13 +765,13 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "onehalfsd_cols_list = [\n", " \"below2_1ha\",\n", - " \"minori_1ha\",\n", + " \"poc_1ha\",\n", " \"spfam_1ha\",\n", " \"disab_1ha\",\n", " \"lep_1ha\",\n", @@ -737,12 +791,12 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "onehalfsd_remain = [\"spfam_1ha\", \"disab_1ha\", \"lep_1ha\", \"over75_1ha\", \"zvhh_1ha\", \"hus_re_1ha\"]\n", - "onehalfsd_cond = ((acs_df[\"minori_1ha\"] == 1) & (acs_df[\"below2_1ha\"] == 1)) | (\n", + "onehalfsd_cond = ((acs_df[\"poc_1ha\"] == 1) & (acs_df[\"below2_1ha\"] == 1)) | (\n", " (acs_df[\"below2_1ha\"] == 1) & (acs_df[onehalfsd_remain].sum(axis=1) >= 3)\n", ")\n", "acs_df[\"epc50p_1ha\"] = np.where(onehalfsd_cond, 1, 0)" @@ -757,7 +811,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -775,7 +829,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -784,21 +838,29 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/9q/xt2lctm54xq6fd45m1lmgp4m0000gp/T/ipykernel_80927/4199737063.py:1: FutureWarning: The provided callable is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n", + " acs_df.groupby(\"epc_class\")[\"epc_2050p\"].agg(sum)\n" + ] + }, { "data": { "text/plain": [ "epc_class\n", - "High 152\n", - "Higher 101\n", - "Highest 60\n", + "High 174\n", + "Higher 131\n", + "Highest 48\n", "NA 0\n", "Name: epc_2050p, dtype: int64" ] }, - "execution_count": 29, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -814,49 +876,28 @@ "## Compare previous EPCs" ] }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], - "source": [ - "census_vintage_crosswalk = pd.read_csv(\n", - " \"https://www2.census.gov/geo/docs/maps-data/data/rel2020/tract/tab20_tract20_tract10_natl.txt\",\n", - " sep=\"|\",\n", - " dtype=str,\n", - ")" - ] - }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ - "census_vintage_crosswalk.rename(\n", - " columns={\"GEOID_TRACT_20\": \"tract_geoid20\", \"GEOID_TRACT_10\": \"tract_geoid10\"}, inplace=True\n", - ")" + "# census_vintage_crosswalk = pd.read_csv(\n", + "# \"https://www2.census.gov/geo/docs/maps-data/data/rel2020/tract/tab20_tract20_tract10_natl.txt\",\n", + "# sep=\"|\",\n", + "# dtype=str,\n", + "# )" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Breaking feature service layer IDs into 8 chunks\n" - ] - } - ], + "outputs": [], "source": [ - "pba50_epc_df = pull_geotable_agol(\n", - " base_url=\"https://services3.arcgis.com/i2dkYWmb4wHvYPda/arcgis/rest/services/communities_of_concern_2020_acs2018/FeatureServer/0\",\n", - " client=gis,\n", - " reproject_to_analysis_crs=False,\n", - ")" + "# census_vintage_crosswalk.rename(\n", + "# columns={\"GEOID_TRACT_20\": \"tract_geoid20\", \"GEOID_TRACT_10\": \"tract_geoid10\"}, inplace=True\n", + "# )" ] }, { @@ -865,27 +906,20 @@ "metadata": {}, "outputs": [], "source": [ - "pba50_epc_df.rename(columns={\"geoid\": \"tract_geoid10\"}, inplace=True)" + "# pba50_epc_df = pull_geotable_agol(\n", + "# base_url=\"https://services3.arcgis.com/i2dkYWmb4wHvYPda/arcgis/rest/services/communities_of_concern_2020_acs2018/FeatureServer/0\",\n", + "# client=gis,\n", + "# reproject_to_analysis_crs=False,\n", + "# )" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "343" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "pba50_epc_df[\"epc_2050\"].sum()" + "# pba50_epc_df.rename(columns={\"geoid\": \"tract_geoid10\"}, inplace=True)" ] }, { @@ -894,12 +928,7 @@ "metadata": {}, "outputs": [], "source": [ - "pba50_epc_cross = pd.merge(\n", - " pba50_epc_df[[\"tract_geoid10\", \"epc_2050\", \"geometry\"]],\n", - " census_vintage_crosswalk[[\"tract_geoid20\", \"tract_geoid10\"]],\n", - " on=\"tract_geoid10\",\n", - " how=\"left\",\n", - ")" + "# pba50_epc_df[\"epc_2050\"].sum()" ] }, { @@ -908,7 +937,12 @@ "metadata": {}, "outputs": [], "source": [ - "acs_df.rename(columns={\"tract_geoid\": \"tract_geoid20\"}, inplace=True)" + "# pba50_epc_cross = pd.merge(\n", + "# pba50_epc_df[[\"tract_geoid10\", \"epc_2050\", \"geometry\"]],\n", + "# census_vintage_crosswalk[[\"tract_geoid20\", \"tract_geoid10\"]],\n", + "# on=\"tract_geoid10\",\n", + "# how=\"left\",\n", + "# )" ] }, { @@ -917,12 +951,21 @@ "metadata": {}, "outputs": [], "source": [ - "# update acs_df with epc_2050 values\n", - "acs_df[\"epc_2050\"] = acs_df[\"tract_geoid20\"].map(\n", - " pba50_epc_cross.sort_values(by=\"epc_2050\", ascending=False)\n", - " .groupby(\"tract_geoid20\")[\"epc_2050\"]\n", - " .first()\n", - ")" + "# acs_df.rename(columns={\"tract_geoid\": \"tract_geoid20\"}, inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "# # update acs_df with epc_2050 values\n", + "# acs_df[\"epc_2050\"] = acs_df[\"tract_geoid20\"].map(\n", + "# pba50_epc_cross.sort_values(by=\"epc_2050\", ascending=False)\n", + "# .groupby(\"tract_geoid20\")[\"epc_2050\"]\n", + "# .first()\n", + "# )" ] }, { @@ -934,24 +977,11 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "epc_2050 466.0\n", - "epc_2050p 313.0\n", - "dtype: float64" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "acs_df[[\"epc_2050\", \"epc_2050p\"]].sum()" + "# acs_df[[\"epc_2050\", \"epc_2050p\"]].sum()" ] }, { @@ -963,20 +993,20 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ - "acs_df.loc[acs_df[\"epc_2050\"].isnull(), \"epc_2050\"] = 0" + "# acs_df.loc[acs_df[\"epc_2050\"].isnull(), \"epc_2050\"] = 0" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ - "acs_df[\"c2050_2050p\"] = acs_df[\"epc_2050p\"] - acs_df[\"epc_2050\"]" + "# acs_df[\"c2050_2050p\"] = acs_df[\"epc_2050p\"] - acs_df[\"epc_2050\"]" ] }, { @@ -988,7 +1018,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -996,7 +1026,7 @@ " acs_df.agg(\n", " {\n", " \"pct_over75\": [\"mean\", \"std\"],\n", - " \"pct_minori\": [\"mean\", \"std\"],\n", + " \"pct_poc\": [\"mean\", \"std\"],\n", " \"pct_lep\": [\"mean\", \"std\"],\n", " \"pct_spfam\": [\"mean\", \"std\"],\n", " \"pct_below2\": [\"mean\", \"std\"],\n", @@ -1012,7 +1042,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -1021,13 +1051,13 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "epc_factors = {\n", " \"pct_over75\": \"Seniors 75 Years and Over\",\n", - " \"pct_minori\": \"Minorities\",\n", + " \"pct_poc\": \"People of Color\",\n", " \"pct_lep\": \"Limited English Proficiency\",\n", " \"pct_spfam\": \"Single Parent Families\",\n", " \"pct_below2\": \"Low-Income (<200% Federal Poverty Level-FPL)\",\n", @@ -1040,7 +1070,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -1057,7 +1087,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -1074,7 +1104,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -1111,19 +1141,19 @@ " 0\n", " Seniors 75 Years and Over\n", " 0.07\n", - " 0.05\n", + " 0.06\n", " 0.10\n", - " 0.12\n", - " 0.15\n", + " 0.13\n", + " 0.16\n", " \n", " \n", " 1\n", " Minorities\n", - " 0.60\n", + " 0.61\n", " 0.23\n", " 0.72\n", - " 0.83\n", - " 0.94\n", + " 0.84\n", + " 0.96\n", " \n", " \n", " 2\n", @@ -1146,10 +1176,10 @@ " \n", " 4\n", " Low-Income (<200% Federal Poverty Level-FPL)\n", - " 0.19\n", + " 0.18\n", " 0.13\n", - " 0.26\n", - " 0.32\n", + " 0.24\n", + " 0.31\n", " 0.38\n", " \n", " \n", @@ -1164,8 +1194,8 @@ " \n", " 6\n", " Zero-Vehicle Household\n", - " 0.09\n", - " 0.14\n", + " 0.10\n", + " 0.13\n", " 0.16\n", " 0.23\n", " 0.30\n", @@ -1185,27 +1215,27 @@ ], "text/plain": [ " factors mean std plus_half_sd \\\n", - "0 Seniors 75 Years and Over 0.07 0.05 0.10 \n", - "1 Minorities 0.60 0.23 0.72 \n", + "0 Seniors 75 Years and Over 0.07 0.06 0.10 \n", + "1 Minorities 0.61 0.23 0.72 \n", "2 Limited English Proficiency 0.07 0.08 0.11 \n", "3 Single Parent Families 0.12 0.09 0.16 \n", - "4 Low-Income (<200% Federal Poverty Level-FPL) 0.19 0.13 0.26 \n", + "4 Low-Income (<200% Federal Poverty Level-FPL) 0.18 0.13 0.24 \n", "5 People with Disability 0.10 0.05 0.12 \n", - "6 Zero-Vehicle Household 0.09 0.14 0.16 \n", + "6 Zero-Vehicle Household 0.10 0.13 0.16 \n", "7 Rent-Burdened 0.10 0.08 0.14 \n", "\n", " plus_one_sd plus_one_half_sd \n", - "0 0.12 0.15 \n", - "1 0.83 0.94 \n", + "0 0.13 0.16 \n", + "1 0.84 0.96 \n", "2 0.15 0.19 \n", "3 0.21 0.26 \n", - "4 0.32 0.38 \n", + "4 0.31 0.38 \n", "5 0.15 0.18 \n", "6 0.23 0.30 \n", "7 0.18 0.22 " ] }, - "execution_count": 46, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -1216,11 +1246,11 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ - "epc_region_stats.to_csv(\"Data/epc_regional_stats_ACS2021.csv\", index=False)" + "epc_region_stats.to_csv(\"Data/epc_regional_stats_ACS2022.csv\", index=False)" ] }, { @@ -1230,22 +1260,13 @@ "## Join census tracts geo to epc df" ] }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [], - "source": [ - "acs_df.rename(columns={\"tract_geoid20\": \"tract_geoid\"}, inplace=True)" - ] - }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ - "epc_gdf = pd.merge(acs_gdf, acs_df, on=\"tract_geoid\", how=\"inner\")" + "acs_df.rename(columns={\"tract_geoid20\": \"tract_geoid\"}, inplace=True)" ] }, { @@ -1254,8 +1275,7 @@ "metadata": {}, "outputs": [], "source": [ - "# # clip to water areas\n", - "# epc_erase_gdf = gpd.overlay(epc_gdf, water_area, how=\"difference\")" + "epc_gdf = pd.merge(acs_gdf, acs_df, on=\"tract_geoid\", how=\"inner\")" ] }, { @@ -1263,15 +1283,6 @@ "execution_count": 51, "metadata": {}, "outputs": [], - "source": [ - "# epc_erase_gdf.explore()" - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": {}, - "outputs": [], "source": [ "final_cols = [\n", " \"tract_geoid\",\n", @@ -1280,40 +1291,40 @@ " \"tot_pop_se\",\n", " \"tot_pop_po\",\n", " \"tot_pop_ci\",\n", + " \"tot_pop_ov\",\n", " \"tot_hh\",\n", - " \"pop_zvhhs\",\n", " \"tot_fam\",\n", - " \"tot_pop_ov\",\n", - " \"pop_hus_re\",\n", - " \"pop_minori\",\n", + " \"pop_poc\",\n", " \"pop_over75\",\n", " \"pop_spfam\",\n", " \"pop_lep\",\n", " \"pop_below2\",\n", " \"pop_disabi\",\n", - " \"pct_minori\",\n", + " \"pop_hus_re\",\n", + " \"pop_zvhhs\",\n", + " \"pct_poc\",\n", " \"pct_over75\",\n", " \"pct_spfam\",\n", " \"pct_lep\",\n", " \"pct_below2\",\n", " \"pct_disab\",\n", - " \"pct_zvhhs\",\n", " \"pct_hus_re\",\n", + " \"pct_zvhhs\",\n", + " \"poc_1_2\",\n", " \"over75_1_2\",\n", - " \"minori_1_2\",\n", " \"spfam_1_2\",\n", - " \"disab_1_2\",\n", " \"lep_1_2\",\n", + " \"disab_1_2\",\n", " \"below2_1_2\",\n", - " \"zvhh_1_2\",\n", " \"hus_re_1_2\",\n", + " \"zvhh_1_2\",\n", " \"epc_2050p\",\n", " \"epc_class\",\n", - " \"epc_2050\",\n", - " \"c2050_2050p\",\n", + " # \"epc_2050\",\n", + " # \"c2050_2050p\",\n", " \"geometry\",\n", "]\n", - "epc_path = \"Data/epc_acs2021.geojson\"\n", + "epc_path = \"Data/epc_acs2022.geojson\"\n", "epc_gdf[final_cols].to_file(epc_path, driver=\"GeoJSON\")" ] }, @@ -1321,2149 +1332,30 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Explore changes in geog" + "## Publish to arcgis online" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 52, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
2547060133072051POLYGON ((-121.85371 37.98550, -121.85291 37.9...06013307205
2548060133072051POLYGON ((-121.85371 37.98550, -121.85291 37.9...06013355107
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "2547 06013307205 1 \n", - "2548 06013307205 1 \n", - "\n", - " geometry tract_geoid20 \n", - "2547 POLYGON ((-121.85371 37.98550, -121.85291 37.9... 06013307205 \n", - "2548 POLYGON ((-121.85371 37.98550, -121.85291 37.9... 06013355107 " - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "pba50_epc_cross.query(\"tract_geoid10 =='06013307205'\")" + "publish_geojson_to_agol(\n", + " geojson_path=epc_path,\n", + " layer_name=\"DRAFT Equity Priority Communities - Plan Bay Area 2050 Plus (ACS 2022)\",\n", + " layer_snippet=\"\"\"This dataset represents tract information related to Equity Priority Communities \n", + " for Plan Bay Area 2050 Plus. The dataset was developed using American Community Survey 2018-2022 data for eight variables considered.\"\"\",\n", + " tags=\"bay area, equity, policy, planning, environmental justice, acs, american community survey, epc, community of concern\",\n", + " client=gis,\n", + " folder=\"plan_policy\",\n", + " # overwrite=True,\n", + " # f_layer_id=\"\",\n", + ")" ] }, { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
578060133553060POLYGON ((-121.98946 37.89978, -121.98154 37.9...06013355107
581060133553040POLYGON ((-121.95734 37.95211, -121.95467 37.9...06013355107
646060133551070POLYGON ((-121.92478 37.95806, -121.92372 37.9...06013355107
661060133551090POLYGON ((-121.80566 37.98249, -121.80273 37.9...06013355107
862060133071010POLYGON ((-121.82414 37.98504, -121.82285 37.9...06013355107
2548060133072051POLYGON ((-121.85371 37.98550, -121.85291 37.9...06013355107
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "578 06013355306 0 \n", - "581 06013355304 0 \n", - "646 06013355107 0 \n", - "661 06013355109 0 \n", - "862 06013307101 0 \n", - "2548 06013307205 1 \n", - "\n", - " geometry tract_geoid20 \n", - "578 POLYGON ((-121.98946 37.89978, -121.98154 37.9... 06013355107 \n", - "581 POLYGON ((-121.95734 37.95211, -121.95467 37.9... 06013355107 \n", - "646 POLYGON ((-121.92478 37.95806, -121.92372 37.9... 06013355107 \n", - "661 POLYGON ((-121.80566 37.98249, -121.80273 37.9... 06013355107 \n", - "862 POLYGON ((-121.82414 37.98504, -121.82285 37.9... 06013355107 \n", - "2548 POLYGON ((-121.85371 37.98550, -121.85291 37.9... 06013355107 " - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid20 == '06013355107'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
OID_TRACT_20tract_geoid20NAMELSAD_TRACT_20AREALAND_TRACT_20AREAWATER_TRACT_20MTFCC_TRACT_20FUNCSTAT_TRACT_20OID_TRACT_10tract_geoid10NAMELSAD_TRACT_10AREALAND_TRACT_10AREAWATER_TRACT_10MTFCC_TRACT_10FUNCSTAT_TRACT_10AREALAND_PARTAREAWATER_PART
761620790371710654006013355107Census Tract 3551.0782054530498136G5020S2074014618263106013307101Census Tract 3071.0121327890G5020S6520
761720790371710654006013355107Census Tract 3551.0782054530498136G5020S2074014618249806013307205Census Tract 3072.0530765550G5020S223470
761820790371710654006013355107Census Tract 3551.0782054530498136G5020S20740371710654006013355107Census Tract 3551.0781989507498136G5020S81971676498136
761920790371710654006013355107Census Tract 3551.0782054530498136G5020S20740371710695206013355109Census Tract 3551.0930406990G5020S564830
762020790371710654006013355107Census Tract 3551.0782054530498136G5020S2074014618329706013355304Census Tract 3553.0498141540G5020S170
762120790371710654006013355107Census Tract 3551.0782054530498136G5020S20740371710699406013355306Census Tract 3553.06671681155020G5020S33550
\n", - "
" - ], - "text/plain": [ - " OID_TRACT_20 tract_geoid20 NAMELSAD_TRACT_20 AREALAND_TRACT_20 \\\n", - "7616 207903717106540 06013355107 Census Tract 3551.07 82054530 \n", - "7617 207903717106540 06013355107 Census Tract 3551.07 82054530 \n", - "7618 207903717106540 06013355107 Census Tract 3551.07 82054530 \n", - "7619 207903717106540 06013355107 Census Tract 3551.07 82054530 \n", - "7620 207903717106540 06013355107 Census Tract 3551.07 82054530 \n", - "7621 207903717106540 06013355107 Census Tract 3551.07 82054530 \n", - "\n", - " AREAWATER_TRACT_20 MTFCC_TRACT_20 FUNCSTAT_TRACT_20 OID_TRACT_10 \\\n", - "7616 498136 G5020 S 20740146182631 \n", - "7617 498136 G5020 S 20740146182498 \n", - "7618 498136 G5020 S 207403717106540 \n", - "7619 498136 G5020 S 207403717106952 \n", - "7620 498136 G5020 S 20740146183297 \n", - "7621 498136 G5020 S 207403717106994 \n", - "\n", - " tract_geoid10 NAMELSAD_TRACT_10 AREALAND_TRACT_10 AREAWATER_TRACT_10 \\\n", - "7616 06013307101 Census Tract 3071.01 2132789 0 \n", - "7617 06013307205 Census Tract 3072.05 3076555 0 \n", - "7618 06013355107 Census Tract 3551.07 81989507 498136 \n", - "7619 06013355109 Census Tract 3551.09 3040699 0 \n", - "7620 06013355304 Census Tract 3553.04 9814154 0 \n", - "7621 06013355306 Census Tract 3553.06 67168115 5020 \n", - "\n", - " MTFCC_TRACT_10 FUNCSTAT_TRACT_10 AREALAND_PART AREAWATER_PART \n", - "7616 G5020 S 652 0 \n", - "7617 G5020 S 22347 0 \n", - "7618 G5020 S 81971676 498136 \n", - "7619 G5020 S 56483 0 \n", - "7620 G5020 S 17 0 \n", - "7621 G5020 S 3355 0 " - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "census_vintage_crosswalk.query(\"tract_geoid20 == '06013355107'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [], - "source": [ - "# pba50_epc_cross.query(\"tract_geoid10 =='06013307205'\").explore()" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
Make this Notebook Trusted to load map: File -> Trust Notebook
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "m = pba50_epc_cross.query(\"tract_geoid10 == '06013307205'\").explore()\n", - "epc_gdf.query(\"tract_geoid == '06013355107'\").explore(m=m, color=\"red\")" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
2581060133361011POLYGON ((-122.03730 37.97333, -122.03601 37.9...06013328000
2582060133361011POLYGON ((-122.03730 37.97333, -122.03601 37.9...06013336101
2583060133361011POLYGON ((-122.03730 37.97333, -122.03601 37.9...06013337100
2584060133361011POLYGON ((-122.03730 37.97333, -122.03601 37.9...06013337202
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "2581 06013336101 1 \n", - "2582 06013336101 1 \n", - "2583 06013336101 1 \n", - "2584 06013336101 1 \n", - "\n", - " geometry tract_geoid20 \n", - "2581 POLYGON ((-122.03730 37.97333, -122.03601 37.9... 06013328000 \n", - "2582 POLYGON ((-122.03730 37.97333, -122.03601 37.9... 06013336101 \n", - "2583 POLYGON ((-122.03730 37.97333, -122.03601 37.9... 06013337100 \n", - "2584 POLYGON ((-122.03730 37.97333, -122.03601 37.9... 06013337202 " - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid10 =='06013336101'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
762060133371000POLYGON ((-122.03111 37.96835, -122.02331 37.9...06013337202
777060133372000POLYGON ((-122.03897 37.95637, -122.03568 37.9...06013337202
2584060133361011POLYGON ((-122.03730 37.97333, -122.03601 37.9...06013337202
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "762 06013337100 0 \n", - "777 06013337200 0 \n", - "2584 06013336101 1 \n", - "\n", - " geometry tract_geoid20 \n", - "762 POLYGON ((-122.03111 37.96835, -122.02331 37.9... 06013337202 \n", - "777 POLYGON ((-122.03897 37.95637, -122.03568 37.9... 06013337202 \n", - "2584 POLYGON ((-122.03730 37.97333, -122.03601 37.9... 06013337202 " - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid20 == '06013337202'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
Make this Notebook Trusted to load map: File -> Trust Notebook
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "m = pba50_epc_cross.query(\"tract_geoid10 == '06013336101'\").explore()\n", - "epc_gdf.query(\"tract_geoid == '06013337202'\").explore(m=m, color=\"red\")" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
2255060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001400800
2256060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001420401
2257060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001420402
2258060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001422000
2259060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001425102
2260060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001425103
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "2255 06001422000 1 \n", - "2256 06001422000 1 \n", - "2257 06001422000 1 \n", - "2258 06001422000 1 \n", - "2259 06001422000 1 \n", - "2260 06001422000 1 \n", - "\n", - " geometry tract_geoid20 \n", - "2255 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001400800 \n", - "2256 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001420401 \n", - "2257 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001420402 \n", - "2258 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001422000 \n", - "2259 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001425102 \n", - "2260 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001425103 " - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid10 =='06001422000'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
286060014203000POLYGON ((-122.32691 37.89249, -122.31544 37.8...06001420402
323060014204000POLYGON ((-122.32691 37.88965, -122.31232 37.8...06001420402
2257060014220001POLYGON ((-122.32519 37.87428, -122.31866 37.8...06001420402
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "286 06001420300 0 \n", - "323 06001420400 0 \n", - "2257 06001422000 1 \n", - "\n", - " geometry tract_geoid20 \n", - "286 POLYGON ((-122.32691 37.89249, -122.31544 37.8... 06001420402 \n", - "323 POLYGON ((-122.32691 37.88965, -122.31232 37.8... 06001420402 \n", - "2257 POLYGON ((-122.32519 37.87428, -122.31866 37.8... 06001420402 " - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid20 =='06001420402'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
Make this Notebook Trusted to load map: File -> Trust Notebook
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "m = pba50_epc_cross.query(\"tract_geoid10 == '06001422000'\").explore()\n", - "epc_gdf[[\"tract_geoid\",'c2050_2050p',\"geometry\"]].query(\"tract_geoid == '06001420402'\").explore(m=m, color=\"red\")" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
2713060750230011POLYGON ((-122.40685 37.73805, -122.39969 37.7...06075023001
2714060750230011POLYGON ((-122.40685 37.73805, -122.39969 37.7...06075980900
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "2713 06075023001 1 \n", - "2714 06075023001 1 \n", - "\n", - " geometry tract_geoid20 \n", - "2713 POLYGON ((-122.40685 37.73805, -122.39969 37.7... 06075023001 \n", - "2714 POLYGON ((-122.40685 37.73805, -122.39969 37.7... 06075980900 " - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid10 =='06075023001'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
tract_geoid10epc_2050geometrytract_geoid20
1068060759809000POLYGON ((-122.40695 37.74050, -122.40459 37.7...06075980900
1178060750251000POLYGON ((-122.41066 37.74242, -122.40938 37.7...06075980900
2714060750230011POLYGON ((-122.40685 37.73805, -122.39969 37.7...06075980900
\n", - "
" - ], - "text/plain": [ - " tract_geoid10 epc_2050 \\\n", - "1068 06075980900 0 \n", - "1178 06075025100 0 \n", - "2714 06075023001 1 \n", - "\n", - " geometry tract_geoid20 \n", - "1068 POLYGON ((-122.40695 37.74050, -122.40459 37.7... 06075980900 \n", - "1178 POLYGON ((-122.41066 37.74242, -122.40938 37.7... 06075980900 \n", - "2714 POLYGON ((-122.40685 37.73805, -122.39969 37.7... 06075980900 " - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pba50_epc_cross.query(\"tract_geoid20 =='06075980900'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
Make this Notebook Trusted to load map: File -> Trust Notebook
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "m = pba50_epc_cross.query(\"tract_geoid10 == '06075023001'\").explore()\n", - "epc_gdf[[\"tract_geoid\",'c2050_2050p',\"geometry\"]].query(\"tract_geoid.isin(['06075023001','06075980900'])\").explore(m=m, color=\"red\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Publish to arcgis online" - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": {}, - "outputs": [], - "source": [ - "# # Add item to ArcGIS Online\n", - "# item_properties = {\n", - "# \"type\": \"GeoJson\",\n", - "# \"description\": \"This data set represents tract information related to Equity Priority Communities for Plan Bay Area 2050 +. The data set was developed using American Community Survey 2017-2021 data for eight variables considered.\",\n", - "# \"title\": \"DRAFT Equity Priority Communities - Plan Bay Area 2050 +\",\n", - "# \"tags\": \"bay area, equity, policy, planning, environmental justice, acs, american community survey, epc, community of concern\",\n", - "# \"overwrite\": True,\n", - "# }\n", - "# item = gis.content.add(item_properties, data=epc_path, folder=\"plan_policy\")" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [], - "source": [ - "# # Publish item as feature service\n", - "# item.publish(file_type=\"geojson\")" - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": {}, - "outputs": [], - "source": [ - "# Get published feature service feature layer id\n", - "flid = \"68eb6442d92143caaa9766855bff296d\"\n", - "fl = gis.content.get(flid)" - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "
\n", - " \n", - " \n", - " \n", - "
\n", - "\n", - "
\n", - " DRAFT Equity Priority Communities - Plan Bay Area 2050\n", - " \n", - "
This data set represents tract information related to Equity Priority Communities for Plan Bay Area 2050 +. The data set was developed using American Community Survey 2017-2021 data for eight variables considered.Feature Layer Collection by content_MTC\n", - "
Last Modified: October 03, 2023\n", - "
0 comments, 48 views\n", - "
\n", - "
\n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 79, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "fl" - ] - }, - { - "cell_type": "code", - "execution_count": 80, - "metadata": {}, - "outputs": [ - { - "ename": "Exception", - "evalue": "User cannot overwrite this service, using this data, as this data is already referring to another service.\n(Error Code: 500)", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/Users/jcroff/Documents/GitHub/Spatial-Analysis-Mapping-Projects/Project-Documentation/Equity-Priority-Communities/equity_priority_communities_build.ipynb Cell 94\u001b[0m line \u001b[0;36m5\n\u001b[1;32m 2\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39marcgis\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mfeatures\u001b[39;00m \u001b[39mimport\u001b[39;00m FeatureLayerCollection\n\u001b[1;32m 4\u001b[0m flc \u001b[39m=\u001b[39m FeatureLayerCollection\u001b[39m.\u001b[39mfromitem(fl)\n\u001b[0;32m----> 5\u001b[0m flc\u001b[39m.\u001b[39;49mmanager\u001b[39m.\u001b[39;49moverwrite(epc_path)\n", - "File \u001b[0;32m~/anaconda3/envs/geo_env/lib/python3.10/site-packages/arcgis/features/managers.py:2270\u001b[0m, in \u001b[0;36mFeatureLayerCollectionManager.overwrite\u001b[0;34m(self, data_file)\u001b[0m\n\u001b[1;32m 2266\u001b[0m \u001b[39m# endregion\u001b[39;00m\n\u001b[1;32m 2267\u001b[0m \n\u001b[1;32m 2268\u001b[0m \u001b[39m# region Perform overwriting\u001b[39;00m\n\u001b[1;32m 2269\u001b[0m \u001b[39mif\u001b[39;00m related_data_item\u001b[39m.\u001b[39mupdate(item_properties\u001b[39m=\u001b[39mparams, data\u001b[39m=\u001b[39mdata_file):\n\u001b[0;32m-> 2270\u001b[0m published_item \u001b[39m=\u001b[39m related_data_item\u001b[39m.\u001b[39;49mpublish(\n\u001b[1;32m 2271\u001b[0m publish_parameters, overwrite\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m\n\u001b[1;32m 2272\u001b[0m )\n\u001b[1;32m 2273\u001b[0m \u001b[39mif\u001b[39;00m published_item \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 2274\u001b[0m \u001b[39mreturn\u001b[39;00m {\u001b[39m\"\u001b[39m\u001b[39msuccess\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mTrue\u001b[39;00m}\n", - "File \u001b[0;32m~/anaconda3/envs/geo_env/lib/python3.10/site-packages/arcgis/gis/__init__.py:12668\u001b[0m, in \u001b[0;36mItem.publish\u001b[0;34m(self, publish_parameters, address_fields, output_type, overwrite, file_type, build_initial_cache, item_id, geocode_service)\u001b[0m\n\u001b[1;32m 12665\u001b[0m \u001b[39m# do general update\u001b[39;00m\n\u001b[1;32m 12666\u001b[0m publish_parameters\u001b[39m.\u001b[39mupdate(publish_parameters_orig)\n\u001b[0;32m> 12668\u001b[0m ret \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_portal\u001b[39m.\u001b[39;49mpublish_item(\n\u001b[1;32m 12669\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mitemid,\n\u001b[1;32m 12670\u001b[0m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m 12671\u001b[0m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m 12672\u001b[0m fileType,\n\u001b[1;32m 12673\u001b[0m publish_parameters,\n\u001b[1;32m 12674\u001b[0m output_type,\n\u001b[1;32m 12675\u001b[0m overwrite,\n\u001b[1;32m 12676\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mowner,\n\u001b[1;32m 12677\u001b[0m folder,\n\u001b[1;32m 12678\u001b[0m buildInitialCache,\n\u001b[1;32m 12679\u001b[0m item_id\u001b[39m=\u001b[39;49mitem_id,\n\u001b[1;32m 12680\u001b[0m )\n\u001b[1;32m 12682\u001b[0m \u001b[39m# Check publishing job status\u001b[39;00m\n\u001b[1;32m 12684\u001b[0m \u001b[39mif\u001b[39;00m (\n\u001b[1;32m 12685\u001b[0m buildInitialCache\n\u001b[1;32m 12686\u001b[0m \u001b[39mand\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_gis\u001b[39m.\u001b[39m_portal\u001b[39m.\u001b[39mis_arcgisonline\n\u001b[1;32m 12687\u001b[0m \u001b[39mand\u001b[39;00m fileType\u001b[39m.\u001b[39mlower() \u001b[39min\u001b[39;00m [\u001b[39m\"\u001b[39m\u001b[39mtilepackage\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mcompacttilepackage\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[1;32m 12688\u001b[0m ):\n", - "File \u001b[0;32m~/anaconda3/envs/geo_env/lib/python3.10/site-packages/arcgis/gis/_impl/_portalpy.py:460\u001b[0m, in \u001b[0;36mPortal.publish_item\u001b[0;34m(self, itemid, data, text, fileType, publishParameters, outputType, overwrite, owner, folder, buildInitialCache, item_id)\u001b[0m\n\u001b[1;32m 458\u001b[0m path \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m folder\n\u001b[1;32m 459\u001b[0m path \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/publish\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m--> 460\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcon\u001b[39m.\u001b[39;49mpost(path, postdata, files)\n\u001b[1;32m 461\u001b[0m \u001b[39mif\u001b[39;00m resp:\n\u001b[1;32m 462\u001b[0m \u001b[39mreturn\u001b[39;00m resp[\u001b[39m\"\u001b[39m\u001b[39mservices\u001b[39m\u001b[39m\"\u001b[39m]\n", - "File \u001b[0;32m~/anaconda3/envs/geo_env/lib/python3.10/site-packages/arcgis/gis/_impl/_con/_connection.py:1074\u001b[0m, in \u001b[0;36mConnection.post\u001b[0;34m(self, path, params, files, **kwargs)\u001b[0m\n\u001b[1;32m 1072\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mException\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mAn unknown error occurred: \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m traceback\u001b[39m.\u001b[39mformat_exc())\n\u001b[1;32m 1073\u001b[0m retry_count \u001b[39m=\u001b[39m \u001b[39m0\u001b[39m\n\u001b[0;32m-> 1074\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_handle_response(\n\u001b[1;32m 1075\u001b[0m resp\u001b[39m=\u001b[39;49mresp,\n\u001b[1;32m 1076\u001b[0m out_path\u001b[39m=\u001b[39;49mout_path,\n\u001b[1;32m 1077\u001b[0m file_name\u001b[39m=\u001b[39;49mfile_name,\n\u001b[1;32m 1078\u001b[0m try_json\u001b[39m=\u001b[39;49mtry_json,\n\u001b[1;32m 1079\u001b[0m force_bytes\u001b[39m=\u001b[39;49mkwargs\u001b[39m.\u001b[39;49mpop(\u001b[39m\"\u001b[39;49m\u001b[39mforce_bytes\u001b[39;49m\u001b[39m\"\u001b[39;49m, \u001b[39mFalse\u001b[39;49;00m),\n\u001b[1;32m 1080\u001b[0m )\n", - "File \u001b[0;32m~/anaconda3/envs/geo_env/lib/python3.10/site-packages/arcgis/gis/_impl/_con/_connection.py:625\u001b[0m, in \u001b[0;36mConnection._handle_response\u001b[0;34m(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[39mreturn\u001b[39;00m data\n\u001b[1;32m 624\u001b[0m errorcode \u001b[39m=\u001b[39m data[\u001b[39m\"\u001b[39m\u001b[39merror\u001b[39m\u001b[39m\"\u001b[39m][\u001b[39m\"\u001b[39m\u001b[39mcode\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39mcode\u001b[39m\u001b[39m\"\u001b[39m \u001b[39min\u001b[39;00m data[\u001b[39m\"\u001b[39m\u001b[39merror\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39melse\u001b[39;00m \u001b[39m0\u001b[39m\n\u001b[0;32m--> 625\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_handle_json_error(data[\u001b[39m\"\u001b[39;49m\u001b[39merror\u001b[39;49m\u001b[39m\"\u001b[39;49m], errorcode)\n\u001b[1;32m 626\u001b[0m \u001b[39mreturn\u001b[39;00m data\n\u001b[1;32m 627\u001b[0m \u001b[39melse\u001b[39;00m:\n", - "File \u001b[0;32m~/anaconda3/envs/geo_env/lib/python3.10/site-packages/arcgis/gis/_impl/_con/_connection.py:648\u001b[0m, in \u001b[0;36mConnection._handle_json_error\u001b[0;34m(self, error, errorcode)\u001b[0m\n\u001b[1;32m 645\u001b[0m \u001b[39m# _log.error(errordetail)\u001b[39;00m\n\u001b[1;32m 647\u001b[0m errormessage \u001b[39m=\u001b[39m errormessage \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m(Error Code: \u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m \u001b[39mstr\u001b[39m(errorcode) \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m--> 648\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mException\u001b[39;00m(errormessage)\n", - "\u001b[0;31mException\u001b[0m: User cannot overwrite this service, using this data, as this data is already referring to another service.\n(Error Code: 500)" - ] - } - ], - "source": [ - "# overwrite feature service\n", - "from arcgis.features import FeatureLayerCollection\n", - "\n", - "flc = FeatureLayerCollection.fromitem(fl)\n", - "flc.manager.overwrite(epc_path)" - ] - }, - { - "cell_type": "markdown", + "cell_type": "markdown", "metadata": {}, "source": [ "### Create Field Map Dictionary to Rename Feature Class Alias" @@ -3475,7 +1367,7 @@ "metadata": {}, "outputs": [], "source": [ - "field_metadata = pd.read_csv(\"Data/EPC_Schema_pba2050p.csv\")" + "# field_metadata = pd.read_csv(\"Data/EPC_Schema_pba2050p.csv\")" ] }, { @@ -3484,7 +1376,7 @@ "metadata": {}, "outputs": [], "source": [ - "field_metadata.head(5)" + "# field_metadata.head(5)" ] }, { @@ -3493,15 +1385,8 @@ "metadata": {}, "outputs": [], "source": [ - "dict(zip(field_metadata[\"Field Name\"], field_metadata[\"Alias\"]))" + "# dict(zip(field_metadata[\"Field Name\"], field_metadata[\"Alias\"]))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {