-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMammalAOH_OnebyOne.R
72 lines (63 loc) · 2.36 KB
/
MammalAOH_OnebyOne.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
# try to run reptiles one by one
rm(list=ls())
gc()
library(aoh)
library(dplyr)
Sys.setenv("GDAL_PYTHON" = "python")
Sys.setenv("GDAL_CALC" = "C:\\OSGeo4W\\apps\\Python39\\Scripts\\gdal_calc.py")
Sys.setenv("GDAL_ESCAPE" = "false")
mammal_narrow <- read.csv("E:/Priority program/WJY/AOH/AOH_errors/narrow_mammal.csv")
spp_range_data <- read_spp_range_data("ReAOH/MAMMALS.zip")
spp_range_data <- spp_range_data[paste0(spp_range_data$id_no,"_",spp_range_data$seasonal) %in% paste0(mammal_narrow$id_no,"_",mammal_narrow$seasonal),]
# dir.create("ReAOH/MAMMALS")
cache_dir<-"ReAOH/cache"
output_dir <- "ReAOH/MAMMALS"
data(crosswalk_lumb_cgls_data)
habitat_data <- get_lumb_cgls_habitat_data(
dir = "ReAOH/cache",
version = "latest",
force = FALSE,
verbose = TRUE
)
elev_data <- get_global_elevation_data(
dir = "ReAOH/cache",
version = "latest",
force = FALSE,
verbose = TRUE
)
max(file.info(paste0("ReAOH/MAMMALS/",dir("ReAOH/MAMMALS")))$mtime)
which(file.info(paste0("ReAOH/MAMMALS/",dir("ReAOH/MAMMALS")))$mtime==max(file.info(paste0("ReAOH/MAMMALS/",dir("ReAOH/MAMMALS")))$mtime))
file.info(paste0("ReAOH/MAMMALS/",dir("ReAOH/MAMMALS")))[32,]
spp_info_data[spp_info_data$id_no==18702,]
which(spp_info_data$id_no==18702)
errlist<-c()
errlistaoh<-c()
pb <- txtProgressBar(min=51,max=nrow(spp_info_data),char = "=",)
for (i in 51:nrow(spp_info_data)){
setTxtProgressBar(pb,i)
spp_info_data_tmp <- spp_info_data[i,]
spp_aoh_data <- try(create_spp_aoh_data(
x = spp_info_data_tmp,
engine = "gdal",
crosswalk_data = crosswalk_lumb_cgls_data,
cache_dir = "ReAOH/cache",
verbose = TRUE,
output_dir = "ReAOH/MAMMALS"))
if(inherits(spp_aoh_data,"try-error")){
errlistaoh <- c(errlistaoh,i)
}
rm(spp_info_data_tmp)
rm(spp_aoh_data)
gc()
}
mammal_aoh_data <- create_spp_aoh_data(spp_info_data,cache_dir = "ReAOH/cache",
verbose = TRUE,
output_dir = "ReAOH/MAMMALS")
saveRDS(mammal_aoh_data,"ReAOH/mammal_aoh_data.rds")
library(dplyr)
mammal_spp_list <- mammal_aoh_data %>%
mutate(filename=paste0(id_no,"_",seasonal)) %>%
select(filename,id_no,seasonal,binomial,category,path)
mammal_spp_list <- as.data.frame(mammal_spp_list)
mammal_spp_list<-mammal_spp_list[,-ncol(mammal_spp_list)]
write.csv(mammal_spp_list,"ReAOH/mammal_spp_list.csv",row.names=F)