-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update lps_sharks with new data, rewrite get_lps_sharks for new dataset
- Loading branch information
Showing
3 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
Binary file not shown.
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,49 +1,58 @@ | ||
## HMS sharks occurence on the shelf | ||
# Data from MRIP - https://www.fisheries.noaa.gov/recreational-fishing-data/recreational-fishing-data-downloads | ||
# Seleted species from categories from Duartes lists from observer data | ||
## HMS sharks from Large Pelagics Survey (LPS) | ||
## Provided by HMS Cliff Hutt | ||
## Last updated 2/6/2025 | ||
library(tidyverse) | ||
library(readxl) | ||
|
||
raw.hms.dir <- here::here("data-raw/hms-mrip") | ||
# Establish directory and define input file name | ||
raw.dir <- here::here("data-raw") | ||
lps_xlsx <- "LPS Pelagic Shark Harvest Estimates 2002-2024.xlsx" | ||
|
||
get_lps_sharks <- function(save_clean = F){ | ||
## Bring in data | ||
lps_csv <- "LPS_shark_catch.csv" | ||
species_list <- "species_list.csv" | ||
hms_cat<- "hms_sp_category.csv" | ||
# Load and format data for SOE | ||
lps_sharks <- readxl::read_excel(file.path(raw.dir,lps_xlsx), sheet = "Sheet3") |> | ||
janitor::row_to_names(1) |> | ||
dplyr::select(-"(blank)") | ||
|
||
d <- read.csv(file.path(raw.dir,lps_csv)) | ||
sp <- read.csv(file.path(raw.hms.dir,species_list)) %>% | ||
dplyr::rename(SP_CODE = sp_code) %>% | ||
dplyr::select(SP_CODE, COMMON_NAME) | ||
sp_cat <- read.csv(file.path(raw.hms.dir,hms_cat)) | ||
# Split dataset into MAB and NE subsets | ||
# MAB | ||
lps_sharks_mab <- lps_sharks[2:24,] |> | ||
dplyr::mutate(Units = "N of Fish", | ||
EPU = "MAB") |> | ||
dplyr::rename("Total" = "Grand Total", | ||
"Year" = "Row Labels", | ||
"Blue_Shark" = "BLUE SHARK", | ||
"Common_Thresher" = "COMMON THRESHER", | ||
"Shortfin_Mako" = "SHORTFIN MAKO") |> | ||
tidyr::pivot_longer(cols = c("Blue_Shark", | ||
"Common_Thresher", | ||
"Shortfin_Mako", | ||
"Total"), | ||
names_to = "Var", values_to = "Value") |> | ||
dplyr::select(Year, Var, Value, EPU, Units) | ||
|
||
region<- data.frame(State.Area = c("VIRGINIA" ,"MARYLAND/DELAWARE","SOUTH NEW JERSEY", "NORTH NEW JERSEY","NEW YORK", | ||
"CONNECTICUT/RHODE ISLAND", "MASSACHUSETTS","NEW HAMPSHIRE/MAINE"), | ||
EPU = c("MAB","MAB","MAB","MAB","MAB","MAB","NE", "NE")) | ||
# NE | ||
lps_sharks_ne <- lps_sharks[26:48,] |> | ||
dplyr::mutate(Units = "N of Fish", | ||
EPU = "NE") |> | ||
dplyr::rename("Total" = "Grand Total", | ||
"Year" = "Row Labels", | ||
"Blue_Shark" = "BLUE SHARK", | ||
"Common_Thresher" = "COMMON THRESHER", | ||
"Shortfin_Mako" = "SHORTFIN MAKO") |> | ||
tidyr::pivot_longer(cols = c("Blue_Shark", | ||
"Common_Thresher", | ||
"Shortfin_Mako", | ||
"Total"), | ||
names_to = "Var", values_to = "Value") |> | ||
dplyr::select(Year, Var, Value, EPU, Units) | ||
|
||
## select those in NEUS Shelf | ||
lps_sharks<- d %>% | ||
dplyr::rename("COMMON_NAME" = Species, | ||
"Total_Catch" = "Total.Catch..Kept.Alive.Dead.") %>% | ||
dplyr::mutate(COMMON_NAME=recode(COMMON_NAME, 'PORBEAGLE SHARK'='PORBEAGLE', | ||
'COMMON THRESHER'='THRESHER SHARK')) %>% | ||
dplyr::filter(!Total_Catch == ".") %>% | ||
left_join(sp_cat, by= "COMMON_NAME") %>% | ||
left_join(region, by = "State.Area") %>% | ||
dplyr::group_by(Year, SP_CATEGORY, EPU) %>% | ||
dplyr::mutate(Total_Catch = as.numeric(Total_Catch)) %>% | ||
dplyr::summarise(Value = sum(Total_Catch)) %>% | ||
dplyr::rename( Time = Year, | ||
Var = SP_CATEGORY) %>% | ||
dplyr::mutate(Units = "N of Fish")%>% | ||
dplyr::select(Time, Var, Value, EPU, Units) | ||
lps_sharks <- rbind(lps_sharks_mab, lps_sharks_ne) | ||
|
||
# metadata ---- | ||
attr(lps_sharks, "tech-doc_url") <- "https://noaa-edab.github.io/tech-doc/recreational-shark-fishing-indicators.html" | ||
attr(lps_sharks, "data_files") <- list( | ||
lps_csv = lps_csv, | ||
hms_cat = hms_cat) | ||
lps_xlsx = lps_xlsx) | ||
attr(lps_sharks, "data_steward") <- c( | ||
"Kimberly Bastille <[email protected]>") | ||
|
||
|
Binary file not shown.