generated from SEFSC/SEFSC-Template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f62940
commit 9d704a5
Showing
25 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 | ||
|