-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_targets.R
107 lines (72 loc) · 3.93 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
library(targets)
library(tarchetypes)
library(knitr)
# file 1_ is not targetted due to compications with using terra and targets. See https://github.com/ropensci/targets/discussions/809
knit('R/2_sp_data_processing.Rmd',output = 'R/2_sp_data_processing.md',quiet = T)
knit('R/3_model_prep.Rmd',output = 'R/3_model_prep.md',quiet = T)
knit('R/4_model_run.Rmd',output = 'R/4_model_run.md',quiet = T)
tar_option_set(packages = c("terra","sf","dplyr","rgbif"))
sp_list_location <- "inputs/species_list/sp_list.txt"
#define the different species
values <- data.frame(taxon_id = readLines(sp_list_location),
data_location = paste0("inputs/species_data/",readLines(sp_list_location),".rds"))
#if we're looking to just test the pipeline
test_mode <- F
if(test_mode){ #only run for 4 species
values <- values[1:4,]
}
effort_mapped <- tar_map(values = values,
names = taxon_id,
tar_target(effort_gbif_data_raw, data_location, format = "file"),
tar_target(effort_gbif_data_processed, process_gbif_data(effort_gbif_data_raw)))
# map the different species
mapped <-tar_map(values = values,
names = taxon_id,
#load in the raw gbif data (with files for each species)
tar_target(gbif_data_raw, data_location, format = "file"),
#process the raw gbif data
tar_target(species_metadata,get_species_metadata(gbif_data_raw)),
tar_target(gbif_data_processed, process_gbif_data(gbif_data_raw)),
#model_prep
tar_target(sdm_data,generate_samples(env_layers,gbif_data_processed)),
# fitting models
tar_target(full_model,fit_model(sdm_data)),
tar_target(sdm_pred,sp_probability(full_model,
env_layers_aoi,
taxon_id,
species_metadata),format ="file"),
# model variability (for determining recording priority)
tar_target(bs_models,fit_bs_models(sdm_data)),
tar_target(sdm_var,sp_variability(bs_models,
env_layers_aoi,
taxon_id,
species_metadata),format ="file"),
#produce report
tar_render(sdm_report,
params = list(species_metadata = species_metadata,
sdm_data = sdm_data,
full_model = full_model,
sdm_pred = sdm_pred,
bs_models = bs_models,
sdm_var = sdm_var),
"R/5_model_eval_report.Rmd",
output_file = paste0("../outputs/by_species/reports/",taxon_id, ".html"))
)
list(
#env_data_load
tar_target(env_layers, "inputs/environmental/env-layers.tif",format="file"),
tar_target(aoi_predict, "inputs/regions/AOI_predict/AOI_predict.shp",format="file"),
tar_target(env_layers_aoi,crop_env_layers(env_layers,aoi_predict),format = "file"),
effort_mapped,
mapped,
tar_combine(name = sp_richness,
mapped$sdm_pred,
command = build_sp_richness(c(!!!.x)),
use_names = F,
format="file"),
tar_combine(name = recording_priority,
mapped$sdm_var,
command= build_rec_priority(c(!!!.x)),
use_names = F,
format="file")
)