-
Notifications
You must be signed in to change notification settings - Fork 2
/
_targets.R
200 lines (142 loc) · 6.03 KB
/
_targets.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
#### CPR Data Targets Pipeline
# 4/28/2021
# Load packages and set specific options for the workflow
options(tidyverse.quiet = T)
suppressPackageStartupMessages(library(targets))
suppressPackageStartupMessages(library(tarchetypes))
suppressPackageStartupMessages(library(sf))
suppressPackageStartupMessages(library(here))
suppressPackageStartupMessages(library(raster))
suppressPackageStartupMessages(library(tidyverse))
# source(here::here("R", "cpr_helper_funs.R"))
source(here("R", "support/gom_cpr_pipeline_support.R"))
# Additional packages to load specific to target(s)
tar_option_set( packages = c("raster", "sf", "rmarkdown", "tidyverse", "gmRi") )
# Define target pipeline: Outlines high-level steps of the analysis
# Format is just a list of all the targets
# Order is not important, package sorts out connections for everything
list(
#### GOM Analyses ####
#### Raw NOAA
tar_target(
name = noaa_zoo,
command = import_noaa_cpr(sample_type = "zoo", return_option = "abundances")),
tar_target(
name = noaa_zoo_key,
command = import_noaa_cpr(sample_type = "zoo", return_option = "key")),
tar_target(
name = noaa_phyto,
command = import_noaa_cpr(sample_type = "phyto", return_option = "abundances")),
tar_target(
name = noaa_phyto_key,
command = import_noaa_cpr(sample_type = "phyto", return_option = "key")),
#### Raw SAHFOS
# MC1 Tables
tar_target(sahfos_mc1_taxa,
sahfos_taxa_key("mc1")),
tar_target(
name = sahfos_eye_mc1,
command = import_sahfos_mc1(mc_taxa_key = sahfos_mc1_taxa, sample_type = "eye")),
tar_target(
name = sahfos_phyto_mc1,
command = import_sahfos_mc1(mc_taxa_key = sahfos_mc1_taxa, sample_type = "phyto")),
tar_target(
name = sahfos_trav_mc1,
command = import_sahfos_mc1(mc_taxa_key = sahfos_mc1_taxa, sample_type = "trav")),
# MC2 Tables
tar_target(sahfos_mc2_taxa,
sahfos_taxa_key("mc2")),
tar_target(
name = sahfos_eye_mc2,
command = import_sahfos_mc2(mc_taxa_key = sahfos_mc2_taxa, sample_type = "eye")),
tar_target(
name = sahfos_phyto_mc2,
command = import_sahfos_mc2(mc_taxa_key = sahfos_mc2_taxa, sample_type = "phyto")),
tar_target(
name = sahfos_trav_mc2,
command = import_sahfos_mc2(mc_taxa_key = sahfos_mc2_taxa, sample_type = "trav")),
# join the two mc periods
tar_target(sahfos_phyto,
bind_mc_tables(sahfos_phyto_mc1, sahfos_phyto_mc2)),
tar_target(sahfos_trav,
bind_mc_tables(sahfos_trav_mc1, sahfos_trav_mc2)),
tar_target(sahfos_eye,
bind_mc_tables(sahfos_eye_mc1, sahfos_eye_mc2)),
tar_target(sahfos_meta,
pull_sahfos_metadata(sahfos_trav)),
#### Unit Conversions ####
# sahfos data is in number per silk transect currently
# which are values centered around a categorical counting system
# conversion goes from actual numbers captured from actual cpr water volume
# to what those rates are in # per 100 meters cubed
tar_target(sahfos_phyto_100m,
sahfos_to_100(sahfos_phyto)),
tar_target(sahfos_trav_100m,
sahfos_to_100(sahfos_trav)),
tar_target(sahfos_eye_100m,
sahfos_to_100(sahfos_eye)),
# Combine Traverse and Eyecount Zooplankton Groups
# this is what sourcing 16_SAHFOS_CPR_Cleanup.R returns
tar_target(sahfos_zoo_100m,
join_zooplankton(sahfos_trav = sahfos_trav_100m,
sahfos_eye = sahfos_eye_100m,
sahfos_meta = sahfos_meta)),
#### Resolving Taxa Differences ####
tar_target(noaa_taxa_resolved,
consolidate_noaa_taxa(noaa_abundances = noaa_zoo)),
# match the column names to the noaa columns
tar_target(sahfos_renamed,
match_sahfos_to_noaa(sahfos_zoo_100m)),
#### Joining Different Sources ####
tar_target(combined_zooplankton,
join_zoo_sources(noaa_taxa_resolved, sahfos_renamed)),
#### Seasonal Splines ####
# Format Dates
tar_target(cpr_spline_prepped,
cpr_spline_prep(combined_zooplankton)),
# Crop to study area
tar_target(gom_area_cropped,
cpr_area_crop(cpr_spline_prepped, study_area = "gom_new")),
# Pull taxa into lists
tar_target(taxa_abundance_list,
split_cpr_by_taxa(gom_area_cropped)),
# Run Models
tar_target(gom_seasonal_splines,
command = map(.x = taxa_abundance_list,
.f = cpr_spline_fun,
spline_bins = 10,
season_bins = 4)),
# Store Predicted Anomalies
tar_target(gom_anomalies,
command = map(gom_seasonal_splines, pluck, "cprdat_predicted")),
# Store Seasonal Averages (yearly and seasonal averages)
tar_target(gom_seasonal_avgs,
command = map_dfr(gom_seasonal_splines, function(x){
pluck(x, "period_summs")}, .id = "taxa" )),
# Store the GAMS
tar_target(gom_spline_models,
command = map(gom_seasonal_splines, pluck, "spline_model")),
#### PCA work ####
# reshape as matrix (pick abundance or anomalies here)
tar_target(anom_z_matrices,
prep_PCA_periods(
cpr_anomalies_long = gom_seasonal_avgs,
matrix_var = "standardized anomalies",
use_focal_species = TRUE,
year_subsets = list("1961-2003" = c(1961,2003),
"All years" = c(1961, 2017))
)),
# Set whether to use annual or seasonal time steps
tar_target(annual_anom_z_matrices,
set_PCA_timestep(period_list = anom_z_matrices, periodicity = "annual")),
# perform PCA's
tar_target(Pershing05_period_PCA,
perform_CPR_PCA(pca_data_list = annual_anom_z_matrices,
pca_group_id = "1961-2003")),
tar_target(All_years_annual_PCA,
perform_CPR_PCA(pca_data_list = annual_anom_z_matrices,
pca_group_id = "All years"))
####______________________####
#### MAB Analyses ####
)
# End of _targets.R