三次插值dtrend

undef("poly3_yao")
; Detrend
; x: array
function poly3_yao(yao:numeric)
local poly3, sizes, Nyear, Nlat, Nlon, x1, x2, x3, x0, x, iLat, iLon, b
begin
    sizes = dimsizes(yao)
    Nyear = sizes(0)
    Nlat = sizes(1)
    Nlon = sizes(2)
    
    x1 = fspan(0, Nyear-1, Nyear)
    x2 = x1^2.0
    x3 = x1^3.0
    x0 = x1
    x0(:) = 1.0
    x = (/x0, x1, x2, x3/)

    poly3 = yao
    do iLat = 0,Nlat-1
        do iLon = 0,Nlon-1
            b = reg_multlin(yao(:,iLat,iLon), x, True)
            poly3(:,iLat,iLon)  = b(0)*x0(:)+b(1)*x1(:)+b(2)*x2(:)+b(3)*x3(:)
        end do 
    end do
    poly3 = where(ismissing(yao), poly3@_FillValue, poly3)
    return(poly3)
end 

你可能感兴趣的:(三次插值dtrend)