-
Notifications
You must be signed in to change notification settings - Fork 1
/
remake raw data.R
220 lines (205 loc) · 13.4 KB
/
remake 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Load libraries
library(stats)
library(stringr)
library(smatr)
library(plyr)
library(tidyr)
library(dplyr)
library(xtable)
library(igraph)
library(rmarkdown)
library(broom)
library(ggtern)
library(ggmap)
library(yaml)
library(mgcv)
library(knitr)
# Source functions
source("R/figures.R")
source("R/FlowerParts.R")
source("R/GraphRepresentation.R")
source("R/Growth.R")
source("R/Investment.R")
source("R/ms-accessory.R")
source("R/ms-RA.R")
source("R/ms-SuppMatt.R")
source("R/ReproductionTissues.R")
source("R/Species.R")
source("R/Summaries.R")
source("R/Utils.R")
source("R/WeightCalculations.R")
# Create directories for outputs
dir.create("ms/RA/figures", FALSE, TRUE)
dir.create("ms", FALSE, TRUE)
dir.create("export", FALSE, TRUE)
# Figures
pdf("ms/RA/figures/schematic.pdf", height = 2.5, width = 7.5)
plotRASexamples()
dev.off()
BAER_PartsList <- make_OrderedListsOfParts_BAER()
BOLE_PartsList <- make_OrderedListsOfParts_BOLE()
COER_PartsList <- make_OrderedListsOfParts_COER()
EPMI_PartsList <- make_OrderedListsOfParts_EPMI()
GRBU_PartsList <- make_OrderedListsOfParts_GRBU()
GRSP_PartsList <- make_OrderedListsOfParts_GRSP()
HATE_PartsList <- make_OrderedListsOfParts_HATE()
HEPU_PartsList <- make_OrderedListsOfParts_HEPU()
LEES_PartsList <- make_OrderedListsOfParts_LEES()
PELA_PartsList <- make_OrderedListsOfParts_PELA()
PEPU_PartsList <- make_OrderedListsOfParts_PEPU()
PHPH_PartsList <- make_OrderedListsOfParts_PHPH()
PILI_PartsList <- make_OrderedListsOfParts_PILI()
PUTU_PartsList <- make_OrderedListsOfParts_PUTU()
pdf("ms/map.pdf", width = 4L, height = 4L)
figure_site_map("data/sites.csv")
dev.off()
IndividualsList <- read_csv("data/individuals.csv")
FlowerPartsData <- read_csv("data/flowerParts.csv")
Reproduction_raw <- read_csv("data/reproduction.csv")
ReproductionData <- filterForAllocation(Reproduction_raw, IndividualsList)
HarvestData_raw <- read_csv("data/harvest.csv")
HarvestData <- preprocessHarvest(HarvestData_raw, IndividualsList)
FloweringCategories <- read_csv("data/flowerCategories.csv")
MultiplierTable <- read_csv("data/multiplierTable.csv")
InvestmentCategories <- yaml.load_file("data/accessoryParts.yml")
LMA_1 <- read_csv("data/LMA.csv")
LMA <- process_LMA(LMA_1)
wood_density_spp1 <- read_csv("data/woodDensity.csv")
wood_density_spp <- process_wood_density(wood_density_spp1)
seedsize <- read_csv("data/seedsize.csv")
leavesPerLength_1 <- read_csv("data/leaves_per_length.csv")
leavesPerLength <- process_leaves_per_length(leavesPerLength_1)
leafLoss_1 <- read_csv("data/leaderGrowthLL.csv")
leafLoss <- process_leaf_loss(leafLoss_1, leavesPerLength)
variable_list <- read_csv("data/variable_metadata.csv")
write.csv(variable_list, "export/Variable_metadata.csv", row.names = FALSE)
BAER_IndividualsList <- filterToBAER(IndividualsList)
BAER_FlowerPartsData <- filterToBAER(FlowerPartsData)
BAER_HarvestData <- filterToBAER(HarvestData)
BAER_ReproductionData <- filterToBAER(ReproductionData)
BAER_PartsSummary <- make_PartsSummary(BAER_FlowerPartsData, BAER_PartsList)
BAER_GraphMaps <- make_BAER_GraphMaps(BAER_PartsSummary, MultiplierTable)
BAER_Investment <- CalculateInvestmentForBAER(BAER_ReproductionData, FloweringCategories, MultiplierTable, BAER_GraphMaps, BAER_PartsSummary)
BAER_ReproductiveCosts <- CalculateReproductiveCostsForBAER(BAER_IndividualsList, InvestmentCategories, BAER_Investment, BAER_PartsSummary)
BAER_Growth <- CalculateGrowthForBAER(BAER_HarvestData, BAER_IndividualsList)
BOLE_IndividualsList <- filterToBOLE(IndividualsList)
BOLE_FlowerPartsData <- filterToBOLE(FlowerPartsData)
BOLE_HarvestData <- filterToBOLE(HarvestData)
BOLE_ReproductionData <- filterToBOLE(ReproductionData)
BOLE_PartsSummary <- make_PartsSummary(BOLE_FlowerPartsData, BOLE_PartsList)
BOLE_GraphMaps <- make_BOLE_GraphMaps(BOLE_PartsSummary, MultiplierTable)
BOLE_Investment <- CalculateInvestmentForBOLE(BOLE_ReproductionData, FloweringCategories, MultiplierTable, BOLE_GraphMaps, BOLE_PartsSummary)
BOLE_ReproductiveCosts <- CalculateReproductiveCostsForBOLE(BOLE_IndividualsList, InvestmentCategories, BOLE_Investment, BOLE_PartsSummary)
BOLE_Growth <- CalculateGrowthForBOLE(BOLE_HarvestData, BOLE_IndividualsList)
COER_IndividualsList <- filterToCOER(IndividualsList)
COER_FlowerPartsData <- filterToCOER(FlowerPartsData)
COER_HarvestData <- filterToCOER(HarvestData)
COER_ReproductionData <- filterToCOER(ReproductionData)
COER_PartsSummary <- make_PartsSummary(COER_FlowerPartsData, COER_PartsList)
COER_GraphMaps <- make_COER_GraphMaps(COER_PartsSummary, MultiplierTable)
COER_Investment <- CalculateInvestmentForCOER(COER_ReproductionData, FloweringCategories, MultiplierTable, COER_GraphMaps, COER_PartsSummary)
COER_ReproductiveCosts <- CalculateReproductiveCostsForCOER(COER_IndividualsList, InvestmentCategories, COER_Investment, COER_PartsSummary)
COER_Growth <- CalculateGrowthForCOER(COER_HarvestData, COER_IndividualsList)
EPMI_IndividualsList <- filterToEPMI(IndividualsList)
EPMI_FlowerPartsData <- filterToEPMI(FlowerPartsData)
EPMI_HarvestData <- filterToEPMI(HarvestData)
EPMI_ReproductionData <- filterToEPMI(ReproductionData)
EPMI_PartsSummary <- make_PartsSummary(EPMI_FlowerPartsData, EPMI_PartsList)
EPMI_GraphMaps <- make_EPMI_GraphMaps(EPMI_PartsSummary, MultiplierTable)
EPMI_Investment <- CalculateInvestmentForEPMI(EPMI_ReproductionData, FloweringCategories, MultiplierTable, EPMI_GraphMaps, EPMI_PartsSummary)
EPMI_ReproductiveCosts <- CalculateReproductiveCostsForEPMI(EPMI_IndividualsList, InvestmentCategories, EPMI_Investment, EPMI_PartsSummary)
EPMI_Growth <- CalculateGrowthForEPMI(EPMI_HarvestData, EPMI_IndividualsList)
GRBU_IndividualsList <- filterToGRBU(IndividualsList)
GRBU_FlowerPartsData <- filterToGRBU(FlowerPartsData)
GRBU_HarvestData <- filterToGRBU(HarvestData)
GRBU_ReproductionData <- filterToGRBU(ReproductionData)
GRBU_PartsSummary <- make_PartsSummary(GRBU_FlowerPartsData, GRBU_PartsList)
GRBU_GraphMaps <- make_GRBU_GraphMaps(GRBU_PartsSummary, MultiplierTable)
GRBU_Investment <- CalculateInvestmentForGRBU(GRBU_ReproductionData, FloweringCategories, MultiplierTable, GRBU_GraphMaps, GRBU_PartsSummary)
GRBU_ReproductiveCosts <- CalculateReproductiveCostsForGRBU(GRBU_IndividualsList, InvestmentCategories, GRBU_Investment, GRBU_PartsSummary)
GRBU_Growth <- CalculateGrowthForGRBU(GRBU_HarvestData, GRBU_IndividualsList)
GRSP_IndividualsList <- filterToGRSP(IndividualsList)
GRSP_FlowerPartsData <- filterToGRSP(FlowerPartsData)
GRSP_HarvestData <- filterToGRSP(HarvestData)
GRSP_ReproductionData <- filterToGRSP(ReproductionData)
GRSP_PartsSummary <- make_PartsSummary(GRSP_FlowerPartsData, GRSP_PartsList)
GRSP_GraphMaps <- make_GRSP_GraphMaps(GRSP_PartsSummary, MultiplierTable)
GRSP_Investment <- CalculateInvestmentForGRSP(GRSP_ReproductionData, FloweringCategories, MultiplierTable, GRSP_GraphMaps, GRSP_PartsSummary)
GRSP_ReproductiveCosts <- CalculateReproductiveCostsForGRSP(GRSP_IndividualsList, InvestmentCategories, GRSP_Investment, GRSP_PartsSummary)
GRSP_Growth <- CalculateGrowthForGRSP(GRSP_HarvestData, GRSP_IndividualsList)
HATE_IndividualsList <- filterToHATE(IndividualsList)
HATE_FlowerPartsData <- filterToHATE(FlowerPartsData)
HATE_HarvestData <- filterToHATE(HarvestData)
HATE_ReproductionData <- filterToHATE(ReproductionData)
HATE_PartsSummary <- make_PartsSummary(HATE_FlowerPartsData, HATE_PartsList)
HATE_GraphMaps <- make_HATE_GraphMaps(HATE_PartsSummary, MultiplierTable)
HATE_Investment <- CalculateInvestmentForHATE(HATE_ReproductionData, FloweringCategories, MultiplierTable, HATE_GraphMaps, HATE_PartsSummary)
HATE_ReproductiveCosts <- CalculateReproductiveCostsForHATE(HATE_IndividualsList, InvestmentCategories, HATE_Investment, HATE_PartsSummary)
HATE_Growth <- CalculateGrowthForHATE(HATE_HarvestData, HATE_IndividualsList)
HEPU_IndividualsList <- filterToHEPU(IndividualsList)
HEPU_FlowerPartsData <- filterToHEPU(FlowerPartsData)
HEPU_HarvestData <- filterToHEPU(HarvestData)
HEPU_ReproductionData <- filterToHEPU(ReproductionData)
HEPU_PartsSummary <- make_PartsSummary(HEPU_FlowerPartsData, HEPU_PartsList)
HEPU_GraphMaps <- make_HEPU_GraphMaps(HEPU_PartsSummary, MultiplierTable)
HEPU_Investment <- CalculateInvestmentForHEPU(HEPU_ReproductionData, FloweringCategories, MultiplierTable, HEPU_GraphMaps, HEPU_PartsSummary)
HEPU_ReproductiveCosts <- CalculateReproductiveCostsForHEPU(HEPU_IndividualsList, InvestmentCategories, HEPU_Investment, HEPU_PartsSummary)
HEPU_Growth <- CalculateGrowthForHEPU(HEPU_HarvestData, HEPU_IndividualsList)
LEES_IndividualsList <- filterToLEES(IndividualsList)
LEES_FlowerPartsData <- filterToLEES(FlowerPartsData)
LEES_HarvestData <- filterToLEES(HarvestData)
LEES_ReproductionData <- filterToLEES(ReproductionData)
LEES_PartsSummary <- make_PartsSummary(LEES_FlowerPartsData, LEES_PartsList)
LEES_GraphMaps <- make_LEES_GraphMaps(LEES_PartsSummary, MultiplierTable)
LEES_Investment <- CalculateInvestmentForLEES(LEES_ReproductionData, FloweringCategories, MultiplierTable, LEES_GraphMaps, LEES_PartsSummary)
LEES_ReproductiveCosts <- CalculateReproductiveCostsForLEES(LEES_IndividualsList, InvestmentCategories, LEES_Investment, LEES_PartsSummary)
LEES_Growth <- CalculateGrowthForLEES(LEES_HarvestData, LEES_IndividualsList)
PELA_IndividualsList <- filterToPELA(IndividualsList)
PELA_FlowerPartsData <- filterToPELA(FlowerPartsData)
PELA_HarvestData <- filterToPELA(HarvestData)
PELA_ReproductionData <- filterToPELA(ReproductionData)
PELA_PartsSummary <- make_PartsSummary(PELA_FlowerPartsData, PELA_PartsList)
PELA_GraphMaps <- make_PELA_GraphMaps(PELA_PartsSummary, MultiplierTable)
PELA_Investment <- CalculateInvestmentForPELA(PELA_ReproductionData, FloweringCategories, MultiplierTable, PELA_GraphMaps, PELA_PartsSummary)
PELA_ReproductiveCosts <- CalculateReproductiveCostsForPELA(PELA_IndividualsList, InvestmentCategories, PELA_Investment, PELA_PartsSummary)
PELA_Growth <- CalculateGrowthForPELA(PELA_HarvestData, PELA_IndividualsList)
PEPU_IndividualsList <- filterToPEPU(IndividualsList)
PEPU_FlowerPartsData <- filterToPEPU(FlowerPartsData)
PEPU_HarvestData <- filterToPEPU(HarvestData)
PEPU_ReproductionData <- filterToPEPU(ReproductionData)
PEPU_PartsSummary <- make_PartsSummary(PEPU_FlowerPartsData, PEPU_PartsList)
PEPU_GraphMaps <- make_PEPU_GraphMaps(PEPU_PartsSummary, MultiplierTable)
PEPU_Investment <- CalculateInvestmentForPEPU(PEPU_ReproductionData, FloweringCategories, MultiplierTable, PEPU_GraphMaps, PEPU_PartsSummary)
PEPU_ReproductiveCosts <- CalculateReproductiveCostsForPEPU(PEPU_IndividualsList, InvestmentCategories, PEPU_Investment, PEPU_PartsSummary)
PEPU_Growth <- CalculateGrowthForPEPU(PEPU_HarvestData, PEPU_IndividualsList)
PHPH_IndividualsList <- filterToPHPH(IndividualsList)
PHPH_FlowerPartsData <- filterToPHPH(FlowerPartsData)
PHPH_HarvestData <- filterToPHPH(HarvestData)
PHPH_ReproductionData <- filterToPHPH(ReproductionData)
PHPH_PartsSummary <- make_PartsSummary(PHPH_FlowerPartsData, PHPH_PartsList)
PHPH_GraphMaps <- make_PHPH_GraphMaps(PHPH_PartsSummary, MultiplierTable)
PHPH_Investment <- CalculateInvestmentForPHPH(PHPH_ReproductionData, FloweringCategories, MultiplierTable, PHPH_GraphMaps, PHPH_PartsSummary)
PHPH_ReproductiveCosts <- CalculateReproductiveCostsForPHPH(PHPH_IndividualsList, InvestmentCategories, PHPH_Investment, PHPH_PartsSummary)
PHPH_Growth <- CalculateGrowthForPHPH(PHPH_HarvestData, PHPH_IndividualsList)
PILI_IndividualsList <- filterToPILI(IndividualsList)
PILI_FlowerPartsData <- filterToPILI(FlowerPartsData)
PILI_HarvestData <- filterToPILI(HarvestData)
PILI_ReproductionData <- filterToPILI(ReproductionData)
PILI_PartsSummary <- make_PartsSummary(PILI_FlowerPartsData, PILI_PartsList)
PILI_GraphMaps <- make_PILI_GraphMaps(PILI_PartsSummary, MultiplierTable)
PILI_Investment <- CalculateInvestmentForPILI(PILI_ReproductionData, FloweringCategories, MultiplierTable, PILI_GraphMaps, PILI_PartsSummary)
PILI_ReproductiveCosts <- CalculateReproductiveCostsForPILI(PILI_IndividualsList, InvestmentCategories, PILI_Investment, PILI_PartsSummary)
PILI_Growth <- CalculateGrowthForPILI(PILI_HarvestData, PILI_IndividualsList)
PUTU_IndividualsList <- filterToPUTU(IndividualsList)
PUTU_FlowerPartsData <- filterToPUTU(FlowerPartsData)
PUTU_HarvestData <- filterToPUTU(HarvestData)
PUTU_ReproductionData <- filterToPUTU(ReproductionData)
PUTU_PartsSummary <- make_PartsSummary(PUTU_FlowerPartsData, PUTU_PartsList)
PUTU_GraphMaps <- make_PUTU_GraphMaps(PUTU_PartsSummary, MultiplierTable)
PUTU_Investment <- CalculateInvestmentForPUTU(PUTU_ReproductionData, FloweringCategories, MultiplierTable, PUTU_GraphMaps, PUTU_PartsSummary)
PUTU_ReproductiveCosts <- CalculateReproductiveCostsForPUTU(PUTU_IndividualsList, InvestmentCategories, PUTU_Investment, PUTU_PartsSummary)
PUTU_Growth <- CalculateGrowthForPUTU(PUTU_HarvestData, PUTU_IndividualsList)
Growth_all <- combine_Growth(BAER_Growth, BOLE_Growth, COER_Growth, EPMI_Growth, GRBU_Growth, GRSP_Growth, HATE_Growth, HEPU_Growth, LEES_Growth, PELA_Growth, PEPU_Growth, PHPH_Growth, PILI_Growth, PUTU_Growth, NULL)
write.csv(SummaryInd, "export/SummaryInd.csv", row.names = FALSE)
PartsSummary_all <- combine_list_elements(BAER_PartsSummary, BOLE_PartsSummary, COER_PartsSummary, EPMI_PartsSummary, GRBU_PartsSummary, GRSP_PartsSummary, HATE_PartsSummary, HEPU_PartsSummary, LEES_PartsSummary, PELA_PartsSummary, PEPU_PartsSummary, PHPH_PartsSummary, PILI_PartsSummary, PUTU_PartsSummary, element = "AvWeightPerUnit")
Investment_FD_all <- combine_list_elements(BAER_Investment, BOLE_Investment, COER_Investment, EPMI_Investment, GRBU_Investment, GRSP_Investment, HATE_Investment, HEPU_Investment, LEES_Investment, PELA_Investment, PEPU_Investment, PHPH_Investment, PILI_Investment, PUTU_Investment, element = "FD")