-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdata.R
More file actions
86 lines (65 loc) · 1.74 KB
/
data.R
File metadata and controls
86 lines (65 loc) · 1.74 KB
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
## Preprocess data, write TAF data tables
## Before:
## After:
## load libraries
library(icesTAF)
library(stockassessment)
# ensure directory
mkdir("data")
# Read underlying data from bootstrap/data
read.ices.taf <- function(file) {
read.ices(
taf.data.path("sam_data", file)
)
}
# ## Catch-numbers-at-age ##
catage <- read.ices.taf("cn.dat")
# ## Catch-weight-at-age ##
wcatch <- read.ices.taf("cw.dat")
wdiscards <- read.ices.taf("dw.dat")
wlandings <- read.ices.taf("lw.dat")
# ## Natural-mortality ##
natmort <- read.ices.taf("nm.dat")
# ## Proportion of F before spawning ##
propf <- read.ices.taf("pf.dat")
# ## Proportion of M before spawning ##
propm <- read.ices.taf("pm.dat")
# maturity ogive
maturity <- read.ices.taf("mo.dat")
# ## Stock-weight-at-age ##
wstock <- read.ices.taf("sw.dat")
# Landing fraction in catch at age
landfrac <- read.ices.taf("lf.dat")
# survey data
surveys <- read.ices.taf("survey.dat")
## 2 Preprocess data
# landings
latage <- catage * landfrac
datage <- catage * (1 - landfrac)
# put surveys in seperate matrices (for writing out)
survey_summer <- surveys[[1]]
survey_spring <- surveys[[2]]
## 3 Write TAF tables to data directory
write.taf(
c(
"catage", "latage", "datage", "wstock", "wcatch",
"wdiscards", "wlandings", "natmort", "propf", "propm",
"landfrac", "survey_summer", "survey_spring"
),
dir = "data"
)
## write model files
dat <- setup.sam.data(
surveys = surveys,
residual.fleet = catage,
prop.mature = maturity,
stock.mean.weight = wstock,
catch.mean.weight = wcatch,
dis.mean.weight = wdiscards,
land.mean.weight = wlandings,
prop.f = propf,
prop.m = propm,
natural.mortality = natmort,
land.frac = landfrac
)
save(dat, file = "data/data.RData")