【问题标题】:focal_hpc: speed up raster analysis in Rfocus_hpc:加快 R 中的栅格分析
【发布时间】:2019-12-21 11:33:20
【问题描述】:

我有一个非常大的光栅文件(行数=14810;列数=12392),我想使用“焦点”函数在特定大小的窗口(例如 5像素 X 5 像素)。我曾经在 R(光栅 R 包)中应用“焦点”功能。但是,对于这么大的栅格大小,该函数非常慢。

我知道“spatial.tools”中有一个名为“focal_hpc”的函数可以加速焦点处理(并行)。但是,我不知道如何指定“平均”函数。我使用了以下脚本:

require(raster)
require(spatial.tools)
tahoe_highrez <- brick(system.file("external/tahoe_highrez.tif", package="spatial.tools"))

res<-focal_hpc(x=tahoe_highrez,fun=mean,window_dims=c(5,5))

但它给了我这个错误:

Error in (function (x, ...)  : 
  call to standardGeneric("mean") apparently not from the body of that generic function

有人使用过这个包和功能吗?

【问题讨论】:

    标签: r spatial raster parallel.foreach


    【解决方案1】:

    嗯。我也是:

    > res<-focal_hpc(x=tahoe_highrez,fun=mean,window_dims=c(5,5))
    Error in (function (x, ...)  : 
      call to standardGeneric("mean") apparently not from the body of that generic function
    

    但是如果你创建一个做同样事情的函数:

    > f = function(...){mean(...)}
    

    它有效...

    > res<-focal_hpc(x=tahoe_highrez,fun=f,window_dims=c(5,5))
    Warning messages:
    1: In .local(x, ...) : min value not known, use setMinMax
    2: In .local(x, ...) : max value not known, use setMinMax
    3: In .local(x, ...) : min value not known, use setMinMax
    > res
    class      : RasterBrick 
    dimensions : 400, 400, 160000, 1  (nrow, ncol, ncell, nlayers)
    resolution : 5.472863e-06, 5.472863e-06  (x, y)
    extent     : -119.9328, -119.9306, 39.28922, 39.29141  (xmin, xmax, ymin, ymax)
    crs        : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
    source     : /tmp/Rtmp2WTR9g/file5f335faf907.grd 
    names      : layer 
    

    我怀疑这与通用函数的分派方式有关。制作一个测试栅格以确保我的函数替换正在计算您想要取平均值的事物的平均值,并阅读文档以获取更多为 focal_hpc 编写函数的示例。

    【讨论】:

    • 我一直在尝试在我没有 root 权限 (SLURM) 的服务器中使用此功能。我已将软件包安装在本地文件夹中,当我尝试并行使用 'focel_hpc' 函数(6 核)时,我确实收到以下错误: e$fun(obj,substitute(ex),parent.frame( ), e$data) : worker 初始化失败: 没有名为'spatial.tools' 的包调用: system.time ... focus_hpc_focal_processing -> %dopar% ->
    • 这是一个不同的问题 - 尝试搜索该问题,然后提出一个新问题。您需要找出 R 在哪里寻找软件包,并可能将您的安装文件夹添加到其中。但是,如果这个提示没有帮助,请提出一个新问题。
    • 感谢您的评论。这也是我的直觉。我已将其作为一个单独的问题发布。 stackoverflow.com/questions/59645694/…
    猜你喜欢
    • 2021-02-13
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多