-
Notifications
You must be signed in to change notification settings - Fork 0
/
FUNCTION_Evaluate_species.R
40 lines (37 loc) · 1.42 KB
/
FUNCTION_Evaluate_species.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
SpeciesEvaluate<-function(filename){
require(data.table)
require(stringr)
require(readr)
s_grid_cell<-as.data.frame(fread(paste("Output/",filename,sep=""),header=TRUE))
name<-substr(filename,start=7,stop = 11)
weight<-substr(filename,start = 13,stop = 9999)
tmpsel<-s_grid_cell[,c("X","selection")]
AddSel<-tmpsel[tmpsel$selection==1,]$X
rm(tmpsel)
rm(s_grid_cell)
gc()
print(paste("Prepared selection",name,weight))
fourlist<-read_csv("Input/SPList_32599.csv")
fourlist$select<-NA
# print("Prepared fourlist")
# pb<-txtProgressBar(min=1,max=nrow(fourlist),char = "=",style = 3,width=50)
##rij don't have PA distribution data,don't use for absolute allarea calculation
for(i in 1:nrow(fourlist)){
rm(spe_table)
gc()
spe_table<-fread(fourlist$sp.file[i],header = TRUE)
fourlist$select[i]<-sum(spe_table[spe_table$id%in%AddSel,"area"],na.rm=TRUE)
# setTxtProgressBar(pb,i)
}
# close(pb)
fourlist$pass_floor<-floor(fourlist$target*0.95-fourlist$InPA)
fourlist[fourlist$select>=fourlist$pass_floor,"Reached"]<-1
fourlist[fourlist$select<fourlist$pass_floor,"Reached"]<-0
fourlist$gap_floor<-floor(fourlist$target-fourlist$InPA)
fourlist[fourlist$gap_floor<=0,"Reached"]<-2
# print(paste(nrow(fourlist[fourlist$Reached==0,]),"unreached species"))
write.csv(fourlist,paste("Output/SPlist_all_",name,"_",weight,sep=""),row.names=F)
print("Output done")
rm(fourlist)
gc()
}