-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreport_sg.R
94 lines (80 loc) · 2.75 KB
/
report_sg.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
### ------------------------------------------------------------------------ ###
### create ICES standard graphs for advice sheet ####
### ------------------------------------------------------------------------ ###
## Before: report/tables_sag.csv
## After:
### load packages
library(TAF)
library(icesSAG)
### ------------------------------------------------------------------------ ###
### preparation ####
### ------------------------------------------------------------------------ ###
### ICES standard graphs
### create token for authentication
### go to https://standardgraphs.ices.dk/manage/index.aspx
### login
### click on create token or go directly to
### https://standardgraphs.ices.dk/manage/CreateToken.aspx
### create new token, save in file
# file.edit("~/.Renviron")
### in the format
### SG_PAT=some_token_......
### save and restart R
### load token
Sys.getenv("SG_PAT")
options(icesSAG.use_token = TRUE)
### assessment year
ass_yr <- 2021
### check assessments keys
key <- findAssessmentKey("ple.27.7e", year = ass_yr)
key_last <- findAssessmentKey("ple.27.7e", year = ass_yr - 1)
### last year's graphs
plot(getSAGGraphs(key_last))
### list of possible elements:
### https://datsu.ices.dk/web/selRep.aspx?Dataset=126
### allowed units:
### https://vocab.ices.dk/?ref=155
### set up stock info
stk_info <- stockInfo(
StockCode = "ple.27.7e",
AssessmentYear = ass_yr,
ContactPerson = "[email protected]",
Purpose = "Advice"
)
### add some more data manually
stk_info$MSYBtrigger <- 2443
stk_info$FMSY <- 0.238
stk_info$Blim <- 1745
stk_info$Flim <- 0.88
stk_info$Bpa <- 2443
stk_info$Fpa <- 0.69 ### updated in 2021, Fp.05 is new basis
stk_info$Fage <- "3-6"
stk_info$RecruitmentAge <- 2
stk_info$RecruitmentDescription <- "Recruitment"
stk_info$RecruitmentUnits <- "NE3" ### NE3 stands for thousands
# stk_info$RecruitmentUnits <- "Relative Recruitment"
stk_info$CatchesLandingsUnits <- "t" ### t for tonnes
stk_info$StockSizeUnits <- "t" ### t for tonnes
stk_info$StockSizeDescription <- "SSB"
# stk_info$StockSizeDescription <- "Stock Size: Relative"
stk_info$FishingPressureDescription <- "F"
# stk_info$FishingPressureDescription <- "Fishing pressure: Relative"
stk_info$Purpose <- "Advice"
stk_info$ModelType <- "A"
stk_info$ModelName <- "XSA"
### load data from assessment/forecast
sag <- read.csv(file = "report/tables_sag.csv", as.is = TRUE)
### set up data
# https://datsu.ices.dk/web/selRep.aspx?Dataset=126 # Record: AF - Fish Data
stk_data <- stockFishdata(
Year = sag$Year,
Recruitment = sag$Recruitment,
TBiomass = sag$TBiomass,
StockSize = sag$StockSize,
Landings = sag$Landings,
Discards = sag$Discards,
FishingPressure = sag$FishingPressure
)
### create xml file
stkxml <- createSAGxml(info, fishdata)
cat(stkxml, file = "SAG_upload.xml")