-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1b_Run_check.R
127 lines (80 loc) · 3.1 KB
/
1b_Run_check.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
## testing bbsBayes2 parallel in HRE env
library(bbsBayes2)
library(tidyverse)
library(foreach)
library(doParallel)
#setwd("C:/github/CWS_2023_BBS_Analyses")
#setwd("C:/Users/SmithAC/Documents/GitHub/CWS_2023_BBS_Analyses")
output_dir <- "D:/CWS_2023_BBS_Analyses/output"
#output_dir <- "output"
sp_list <- readRDS("species_list.rds") %>%
filter(model == TRUE)
sp_track <- sp_list
complete_running_only <- FALSE # change to FALSE if assessing whether species could be run
for(i in 1:nrow(sp_list)){
sp <- as.character(sp_list[i,"english"])
aou <- as.integer(sp_list[i,"aou"])
if(!file.exists(paste0(output_dir,"/fit_",aou,".rds"))){
if(file.exists(paste0("fit_",aou,"-1.csv"))){
sp_track[i,"test"] <- paste0("Running_",as.character(Sys.info()["nodename"]))
next
}
if(complete_running_only){next}
# identifying first years for selected species ----------------------------
fy <- NULL
if(aou %in% c(4661,4660)){ #Alder and Willow Flycatcher
fy <- 1978 #5 years after the split
}
if(aou %in% c(10,11,22860)){ # Clark's and Western Grebe and EUCD
fy <- 1990 #5 years after the split and first year EUCD observed on > 3 BBS routes
}
if(aou == 6121){ # CAve Swallow
fy = 1985
}
strat <- "bbs_cws"
s <- try(stratify(by = strat,
species = sp,
quiet = TRUE) %>%
prepare_data(min_max_route_years = 2,
quiet = TRUE,
min_year = fy),silent = TRUE)
if(class(s) == "try-error"){sp_track[i,"test"] <- as.character(paste(s[1]))
next}
## bbsBayes2 models do not currently work unless n_strata > 1
if(nrow(s$meta_strata) == 1){ sp_track[i,"test"] <- "One-stratum"}
if(nrow(s$meta_strata) > 2){ #spatial models are irrelevant with < 3 strata
sp_track[i,"test"] <- "Sufficient data but Missing"
}
}else{# end of if file.exists
if(file.exists(paste0("fit_",aou,"-1.csv"))){
sp_track[i,"test"] <- "Both_check"
}else{
sp_track[i,"test"] <- "Complete"
}
}
}
table(sp_track$test,sp_track$vm)
saveRDS(sp_track,paste0("sp_track",as.character(Sys.info()["nodename"]),".rds"))
sp_complete <- sp_track
# sp_track_alt <- readRDS("sp_trackWNCRLABN72960.rds") %>%
# ungroup() %>%
# mutate(test = ifelse(aou %in% c(5110,5600,4980,3900),
# "Running_ECCClaptop",test)) %>%
# filter(test == "Complete" | grepl("Running",test))
#
# sp_complete <- sp_track %>%
# filter(!aou %in% sp_track_alt$aou) %>%
# bind_rows(.,sp_track_alt)
sp_done <- sp_complete %>%
filter(test == "Complete" | grepl("Running",test))
sp_miss <- sp_complete %>% filter(grepl("Sufficient",test))
if(nrow(sp_miss) > 0){
stop(paste(paste("There are",nrow(sp_miss),"species missing. Including"),
paste(sp_miss$english, collapse = ", ")))
saveRDS(sp_miss,"species_missing.rds")
}
# combine and compare with last year --------------------------------------
#
# lastyear = read_csv("data/All_2022_BBS_trends.csv") %>%
# filter(Region == "Continental",
# Trend_Time == "Long-term")