用NCL很多年,确实方便,但是若让我信手写来一段程序漂亮地做个相关分析附带检验,还是要扒拉官网调教半天(方便个鬼啊)。所以决定以后常用的代码模板在此分享。满满干货,欢迎打赏!
Contour、Shaded、Lat-Lon、Scalar:
Code:
coe=escorc(index,sst_summer_dtrend(lat|:,lon|:,time|:))
coe!0="lat"
coe!1="lon"
coe&lat=sst_summer_dtrend&lat
coe&lon=sst_summer_dtrend&lon
coe_ttest=coe
coe_ttest=coe@_FillValue
dim_coe_ttest=dimsizes(coe_ttest)
do i=0,dim_coe_ttest(0)-1
do j=0,dim_coe_ttest(1)-1
n = dimsizes(index)
df = n-2 ; degree of freedom
t = coe(i,j)*sqrt((n-2)/(1-coe(i,j)^2))
p = student_t(t, df)
psig = 0.05 ; test significance level: p>psig not significant; p<psig significant
if ((.not.ismissing(p)).and.(p.le.psig)) then
coe_ttest(i,j)=1
else
coe_ttest(i,j)=0
end if
end do
end do
copy_VarCoords(coe,coe_ttest)
printMinMax(coe_ttest,False)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;resourse
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
res = True
res@cnFillOn = True
res@cnLinesOn = False
res@mpCenterLonF = 180
res@gsnDraw = False
res@gsnFrame = False
res@mpMinLatF = -20
res@mpMaxLatF = 30
res@mpMinLonF = 30
res@mpMaxLonF = 130
res@cnLevelSelectionMode = "ExplicitLevels"
res@cnLevels = fspan(-0.5,0.5,11)
;resShade
resShade=True
resShade@gsnFrame=False
resShade@gsnDraw=False
resShade@gsnSpreadColors = True
resShade@mpCenterLonF = 180
resShade@cnFillOn=False
resShade@cnLinesOn=False
resShade@cnLineLabelsOn=False
resShade@cnInfoLabelOn=False
resShade@cnLevelSelectionMode="ExplicitLevels"
resShade@cnLevels=(/0,0.90,0.95/)
opt = True
opt@gsnShadeFillType = "pattern" ; pattern fill
opt@gsnShadeHigh = 17 ; use pattern #2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;plot
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wks=gsn_open_wks("eps","./"+get_script_prefix_name)
plot=gsn_csm_contour_map(wks,coe,res)
plot_shade=gsn_csm_contour(wks,coe_ttest,resShade)
plot_ttest=gsn_contour_shade(plot_shade,0,0.95,opt)
overlay(plot,plot_ttest)
draw(plot)
frame(wks)
Figure:
Contour、Shaded、Lat-Lon、Scalar+Vector:
Code:
uvwnd_coe_ttest=where(uwnd_coe_ttest.gt.vwnd_coe_ttest,uwnd_coe_ttest,vwnd_coe_ttest)
copy_VarCoords(vwnd_coe,uvwnd_coe_ttest)
;resWind
resWind=True
resWind@gsnFrame=False
resWind@gsnDraw=False
resWind@gsnAddCyclic=True
resWind@gsnSpreadColors = True
resWind@lbLabelBarOn=False
resWind@vcRefMagnitudeF=0.8
resWind@vcRefLengthF=0.045
resWind@vcGlyphStyle="CurlyVector"
resWind@vcRefAnnoOrthogonalPosF=-1.0
resWind@vcMonoLineArrowColor = False
resWind@vcLevelSelectionMode= "ExplicitLevels"
resWind@vcLevels= (/0.95/)
resWind@vcLevelColors= (/ "black","green"/)
resWind@vcMinDistanceF=0.02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;plot
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wks=gsn_open_wks("eps","./"+get_script_prefix_name)
plot=gsn_csm_contour_map(wks,sst_coe,res)
plot_shade=gsn_csm_contour(wks,sst_coe_ttest,resShade)
plot_ttest=gsn_contour_shade(plot_shade,0,0.95,opt)
plot_wind_ttest=gsn_csm_vector_scalar(wks,uwnd_coe(lat|:,lon|:),vwnd_coe(lat|:,lon|:),uvwnd_coe_ttest(lat|:,lon|:),resWind)
overlay(plot,plot_ttest)
overlay(plot,plot_wind_ttest)
draw(plot)
frame(wks)