Skip to content

Commit

Permalink
semi-automated RVC code
Browse files Browse the repository at this point in the history
  • Loading branch information
CarissaGervasi-NOAA committed Jul 8, 2024
1 parent 3f62940 commit 9d704a5
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 18 deletions.
Binary file modified indicator_data/RVC/RUVdensity_PRICO_BAL VETU.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_PRICO_EPI GUTT.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_PRICO_LUT ANAL.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_PRICO_OCY CHRY.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_PRICO_SPA AURO.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_PRICO_SPA VIRI.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STTSTJ_BAL VETU.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STTSTJ_EPI GUTT.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STTSTJ_LUT ANAL.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STTSTJ_OCY CHRY.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STTSTJ_SPA AURO.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STTSTJ_SPA VIRI.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STX_BAL VETU.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STX_EPI GUTT.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STX_LUT ANAL.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STX_OCY CHRY.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STX_SPA AURO.RData
Binary file not shown.
Binary file modified indicator_data/RVC/RUVdensity_STX_SPA VIRI.RData
Binary file not shown.
Binary file added indicator_data/RVC/combined_prico_2001_2023.rds
Binary file not shown.
Binary file added indicator_data/RVC/combined_sttstj_2001_2023.rds
Binary file not shown.
Binary file added indicator_data/RVC/combined_stx_2001_2023.rds
Binary file not shown.
Binary file modified indicator_objects/RVC_PR.RData
Binary file not shown.
Binary file modified indicator_objects/RVC_STSJ.RData
Binary file not shown.
Binary file modified indicator_objects/RVC_STX.RData
Binary file not shown.
89 changes: 71 additions & 18 deletions indicator_processing/non_automated/RVC.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
# The indicator of interest is the abundance of economically important fish.
# Identified target species for the Caribbean region: yellowtail snapper, queen triggerfish, red hind, redband parrotfish, stoplight parrotfish, mutton snapper.

#install.packages('devtools')
#devtools::install_github('jeremiaheb/rvc')
library(rvc)

# find root directory for project ---------------

directory <- rprojroot::find_rstudio_root_file() # MK - set root path so that all links below work with master file

# first process automated downloads --------------

setwd(directory)

# The data portal has more information on the data: https://grunt.sefsc.noaa.gov/rvc_analysis20/

# Species of interest:
Expand All @@ -33,11 +21,78 @@ setwd(directory)

# NOTE: as of 3/1/2024 calibrations have not been completed for all species. This means the data on the portal only go back to 2016. To get the full time series (2001 onward) we needed to get the calibrated data from Jeremiah Blondeau ([email protected]). Species specific calibrations were done. The calibrated_species.csv file is a list of all the species that have thus far been calibrated. All species of interest have been calibrated except for mutton snapper. For mutton snapper we can only use data from 2017 onward.

#This is the list of calibrated species as of 2024.
calibrated = read.csv("indicator_data/RVC/calibrated_species.csv")

prico = readRDS("indicator_data/RVC/prico_2001_2021_calibrated.rds")
sttstj = readRDS("indicator_data/RVC/sttstj_2001_2021_calibrated.rds")
stx = readRDS("indicator_data/RVC/stx_2001_2021_calibrated.rds")


rm(list = ls())
dev.off()


#install.packages('devtools')
#devtools::install_github('jeremiaheb/rvc')
library(rvc)

styear = 2001
enyear = 2023 #to update the plots when new data are added to the online portal, just update this end year and the code will automatically update.



# Define the regions and corresponding file paths
regions <- c("prico", "sttstj", "stx")
data_2001_2021_paths <- c("indicator_data/RVC/prico_2001_2021_calibrated.rds",
"indicator_data/RVC/sttstj_2001_2021_calibrated.rds",
"indicator_data/RVC/stx_2001_2021_calibrated.rds")

# Function to combine data for a given region
combine_data <- function(region, data_2001_2021_path) {
# Load the 2001-2021 data
data_2001_2021 <- readRDS(data_2001_2021_path)

# Load the new data using the getRvcData function
data_2023 <- getRvcData(years = 2023:enyear, regions = toupper(region))

# Initialize an empty list to store combined data
combined_data <- list()

# Iterate over the list elements and combine them
for (element in names(data_2001_2021)) {
if (element %in% names(data_2023)) {
# Combine data frames from both lists
combined_data[[element]] <- bind_rows(data_2001_2021[[element]], data_2023[[element]])
} else {
# If the element is not in the 2023 data, just use the 2001-2021 data
combined_data[[element]] <- data_2001_2021[[element]]
}
}

# Add any elements that are only in the 2023 data
for (element in names(data_2023)) {
if (!element %in% names(data_2001_2021)) {
combined_data[[element]] <- data_2023[[element]]
}
}

return(combined_data)
}

# Loop over regions to combine data and save the results
for (i in seq_along(regions)) {
region <- regions[i]
data_2001_2021_path <- data_2001_2021_paths[i]

combined_data <- combine_data(region, data_2001_2021_path)

# Save the combined dataset
saveRDS(combined_data, paste0("indicator_data/RVC/combined_", region, "_2001_2023.rds"))
}



prico = readRDS("indicator_data/RVC/combined_prico_2001_2023.rds")
sttstj = readRDS("indicator_data/RVC/combined_sttstj_2001_2023.rds")
stx = readRDS("indicator_data/RVC/combined_stx_2001_2023.rds")

## Make a list of species
## You can use full scientific names, common names, or
Expand All @@ -46,9 +101,7 @@ stx = readRDS("indicator_data/RVC/stx_2001_2021_calibrated.rds")
spcs = c("OCY CHRY", "LUT ANAL", "BAL VETU", "EPI GUTT", "SPA AURO", "SPA VIRI")


## Code to bring in data from the server if needed for updating
## Download desired Regions data from server
#carib = getRvcData(years = 2016:2021, regions = c("PRICO","STTSTJ","STX"))



# Extract the time series for each species and each area
Expand Down

0 comments on commit 9d704a5

Please sign in to comment.