NCL滤波器学习(官网实例三代码分析)

带通滤波器通过filwgts_lanczos:

使用201权值生成并应用一个20-100天的带通滤波器。还显示了过滤器的响应函数。

Lanczos过滤权重应用于1980-2005年期间的整个每日系列。绘制的值没有任何缺失点“端点”,因为绘制的时间段(1995-1998)是整个系列的一个子集。

; ****************************** ; filters_3.ncl ; ************************************ ;
; These files are loaded by default in NCL V6.2.0 and newer ; 
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; 
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" ; 
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" 
begin 
                                                ; diri = "/Users/shea/Data/AMWG/" 
diri = "./" vName = "U_anom"                    ; name of variable on the file 
fili = "uwnd.day.850.anomalies.1980-2005.nc" 
f = addfile(diri+fili, "r") 
x = f->$vName$(:,{0},{120}) 
; ******************** ; create the filter weights and apply ; ************************* 
ihp = 2                                         ; band pass 
sigma = 1.0                                     ; Lanczos sigma 
nWgt = 201                                      ; loose 100 each end 
fca = 1./100.                                   ; start freq 
fcb = 1./20.                                    ; last freq 
wgt = filwgts_lanczos (nWgt, ihp, fca, fcb, sigma ) 
printVarSummary(wgt) 
xBPF = wgt_runave ( x, wgt, 0 )                 ; 20-100 day 
printVarSummary(xBPF) 
; ******************* ; create new date array for use on the plot ; ********************* 
date = cd_calendar(x&time,-2)                   ; yyyymmdd 
yrfrac = yyyymmdd_to_yyyyfrac (date, 0) 
delete(yrfrac@long_name) 
delete(x@long_name) 
pStrt = 19950101                                ; 4 years: winter 96-97 MJO gold standard 
pLast = 19981231 
iStrt = ind(date.eq.pStrt)                      ; user specified dates 
iLast = ind(date.eq.pLast) 
delete(date) 
pltType = "png"                                 ; send graphics to PNG file 
pltName = "filters" 
plot = new ( 2, "graphic") 
wks = gsn_open_wks (pltType,pltName) 
res = True                                      ; plot mods desired 
res@gsnDraw = False                             ; don't draw 
res@gsnFrame = False                            ; don't advance frame yet 
res@vpHeightF = 0.4                             ; change aspect ratio of plot 
res@vpWidthF = 0.8 
res@vpXF = 0.1                                  ; start plot at x ndc coord 
res@gsnYRefLine = 0.0                           ; create a reference line 
res@gsnCenterString = "Anomaly U [0, 100E]" 
res@tmXBFormat = "f" 
plot(0) = gsn_csm_xy (wks,yrfrac(iStrt:iLast),x(iStrt:iLast),res) 
res@gsnCenterString = "Band Pass Filtered: 20-100 day" 
plot(1) = gsn_csm_xy (wks,yrfrac(iStrt:iLast),xBPF(iStrt:iLast),res) 
resP = True 
resP@gsnMaximize = True 
gsn_panel(wks,plot,(/2,1/),resP)                ; Create XY plot of frequency versus response 
xyres = True 
xyres@gsnMaximize = True 
xyres@gsnFrame = False 
xyres@tiMainString = "Band Pass: 20-100 srate=1: sigma = " + sigma 
xyres@tiXAxisString = "frequency" 
xyres@tiYAxisString = "response" 
xyres@gsnLeftString = "fca=" + fca + "; fcb=" + fcb 
xyres@gsnRightString = nWgt 
xyres@trXMaxF = 0.1 
xyres@trYMaxF = 1.1 
xyres@trYMinF = -0.1 
plot = gsn_csm_xy(wks, wgt@freq, wgt@resp, xyres) 
X = (/0.0, fca, fca, fcb, fcb, 0.1/) ; ideal filter 
Y = (/0.0, 0.0, 1.0, 1.0, 0.0, 0.0 /) 
resGs = True 
resGs@gsLineThicknessF = 1.0 
gsn_polyline(wks,plot,X,Y,resGs) 
frame(wks) 
end 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值