- 积分
- 378
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-12-2
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2020-5-8 21:45:38
|
显示全部楼层
按照NCL官网的函数提供者的代码,这就是以i至i+n-1(n为滑动点数)来计算i时刻的相关系数,我数理基础比较弱,我理解林老师1978年文献中提到的滑动系数计算方法和这个是一样,下面附上面提到的代码,仅供参考。
Here I am contributing a function to calculate running/moving
correlation..............
; Function to calculate running/moving correlation..
undef ("run_cor")
function run_cor(x:numeric,y:numeric,time:numeric,wSize:integer)
;**********************************************************************
; x and y: numeric array of 1D [eg: x(time) and y(time)]
; x and y should have same size
; time: numeric array of 1D that represent time coordinate of x or y
; time coordinate must have recognized by ut_calendar
; wSize is the scalar integer that specifies window size.[e.g 11 yr, 15
year, 21 year, etc]
;Sample usage: x(time) and y(time).
; cor_11=run_cor(x,y,time,11)
; cor_15=run_cor(x,y,time,15)
; cor_21=run_cor(x,y,time,21)
;************************************************************************
local aa,bb,i,cor,k,N
begin
N=dimsizes(x)
cor=new((/(N-(wSize-1))/),float)
date=new((/(N-(wSize-1))/),integer)
utc_date=ut_calendar(time,0)
year = floattointeger(utc_date(:,0))
k=(wSize-1)/2
do j=0,N-(wSize)
date(j)=year(k)+j
end do
do i=0,(N-wSize)
aa=x(i:i+(wSize-1))
bb=y(i:i+(wSize-1))
cor(i)=escorc(aa,bb)
end do
cor!0="time"
cor&time=date
return(cor)
end |
|