-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_targets.R
448 lines (381 loc) · 12 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
library(targets)
library(tarchetypes)
source("src/functions.R")
source("src/glider_funcs.R")
source("src/util_funcs.R")
options(tidyverse.quiet = TRUE)
tar_option_set(packages = c("data.table", "sf", "glatos", "geosphere", "viridisLite", "ggplot2", "raster", "flextable", "terra", "geosphere", "leaflet", "readxl", "leafgl", "spatstat.core", "tidyverse", "DT", "kableExtra"))
list(
# load path to range curve data collected by Binder in 2016 in GB with V13 tags
tar_target(
raw_log_reg_H_GBE,
"data/Results/Results/GBE/LogisticRegressions/HighPower/logisticResultsH.csv",
format = "file"
),
# load path to Saginaw Bay Reef locations
tar_target(
raw_SB_reefs,
"data/Saginaw Bay Reef Locations.xlsx",
format = "file"
),
# load path to LWF receivers
tar_target(
raw_grid,
"data/us_receivers_20201215.csv",
format = "file"
),
# load path to Sag Bay polygon from EPA-AOC
tar_target(
raw_sbay,
"data/aoc_mi_saginaw_river_bay/AOC_MI_SAGINAW_RIVER_BAY.shp",
format = "file"
),
# Convert SB polygon of SB to wgs84
tar_target(
sbay,
{shp <- st_read(raw_sbay, quiet = TRUE);
shp <- shp[shp$AOC == "AREA OF CONERN",];
st_transform(shp, crs = 4326)
},
format = "rds"
),
# Convert LWF grid to sf object
tar_target(
grid,
{grd <- fread(raw_grid);
grd <- grd[!(station %in% c("YTZ-035", "YTZ-031", "YTZ-030", "YTZ-034", "YTZ-039", "YTZ-042", "YTZ-038")),];
st_as_sf(grd, coords = c("longitude", "latitude"), remove = FALSE, crs = 4326, agr = "constant")
},
format = "rds"
),
# write out planning map
tar_target(
plan_map,
.plan_map(grid, reefs, dirty_lines, grid10km = grid_10km_dup_reefs, bay_outline = sbay, pth = "output/comb_plan_map.html", write = TRUE),
format = "file"
),
# raw file for lake huron bathymetry data
tar_target(
raw_bathy,
"data/LH_bathy/huron_lld.tif",
),
tar_target(
bathy,
prep_bathy(raw_bathy, xmin_out = -83.96, xmax_out = -82.535, ymin_out = 43.5, ymax_out = 44.44, out_pth = "~/Documents/WA_sources_of_reproduction_2021/grid_planing/output/bathy_SB.tif"),
format = "file"
),
tar_target(
grid_depth,
depth_extract(raw_recs = grid, bathy = bathy, lidar = NULL),
format = "rds"
),
## tar_target(
## map,
## grid_map(bathy,
## grid = grid_depth,
## sbay,
## reefs = reefs,
## rec_grid = inner_bay_rec_grid,
## spawn_rivers = spawn_rivs,
## bay_mth = bay_mth_grd,
## sim_fish = sim_tracks,
## rand_grid = inner_bay_rec_grid_rand,
## pth = "docs/index.html"),
## format = "file"
## ),
tar_target(
rec_grid,
.grid(poly = sbay, cellsize = c(10000, 10000), in_crs = 3175, out_crs = 4326),
format = "rds"
),
# read in Sag Bay reefs
# subset only 4 main reefs
tar_target(
dirty_reefs,
{out <- as.data.table(read_xlsx(path = raw_SB_reefs, range = "Reefs!D6:I15"));
out <- out[Reef %in% c("Tawas Reef", "Little Charity Island Reef", "Duck Reef", "Coreyon (restored)", "North Island Reef"),]
#fwrite(out, "data/SB_reefs.csv")
},
format = "fst_dt"
),
# proposed sturgeon river recs
tar_target(
sturgeon,
"data/Potential Receiver Deployments Saginaw River System 3.3.22.xlsx",
format = "file"
),
# hard coded release locations!!!! this is going to be a problem!!!!
tar_target(
dirty_sturgeon,
{out <- as.data.table(read_xlsx(path = sturgeon, range = "Sheet1!A1:D16"));
out <- out[c(1,3,5,9), id := "Rel"][is.na(id), id := "rec_pt"]
out <- st_as_sf(out, coords = c("Longitude", "Latitide"), crs = 4326, agr = "constant")
},
format = "rds"
),
# contains possible tributary deployments
tar_target(
rec_lines,
"data/LH_tribs_lines.csv",
format = "file"
),
tar_target(
dirty_lines,
{out <- fread(rec_lines);
out <- out[GLATOS_ARRAY %in% c("HBC", "OSC"),];
out <- out[STATION_NO %% 2 == 1,];
out[,STATION_NO := 1:.N, by = .(GLATOS_ARRAY)]
# out[, `:=`(center_lat = mean(DEPLOY_LAT), center_lon = mean(DEPLOY_LONG)), by = .(GLATOS_ARRAY, STATION_NO)]
out[, `:=`(site = paste(GLATOS_ARRAY, STATION_NO, sep = "_"))]
out<- st_as_sf(out, coords = c("DEPLOY_LONG", "DEPLOY_LAT"), agr = "constant", crs = 4326)
},
format = "rds"
),
tar_target(
reefs,
clean_reefs(x = dirty_reefs),
format = "rds"
),
tar_target(
raw_spawn_riv,
"data/spawning_rivers.csv",
format = "file"
),
tar_target(
spawn_rivs,
.spawn_rivs(raw = raw_spawn_riv),
format = "rds"
),
# this is raw layer for Saginaw Bay mouth sub-array. Adjust the size of this and the inner- bay sub-array should automatically adjust.
tar_target(
sag_bay_mth_raw,
"data/SB_mouth.gpkg",
format = "file"
),
tar_target(
sag_bay_mth,
sf::st_read(sag_bay_mth_raw, quiet = TRUE, agr = "constant"),
format = "rds"
),
tar_target(
bay_mth,
sf::st_intersection(sag_bay_mth, sbay),
format = "rds"
),
# create bay mouth array
tar_target(
bay_mth_grd,
.grid(poly = bay_mth, cellsize = c(5000, 5000), in_crs = 3175, out_crs = 4326),
format = "rds"
),
tar_target(
GL_poly,
fix_CRS(),
format = "rds"
),
tar_target(
LH,
crop(GL_poly, xmin = -84.387, xmax = -82.0915, ymin = 43, ymax = 45),
format = "rds"
),
# contains summary of map and receiver deployments locations for most recent design (2022-07-06)
tar_render(
dtc_summary,
"src/coords.rmd",
output_dir = "docs",
output_file = "index.html"
),
# create simulated tracks. Adjust inputs in "crw_in_polygon_updated" to change nature of tracks
## tar_target(
## sim_tracks,
## .sim_tracks(
## n_trks = 2,
## poly = LH,
## theta = c(0,25),
## stepLen = 1000,
## initHeading = 40,
## nsteps = 150,
## initPos = c(-83.6248, 43.8824),
## sp_out = FALSE,
## show_progress = FALSE,
## recs = bay_mth_grd),
## format = "fst_dt"
## ),
# calculate min distance between fish and all receivers in grid
## tar_target(
## min_dist,
## sim_fish_rec_dist(fsh_trks = sim_tracks, rec_grid = bay_mth_grd),
## format = "fst_dt"
## ),
#transmissions for all simulated fish tracks and simulated tags
## tar_target(
## sim_tag_trans,
## .sim_tag_trans(
## path = sim_tracks,
## vel = 0.5,
## delayRng = c(280,400),
## burstDur = 5,
## EPSG = 3175,
## sp_out = FALSE),
## format = "fst_dt"
## ),
## # determine which transmission were detected or not on bay mouth receivers only
## tar_target(
## sim_dtc_low_perf,
## .sim_dtc(dtc_trans = sim_tag_trans,
## recLoc = bay_mth_grd,
## EPSG = 3175,
## sp_out = FALSE,
## show_progress = FALSE,
## min_dist = sim_tracks,
## ba = c(2.913904, -0.0051440101)),
## format = "fst_dt"
## ),
## # determine which transmissions were detected or not on bay mouth receivers only
## tar_target(
## sim_dtc_high_perf,
## .sim_dtc(dtc_trans = sim_tag_trans,
## recLoc = bay_mth_grd,
## EPSG = 3175,
## sp_out = FALSE,
## show_progress = FALSE,
## min_dist = sim_tracks,
## ba = c(3.104209, -0.0021253279)),
## format = "fst_dt"
## ),
# create "inner bay" area by removing bay mouth region from sag bay polygon
## tar_target(
## in_bay,
## .difference(x = sbay, y = sag_bay_mth),
## format = "rds"
## ),
# create "inner bay" receiver grid
# also consider spatstat::nncross for nearest neighbour type analysis
# see nngeo::st_nn function. Prehaps easier to randomly place points in Sag Bay and then remove all points that are within a spedified distance?
# generate random points in polygon with minimum distance from one another and from polygon boundary
# https://gis.stackexchange.com/questions/163287/randomly-sampling-points-in-r-with-minimum-distance-constraint
## tar_target(
## inner_bay_rec_grid,
## .inner_bay_rec_grid(bbox = c(xmin = -83.948193, xmax = -82.946270, ymin = 43.595602, ymax = 44.277664),
## cellsize = c(10000, 10000),
## inner_bay_poly = in_bay,
## reefs = reefs),
## format = "rds"
## ),
# grid entire sag bay
# 5 km
tar_target(
grid_5km,
.inner_bay_rec_grid(bbox = c(xmin = -83.948193, xmax = -82.946270, ymin = 43.595602, ymax = 44.277664),
cellsize = c(5000, 5000),
inner_bay_poly = sbay,
reefs = reefs),
format = "rds"
),
# 10 km
tar_target(
grid_10km,
.inner_bay_rec_grid(bbox = c(xmin = -83.948193, xmax = -82.946270, ymin = 43.595602, ymax = 44.277664),
cellsize = c(10000, 10000),
inner_bay_poly = sbay,
reefs = reefs),
format = "rds"
),
# 10 km base grid(includes both recevier and grid points, some overlap, 2022-07-11)
tar_target(
grid_10km_dup_reefs,
.inner_bay_rec_grid(bbox = c(xmin = -83.948193, xmax = -82.946270, ymin = 43.595602, ymax = 44.277664),
cellsize = c(10000, 10000),
inner_bay_poly = sbay,
reefs = reefs,
all_dups = TRUE),
format = "rds"
),
# 15 km
tar_target(
grid_15km,
.inner_bay_rec_grid(bbox = c(xmin = -83.948193, xmax = -82.946270, ymin = 43.595602, ymax = 44.277664),
cellsize = c(15000, 15000),
inner_bay_poly = sbay,
reefs = reefs),
format = "rds"
),
# adjusted grid to avoid shipping lanes, shallow water, etc
tar_target(
raw_adj_grid,
"data/grid_adj_20220621.csv",
format = "file"
),
# visualize and clean up pts for rec deployments (latest version of grid 2022-06-23)
tar_target(
leaflet_pts,
clean_leaflet(reefs = reefs, LH_grid = grid, dirty_lines = dirty_lines, sag_grid = grid_10km_dup_reefs, adjustments = raw_adj_grid, sturgeon = dirty_sturgeon_pts, rivs = spawn_rivs),
format = "rds"
),
# create gpx of only points in bay that HBBS is responsible for tending (2022-07-06)
tar_target(
gpx_file,
{
foo <- leaflet_pts %>% filter(glatos_array != "YTZ" & !is.na(glatos_array) & !(glatos_array %in% c("KAW", "RIF", "AUG", "TAW", "PIN", "SGN", "PNC", "QUA", "PIG"))) %>% select(site) %>% rename(name = site)
st_write(foo, "output/Sbay_walleye_recs.gpx", driver = "GPX", append = FALSE)
return("output/Sbay_walleye_recs.gpx")},
format = "file"
),
# create gpx of all points in bay (no LWF receivers, but include all sag tribs)(2022-07-06)
tar_target(
gpx_file_all,
{foo <- leaflet_pts %>% filter(glatos_array != "YTZ" | is.na(glatos_array)) %>% select(site) %>% rename(name = site)
st_write(foo, "output/Sbay_walleye_recs_all.gpx", driver = "GPX", append = FALSE)
return("output/Sbay_walleye_recs_all.gpx")},
format = "file"
),
# create kml of all points in bay (no LWF receivers, but all sag tribs) (2022-07-06)
tar_target(
kml_all,
{foo <- leaflet_pts %>% filter(glatos_array != "YTZ" | is.na(glatos_array)) %>% select(site) %>% rename(name = site)
st_write(foo, "output/Sbay_walleye_recs_all.kml", driver = "kml", append = FALSE)
return("output/Sbay_walleye_recs_all.kml")},
format = "file"
),
tar_target(
raw_sturgeon,
"data/Proposed Sturgeon Receivers in Tribs v1 (1).kmz",
format = "file"
),
tar_target(
dirty_sturgeon_pts,
{foo <- sf::st_read(raw_sturgeon)
foo <- st_zm(foo)
setDT(foo)
# add site names
foo[, site := c("TRA_1", "TRR_1", "TRL_1", "CRA_1", "CRR_1", "CRL_1", "FRR_1", "FRL_1", "FRL_2", "FRL_3", "SHA_1", "SHR_1", "SHL_1", "SHL_2", "SHL_3", "SAG_1", "SAG_2", "SAG_3", "SAG_4", "SAG_5")]
foo <- st_as_sf(foo)
},
format = "rds"
),
# add in receiver maintenance data for all Sag Bay
tar_target(
raw_maintenance,
"data/WA_rec_maintenance_20220701.csv",
format = "file"
),
# latest packing list for receiver deployments (2022-07-06)
tar_render(
HBBS_rec_prep,
"src/HBBS_rec_list.rmd",
output_dir = "output",
output_file = "HBBS_rec_deps_WA.html"
),
# add in MDNR and Purdue gear deployments in Saginaw Bay (2022-07-07)
tar_target(
purdue_raw,
"data/Saginaw Bay instrument package locations.xlsx",
format = "file"
),
tar_target(
purdue,
.purdue(x = purdue_raw),
format = "rds"
)
)
#)