-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmp_ndvi_fapar.r
62 lines (48 loc) · 1.85 KB
/
dmp_ndvi_fapar.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
library(GGally)
library(rgdal)
library(gdalUtils) #to transform the file format
library(raster)
library(RStoolbox)
library(ncdf4)
#install.packages("sf")
library(sf)
setwd ("D:/toy/")
dmp <- raster ("rasterDMP.tif")
ndvi <- raster ("rasterNDVI.tif")
fapar <- raster ("rasterFAPAR.tif")
cl <- colorRampPalette(c('white', 'pink', 'red', 'dark green'))
par(mfrow=c(3,1))
plot(dmp, col=cl, main= "Dry Matter Productivity 300") # plot(d, col=cl, main="Densities of covid-19")
plot(ndvi, col=cl, main="NDVI300")
plot(fapar, col=cl, main="FAPAR300")
#plot(dmp, col=cl, main= "Dry Matter Productivity 300")
#plot(ndvi,col=cl, main="NDVI300")
#plot(fapar, col=cl, main="FAPAR300")
# crop my AOI
ext <- c(75.10, 75.60, 12.05, 12.55)
dmp.up <- crop(dmp,ext)
ndvi.up <- crop(ndvi,ext)
fapar.up <- crop(fapar,ext)
par(mfrow=c(3,1))
plot(dmp.up, col=cl, main= "Dry Matter Productivity 300")
plot(ndvi.up,col=cl, main="NDVI300")
plot(fapar.up, col=cl, main="FAPAR300")
random.points <- function(raster,n)
{
lin <- rasterToContour(is.na(raster))
pol <- as(st_union(st_polygonize(st_as_sf(lin))), 'Spatial')
pts <- spsample(pol[1,], n, type = 'random')
}
# then select 1000 points randomly from faPAR10 rasters
pts <- random.points(dmp.up, 1000)
plot(dmp.up$pts)
############# new part
DMPp <- extract(dmp.up, pts)
NDVIp <- extract(ndvi.up, pts) # extract 1000 random points from copNDVI
faPARp <- extract(fapar.up,pts)
#build the linear model between copNDVIp and faPAR10 (copNDVIp because the calculation is faster with less values)
# the line is calculated by reducing the distance between the points (x;y) in the graph
# phothosythesis vs biomass
model2 <- lm(dmp.up ~ ndvi.up) # R = 0.4 because in conifer forest biomass is high and phothosynthesis but not that high. p = 2 ^-16 two variables are related each other
plot(faPAR10p, NDVIp)
abline(model2, col="red")