登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 HDdd 于 2020-4-5 15:12 编辑
闲来无事 分享一下回归分析以及显著性检验的脚本
;load"$NCARG_ROOT/lib/ncarg/nclscripts/cnmap/cnmap.ncl"
;***********************************************************
begin ;duqu1987-2016desoi&pdozhishu diri = "/cygdrive/G/ncl/qhtj/" soizs =asciiread(diri+"SOI-1951-CURRENT.txt", -1, "float") printVarSummary(soizs)
;duqu1987-2016sst fili = "sst.mon.mean.nc" f = addfile(diri+fili,"r") yyyymm = cd_calendar( f->time, -1) print(yyyymm(0)) ymstrt = 198701 ymlast = 201612 istrt = ind(yyyymm.eq.ymstrt) ilast = ind(yyyymm.eq.ymlast) temp = f->sst; printVarSummary(temp); temper = temp(istrt:ilast,{:},{:}) printVarSummary(temper) sst =temper(lat|:,lon|:,time|:); printVarSummary(sst) ; jisuanhuiguixishubingzuojianyan rc = regCoef(soizs,sst);返回值为tval(t值统计量tval=rc@tval)和nptxy(自由度df=rc@nptxy-2) printVarSummary(rc);
rc@long_name = "Trend" rc!0 = "lat" rc!1 = "lon" rc&lat = sst&lat rc&lon = sst&lon printVarSummary(rc)
tval = onedtond(rc@tval,dimsizes(rc)); df = onedtond(rc@nptxy, dimsizes(rc)) - 2 b = tval;betainc(x, a, b)的x,a,b的维度必须一致 b = 0.5 b!0 = "lat" b!1 = "lon" b&lat = sst&lat b&lon = sst&lon printVarSummary(b)
prob = betainc(df/(df+tval^2),df/2.0,b); prob!0 = "lat" prob!1 = "lon" prob&lat = sst&lat prob&lon = sst&lon wks = gsn_open_wks("png",diri+"soiIII") gsn_define_colormap(wks,"BlueRedGray")
;************************************************ ; plotting parameters(画相关系数rc) ;************************************************ res = True res@gsnDraw = False res@gsnFrame = False res@gsnMaximize = True ; make large res@gsnAddCyclic = False res@cnFillOn = True ; turn on color res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour linelabels ;;res@cnFillMode = "RasterFill" res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels res@cnMinLevelValF = -1 ; set min contourlevel res@cnMaxLevelValF = 1 ; set max contourlevel res@cnLevelSpacingF = 0.1 ; set contourinterval res@mpOutlineBoundarySets = "Geophysical" ; res@mpMinLatF = -30. res@mpMaxLatF = 60. res@mpMinLonF = 105. res@mpMaxLonF = 265. res@mpCenterLonF = 180. res@mpGeophysicalLineThicknessF = 2. ; double the thickness of geophysicalboundaries res@mpNationalLineThicknessF = 2. ; double the thickness of national boundaries res@mpOutlineOn = True ; turn off outline res@mpFillOn = False ; turn off map fill
res@tiMainString = "Regression Test of SOI andSST(1987-2016)" base = gsn_csm_contour_map(wks,rc,res) ;============================================< ;add 画通过显著性检验的区域 ;============================================< res2 = True res2@gsnDraw = False; res2@gsnFrame =False; res2@cnFillOn = True res2@cnLinesOn = False; res2@cnLineLabelsOn = False res2@cnInfoLabelOn = False; res2@lbLabelBarOn = False; res2@cnMonoFillPattern = False res2@cnLevelSelectionMode ="ExplicitLevels" res2@cnLevels = (/0.05/); res2@cnFillPatterns = (/7,-1/); res2@cnFillColors = (/1,-1/); res2@gsnLeftString = "" plot = gsn_csm_contour(wks,prob,res2)
overlay(base, plot) draw(base) frame(wks) end
|