Skip to content

Commit

Permalink
Merge pull request #84 from Metropolitan-Council/76-natural-systems-d…
Browse files Browse the repository at this point in the history
…ata-sourcing

Natural systems data sourcing
  • Loading branch information
eroten authored Jun 14, 2024
2 parents 9151b37 + 3a50f5b commit 47f21ff
Show file tree
Hide file tree
Showing 159 changed files with 20,568 additions and 4,891 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,21 @@ _transportation/data-raw/epa/metc_lggit_11.28.23.xlsm
_waste/data-raw/wastewater/GHGEmissions_2019-2021_CorrectedWSCA.xlsx

_transportation/data-raw/epa/community_ghg_inventorytool_11.28.23 2/
_nature/data-raw/ESA_WorldCover_10m_2021_v200_N42W093_Map.tif
_nature/data-raw/ESA_WorldCover_10m_2021_v200_N42W096_Map.tif
_nature/data-raw/ESA_WorldCover_10m_2021_v200_N45W093_Map.tif
_nature/data-raw/ESA_WorldCover_10m_2021_v200_N45W096_Map.tif
_nature/data-raw/land_cover_seq_rates.csv
_nature/data-raw/DBO_RPTAdministrativeBoundary.dbf
_nature/data-raw/DBO_RPTAdministrativeBoundary.cpg
_nature/data-raw/DBO_RPTAdministrativeBoundary.prj
_nature/data-raw/DBO_RPTAdministrativeBoundary.sbx
_nature/data-raw/DBO_RPTAdministrativeBoundary.sbn
_nature/data-raw/DBO_RPTAdministrativeBoundary.shp
_nature/data-raw/DBO_RPTAdministrativeBoundary.shp.xml
_nature/data-raw/DBO_RPTAdministrativeBoundary.shx
_nature/data-raw/land_cover_stock.csv
/_nature/_natural_systems_files

