You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从BFAST输出中提取趋势与季节成分的突变时间?

提取常规BFAST栅格输出中趋势与季节成分的突变时间

先理清楚常规BFAST的栅格输出结构

用bfast处理SpatRaster后,返回的是嵌套列表——每个元素对应一个像元的bfast结果对象。核心数据都在$output字段里:

  • 趋势成分的突变点存在$output$bp
  • 季节成分的突变点(仅当启用季节突变检测时)存在$output$season$bp

提取趋势成分的突变时间

直接遍历每个像元的结果,取出突变点索引后转成实际日期即可:

# 假设bfast_raster是常规bfast处理后的栅格列表输出
# 先拿到原始时间序列的日期向量(和你的VI_m图层名对应)
date_vec <- as.Date(names(VI_m))

# 提取趋势突变点(先拿索引,再转日期)
trend_breaks <- lapply(bfast_raster, function(x) {
  if (!is.null(x$output)) {
    x$output$bp  # 返回时间序列中的位置索引
  } else {
    NA  # 处理数据缺失导致bfast运行失败的像元
  }
})

# 把索引转成实际日期
trend_breaks_dates <- lapply(trend_breaks, function(bp) {
  if (!is.na(bp)) date_vec[bp] else NA
})

# 转成SpatRaster方便空间分析/可视化
trend_breaks_raster <- rast(trend_breaks_dates, template = VI_m[[1]])

提取季节成分的突变时间

注意:只有当调用bfast时启用了季节突变检测(比如用season="dummy",或season="harmonic"搭配合理的h参数),才会有季节突变点。提取逻辑和趋势类似:

# 提取季节突变点索引
season_breaks <- lapply(bfast_raster, function(x) {
  if (!is.null(x$output$season)) {
    x$output$season$bp
  } else {
    NA
  }
})

# 转成实际日期
season_breaks_dates <- lapply(season_breaks, function(bp) {
  if (!is.na(bp)) date_vec[bp] else NA
})

# 转成SpatRaster
season_breaks_raster <- rast(season_breaks_dates, template = VI_m[[1]])

封装成批量处理函数(省得重复写)

把上面的逻辑打包成函数,用起来更高效:

extract_bfast_breaks <- function(bfast_raster, date_vec, template_raster) {
  # 提取趋势突变
  trend_bp <- lapply(bfast_raster, function(x) {
    if (!is.null(x$output)) x$output$bp else NA
  })
  trend_dates <- lapply(trend_bp, function(bp) if (!is.na(bp)) date_vec[bp] else NA)
  
  # 提取季节突变
  season_bp <- lapply(bfast_raster, function(x) {
    if (!is.null(x$output$season)) x$output$season$bp else NA
  })
  season_dates <- lapply(season_bp, function(bp) if (!is.na(bp)) date_vec[bp] else NA)
  
  # 返回两个突变栅格
  list(
    trend_breaks = rast(trend_dates, template = template_raster),
    season_breaks = rast(season_dates, template = template_raster)
  )
}

# 调用示例
breaks_result <- extract_bfast_breaks(bfast_raster, date_vec, VI_m[[1]])
# 趋势突变栅格:breaks_result$trend_breaks
# 季节突变栅格:breaks_result$season_breaks

几个关键注意事项

  • 季节突变不是默认开启的:如果bfast调用用了season="none"或固定谐波模型,$output$season$bp会不存在,返回全NA。
  • 日期必须对齐:date_vec要和输入bfastts的时间序列完全匹配,否则转换出的日期会出错。
  • 异常像元要处理:部分像元可能因数据缺失过多导致bfast运行失败,一定要加is.null判断避免报错。

内容的提问来源于stack exchange,提问作者ManchPanch _

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 17:40:03