forked from stateofindiasbirds/soib_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00_pipeline_multimachine.R
116 lines (83 loc) · 3 KB
/
00_pipeline_multimachine.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
# necessary packages, functions/scripts, data
library(tidyverse)
library(glue)
library(tictoc)
source("00_scripts/00_functions.R")
load("00_data/analyses_metadata.RData")
# full country runs -------------------------------------------------------
my_assignment <- 1:1000 # CHANGE FOR YOUR SUBSET
# STEP 1: Create subsampled data files using subsampled GROUP.IDs
# Requires:
# - tidyverse, tictoc
# - data files:
# - "dataforanalyses.RData"
# - "randomgroupids.RData"
# Outputs:
# - "dataforsim/dataX.RData files
cur_mask <- "none" # analysis for full country (not masks)
tic(glue("Generated subsampled data for full country (sims {min(my_assignment)}:{max(my_assignment)})"))
source("00_scripts/create_random_datafiles.R")
toc()
# STEP 2: Run trends models for all selected species
# Requires:
# - tidyverse, tictoc, lme4, VGAM, parallel, foreach, doParallel
# - data files:
# - "dataforsim/dataX.RData"
# - "specieslists.RData"
# Outputs:
# - "trends/trendsX.csv" files
cur_mask <- "none" # analysis for full country (not masks)
tic(glue("Species trends for full country (sims {min(my_assignment)}:{max(my_assignment)})"))
source("00_scripts/run_species_trends.R")
toc()
rm(my_assigment)
# mask runs -------------------------------------------------------------------
cur_mask <- "woodland" # CHANGE FOR YOUR MASK {woodland, cropland, ONEland}
# STEP 1: Create subsampled data files using subsampled GROUP.IDs
tic(glue("Generated subsampled data for {cur_mask}"))
source("00_scripts/create_random_datafiles.R")
toc()
# STEP 2: Run trends models for all selected species
tic(glue("Species trends for {cur_mask}"))
source("00_scripts/run_species_trends.R")
toc()
# state runs --------------------------------------------------------------
# list of states assigned (CHANGE FOR YOUR SUBSET)
my_states <- c("Tamil Nadu")
# my_states <- c("Telangana", "Chhattisgarh", "Jammu and Kashmir", "Assam",
# "Andhra Pradesh", "Puducherry", "Madhya Pradesh")
# STEP 1: Create subsampled data files using subsampled GROUP.IDs
tic.clearlog()
tic("Generated subsampled data for all assigned states")
analyses_metadata %>%
filter(MASK.TYPE == "state") %>%
distinct(MASK) %>%
filter(MASK %in% my_states) %>%
pull(MASK) %>%
# walking over each state
walk(~ {
tic(glue("Generated subsampled data for {.x} state"))
assign("cur_mask", .x, envir = .GlobalEnv)
source("00_scripts/create_random_datafiles.R")
toc(log = TRUE)
})
toc(log = TRUE, quiet = TRUE)
tic.log()
# STEP 2: Run trends models for all selected species
tic.clearlog()
tic("Ran species trends for all assigned states")
analyses_metadata %>%
filter(MASK.TYPE == "state") %>%
distinct(MASK) %>%
filter(MASK %in% my_states) %>%
pull(MASK) %>%
# walking over each state
walk(~ {
tic(glue("Ran species trends for {.x} state"))
assign("cur_mask", .x, envir = .GlobalEnv)
source("00_scripts/run_species_trends.R")
toc(log = TRUE)
})
toc(log = TRUE, quiet = TRUE)
tic.log()
rm(my_states)