From ed8293efcb2c0075c399fd2156332cca83997a19 Mon Sep 17 00:00:00 2001 From: Sam Powers <121890478+sampowers-usds@users.noreply.github.com> Date: Fri, 3 Feb 2023 14:11:08 -0500 Subject: [PATCH] ipython notebook to debug greenspace indicator --- .../ipython/greenspace_indicator.ipynb | 1758 +++++++++++++++++ 1 file changed, 1758 insertions(+) create mode 100644 data/data-pipeline/data_pipeline/ipython/greenspace_indicator.ipynb diff --git a/data/data-pipeline/data_pipeline/ipython/greenspace_indicator.ipynb b/data/data-pipeline/data_pipeline/ipython/greenspace_indicator.ipynb new file mode 100644 index 00000000..ade49b04 --- /dev/null +++ b/data/data-pipeline/data_pipeline/ipython/greenspace_indicator.ipynb @@ -0,0 +1,1758 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 152, + "id": "72828ab5", + "metadata": {}, + "outputs": [], + "source": [ + "library(tidyverse)\n", + "library(rjson)" + ] + }, + { + "cell_type": "markdown", + "id": "8ade6145", + "metadata": {}, + "source": [ + "Read in the downloaded data set" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "896cb958", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "\u001b[36m──\u001b[39m \u001b[1m\u001b[1mColumn specification\u001b[1m\u001b[22m \u001b[36m────────────────────────────────────────────────────────\u001b[39m\n", + "cols(\n", + " GEOID10_TRACT = \u001b[32mcol_double()\u001b[39m,\n", + " `Does the tract have at least 35 acres in it?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Share of the tract's land area that is covered by impervious surface as a percent` = \u001b[32mcol_double()\u001b[39m,\n", + " `Share of the tract's land area that is covered by impervious surface or cropland as a percent` = \u001b[32mcol_double()\u001b[39m,\n", + " `Share of the tract's land area that is covered by cropland as a percent` = \u001b[32mcol_double()\u001b[39m\n", + ")\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\n", + "
A tibble: 6 × 5
GEOID10_TRACTDoes the tract have at least 35 acres in it?Share of the tract's land area that is covered by impervious surface as a percentShare of the tract's land area that is covered by impervious surface or cropland as a percentShare of the tract's land area that is covered by cropland as a percent
<dbl><lgl><dbl><dbl><dbl>
27139080202TRUE37.361037.5887 0.227730
27139080204TRUE26.897927.6588 0.760943
27139080100TRUE39.451639.9349 0.483341
27139080302TRUE18.260537.639119.378600
27139080400TRUE47.438148.4268 0.988653
27139080500TRUE42.809943.9226 1.112750
\n" + ], + "text/latex": [ + "A tibble: 6 × 5\n", + "\\begin{tabular}{lllll}\n", + " GEOID10\\_TRACT & Does the tract have at least 35 acres in it? & Share of the tract's land area that is covered by impervious surface as a percent & Share of the tract's land area that is covered by impervious surface or cropland as a percent & Share of the tract's land area that is covered by cropland as a percent\\\\\n", + " & & & & \\\\\n", + "\\hline\n", + "\t 27139080202 & TRUE & 37.3610 & 37.5887 & 0.227730\\\\\n", + "\t 27139080204 & TRUE & 26.8979 & 27.6588 & 0.760943\\\\\n", + "\t 27139080100 & TRUE & 39.4516 & 39.9349 & 0.483341\\\\\n", + "\t 27139080302 & TRUE & 18.2605 & 37.6391 & 19.378600\\\\\n", + "\t 27139080400 & TRUE & 47.4381 & 48.4268 & 0.988653\\\\\n", + "\t 27139080500 & TRUE & 42.8099 & 43.9226 & 1.112750\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 6 × 5\n", + "\n", + "| GEOID10_TRACT <dbl> | Does the tract have at least 35 acres in it? <lgl> | Share of the tract's land area that is covered by impervious surface as a percent <dbl> | Share of the tract's land area that is covered by impervious surface or cropland as a percent <dbl> | Share of the tract's land area that is covered by cropland as a percent <dbl> |\n", + "|---|---|---|---|---|\n", + "| 27139080202 | TRUE | 37.3610 | 37.5887 | 0.227730 |\n", + "| 27139080204 | TRUE | 26.8979 | 27.6588 | 0.760943 |\n", + "| 27139080100 | TRUE | 39.4516 | 39.9349 | 0.483341 |\n", + "| 27139080302 | TRUE | 18.2605 | 37.6391 | 19.378600 |\n", + "| 27139080400 | TRUE | 47.4381 | 48.4268 | 0.988653 |\n", + "| 27139080500 | TRUE | 42.8099 | 43.9226 | 1.112750 |\n", + "\n" + ], + "text/plain": [ + " GEOID10_TRACT Does the tract have at least 35 acres in it?\n", + "1 27139080202 TRUE \n", + "2 27139080204 TRUE \n", + "3 27139080100 TRUE \n", + "4 27139080302 TRUE \n", + "5 27139080400 TRUE \n", + "6 27139080500 TRUE \n", + " Share of the tract's land area that is covered by impervious surface as a percent\n", + "1 37.3610 \n", + "2 26.8979 \n", + "3 39.4516 \n", + "4 18.2605 \n", + "5 47.4381 \n", + "6 42.8099 \n", + " Share of the tract's land area that is covered by impervious surface or cropland as a percent\n", + "1 37.5887 \n", + "2 27.6588 \n", + "3 39.9349 \n", + "4 37.6391 \n", + "5 48.4268 \n", + "6 43.9226 \n", + " Share of the tract's land area that is covered by cropland as a percent\n", + "1 0.227730 \n", + "2 0.760943 \n", + "3 0.483341 \n", + "4 19.378600 \n", + "5 0.988653 \n", + "6 1.112750 " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "nlcd_dat_path = list.files(\"../data/dataset/nlcd_nature_deprived\", full.names = TRUE)\n", + "nlcd_raw_dat = read_csv(nlcd_dat_path)\n", + "head(nlcd_raw_dat)" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "id": "99ea6633", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "0" + ], + "text/latex": [ + "0" + ], + "text/markdown": [ + "0" + ], + "text/plain": [ + "[1] 0" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "72539" + ], + "text/latex": [ + "72539" + ], + "text/markdown": [ + "72539" + ], + "text/plain": [ + "[1] 72539" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "impervious_in = pull(nlcd_raw_dat,4) ## impervious surfaces or cropland\n", + "sum(impervious_in[is.na(impervious_in)]) ## check for missing data\n", + "length(impervious_in)\n", + "sum(impervious_in >= quantile(impervious_in, .9)) ## calculate the number at or above 90th percentile" + ] + }, + { + "cell_type": "markdown", + "id": "f9489512", + "metadata": {}, + "source": [ + "There are 7254 tracts in the read in that have an impervious surface percent above the 90%" + ] + }, + { + "cell_type": "markdown", + "id": "61a16a12", + "metadata": {}, + "source": [ + " Then the data gets pulled into an ETL process and combined into one data set where scores are calculated. Lets check that output.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "a8a4fb7b", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "\u001b[36m──\u001b[39m \u001b[1m\u001b[1mColumn specification\u001b[1m\u001b[22m \u001b[36m────────────────────────────────────────────────────────\u001b[39m\n", + "cols(\n", + " .default = col_double(),\n", + " GEOID10_TRACT = \u001b[31mcol_character()\u001b[39m,\n", + " `Does the tract have at least 35 acres in it?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Contains agricultural value` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Names of Tribal areas within Census tract` = \u001b[31mcol_character()\u001b[39m,\n", + " `Percent individuals age 25 or over with less than high school degree in 2009` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Percentage households below 100% of federal poverty line in 2009` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Unemployment (percent) in 2009` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Total population in 2009` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Number of Tribal areas within Census tract for Alaska` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Number of Tribal areas within Census tract` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Median household income as a percent of territory median income in 2009` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Is there at least one abandoned mine in this census tract?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Income data has been estimated based on neighbor income` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Is there at least one Formerly Used Defense Site (FUDS) in the tract?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Tract-level redlining score meets or exceeds 3.25` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Identified as disadvantaged due to tribal overlap` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Percent individuals age 25 or over with less than high school degree in 2009 (percentile)` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Percentage households below 100% of federal poverty line in 2009 (percentile)` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Unemployment (percent) in 2009 (percentile)` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Total population in 2009 (percentile)` = \u001b[33mcol_logical()\u001b[39m\n", + " # ... with 103 more columns\n", + ")\n", + "\u001b[36mℹ\u001b[39m Use \u001b[30m\u001b[47m\u001b[30m\u001b[47m`spec()`\u001b[47m\u001b[30m\u001b[49m\u001b[39m for the full column specifications.\n", + "\n", + "\n", + "Warning message:\n", + "“2219 parsing failures.\n", + " row col expected actual file\n", + "1182 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 1.0 '../data/score/csv/full/usa.csv'\n", + "1182 Number of Tribal areas within Census tract for Alaska (percentile) 1/0/T/F/TRUE/FALSE 0.19230769230769232 '../data/score/csv/full/usa.csv'\n", + "1183 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 4.0 '../data/score/csv/full/usa.csv'\n", + "1183 Number of Tribal areas within Census tract for Alaska (percentile) 1/0/T/F/TRUE/FALSE 0.6634615384615384 '../data/score/csv/full/usa.csv'\n", + "1184 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 3.0 '../data/score/csv/full/usa.csv'\n", + ".... .................................................................. .................. ................... ................................\n", + "See problems(...) for more details.\n", + "”\n" + ] + } + ], + "source": [ + "score_data_full_path = list.files(\"../data/score/csv/full\", full.names = TRUE)[2]\n", + "score_dat_full = read_csv(score_data_full_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "d6953e4d", + "metadata": {}, + "outputs": [], + "source": [ + "score_full_cols = colnames(score_dat_full)\n", + "score_full_cols\n", + "impervious_cols = score_full_cols[grepl(\"impervious\", score_full_cols)]\n", + "score_dat_impervious = score_dat_full[,impervious_cols ]\n", + "head(score_dat_impervious)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "4def474c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\n", + "
A tibble: 6 × 4
Share of the tract's land area that is covered by impervious surface or cropland as a percentShare of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percentGreater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?
<dbl><dbl><lgl><lgl>
21.24750.2685590FALSEFALSE
42.12540.5569694FALSEFALSE
18.37480.2323578FALSEFALSE
37.92300.4961469FALSEFALSE
51.48350.6894912FALSEFALSE
54.54830.7298005FALSEFALSE
\n" + ], + "text/latex": [ + "A tibble: 6 × 4\n", + "\\begin{tabular}{llll}\n", + " Share of the tract's land area that is covered by impervious surface or cropland as a percent & Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile) & Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent & Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?\\\\\n", + " & & & \\\\\n", + "\\hline\n", + "\t 21.2475 & 0.2685590 & FALSE & FALSE\\\\\n", + "\t 42.1254 & 0.5569694 & FALSE & FALSE\\\\\n", + "\t 18.3748 & 0.2323578 & FALSE & FALSE\\\\\n", + "\t 37.9230 & 0.4961469 & FALSE & FALSE\\\\\n", + "\t 51.4835 & 0.6894912 & FALSE & FALSE\\\\\n", + "\t 54.5483 & 0.7298005 & FALSE & FALSE\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 6 × 4\n", + "\n", + "| Share of the tract's land area that is covered by impervious surface or cropland as a percent <dbl> | Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile) <dbl> | Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent <lgl> | Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income? <lgl> |\n", + "|---|---|---|---|\n", + "| 21.2475 | 0.2685590 | FALSE | FALSE |\n", + "| 42.1254 | 0.5569694 | FALSE | FALSE |\n", + "| 18.3748 | 0.2323578 | FALSE | FALSE |\n", + "| 37.9230 | 0.4961469 | FALSE | FALSE |\n", + "| 51.4835 | 0.6894912 | FALSE | FALSE |\n", + "| 54.5483 | 0.7298005 | FALSE | FALSE |\n", + "\n" + ], + "text/plain": [ + " Share of the tract's land area that is covered by impervious surface or cropland as a percent\n", + "1 21.2475 \n", + "2 42.1254 \n", + "3 18.3748 \n", + "4 37.9230 \n", + "5 51.4835 \n", + "6 54.5483 \n", + " Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)\n", + "1 0.2685590 \n", + "2 0.5569694 \n", + "3 0.2323578 \n", + "4 0.4961469 \n", + "5 0.6894912 \n", + "6 0.7298005 \n", + " Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent\n", + "1 FALSE \n", + "2 FALSE \n", + "3 FALSE \n", + "4 FALSE \n", + "5 FALSE \n", + "6 FALSE \n", + " Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?\n", + "1 FALSE \n", + "2 FALSE \n", + "3 FALSE \n", + "4 FALSE \n", + "5 FALSE \n", + "6 FALSE " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "90f2ec46", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "1595" + ], + "text/latex": [ + "1595" + ], + "text/markdown": [ + "1595" + ], + "text/plain": [ + "[1] 1595" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "1595" + ], + "text/latex": [ + "1595" + ], + "text/markdown": [ + "1595" + ], + "text/plain": [ + "[1] 1595" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# check base score.\n", + "sum(is.na(score_dat_impervious[,1]))\n", + "nrow(score_dat_impervious) - length(impervious_in) ## the missing tracts were initiated after the join. they aren't in the original data set. Its likely because of the CONUS issue. \n", + "sum(score_dat_impervious[,1] >= quantile(score_dat_impervious[,1], .9, na.rm = TRUE), na.rm = TRUE) ## calculate the number at or above 90th percentile" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "0aa90b2b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Check the calculated percentile\n", + "sum(score_dat_impervious[, 2] >= .9, na.rm = TRUE)\n", + "## the calculated percentile lines up" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "8ec31ba9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Check in on the TRUE/FALSE Flag\n", + "sum(score_dat_impervious[,3] == TRUE)\n", + "## okay, the flag here is correct as well. So where does it go wrong?" + ] + }, + { + "cell_type": "markdown", + "id": "a8199ac4", + "metadata": {}, + "source": [ + "Next, the data gets post processed to add in demographic information about the tracts" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "bcd854e3", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "\u001b[36m──\u001b[39m \u001b[1m\u001b[1mColumn specification\u001b[1m\u001b[22m \u001b[36m────────────────────────────────────────────────────────\u001b[39m\n", + "cols(\n", + " .default = col_double(),\n", + " `Census tract 2010 ID` = \u001b[31mcol_character()\u001b[39m,\n", + " `County Name` = \u001b[31mcol_character()\u001b[39m,\n", + " `State/Territory` = \u001b[31mcol_character()\u001b[39m,\n", + " `Identified as disadvantaged without considering neighbors` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Identified as disadvantaged based on neighbors and relaxed low income threshold only` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Identified as disadvantaged due to tribal overlap` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Identified as disadvantaged` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Income data has been estimated based on geographic neighbor income` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for expected agriculture loss rate and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for expected building loss rate and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for expected population loss rate and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for share of properties at risk of flood in 30 years` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for share of properties at risk of flood in 30 years and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for share of properties at risk of fire in 30 years` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for share of properties at risk of fire in 30 years and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for energy burden and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for PM2.5 exposure and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for diesel particulate matter and is low income?` = \u001b[33mcol_logical()\u001b[39m,\n", + " `Greater than or equal to the 90th percentile for traffic proximity and is low income?` = \u001b[33mcol_logical()\u001b[39m\n", + " # ... with 32 more columns\n", + ")\n", + "\u001b[36mℹ\u001b[39m Use \u001b[30m\u001b[47m\u001b[30m\u001b[47m`spec()`\u001b[47m\u001b[30m\u001b[49m\u001b[39m for the full column specifications.\n", + "\n", + "\n", + "Warning message:\n", + "“52 parsing failures.\n", + " row col expected actual file\n", + "1182 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 8.0 '../data/score/downloadable/beta-communities.csv'\n", + "1183 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 4.0 '../data/score/downloadable/beta-communities.csv'\n", + "1184 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 1.0 '../data/score/downloadable/beta-communities.csv'\n", + "1185 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 1.0 '../data/score/downloadable/beta-communities.csv'\n", + "1203 Number of Tribal areas within Census tract for Alaska 1/0/T/F/TRUE/FALSE 5.0 '../data/score/downloadable/beta-communities.csv'\n", + ".... ..................................................... .................. ...... .................................................\n", + "See problems(...) for more details.\n", + "”\n" + ] + } + ], + "source": [ + "score_post_full_path = list.files(\"../data/score/downloadable\", pattern = \".csv\", full.names = TRUE)[3]\n", + "score_post = read_csv(score_post_full_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "ad43a10e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\n", + "
A tibble: 6 × 4
Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percentShare of the tract's land area that is covered by impervious surface or cropland as a percentShare of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)
<lgl><lgl><dbl><dbl>
FALSEFALSE 76010
FALSEFALSE205826
FALSEFALSE235329
FALSEFALSE233329
FALSEFALSE395551
FALSEFALSE193724
\n" + ], + "text/latex": [ + "A tibble: 6 × 4\n", + "\\begin{tabular}{llll}\n", + " Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income? & Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent & Share of the tract's land area that is covered by impervious surface or cropland as a percent & Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)\\\\\n", + " & & & \\\\\n", + "\\hline\n", + "\t FALSE & FALSE & 760 & 10\\\\\n", + "\t FALSE & FALSE & 2058 & 26\\\\\n", + "\t FALSE & FALSE & 2353 & 29\\\\\n", + "\t FALSE & FALSE & 2333 & 29\\\\\n", + "\t FALSE & FALSE & 3955 & 51\\\\\n", + "\t FALSE & FALSE & 1937 & 24\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 6 × 4\n", + "\n", + "| Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income? <lgl> | Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent <lgl> | Share of the tract's land area that is covered by impervious surface or cropland as a percent <dbl> | Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile) <dbl> |\n", + "|---|---|---|---|\n", + "| FALSE | FALSE | 760 | 10 |\n", + "| FALSE | FALSE | 2058 | 26 |\n", + "| FALSE | FALSE | 2353 | 29 |\n", + "| FALSE | FALSE | 2333 | 29 |\n", + "| FALSE | FALSE | 3955 | 51 |\n", + "| FALSE | FALSE | 1937 | 24 |\n", + "\n" + ], + "text/plain": [ + " Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?\n", + "1 FALSE \n", + "2 FALSE \n", + "3 FALSE \n", + "4 FALSE \n", + "5 FALSE \n", + "6 FALSE \n", + " Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent\n", + "1 FALSE \n", + "2 FALSE \n", + "3 FALSE \n", + "4 FALSE \n", + "5 FALSE \n", + "6 FALSE \n", + " Share of the tract's land area that is covered by impervious surface or cropland as a percent\n", + "1 760 \n", + "2 2058 \n", + "3 2353 \n", + "4 2333 \n", + "5 3955 \n", + "6 1937 \n", + " Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)\n", + "1 10 \n", + "2 26 \n", + "3 29 \n", + "4 29 \n", + "5 51 \n", + "6 24 " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "score_post_cols = colnames(score_post)\n", + "score_post_impervious_cols = score_post_cols[grepl(\"impervious\", score_post_cols)]\n", + "score_post_impervious = score_post[,score_post_impervious_cols]\n", + "head(score_post_impervious)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "c62ea209", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "1595" + ], + "text/latex": [ + "1595" + ], + "text/markdown": [ + "1595" + ], + "text/plain": [ + "[1] 1595" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "1595" + ], + "text/latex": [ + "1595" + ], + "text/markdown": [ + "1595" + ], + "text/plain": [ + "[1] 1595" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "7258" + ], + "text/latex": [ + "7258" + ], + "text/markdown": [ + "7258" + ], + "text/plain": [ + "[1] 7258" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# check base score. That still came through\n", + "sum(is.na(score_post_impervious[,3]))\n", + "nrow(score_post_impervious) - length(impervious_in) \n", + "sum(score_post_impervious[,3] >= quantile(score_post_impervious[,3], .9, na.rm = TRUE), na.rm = TRUE) ## calculate the number at or above 90th percentile" + ] + }, + { + "cell_type": "markdown", + "id": "89be6c95", + "metadata": {}, + "source": [ + "I think there is likely just a rounding error that made that 7258 instead of 7254" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "2a905ca6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "sum(score_post_impervious[, 4] >= 90, na.rm = TRUE)" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "7a1116b0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "sum(score_post_impervious[,2] == TRUE)" + ] + }, + { + "cell_type": "markdown", + "id": "f6cd3ce5", + "metadata": {}, + "source": [ + "Take a look at the tiles themselves. " + ] + }, + { + "cell_type": "code", + "execution_count": 218, + "id": "256b3cf6", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "\u001b[36m──\u001b[39m \u001b[1m\u001b[1mColumn specification\u001b[1m\u001b[22m \u001b[36m────────────────────────────────────────────────────────\u001b[39m\n", + "cols(\n", + " .default = col_logical(),\n", + " GTF = \u001b[31mcol_character()\u001b[39m,\n", + " SF = \u001b[31mcol_character()\u001b[39m,\n", + " CF = \u001b[31mcol_character()\u001b[39m,\n", + " DF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " AF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " HDF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " DSF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " EBF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " EALR_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " EBLR_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " EPLR_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " HBF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " LLEF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " LIF_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " LMI_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " PM25F_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " HSEF = \u001b[32mcol_double()\u001b[39m,\n", + " P100_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " P200_I_PFS = \u001b[32mcol_double()\u001b[39m,\n", + " LPF_PFS = \u001b[32mcol_double()\u001b[39m\n", + " # ... with 30 more columns\n", + ")\n", + "\u001b[36mℹ\u001b[39m Use \u001b[30m\u001b[47m\u001b[30m\u001b[47m`spec()`\u001b[47m\u001b[30m\u001b[49m\u001b[39m for the full column specifications.\n", + "\n", + "\n", + "Warning message:\n", + "“513 parsing failures.\n", + " row col expected actual file\n", + "1182 TA_COUNT_AK 1/0/T/F/TRUE/FALSE 1.0 '../data/score/csv/tiles/usa.csv'\n", + "1183 TA_COUNT_AK 1/0/T/F/TRUE/FALSE 4.0 '../data/score/csv/tiles/usa.csv'\n", + "1184 TA_COUNT_AK 1/0/T/F/TRUE/FALSE 3.0 '../data/score/csv/tiles/usa.csv'\n", + "1187 TA_COUNT_AK 1/0/T/F/TRUE/FALSE 7.0 '../data/score/csv/tiles/usa.csv'\n", + "1189 TA_COUNT_AK 1/0/T/F/TRUE/FALSE 3.0 '../data/score/csv/tiles/usa.csv'\n", + ".... ........... .................. ...... .................................\n", + "See problems(...) for more details.\n", + "”\n" + ] + } + ], + "source": [ + "score_tiles_path = list.files(\"../data/score/csv/tiles\", pattern = \".csv\", full.names = TRUE)\n", + "score_tiles = read_csv(score_tiles_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 222, + "id": "097afdae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\n", + "
A tibble: 1 × 2
IS_PFSIS_ET
<int><int>
72543247
\n" + ], + "text/latex": [ + "A tibble: 1 × 2\n", + "\\begin{tabular}{ll}\n", + " IS\\_PFS & IS\\_ET\\\\\n", + " & \\\\\n", + "\\hline\n", + "\t 7254 & 3247\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 1 × 2\n", + "\n", + "| IS_PFS <int> | IS_ET <int> |\n", + "|---|---|\n", + "| 7254 | 3247 |\n", + "\n" + ], + "text/plain": [ + " IS_PFS IS_ET\n", + "1 7254 3247 " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "score_tiles %>% select(IS_PFS, IS_ET) %>%\n", + "summarise(\n", + " IS_PFS = sum(IS_PFS >=.9, na.rm = TRUE) \n", + " , IS_ET = sum(IS_ET) # okay, there is a probem here. \n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 225, + "id": "bb3a53e0", + "metadata": {}, + "outputs": [], + "source": [ + "score_mapping_path = list.files(\"../data/score/csv/tiles\", pattern = \"json\", full.names = TRUE)\n", + " score_mapping = fromJSON(file = score_mapping_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 233, + "id": "716ecfad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "
A tibble: 2 × 2
abbrevnames
<chr><named list>
IS_PFSShare of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)
IS_ET Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?
\n" + ], + "text/latex": [ + "A tibble: 2 × 2\n", + "\\begin{tabular}{ll}\n", + " abbrev & names\\\\\n", + " & \\\\\n", + "\\hline\n", + "\t IS\\_PFS & Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile)\\\\\n", + "\t IS\\_ET & Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 2 × 2\n", + "\n", + "| abbrev <chr> | names <named list> |\n", + "|---|---|\n", + "| IS_PFS | Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile) |\n", + "| IS_ET | Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income? |\n", + "\n" + ], + "text/plain": [ + " abbrev\n", + "1 IS_PFS\n", + "2 IS_ET \n", + " names \n", + "1 Share of the tract's land area that is covered by impervious surface or cropland as a percent (percentile) \n", + "2 Greater than or equal to the 90th percentile for share of the tract's land area that is covered by impervious surface or cropland as a percent and is low income?" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tibble(\n", + " abbrev = names(score_mapping)\n", + " , names = flatten(score_mapping )\n", + " ) %>%\n", + "filter(grepl(\"impervious\", names))" + ] + }, + { + "cell_type": "markdown", + "id": "289a9e93", + "metadata": {}, + "source": [ + "Next, we have the Json with the shape files. And the problem propogates into the .json files. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c6495df9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 165, + "id": "c81c867e", + "metadata": {}, + "outputs": [], + "source": [ + "high_res_json_path = list.files(\"../data/score/geojson\", pattern = \"high\", full.names = TRUE)\n", + "high_res_json <- fromJSON(file = high_res_json_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "id": "142c8a38", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "List of 3\n", + " $ type : chr \"FeatureCollection\"\n", + " $ crs :List of 2\n", + " ..$ type : chr \"name\"\n", + " ..$ properties:List of 1\n", + " .. ..$ name: chr \"urn:ogc:def:crs:OGC:1.3:CRS84\"\n", + " $ features:List of 74134\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " ..$ :List of 3\n", + " .. ..$ type : chr \"Feature\"\n", + " .. ..$ properties:List of 123\n", + " .. ..$ geometry :List of 2\n", + " .. [list output truncated]\n" + ] + } + ], + "source": [ + "glimpse(high_res_json)" + ] + }, + { + "cell_type": "markdown", + "id": "ae309c2c", + "metadata": {}, + "source": [ + "We want IS_PFS and IS_ET" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "id": "dbf131fa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "'FeatureCollection'" + ], + "text/latex": [ + "'FeatureCollection'" + ], + "text/markdown": [ + "'FeatureCollection'" + ], + "text/plain": [ + "[1] \"FeatureCollection\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "0.26" + ], + "text/latex": [ + "0.26" + ], + "text/markdown": [ + "0.26" + ], + "text/plain": [ + "[1] 0.26" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "FALSE" + ], + "text/latex": [ + "FALSE" + ], + "text/markdown": [ + "FALSE" + ], + "text/plain": [ + "[1] FALSE" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "high_res_json$type\n", + "high_res_json$features[[1]]$properties$IS_PFS\n", + "high_res_json$features[[1]]$properties$IS_ET" + ] + }, + { + "cell_type": "code", + "execution_count": 201, + "id": "56e93d0e", + "metadata": {}, + "outputs": [], + "source": [ + "impervious_json = map(\n", + " # 1:10, \n", + " 1:length(high_res_json$features), \n", + " ~ tibble(\n", + " GEOID = high_res_json$features[[.x]]$properties$GEOID\n", + " , IS_PFS = as.numeric(high_res_json$features[[.x]]$properties$IS_PFS)\n", + " , IS_ET = high_res_json$features[[.x]]$properties$IS_ET\n", + " )\n", + " ) " + ] + }, + { + "cell_type": "code", + "execution_count": 202, + "id": "961e6d31", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\n", + "
A tibble: 6 × 3
GEOIDIS_PFSIS_ET
<chr><dbl><lgl>
010730011000.26FALSE
010730014000.55FALSE
010730020000.23FALSE
010730038020.49FALSE
010730040000.68FALSE
010730051010.72FALSE
\n" + ], + "text/latex": [ + "A tibble: 6 × 3\n", + "\\begin{tabular}{lll}\n", + " GEOID & IS\\_PFS & IS\\_ET\\\\\n", + " & & \\\\\n", + "\\hline\n", + "\t 01073001100 & 0.26 & FALSE\\\\\n", + "\t 01073001400 & 0.55 & FALSE\\\\\n", + "\t 01073002000 & 0.23 & FALSE\\\\\n", + "\t 01073003802 & 0.49 & FALSE\\\\\n", + "\t 01073004000 & 0.68 & FALSE\\\\\n", + "\t 01073005101 & 0.72 & FALSE\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 6 × 3\n", + "\n", + "| GEOID <chr> | IS_PFS <dbl> | IS_ET <lgl> |\n", + "|---|---|---|\n", + "| 01073001100 | 0.26 | FALSE |\n", + "| 01073001400 | 0.55 | FALSE |\n", + "| 01073002000 | 0.23 | FALSE |\n", + "| 01073003802 | 0.49 | FALSE |\n", + "| 01073004000 | 0.68 | FALSE |\n", + "| 01073005101 | 0.72 | FALSE |\n", + "\n" + ], + "text/plain": [ + " GEOID IS_PFS IS_ET\n", + "1 01073001100 0.26 FALSE\n", + "2 01073001400 0.55 FALSE\n", + "3 01073002000 0.23 FALSE\n", + "4 01073003802 0.49 FALSE\n", + "5 01073004000 0.68 FALSE\n", + "6 01073005101 0.72 FALSE" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "impervious_json_df <- bind_rows(impervious_json)\n", + "head(impervious_json_df)" + ] + }, + { + "cell_type": "code", + "execution_count": 203, + "id": "1aa32ec9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "7254" + ], + "text/latex": [ + "7254" + ], + "text/markdown": [ + "7254" + ], + "text/plain": [ + "[1] 7254" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "3247" + ], + "text/latex": [ + "3247" + ], + "text/markdown": [ + "3247" + ], + "text/plain": [ + "[1] 3247" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "sum(impervious_json_df$IS_PFS >= .9)\n", + "sum(impervious_json_df$IS_ET)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 205, + "id": "190aa389", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\t\n", + "\n", + "
A tibble: 6 × 3
GEOIDIS_PFSIS_ET
<chr><dbl><lgl>
010730045000.94FALSE
040131076010.90FALSE
040131085010.90FALSE
040131105010.95FALSE
040131105020.91FALSE
040190001000.92FALSE
\n" + ], + "text/latex": [ + "A tibble: 6 × 3\n", + "\\begin{tabular}{lll}\n", + " GEOID & IS\\_PFS & IS\\_ET\\\\\n", + " & & \\\\\n", + "\\hline\n", + "\t 01073004500 & 0.94 & FALSE\\\\\n", + "\t 04013107601 & 0.90 & FALSE\\\\\n", + "\t 04013108501 & 0.90 & FALSE\\\\\n", + "\t 04013110501 & 0.95 & FALSE\\\\\n", + "\t 04013110502 & 0.91 & FALSE\\\\\n", + "\t 04019000100 & 0.92 & FALSE\\\\\n", + "\\end{tabular}\n" + ], + "text/markdown": [ + "\n", + "A tibble: 6 × 3\n", + "\n", + "| GEOID <chr> | IS_PFS <dbl> | IS_ET <lgl> |\n", + "|---|---|---|\n", + "| 01073004500 | 0.94 | FALSE |\n", + "| 04013107601 | 0.90 | FALSE |\n", + "| 04013108501 | 0.90 | FALSE |\n", + "| 04013110501 | 0.95 | FALSE |\n", + "| 04013110502 | 0.91 | FALSE |\n", + "| 04019000100 | 0.92 | FALSE |\n", + "\n" + ], + "text/plain": [ + " GEOID IS_PFS IS_ET\n", + "1 01073004500 0.94 FALSE\n", + "2 04013107601 0.90 FALSE\n", + "3 04013108501 0.90 FALSE\n", + "4 04013110501 0.95 FALSE\n", + "5 04013110502 0.91 FALSE\n", + "6 04019000100 0.92 FALSE" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "impervious_json_df %>% filter(IS_PFS >= .9, IS_ET == FALSE) %>% head() " + ] + }, + { + "cell_type": "markdown", + "id": "f08da689", + "metadata": {}, + "source": [ + "okay, how did we get that the IS_ET is false when IS_PFS >= .9?" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "R", + "language": "R", + "name": "ir" + }, + "language_info": { + "codemirror_mode": "r", + "file_extension": ".r", + "mimetype": "text/x-r-source", + "name": "R", + "pygments_lexer": "r", + "version": "4.0.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}