如何找到逐像素标准偏差? [英] How can I find the pixel-wise standard deviation?
问题描述
我有 20 个具有相同分辨率和范围的栅格.这是一个时间序列,每个栅格是一年.
I have 20 rasters with same resolution and extent. It's a time series and each raster is for one year.
我想计算所有栅格的像素标准偏差.到目前为止,我使用的是栅格包.
And I want to calculate the pixel-wise standard deviation of all rasters.So far, I am using the raster package.
qq2<-list(maxras1,maxras2,maxras3,maxras4,maxras5,maxras6,maxras7,maxras8,maxras9,maxras10)
qq2stack<-stack(qq2)
qq2mean<-mean(qq2stack)
qq2sd<-sd(qq2stack)
均值有效.但是标准偏差给了我这个错误:
The mean works. But standard deviation is giving me this error:
Error in as.double(x) :
cannot coerce type 'S4' to vector of type 'double'
推荐答案
不幸的是,正如您在我上面的评论后注意到的那样,逐像素分析可能很慢.我认为您接下来要尝试的是并行化该过程.假设您有一个多核处理器,您可以利用 calc()
及其内置的多进程优化:
Unfortunately, as you note after my comment above, per-pixel analyses can be slow. I think the next thing for you to try is to parallelize the process. Assuming you have a multi-core processor you can take advantage of calc()
and its built-in multi-process optimization:
cores <- 4
beginCluster(cores, type='SOCK')
calc(qq2stack, fun=sd)
endCluster()
如果您的操作/硬件环境支持,这将导致显着的加速.显然,您也可以根据自己的架构增加进程数.
This would result in a significant speed-up if your operating/hardware environment supports it. Obviously, you can increase the number of processes as well depending on your architecture.
这篇关于如何找到逐像素标准偏差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!