gpt4 book ai didi

r 栅格覆盖函数 - landsat 堆栈错误

转载 作者:行者123 更新时间:2023-12-02 01:12:49 26 4
gpt4 key购买 nike

我遇到了 R 中覆盖函数的异常问题。我们正在尝试用另一层的值填充多云像素。我可以按如下方式使其与堆栈一起正常工作 -

library(raster)
r1 <- raster(ncols=36, nrows=18)
r1[] <- 1:ncell(r1)
r1b <- r1a <- r1
r1_stack <- stack(r1, r1a, r1b)

r2 <- setValues(r1, runif(ncell(r1)))
r2b <- r2a <- r2
r_stack <- stack(r2, r2a, r2b)

r_stack[r_stack < 0.5] <- NA

r3 <- cover(r_stack, r1_stack)

但后来我尝试用光栅堆栈做同样的事情,但我得到了错误:

Error in as.character(x) : 
cannot coerce type 'closure' to vector of type 'character'

代码:

# get all tifs
LS5_032_032_2008_09_21 <- list.files("LT050340302008090301T1-SC20170526100900/",
pattern = glob2rx("*band*.tif$"), full.names = T)


# stack bands
cloudy_scene <- stack(LS5_032_032_2008_09_21)
# import cloud mask
cloud_mask <- raster('LT050340302008090301T1-SC20170526100900/LT05_L1TP_034030_20080903_20160905_01_T1_sr_cloud_qa.tif')

# mask data
masked_data <- mask(cloudy_scene, mask = cloud_mask, maskvalue=0, inverse=TRUE)

####### get cloud free data
# get files
LS5_2008_09_19 <- list.files("LT050340302008091901T1-SC20170526101124/",
pattern = glob2rx("*band*.tif$"), full.names = T)

# subset and stack cloud free bands
cloud_free_data <- stack(LS5_2008_09_19)

# use cover function to assign NA pixels to corresponding pixels in other scene
cover <- cover(masked_data, cloud_free_data)

TRACEBACK() 输出:

9: toupper(format)
8: .defaultExtension(format)
7: .getExtension(filename, filetype)
6: .local(x, filename, ...)
5: writeStart(outRaster, filename = filename, format = format, datatype = datatype,
overwrite = overwrite)
4: writeStart(outRaster, filename = filename, format = format, datatype = datatype,
overwrite = overwrite)
3: .local(x, y, ...)
2: cover(masked_data, cloud_free_data)
1: cover(masked_data, cloud_free_data)

更新:我尝试对数据重新采样 - 仍然无效

cloud_free_resam <- resample(cloud_free_data, masked_data)
cover <- cover(masked_data, cloud_free_resam)

错误:

Error in as.character(x) : 
cannot coerce type 'closure' to vector of type 'character'

我也尝试裁剪两层 - 同样的错误

# find intersection boundary
crop_extent <- intersect(extent(cloud_free_data), extent(masked_data))
cloud_free_data <- crop(cloud_free_data, crop_extent)
masked_data <- crop(masked_data, crop_extent)

# use cover function to assign NA pixels to corresponding pixels in other scene
cover <- cover(masked_data, cloud_free_data)

获取数据:(警告:317mb 下载 - 解压为 ~1gb) https://ndownloader.figshare.com/files/8561230

有什么想法可能导致此特定数据集出现此错误吗?我敢肯定我们错过了一些非常基本的东西,但是……什么?提前谢谢你。

莉亚

最佳答案

这是一个错误。覆盖两个多层 Raster* 对象无法写入磁盘。这可以在简单的示例中通过设置

看出
rasterOptions(todisk=TRUE)

我已经在 2-6.1 版本(即将发布)中修复了这个问题

关于r 栅格覆盖函数 - landsat 堆栈错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44295842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com