R语言:栅格序列逐像元相关性分析

17 篇文章 43 订阅

原理内容:

library(terra)
library(Hmisc)
v1  = rast(array(runif(10*10*20),c(10,10,20)))#生成10*10测验栅格
v2  = rast(array(runif(10*10*20),c(10,10,20)))
z = c(v1,v2)
names(z)
nlyr(z)
fun_cor =  function(x) {
  Rs = Hmisc::rcorr(x[1:20], x[21:40], type = "spearman")
  Rx = Rs$r[2]
  Px = Rs$P[2]
  return(c(Rx, Px))
}
r_ndvi_pre = app(z, fun_cor, cores=4)
names(r_ndvi_pre) <- c('coefficient','p_value')
plot(r_ndvi_pre)

代入栅格数据并输出结果图像:


library(terra)
library(Hmisc)
ndvi <- rast(dir("F:/test/NDVI",full.names = T,pattern = '.tif$'))
tem <- rast(dir("F:/test/tem_April",full.names = T,pattern = '.tif$'))
pre <- rast(dir("F:/test/pre_April",full.names = T,pattern = '.tif$'))
z = c(ndvi,tem)
names(z)
nlyr(z)
fun_cor =  function(x) {
  Rs = Hmisc::rcorr(x[1:12], x[13:24], type = "spearman")
  Rx = Rs$r[2]
  Px = Rs$P[2]
  return(c(Rx, Px))
}
r_ndvi_pre = app(z, fun_cor, cores=4)
names(r_ndvi_pre) <- c('coefficient','p_value')
plot(r_ndvi_pre)
r <- subset(r_ndvi_pre,1)
p <- subset(r_ndvi_pre,1)
writeRaster(r, filename = "E:/test/result/r.tif")#r,输入结果路径及文件名
writeRaster(P, filename = "E:/test/result/p.tif")#p,输出结果为P值
  • 10
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jackson的生态模型

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值