现在,我得到了我接下来要做的事情来绘制图表,其中我有一个带有值的矢量avg_ndvi
和带有标签的rasterNames
。
还有其他更聪明的方法可以实现同样的目标吗?因为最后我有兴趣在同一行中添加terra产品并获得8天复合,但可能只显示标签是一些间隔,可能是每个月,或每16天。
#------------ Load the library--------
library(raster)
library(rgdal)
library(rasterVis)
setwd("C:/Working_Folder/R")
aqua_ndvi_path <- "aqua_ndvi_2015"
avg_ndvi<-vector()
date_ndvi <- vector()
#now load the Tiffs:
all_ndvi <- list.files(aqua_ndvi_path,
full.names = TRUE,
pattern = ".tif$")
ndvi_stack <- stack(all_ndvi)
# ndvi_stack_brick <- brick(ndvi_stack)
rasterNames <- gsub("MYD13Q1_2015.","", names(ndvi_stack)) # remove some portion of file name
rasterNames <- gsub(".250m_16_days_NDVI","",rasterNames) # remove some portion of the file name
rasterNames # This will give me short names so that i can use it as a label in graph/plot later
## --------- scale ndvi value by 10000 and calculate ndvi average of each raster and store it in the vector---------
for (i in all_ndvi) {
j=cellStats(brick(i),mean)
j=j*0.0001
avg_ndvi<- c(avg_ndvi,j)
}
print(avg_ndvi)