【问题标题】:Partial summation of RasterBrickRasterBrick 的部分求和
【发布时间】:2021-06-09 11:55:34
【问题描述】:

我使用 raster 包读取 NetCDF 文件并希望在 R 中对其进行处理。几次操作后,我得到了 RasterBrick 对象 r_daily,其中 1461 层对应于 4 年内的每日值:

> r_daily
class      : RasterBrick 
dimensions : 360, 720, 259200, 1461  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
> names(r_daily)
[1] "y2011.01.01" "y2011.01.02" "y2011.01.03" "y2011.01.04"
[5] "y2011.01.05" "y2011.01.06" "y2011.01.07" ...

现在我只想对每年的所有值求和以获得 RasterBrick 对象r_yearly

> r_yearly
class      : RasterBrick 
dimensions : 360, 720, 259200, 4  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 

感谢任何帮助或提示!

【问题讨论】:

    标签: r netcdf r-raster


    【解决方案1】:

    我现在在this post找到了一个以前没有遇到过的好解决方案。

        years <- names(r_daily) %>%
          substr(2,5) %>%
          as.numeric()
        r_yearly<- raster::stackApply(r_daily, years, fun = sum)
    

    【讨论】:

      猜你喜欢
      • 2023-02-22
      • 2020-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      相关资源
      最近更新 更多