-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUncertainity-effect-on-phenology
60 lines (52 loc) · 2.02 KB
/
Uncertainity-effect-on-phenology
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
This code is written to assess effect of uncertainty on the phenology of the rapeseed plantation in Bulgaria. With this aim, we applied 2% uncertainty on the simulated raster.
The uncertainity effect is rarely discussed in the literature.Our results discussed them in detail.
This work have already submitted for publication under the title 'Potential Impacts of Radiometric Uncertainty on the Estimation of Land Surface Phenology Metrics'.
##copy the content in Rstudio
###### Summer School Exercise - WP2
###### September 2021
## Setting up working directory
library(raster)
library(rgdal)
setwd("C:/Users/u0115271/Documents/PhD/Courses/Summer School/SENSECO 2021/project/data")
## Loading data
files <- list.files("P1-NoClouds", full.names = TRUE, patter="*.tif$")
p1 <- stack(files)
plot(p1[[62]])
## Removing outliers
out <- brick(extent(p1), nrows=nrow(p1), ncols=ncol(p1), crs=proj4string(p1), nl=nlayers(p1))
for (i in 1:nlayers(p1)){
pi <- p1[[i]]
qi <- quantile(getValues(pi), c(0.05, 0.95), na.rm=T)
pi[pi<qi[1]]<-NA
pi[pi>qi[2]]<-NA
out[[i]] <- pi
}
## Calculating average NDVI for each time step
## (used as the "typical" NDVI for that date)
avg <- c()
for (i in 1:nlayers(out)){
avg[i] <- mean(getValues(out[[i]]), na.rm=T)
}
plot(avg, type="l")
## Simulating time series
out_df <- as.data.frame(matrix(rep(NA,64), ncol = 64))
for (y in 1:1000){
sim_ts <- c()
for (i in 1:length(avg)){
dat <- rnorm(100000, mean = 0, sd = avg[i]*0.02)
sim_noise <- dat[sample(1:length(dat), 1)]
sim_ts[i] <- sim_noise+avg[i]
}
out_df[y,]<-sim_ts
}
## Putting simulated time series in a raster
sim_raster <- raster(ncols=10, nrows=100)
final_stack <- brick(extent(sim_raster), ncols=ncol(sim_raster), nrows=nrow(sim_raster), nl=64)
for(i in 1:ncol(out_df)){
sim_raster <- raster(ncols=10, nrows=100)
sim_raster[c(1:1000)] <- out_df[,i]
final_stack[[i]] <- sim_raster
}
## Exporting simulated rasters
files <- list.files("P1-NoClouds", patter="*.tif$")
writeRaster(final_stack, paste0("simulated_raster/",files), bylayer=TRUE)