英文:
Preparing input data to run bfastSpatial & bfast
问题
我想要识别整个NDVI时间序列的断点,然后显示断点的幅度和频率。我的输入数据是以.tif格式存储的每日NDVI时间序列。每个图像都以其日期命名(20031002,20031101,20031201,...)。我使用以下代码来准备我的数据,但遇到了一个错误。在此提前感谢您的时间。
setwd(".../ndvi")
list.grid <- list.files(pattern = ".tif$", recursive = TRUE)
d <- c("20000101","20000102","20000103","20000104","20000105", …)
saveRDS(d, file = "dates.rds")
date_NDVI <- readRDS("dates.rds")
NDVI_S <- raster::stack(list.grid)
NDVI_S <- setZ(NDVI_S, as.Date(date_NDVI$date), name="time")
bfmSpatial(NDVI_S, start=c(2000,1), order=1, mc.cores=8, returnLayers = c("breakpoint", "magnitude", "error"))
错误信息:在date_NDVI$date上使用$操作符无效。
英文:
I want to identify breakpoints for the whole NDVI time series and then show magnitude and frequency of the breakpoints. My input data is a daily NDVI time series in .tif format. Each image is named by its date (20031002, 20031101, 20031201, …). I use this code to prepare my data but I am faced with an error. In advance, I appreciate your time.
setwd("…/ndvi")
list.grid<-list.files(pattern = ".tif$", recursive = TRUE)
d <- c("20000101","20000102","20000103","20000104","20000105", …)
saveRDS(d, file = "dates.rds")
date_NDVI<-readRDS("dates.rds")
NDVI_S <- raster::stack(list.grid)
NDVI_S<-setZ(NDVI_S,as.Date(date_NDVI$date),name="time")
bfmSpatial(NDVI_S, start=c(2000,1), order=1, mc.cores=8,returnLayers = c("breakpoint", "magnitude", "error"))
Error in date_NDVI$date : $ operator is invalid for atomic vectors
答案1
得分: 0
你发布的错误意味着date_NDVI
已经是一个向量,所以你不需要使用$
运算符来访问日期(如果date_NDVI
是一个data.frame的情况下需要使用)。然后,你只需要指定日期的格式(使用as.Date
),并将它们设置为Z值(使用setZ
)。最后,你应该能够运行bfast分析。
library(raster)
library(bfastSpatial)
setwd("../ndvi")
list.grid <- list.files(pattern = ".tif$", recursive = TRUE)
d <- c("20000101","20000102","20000103","20000104","20000105", ...)
NDVI_S <- raster::stack(list.grid)
NDVI_S <- setZ(NDVI_S, as.Date(d, format = "%Y%m%d"), name="time")
# 检查起始日期和mc.cores值(Windows操作系统不接受mc.cores > 1)
resul <- bfmSpatial(NDVI_S, start=c(2005,1), order=1, mc.cores=8, returnLayers = c("breakpoint", "magnitude", "error"))
英文:
The error you posted means that date_NDVI
is already a vector, so you do not need to use an $
operator to access the dates (this would be the case if date_NDVI
was a data.frame). Then, you just need to indicate the format in which the dates are given (using as.Date
) and set them as a Z value (using setZ
). Finally, you shoud be able to run the bfast analysis.
library(raster)
library(bfastSpatial)
setwd("…/ndvi")
list.grid <- list.files(pattern = ".tif$", recursive = TRUE)
d <- c("20000101","20000102","20000103","20000104","20000105", …)
NDVI_S <- raster::stack(list.grid)
NDVI_S <- setZ(NDVI_S, as.Date(d, format = "%Y%m%d"), name="time")
# Check the start date and mc.cores values (windows OS do not accept mc.cores >1)
resul <- bfmSpatial(NDVI_S, start=c(2005,1), order=1, mc.cores=8,returnLayers = c("breakpoint", "magnitude", "error"))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论