begin ;======================creating random data, use index(year,day) to replace z = generate_2d_array(20,20,-10.,10.,0,(/50,90/)) ;90 days 50 years z!0="year" z&year=ispan(1951,2000,1) z!1="day" z&day=fspan(1,90,90) ; print(z) ;======calculate Spectra nday=90 nyear=50;=same as z above, use index(year,day) to replace d = 0 ; detrending opt: 0=>remove mean 1=>remove mean + detrend sm = 21 ; smooth: should be at least 3 and odd pct = 0.10 ; percent taper: (0.0 <= pct <= 1.0) 0.10 common. i=0 ;====a test calculation to decide the dimemtion sdof=specx_anal(z(i,:),d,sm,pct) splt=specx_ci(sdof,0.05,0.95) ;95% freq=sdof@frq ;frequency period=1./freq ;period copy_VarCoords(freq,period) spcx=splt(0,:) ;strength of spectrum splt_up=splt(3,:) ;===95% red noise change to 90 in line22 splt if neccessary nfreq=dimsizes(freq) spcx_year=new((/nfreq,nyear/),"float") random=random_uniform(-1,1,(/nfreq,nyear/)) do i=0,nyear-1 sdof=specx_anal(z(i,:),d,sm,pct) splt=specx_ci(sdof,0.05,0.95) ;95% spcx=splt(0,:) ;strength of spectrum splt_up=splt(3,:) do j=0,nfreq-1 ; if (spcx(j) .ge. splt_up(j)) then if (random(j,i) .ge. 0) then spcx_year(j,i)=1. else spcx_year(j,i)=0. end if end do end do spcx_year!1="year" spcx_year&year=ispan(1951,2000,1) spcx_year!0="lev" spcx_year&lev=1./sdof@frq yarray=spcx_year do i=0,nyear-1 yarray(:,i)=1./sdof@frq end do xarray=spcx_year do i=0,nfreq-1 xarray(i,:)=ispan(1951,2000,1) end do copy_VarCoords(spcx_year,yarray) copy_VarCoords(spcx_year,xarray) ; print(1./sdof@frq) ; spcx_year_trans=spcx_year(period|:,year|:) ; printVarSummary(spcx_year_trans) ; print(spcx_year_trans) ;=============ploting wks1=gsn_open_wks("pdf","./spec_test.ncl") cres=True cres@gsnAddCyclic=False cres@gsnFrame=False cres@gsnDraw=False cres@vpWidthF=0.6 cres@vpHeightF=0.3 cres@trGridType= "TriangularMesh" cres@sfXArray=xarray cres@sfYArray=yarray cres@trYMaxF=60 cres@cnFillOn=True cres@cnLinesOn=False cres@cnFillMode= "CellFill" cres@cnFillColors=(/"gray","Black"/) cres@cnLevels=(/0.5/) cres@cnLevelSelectionMode="ExplicitLevels" cres@lbLabelBarOn=False cres@cnInfoLabelOn=False cres@cnLineLabelsOn=False plot=gsn_csm_contour(wks1,spcx_year,cres) draw(plot) frame(wks1) end