Skip to content

Commit

Permalink
Read stock assessment results from SAG database
Browse files Browse the repository at this point in the history
  • Loading branch information
arni-magnusson committed Nov 27, 2023
1 parent ada489c commit 2083f34
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
30 changes: 29 additions & 1 deletion selectivity/R/sag/boot/sag.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Download stock assessment results and reference points from SAG database

library(TAF)
library(icesSAG)

Expand All @@ -16,17 +18,43 @@ stocks.2023 <- stocks.2023[stocks.2023$SpeciesName=="Gadus morhua" &
stocks.2023$Purpose == "Advice",]

# Download summary tables
message("2020 summary tables")
sumtab.2020 <- sapply(stocks.2020$AssessmentKey, getSummaryTable)
names(sumtab.2020) <- stocks.2020$StockKeyLabel
message("2021 summary tables")
sumtab.2021 <- sapply(stocks.2021$AssessmentKey, getSummaryTable)
names(sumtab.2021) <- stocks.2021$StockKeyLabel
message("2022 summary tables")
sumtab.2022 <- sapply(stocks.2022$AssessmentKey, getSummaryTable)
names(sumtab.2022) <- stocks.2022$StockKeyLabel
message("2023 summary tables")
sumtab.2023 <- sapply(stocks.2023$AssessmentKey, getSummaryTable)
names(sumtab.2023) <- stocks.2023$StockKeyLabel

# Write tables
# Download reference points
message("2020 reference points")
refpt.2020 <- sapply(stocks.2020$AssessmentKey, getFishStockReferencePoints)
names(refpt.2020) <- stocks.2020$StockKeyLabel
message("2021 reference points")
refpt.2021 <- sapply(stocks.2021$AssessmentKey, getFishStockReferencePoints)
names(refpt.2021) <- stocks.2021$StockKeyLabel
message("2022 reference points")
refpt.2022 <- sapply(stocks.2022$AssessmentKey, getFishStockReferencePoints)
names(refpt.2022) <- stocks.2022$StockKeyLabel
message("2023 reference points")
refpt.2023 <- sapply(stocks.2023$AssessmentKey, getFishStockReferencePoints)
names(refpt.2023) <- stocks.2023$StockKeyLabel

# Write tables and lists
write.taf(stocks.2020, quote=TRUE)
write.taf(stocks.2021, quote=TRUE)
write.taf(stocks.2022, quote=TRUE)
write.taf(stocks.2023, quote=TRUE)
saveRDS(sumtab.2020, "sumtab_2020.rds")
saveRDS(sumtab.2021, "sumtab_2021.rds")
saveRDS(sumtab.2022, "sumtab_2022.rds")
saveRDS(sumtab.2023, "sumtab_2023.rds")
saveRDS(refpt.2020, "refpt_2020.rds")
saveRDS(refpt.2021, "refpt_2021.rds")
saveRDS(refpt.2022, "refpt_2022.rds")
saveRDS(refpt.2023, "refpt_2023.rds")
19 changes: 18 additions & 1 deletion selectivity/R/sag/data.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
## Preprocess data, write TAF data tables

## Before:
## Before: refpt_2020.rds, refpt_2021.rds, refpt_2022.rds, refpt_2023.rds,
## stocks_2020.csv, stocks_2021.csv, stocks_2022.csv, stocks_2023.csv,
## sumtab_2020.rds, sumtab_2021.rds, sumtab_2022.rds, sumtab_2023.rds
## (boot/data/sag)
## After:

library(TAF)

mkdir("data")

# Read SAG data
stocks.2020 <- read.taf("boot/data/sag/stocks_2020.csv")
stocks.2021 <- read.taf("boot/data/sag/stocks_2021.csv")
stocks.2022 <- read.taf("boot/data/sag/stocks_2022.csv")
stocks.2023 <- read.taf("boot/data/sag/stocks_2023.csv")
sumtab.2020 <- readRDS("boot/data/sag/sumtab_2020.rds")
sumtab.2021 <- readRDS("boot/data/sag/sumtab_2021.rds")
sumtab.2022 <- readRDS("boot/data/sag/sumtab_2022.rds")
sumtab.2023 <- readRDS("boot/data/sag/sumtab_2023.rds")
refpt.2020 <- readRDS("boot/data/sag/refpt_2020.rds")
refpt.2021 <- readRDS("boot/data/sag/refpt_2021.rds")
refpt.2022 <- readRDS("boot/data/sag/refpt_2022.rds")
refpt.2023 <- readRDS("boot/data/sag/refpt_2023.rds")

0 comments on commit 2083f34

Please sign in to comment.