-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on 2023 update to gpra/neport summaries
- Loading branch information
Showing
42 changed files
with
2,828 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,35 @@ | ||
library(tidyverse) | ||
library(here) | ||
library(googlesheets4) | ||
library(googledrive) | ||
|
||
# auth google drive | ||
drive_auth(email = '[email protected]') | ||
gs4_auth(token = drive_token()) | ||
# simple version of all restoration projects -------------------------------------------------- | ||
|
||
# HMPU compiled table ------------------------------------------------------------------------- | ||
# from https://github.com/tbep-tech/TBEP_Habitat_Restoration | ||
pth <- 'https://raw.githubusercontent.com/tbep-tech/TBEP_Habitat_Restoration/main/Habitat_Restoration_Clean.csv' | ||
|
||
# curated table, pull data prior to 2006 to join with GPRA | ||
# https://docs.google.com/spreadsheets/d/1IkGidfU4SQJ_ZtOEqfn8licNCuWGlq_MtGuWWuIL1Js/edit#gid=2008440809 | ||
rstdat <- read_sheet('1IkGidfU4SQJ_ZtOEqfn8licNCuWGlq_MtGuWWuIL1Js', sheet = 'FullDatabase') | ||
|
||
rstdat <- rstdat %>% | ||
rstdatall <- read.csv(pth, stringsAsFactors = F) %>% | ||
select( | ||
`Federal Fiscal Year` = `Year Reported`, | ||
`HMPU habitat 1` = `HMPU Habitat Type for Restoration`, | ||
Acres, | ||
`Activity Name` = `Basic Activity (Enhance/Rest)`, | ||
`Miles` = `Linear Miles`, | ||
`Feet` = `Linear Feet` | ||
) %>% | ||
filter(`Federal Fiscal Year` < 2006) | ||
|
||
# GPRA raw data | ||
# https://docs.google.com/spreadsheets/d/1QFX5XXpTgAr4u9wrxa_TUOuF5roUqEhJzZEDUiHi3SE/edit?usp=sharing | ||
rstdat2 <- read_sheet('1QFX5XXpTgAr4u9wrxa_TUOuF5roUqEhJzZEDUiHi3SE') | ||
|
||
# GPRA to HMPU lookup table | ||
# https://docs.google.com/spreadsheets/d/1jYbODoAHXPqYC69fanINDoRkKmMl6oY9qltqdkC6UfM/edit#gid=741038946 | ||
lkup <- read_sheet('1jYbODoAHXPqYC69fanINDoRkKmMl6oY9qltqdkC6UfM') | ||
|
||
# GRPA manually assigned lookup table | ||
# https://docs.google.com/spreadsheets/d/1bZtu4P1ji4pdSRcAnWSksHl1AJ-b3pFqxXedSdSHwBY/edit#gid=0 | ||
lkupmanual <- read_sheet('1bZtu4P1ji4pdSRcAnWSksHl1AJ-b3pFqxXedSdSHwBY') %>% | ||
select(`View Detail`, `HMPU habitat 1`) | ||
|
||
# create input for table function | ||
rstdat2 <- rstdat2 %>% | ||
left_join(lkup, by = c('Habitat Type', 'Restoration Technique')) %>% | ||
left_join(lkupmanual, by = 'View Detail') %>% | ||
unite('HMPU habitat 1', `HMPU habitat 1.x`, `HMPU habitat 1.y`, na.rm = T) | ||
|
||
rstdatall <- bind_rows(rstdat, rstdat2) %>% | ||
select( | ||
Year = `Federal Fiscal Year`, | ||
Category = `HMPU habitat 1`, | ||
Acres, | ||
Activity = `Activity Name`, | ||
`Linear Miles` = `Miles`, | ||
`Linear Ft` = `Feet` | ||
) %>% | ||
rowwise() %>% | ||
Year = Federal_Fiscal_Year, | ||
Category = PrimaryHabitat, | ||
Activity = GeneralActivity, | ||
Acres, | ||
Miles, | ||
Feet | ||
) %>% | ||
filter(Category != 'Other') %>% | ||
mutate( | ||
Miles = sum(`Linear Miles`, `Linear Ft` / 5280, na.rm = T), | ||
Activity = case_when( | ||
Activity %in% c('Establishment', 'Reestablishment', 'Restoration') ~ 'Restoration', | ||
Activity %in% c('Enhancement', 'Maintenance', 'Protection', 'Rehabilitation') ~ 'Enhancement' | ||
Category = case_when( | ||
Category == 'Living shorelines' ~ 'Living Shorelines', | ||
T ~ Category | ||
), | ||
Category = ifelse(Category == '', NA, Category) | ||
Acres = gsub('Enhancement', '', Acres), | ||
Acres = as.numeric(Acres), | ||
Miles = case_when( | ||
is.na(Miles) & !is.na(Feet) ~ Feet / 5280, | ||
T ~ Miles | ||
), | ||
Category = ifelse(Category == '', NA, Category), | ||
Activity = ifelse(Activity == '', NA, Activity) | ||
) %>% | ||
ungroup() %>% | ||
select(Year, Category, Activity, Acres, Miles) | ||
|
||
save(rstdatall, file = here('data/rstdatall.RData')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.