forked from PEM-Humboldt/gsi_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_GSI.R
78 lines (59 loc) · 2.39 KB
/
4_GSI.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
library(raster)
library(rgdal)
library(hyperSpec)
# ---------------------------
# Data loading
# ---------------------------
wd <- 'F:/GSI/'
setwd(wd)
dir.create("GSI/")
GRS.geo<- '+proj=longlat +datum=WGS84 +no_defs'
col<-getData(name = 'GADM', country = 'COL', level = 0) #Areo of interes (AOI)
col@data$OBJECTID<-1
colr<-raster(extent(col), res=0.008333333)
colrast<- rasterize(col,colr)
# ---------------------------
# 4. GSI / Gap selection index
# ---------------------------
# Estandarizacion de valores
#densRegistros <- raster('INDICE_DENSIDAD.tif')
#d <- raster('INDICE_AMBIENTAL.tif')
DENSIDAD <- raster("1_Records/Vac_dens_rescal_1km.tif")
crs(DENSIDAD)<-GRS.geo
AMBIENTAL <- raster("2_Ambiental/ambiental_dimension_GSI_rescal.tif")
crs(AMBIENTAL)<-GRS.geo
COMPLEMENTARIEDAD_BOOT<-raster("3_Complementarity/Complementariedad_Bootstrap.tif")
crs(COMPLEMENTARIEDAD_BOOT)<-GRS.geo
COMPLEMENTARIEDAD_JACK<-raster("3_Complementarity/Complementariedad_Jacknife.tif")
crs(COMPLEMENTARIEDAD_JACK)<-GRS.geo
ambiental_resample <-resample(AMBIENTAL, DENSIDAD)
comp_jack <-resample(COMPLEMENTARIEDAD_JACK, DENSIDAD)
comp_boot <-resample(COMPLEMENTARIEDAD_BOOT, DENSIDAD)
AMBValsNoNA <- AMBIENTAL[!is.na(AMBIENTAL[])]
AMBValsNoNANoZeros <- AMBIENTAL[!is.na(AMBIENTAL[]) & AMBIENTAL[] != 0]
hist(AMBValsNoNA, main = 'Ambiental no NA')
hist(AMBValsNoNANoZeros, main = 'Ambiental /n no NA no 0')
# # Completness
par(mfrow = c(1, 2))
plot(COMPLEMENTARIEDAD_BOOT, main = 'Bootstrap')
plot(col, add = TRUE)
plot(COMPLEMENTARIEDAD_JACK, main = 'Jackknife')
plot(col, add = TRUE)
# GSI / GAP INDEX
rasterOptions(tolerance = 0.1)
GSI_BOOT <- (3- DENSIDAD - ambiental_resample- comp_boot)/3
GSI_JACK <- (3-DENSIDAD - ambiental_resample - comp_jack)/3
par(mfrow = c(1, 2))
plot(GSI_BOOT, main = 'GAP SELCTION INDEX (BOOT)', zlim = c(0, 1))
plot(col, add = TRUE)
plot(GSI_JACK, main = 'GAP SELCTION INDEX (JACK)', zlim = c(0, 1))
plot(col, add = TRUE)
densJack <- density(GSI_JACK, main = 'Jackk', xlim = c(0, 1))
densBoot <- density(GSI_BOOT, main = 'Boot', xlim = c(0, 1))
par(mfrow = c(1, 1))
plot(densJack, main = 'GSI values', col = 'blue', ylim = c(0, 10))
lines(densBoot, col = 'red')
legend('topleft', legend = c('Jackknife', 'Bootstrap'),
lty = c(1, 1), lwd = c(1, 1), col = c('blue', 2))
writeRaster(GSI_BOOT,"GSI/INDICE_GSI_BOOT.tif", overwrite = TRUE)
writeRaster(GSI_JACK,"GSI/INDICE_GSI_JACK.tif", overwrite = TRUE)