【问题标题】:How to obtain Dates of annual maximum gridcell values of rasterbrick?如何获取光栅砖年度最大网格单元值的日期?
【发布时间】:2018-03-21 07:07:23
【问题描述】:

我如何获得两个栅格,分别给出每个网格单元每年的最大值,并给出最大值出现的日期。下面是可重现的示例,其中包含我已实施的一些步骤。

library(raster)

# Create a raster

r1 <- raster(nrow=10, ncol=7)
r <- stack(setValues(r1, runif(ncell(r1))),
           setValues(r1, runif(70 ,0.6,0.9)),
           setValues(r1, runif(70 ,0.2,0.4)),
           setValues(r1, runif(70 ,1,2)),
           setValues(r1, runif(70 ,0.5,1.0)),
           setValues(r1, runif(70 ,0.3,0.9)),
           setValues(r1, runif(70 ,1,2)))
r

# Make Dates. This is random, i have about 24000 values.

Dates<-data.frame(Date=c("2000-01-02","2000-01-03","2000-02-03",
           "2001-09-02","2001-09-03","2001-10-01",
           "2001-10-02"))

Date_val<-as.Date(Dates$Date,format="%Y-%m-%d")
Date_val

r.dt<-setZ(r,Date_val)

# Get indices to make annual maxima value for each grid cells

indices <- format(as.Date(getZ(r.dt), format = "%Y-%b-%d"), format = "%Y")

# Implement stackApply to get maximum value each year.

rmax<-stackApply(r.dt,indices = indices,fun=max,na.rm=T)
plot(rmax)

【问题讨论】:

    标签: r time-series raster r-raster


    【解决方案1】:

    你可以的

    wmax <- stackApply(r.dt, indices = indices, fun=function(i,...) which.max(i))
    

    获取引用日期向量的索引

    要获取(整数)日期表示,即自 1970 年 1 月 1 日以来的天数,您可以为每一年做这样的事情

    m2000 = data.frame(from=1:3, to=as.integer(Date_val)[1:3])
    x <- subs(wmax[[1]], m2000)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-06
      • 2019-11-02
      • 2023-03-17
      • 2021-12-14
      • 2014-01-11
      • 2016-12-25
      • 2019-09-21
      • 1970-01-01
      相关资源
      最近更新 更多