使用calc与堆叠的栅格砖

时间:2018-04-21 23:07:50

标签: r raster lm

我正在尝试在R中的两个栅格砖上运行线性模型。这两块砖来自不同的来源,但据我所知,它具有相同的尺寸(lon,lat,time)。我收到错误:“dimnames(x)中的错误< - dn:'dimnames'的长度[2]不等于数组范围”。

我的代码:

#stack two raster bricks
s <- stack(rasterbrick1, rasterbrick2)

fun=function(x) { if (is.na(x[1])){ NA } else { lm(x[1:15] ~ x[16:30])$coefficients[2] }}
slope <- calc(s, fun)

两个栅格的dimnames()都为NULL。两种栅格具有相同的尺寸(360 720 15)。两个栅格都有相同的名称()。当我使用来自同一来源的raster2和raster3时,该功能正常工作。显然rasterbrick1和rasterbrick2之间存在某种不匹配,但我不知道如何弄清楚它是什么,因为我检查的所有内容都匹配。

我知道这可能很难回答,因为它似乎是特定于数据的,但是非常感谢任何帮助,即使您可以给我一些关于要查明错配的元素的想法。

编辑:我不确定如何显示s(请告诉我是否有更好的方法),但这里是head - s - 数据集的开头主要是零和NA。

index_2002.1 index_2003.1 index_2004.1 index_2005.1 index_2006.1 index_2007.1 index_2008.1
[1,]            0            0            0            0            0            0            0
[2,]            0            0            0            0            0            0            0
[3,]            0            0            0            0            0            0            0
 index_2009.1 index_2010.1 index_2011.1 index_2012.1 index_2013.1 index_2014.1 index_2015.1
[1,]            0            0            0            0            0            0            0
[2,]            0            0            0            0            0            0            0
[3,]            0            0            0            0            0            0            0
 index_2016.1 index_2002.2 index_2003.2 index_2004.2 index_2005.2 index_2006.2 index_2007.2
[1,]            0          NaN          NaN          NaN          NaN          NaN          NaN
[2,]            0          NaN          NaN          NaN          NaN          NaN          NaN
[3,]            0          NaN          NaN          NaN          NaN          NaN          NaN
index_2008.2 index_2009.2 index_2010.2 index_2011.2 index_2012.2 index_2013.2 index_2014.2
[1,]          NaN          NaN          NaN          NaN          NaN          NaN          NaN
[2,]          NaN          NaN          NaN          NaN          NaN          NaN          NaN
[3,]          NaN          NaN          NaN          NaN          NaN          NaN          NaN
index_2015.2 index_2016.2
[1,]          NaN          NaN
[2,]          NaN          NaN
[3,]          NaN          NaN

traceback()给出以下内容:

traceback()
13: `colnames<-`(`*tmp*`, value = "layer")
12: .local(x, ...)
11: getValues(x)
10: getValues(x)
9: apply(getValues(x), 2, FUN = function(x) {
   c(min(x, na.rm = TRUE), max(x, na.rm = TRUE))
})
8: setMinMax(x)
7: setMinMax(x)
6: .local(x, values, ...)
5: setValues(out, x)
4: setValues(out, x)
3: .local(x, fun, ...)
2: calc(s, fun)
1: calc(s, fun)

0 个答案:

没有答案
相关问题