- 积分
- 3921
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-10-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
各位大神,我想要将站点EOF的2空间模态和时间模态画在一起,研究了一下官网,自己改了一下,但是提示gsn_panel: warning: you have more plots than you have panels.(0) Only 1 plots will be drawn.但是实在找不到自己出错在哪儿了,麻烦大家帮我看看了!万分感谢!- 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"
- load "$NCARG_ROOT/lib/ncarg/nclscripts/cnmap/cnmap.ncl"
- load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
- begin
- path = "/disk02/hg-ws/data40G/quanguo/test/kongzhi/eof/"
- f = addfile(path+"rasu3d.nc", "r")
- rasu = f->rasu3d
- lat = f->lat
- lon = f->lon
- ndim = 1178
- neof = 2
- optEOF = True
- optEOF@jopt = 0
- optETS = True
- optETS@jopt =0
- ; =================================================================
- ; create weights: sqrt(cos(lat)) [or sqrt(gw) ] for covariance
- ; ; =================================================================
- rad = 4.0*atan(1.0)/180.0
- clat = cos(rad*lat)
- clat = where(clat.lt.0, 0.0, clat) ; avoid a potential numerical issue at pole
- clat = sqrt( clat ) ; avoid a potential numerical issue at pole
- ; =================================================================
- ; weight all observations
- ; =================================================================
- ; copy meta data
- wSH = rasu*conform(rasu, clat, 1)
- copy_VarCoords(rasu,wSH)
- ; wSH@long_name = "Wgt: "+wSH@long_name
- ; =================================================================
- ; Reorder (lat,lon,time) the *weighted* input data
- ; Access the area of interest via coordinate subscripting
- ; =================================================================
- x = wSH(lat|:,lon|:,time|:)
- x@_FillValue = 999999
- eof = eofunc_Wrap(x, neof, optEOF)
- eof_ts = eofunc_ts_Wrap(x, eof, optETS)
- printVarSummary( eof ) ; examine EOF variables
- printVarSummary( eof_ts )
-
- eoff=new((/ndim ,neof /),"float")
- do j=0,neof -1
- do i=0,ndim -1
- eoff(i,j) = eof(j,i,i)
- end do
- end do
- ; =================================================================
- ; Normalize time series: Sum spatial weights over the area of used
- ; =================================================================
- dimx = dimsizes( x )
- mln = dimx(1)
- sumWgt = mln*sum( clat(:) )
- eof_ts = eof_ts/sumWgt
- ;print(sum( clat(:) ))
- ;exit
-
- ;*******************************************
- ;North significance test: any pcvar, eval_transpose, eval can be used
- ;*******************************************
- ;sig = new((/40,60/),"logical")
- dimp = dimsizes( rasu )
- ntim = dimp(0)
- ;print(ntim)
- ; ; max # eigenvalues possible
- prinfo = True
- sig_ev = eofunc_north(eof@eval, ntim, prinfo)
- sig_pcv = eofunc_north(eof@pcvar, ntim, prinfo)
- sig_evt = eofunc_north(eof@eval_transpose, ntim, prinfo)
- ; printVarSummary(sig)
- ;----------------------------------------------------------------------
- ; This function attaches a labelbar to the given plot.
- ;----------------------------------------------------------------------
- function attach_labelbar(wks,map,arr[*]:numeric,colors[*])
- local lbres, vph, vpw, nboxes
- begin
- getvalues map
- "vpHeightF" : vph
- "vpWidthF" : vpw
- end getvalues
- nboxes = dimsizes(colors)
-
- lbres = True ; labelbar only resources
- lbres@lbAutoManage = False ; Necessary to control sizes
- lbres@lbFillColors = colors
- lbres@vpWidthF = 0.7 * vpw ; labelbar width
- lbres@vpHeightF = 0.2 * vph ; labelbar height
- lbres@lbMonoFillPattern = True ; Solid fill pattern
- lbres@lbLabelFontHeightF = 0.01 ; font height. default is small
- lbres@lbOrientation = "horizontal"
- lbres@lbPerimOn = False
- lbres@lbLabelAlignment = "InteriorEdges"
- lbid = gsn_create_labelbar(wks,nboxes,""+arr,lbres)
- amres = True
- amres@amJust = "TopCenter"
- amres@amParallelPosF = 0.0 ; Center
- amres@amOrthogonalPosF = 0.6 ; Bottom
- annoid = gsn_add_annotation(map,lbid,amres)
- return(annoid)
- end
- ;============================================================
- ; PLOTS
- ;============================================================
-
- wks = gsn_open_wks("pdf","eofrasu")
- gsn_define_colormap(wks,"rainbow+gray") ; choose colormap
- plot = new(neof,graphic)
- dum1 =new(neof,graphic)
- map=new(neof,graphic)
- ;=================Set Map=================;
- res = True
- res@tiMainString = " "
- res@gsnMaximize = True
- res@gsnDraw = False
- res@gsnFrame = False
- res@mpMinLatF = 17.
- res@mpMaxLatF = 55.
- res@mpMinLonF = 72.
- res@mpMaxLonF = 136.
- res@mpFillOn = True
- ; res@mpLandFillColor = 100
- res@mpOutlineOn = False ; Use outlines from shapefile
- ;res@cnFillDrawOrder = "PreDraw"
- res@mpDataBaseVersion = "MediumRes"
- res@mpDataSetName = "Earth..4"
- res@mpAreaMaskingOn = True
- res@mpMaskAreaSpecifiers = (/"China","Taiwan","Disputed area between India and China","India:Arunachal Pradesh"/)
- res@mpLandFillColor = "white"
- res@mpInlandWaterFillColor = "white"
- res@mpOceanFillColor = "white"
- res@mpOutlineBoundarySets = "NoBoundaries"
- res@vpXF = 0.05 ;離屏幕左端的距離
- res@vpWidthF = 0.4 ;圖的寬度
- res@vpYF = 0.2 ;離屏幕頂端的距離
- res@vpHeightF = 0.3 ;圖的高度
- res@mpGeophysicalLineThicknessF= 1. ; double the thickness of geophysical boundaries
- res@mpNationalLineThicknessF= 1.
- res@pmTickMarkDisplayMode = "Always"
- ; panel plot only resources
- resP = True ; modify the panel plot
- resP@gsnMaximize = True ; large format
- resP@gsnPanelLabelBar = True ; add common colorbar
- ; resP@lbLabelAutoStride = True ; auto stride on labels
- resP@gsnPanelYWhiteSpacePercent = 2
- resP@gsnPanelXWhiteSpacePercent = 2
- ;*******************************************
- ; second plot
- ;*******************************************
- ; EOF time series [bar form]
- rts = True
- rts@gsnDraw = False ; don't draw yet
- rts@gsnFrame = False ; don't advance frame yet
- rts@gsnScale = True ; force text scaling
- rts@vpHeightF = 0.40 ; Changes the aspect ratio
- rts@vpWidthF = 0.85
- rts@vpXF = 0.10 ; change start locations
- rts@vpYF = 0.75 ; the plot
- rts@trXMinF = 1967
- rts@trXMaxF = 2014
- rts@tiYAxisString = "" ; y-axis label
- resz = True
- resz@xyLineColors = "red"
- ; panel plot only resources
- rtsP = True ; modify the panel plot
- rtsP@gsnMaximize = True ; large format
- rtsP@txString = "EOF Time Series for rasu"
- year = ispan (1967,2014,1)
- ;****************************************************
- do n=0,1
- res@gsnLeftString = "EOF "+(n+1)
- res@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
- ;res@tmXBLabelFontHeightF = 0.005
- ;res@tmYBLabelFontHeightF = 0.005
- res@gsnLeftStringFontHeightF = 0.01
- res@gsnRightStringFontHeightF = 0.01
- map(n)= gsn_csm_map(wks,res)
- ;=================Draw Map=================;
- cnres = True
- cnres@china = True ; draw china map or not
- cnres@river = True ; draw changjiang&huanghe or not
- cnres@province = True ; draw province boundary or not
- cnres@nanhai = False ; draw nanhai or not
- cnres@diqu = True
- chinamap = add_china_map(wks,map(n),cnres)
- ;***************************
- ; Plot rotated patterns
- ;*******************************************
- npts = ndim
- arr = (/-0.12,-0.08,-0.04,0,0.04,0.08,0.12/)
-
- narr = dimsizes(arr)
- labels = new(narr+1,string) ; Labels for legend.
- RR = eoff(:,n) ; This is dummy data for determining
-
- ;
- num_distinct_markers = dimsizes(arr)+1 ; number of distinct markers
- lat_new = new((/num_distinct_markers,dimsizes(RR)/),float,-99999)
- lon_new = new((/num_distinct_markers,dimsizes(RR)/),float,-99999)
-
- ;---Group the points according to which range they fall in.
- do i = 0, num_distinct_markers-1
- if (i.eq.0) then
- indexes = ind(RR.lt.arr(0))
- end if
- if (i.eq.num_distinct_markers-1) then
- indexes = ind(RR.ge.max(arr))
- end if
- if (i.gt.0.and.i.lt.num_distinct_markers-1) then
- indexes = ind(RR.ge.arr(i-1).and.RR.lt.arr(i))
- end if
-
- ;index into range
- if (.not.any(ismissing(indexes))) then
- npts_range = dimsizes(indexes) ; # of points in this range.
- lat_new(i,0:npts_range-1) = lat(indexes)
- lon_new(i,0:npts_range-1) = lon(indexes)
- end if
- delete(indexes) ; Necessary b/c "indexes" may be a different
- ; size next time.
- end do
- ; Begin plotting section.
- ;==================================
- gsres = True
- gsres@gsMarkerIndex = 16
- gsres@gsMarkerSizeF = 6. ; Increase marker size by a factor of 10.
- ;---Get nice spacing through color map for marker colors
- getvalues wks
- "wkColorMapLen" : clen ; number of colors in color map
- end getvalues
- nstep = (clen-2)/narr
- colors = ispan(3,clen-1,nstep)
- ;---Loop through each "bin" and attach the markers to the map.
- ;draw eof
- do i = 0, num_distinct_markers-1
- if (.not.ismissing(lat_new(i,0)))
- gsres@gsMarkerColor = colors(i)
- dumstr = unique_string("marker")
- dum1(n) = gsn_add_polymarker(wks,map(n),lon_new(i,:),lat_new(i,:),gsres)
- end if
- end do
- ;draw time series
- rts@gsnLeftString = "EOF "+(n+1)
- rts@gsnRightString = sprintf("%5.1f", eof@pcvar(n )) +"%"
- plot(n) = gsn_csm_xy (wks,year,eof_ts(n,:),rts)
- draw(map(n))
- frame(wks)
- delete([/lat_new,lon_new/])
- end do
- res_U = True
- res_U@gsnFrame = False
- res_U@gsnPanelTop = 0.90
- res_U@gsnPanelBottom = 0.45
- res_U@gsnPanelLabelBar = True
- res_U@pmLabelBarWidthF = 0.6
- res_U@lbBoxEndCapStyle = "TriangleBothEnds" ; default is "RectangleEnds"
-
- res_L = True
- res_L@gsnFrame = False
- res_L@gsnPanelTop = 0.45
- res_L@gsnPanelLabelBar = True
- res_L@pmLabelBarWidthF = 0.6
- res_L@lbBoxEndCapStyle = "TriangleHighEnd" ; Low end will have rectangle end
- txres = True
- txres@txFontHeightF = 0.03
- gsn_text_ndc(wks,"lbBoxEndCapStyle: triangle-end labelbars",0.5,0.95,txres)
-
- gsn_panel(wks,dum1,(/1,1/),res_U)
- gsn_panel(wks,plot,(/1,1/),res_L)
-
- frame(wks)
- ;psres = True
- ;maximize_output(wks,psres) ; calls draw and frame for you
- end
-
复制代码
|
|