site_libs/
_nature/_natural_systems_files/*
2 changes: 0 additions & 2 deletions R/_export_plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,3 @@ purrr::map(
)
}
)


4 changes: 3 additions & 1 deletion R/_load_pkgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ if (exists("load_packages") == FALSE) {
suppressMessages(library(leaflet, quietly = TRUE))
suppressMessages(library(scales, quietly = TRUE))
suppressMessages(library(webshot, quietly = TRUE))

suppressMessages(library(terra, quietly = TRUE))
suppressMessages(library(tidyterra, quietly = TRUE))
suppressMessages(library(FedData, quietly = TRUE))

# tables -----
suppressMessages(library(knitr, quietly = TRUE))
Expand Down
23 changes: 20 additions & 3 deletions R/cprg_colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ category_colors <-

# PuRd
"Solid waste" = "#ce1256",
"Wastewater" = "#c994c7"
"Wastewater" = "#c994c7",

# Gn
"Sequestration" = "#006f3c",
"Stock" = "#27b376"
)


Expand All @@ -53,8 +57,15 @@ source_colors <- list(
# energy levels
"Electricity" = "#0868ac",
"Natural gas" = "#4eb3d3",
"Propane" = "#006d2c",
"Kerosene" = "#a1d99b"
"Propane" = "#2f4f4f",
"Kerosene" = "#004242",

# nature
"Tree" = "#006d2c",
"Grassland" = "#22b600",
"Wetland" = "#26cc00",
"Urban tree" = "#7be382",
"Urban grassland" = "#a1d99b"
)


Expand All @@ -75,3 +86,9 @@ management_method_colors <- list(
"Landfill" = source_colors$Landfill,
"Onsite" = "#750a31"
)

# european space agency colors
esa_color <- c(
"forestgreen", "brown4", "yellow2", "wheat3", "red",
"plum", "lightblue", "navy", "mediumturquoise"
)
2 changes: 2 additions & 0 deletions R/fix_style.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if (!nzchar(Sys.getenv("QUARTO_PROJECT_RENDER_ALL"))) {
fs::dir_copy("style", "docs/_energy/style/", overwrite = TRUE)
fs::dir_copy("style", "docs/_waste/style/", overwrite = TRUE)
fs::dir_copy("style", "docs/_meta/style/", overwrite = TRUE)
fs::dir_copy("style", "docs/_nature/style/", overwrite = TRUE)
fs::dir_copy("style", "docs/_agriculture/style/", overwrite = TRUE)
fs::dir_copy("assets/maps", "docs/_meta/assets/maps", overwrite = TRUE)
quit()
}
2 changes: 1 addition & 1 deletion R/plot_county_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ plot_county_emissions <- function(county_emissions,
)
) %>%
councilR::plotly_layout(
main_title = paste0(.sector, " emissions"),
main_title = if_else(.sector == "Nature", "Natural systems sequestration", paste0(.sector, " emissions")),
subtitle = "",
x_title = stringr::str_to_title(unique(plot_data$geog_level)),
y_title = "Metric tons CO<sub>2</sub>e",
Expand Down
2 changes: 1 addition & 1 deletion R/plot_sector_county_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ plot_county_sector_emissions <- function(county_emissions,
)
) %>%
councilR::plotly_layout(
main_title = paste0(.sector, " emissions"),
main_title = if_else(.sector == "Nature", "Natural systems sequestration", paste0(.sector, " emissions")),
subtitle = "",
y_title = stringr::str_to_title(unique(plot_data$geog_level)),
x_title = "Metric tons CO<sub>2</sub>e",
Expand Down
60 changes: 53 additions & 7 deletions _meta/data-raw/compile_county_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,38 @@ propane_kerosene_emissions <- readRDS("_energy/data/fuel_use.RDS") %>%
) %>%
select(names(transportation_emissions))

## natural systems ----

natural_systems_sequestration <- readRDS("_nature/data/county_landcover_sequestration_2021.RDS") %>%
mutate(
sector = "Nature",
geog_level = "county",
geog_name = county,
category = "Sequestration",
source = stringr::str_to_sentence(str_replace_all(land_cover_type, "_", " ")),
data_source = "ESA WorldCover & NLCD 2021",
factor_source = "Various primary literature",
year = 2021,
emissions_metric_tons_co2e = sequestration_potential,
) %>%
ungroup() %>%
select(names(transportation_emissions))

natural_systems_stock <- readRDS("_nature/data/county_landcover_sequestration_2021.RDS") %>%
mutate(
sector = "Nature",
geog_level = "county",
geog_name = county,
category = "Stock",
source = stringr::str_to_sentence(str_replace_all(land_cover_type, "_", " ")),
data_source = "ESA WorldCover & NLCD 2021",
factor_source = "Various primary literature",
year = 2021,
emissions_metric_tons_co2e = stock_potential,
) %>%
ungroup() %>%
select(names(transportation_emissions))

# combine and write metadata----

emissions_all <- bind_rows(
Expand All @@ -118,7 +150,9 @@ emissions_all <- bind_rows(
electric_emissions,
natural_gas_emissions,
ww_emissions,
solid_waste
solid_waste,
natural_systems_sequestration,
natural_systems_stock
) %>%
left_join(
cprg_county %>%
Expand All @@ -143,7 +177,13 @@ emissions_all <- bind_rows(
"Electricity",
"Natural gas",
"Propane",
"Kerosene"
"Kerosene",
# nature levels
"Urban grassland",
"Urban tree",
"Grassland",
"Tree",
"Wetland"
),
ordered = TRUE
),
Expand All @@ -157,7 +197,9 @@ emissions_all <- bind_rows(
"Passenger vehicles",
"Commercial vehicles",
"Wastewater",
"Solid waste"
"Solid waste",
"Sequestration",
"Stock"
),
ordered = TRUE
)
Expand All @@ -176,11 +218,12 @@ emissions_all <- bind_rows(
mutate(emissions_per_capita = round(emissions_metric_tons_co2e / county_total_population, digits = 2)) %>%
select(year, geog_level, geog_id, geog_name, everything())

# splitting off carbon stock here as it is a capacity, not a rate
carbon_stock <- emissions_all %>% filter(category == "Stock")
emissions_all <- emissions_all %>% filter(category != "Stock")


mean(emissions_all$emissions_per_capita)

sum(emissions_all$emissions_metric_tons_co2e) / sum(cprg_county_pop$population)
mean(emissions_all$emissions_per_capita[!emissions_all$category == "Stock"])
sum(emissions_all$emissions_metric_tons_co2e[!emissions_all$category == "Stock"]) / sum(cprg_county_pop$population)

emissions_all_meta <- tibble::tribble(
~"Column", ~"Class", ~"Description",
Expand Down Expand Up @@ -208,6 +251,9 @@ write.csv(emissions_all, "_meta/data/cprg_county_emissions.CSV", row.names = FAL

county_emissions <- emissions_all

saveRDS(carbon_stock, "_meta/data/cprg_county_carbon_stock.RDS")
saveRDS(emissions_all_meta, "_meta/data/cprg_county_carbon_stock_meta.RDS")

# save emissions to shared drive location
# source("R/fetch_path.R")

Expand Down
Loading

0 comments on commit 47f21ff

Please sign in to comment.