-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_HERAS_raw_data.R
124 lines (99 loc) · 3.21 KB
/
1_HERAS_raw_data.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
rm(list = ls())
#### Packages ####
library(ggplot2)
library(mapplots) # draw.pie
data("coast") # coastlines
library(maps)
library(mapdata)
library(gdata) # drop.levels
library(reshape) # melt and cast
library(gstat)
library(sp)
path <- 'C:/git/HERAS'
try(setwd(path),silent=TRUE)
mainPath <- file.path(".")
dataPath <- file.path(".","data")
functionPath <- file.path(".","functions")
# network data path
dataPath <- file.path('Z:/HERAS/data')
source(file.path(functionPath,"load_ICESdB.R"))
source(file.path(functionPath,"plot_biotic.R"))
source(file.path(functionPath,"plot_acoustic.R"))
source(file.path(functionPath,"mk_report_ICESdB.R"))
source(file.path(functionPath,"mk_length_matrix.R"))
mkReport <- FALSE
mkPlot <- FALSE
# load species list - in git data path
fileName <- 'species_codes_201911.csv'
speciesList <- read.csv(file.path(".","data",fileName), fill = TRUE, header = TRUE)
surveyYearMat <- c(2019,2018,2017)
surveyYearMat <- c(2019)
for(surveyYear in surveyYearMat){
reportPath <- file.path(".","reports",surveyYear)
figurePath <- file.path(".","figures",'raw_data',surveyYear)
rawDataPath <- file.path(dataPath,'raw_data',surveyYear)
# build directory list
dataDirs <- list.dirs(path = rawDataPath, full.names = TRUE, recursive = TRUE)
dataDirs <- dataDirs[2:length(dataDirs)]
count <- 0
# loop on directories (i.e. each country)
for(idxDir in dataDirs){
count <- count + 1
print(idxDir)
fileMat <- list.files(path = idxDir,pattern = "\\.csv$")
### load data
for(idxFile in fileMat){
A <- load_ICESdb(idxDir,idxFile)
header <- A[[1]]
for(idxHeader in 2:length(A)){
eval(parse(text = paste0(header[idxHeader-1],
'=A[[',
as.character(idxHeader),']]')))
}
}
length(Biology$BiologyIndividualAge[!Biology$BiologyIndividualAge == ''])
length(Biology$BiologyIndividualSex[!Biology$BiologyIndividualSex == ''])
length(Biology$BiologyIndividualMaturity[!Biology$BiologyIndividualMaturity == ''])
A <- Biology[!Biology$BiologyIndividualSex == '',]
dim(A[A$CatchSpeciesCode == 126417,])
dim(A[A$CatchSpeciesCode == 126425,])
if(mkPlot){
### plot Biotic data
plot_biotic(Cruise,
Biology,
Catch,
Haul,
speciesList,
figurePath)
### plot Acoustic data
plot_acoustic(Data,
Cruise,
Haul,
figurePath)
}
if(mkReport){
# make report
mk_report_ICESdB(Cruise,
Biology,
Catch,
Haul,
Data,
speciesList,
reportPath)
}
if(count == 1){
CatchAll <- Catch
HaulAll <- Haul
BiologyAll <- Biology
CruiseAll <- Cruise
DataAll <- Data
}else{
CatchAll <- rbind(CatchAll,Catch)
HaulAll <- rbind(HaulAll,Haul)
BiologyAll <- rbind(BiologyAll,Biology)
CruiseAll <- rbind(CruiseAll,Cruise)
DataAll <- rbind(DataAll,Data)
}
}
save(CatchAll, HaulAll, BiologyAll, CruiseAll, DataAll, file = file.path(rawDataPath,paste0(surveyYear,"_HERAS",".Rdata")))
}