爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 2598|回复: 2

gsn_panel在站点打点图总应用出错

[复制链接]

新浪微博达人勋

发表于 2018-1-20 17:08:58 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
各位大神,我想要将站点EOF的2空间模态和时间模态画在一起,研究了一下官网,自己改了一下,但是提示gsn_panel: warning: you have more plots than you have panels.(0)    Only 1 plots will be drawn.但是实在找不到自己出错在哪儿了,麻烦大家帮我看看了!万分感谢!
  1. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
  2. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
  3. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
  4. load "$NCARG_ROOT/lib/ncarg/nclscripts/cnmap/cnmap.ncl"
  5. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"

  6. begin
  7. path = "/disk02/hg-ws/data40G/quanguo/test/kongzhi/eof/"  
  8. f = addfile(path+"rasu3d.nc", "r")

  9. rasu = f->rasu3d
  10. lat = f->lat
  11. lon = f->lon


  12. ndim         =  1178
  13. neof         = 2
  14. optEOF       =  True
  15. optEOF@jopt  =  0  
  16. optETS       = True
  17. optETS@jopt  =0

  18. ; =================================================================
  19. ; create weights:  sqrt(cos(lat))   [or sqrt(gw) ] for covariance
  20. ; ; =================================================================
  21.    rad    = 4.0*atan(1.0)/180.0
  22.    clat   = cos(rad*lat)           
  23.    clat   = where(clat.lt.0, 0.0, clat)  ; avoid a potential numerical issue at pole
  24.    clat   = sqrt( clat )  ; avoid a potential numerical issue at pole
  25. ; =================================================================
  26. ; weight all observations
  27. ; =================================================================
  28.                                    ; copy meta data
  29.   wSH   = rasu*conform(rasu, clat, 1)
  30.   copy_VarCoords(rasu,wSH)
  31. ;  wSH@long_name = "Wgt: "+wSH@long_name
  32. ; =================================================================
  33. ; Reorder (lat,lon,time) the *weighted* input data
  34. ; Access the area of interest via coordinate subscripting
  35. ; =================================================================
  36.   x      = wSH(lat|:,lon|:,time|:)
  37.   x@_FillValue = 999999
  38.   eof    = eofunc_Wrap(x, neof, optEOF)      
  39.   eof_ts = eofunc_ts_Wrap(x, eof, optETS)

  40.   printVarSummary( eof )                         ; examine EOF variables
  41.   printVarSummary( eof_ts )

  42.     eoff=new((/ndim ,neof /),"float")
  43. do j=0,neof -1
  44.   do i=0,ndim -1  
  45.     eoff(i,j) = eof(j,i,i)
  46.   end do
  47. end do
  48. ; =================================================================
  49. ; Normalize time series: Sum spatial weights over the area of used
  50. ; =================================================================
  51.   dimx   = dimsizes( x )
  52.   mln    = dimx(1)
  53.   sumWgt = mln*sum( clat(:) )
  54.   eof_ts = eof_ts/sumWgt
  55. ;print(sum( clat(:) ))
  56. ;exit
  57.   
  58. ;*******************************************
  59. ;North significance test: any pcvar, eval_transpose, eval can be used
  60. ;*******************************************
  61.     ;sig  = new((/40,60/),"logical")
  62.     dimp   = dimsizes( rasu )
  63.     ntim   = dimp(0)  
  64.     ;print(ntim)
  65. ;                                           ; max # eigenvalues possible
  66.     prinfo = True
  67.     sig_ev  = eofunc_north(eof@eval, ntim, prinfo)
  68.     sig_pcv = eofunc_north(eof@pcvar, ntim, prinfo)
  69.     sig_evt = eofunc_north(eof@eval_transpose, ntim, prinfo)  
  70. ;   printVarSummary(sig)

  71. ;----------------------------------------------------------------------
  72. ; This function attaches a labelbar to the given plot.
  73. ;----------------------------------------------------------------------
  74. function attach_labelbar(wks,map,arr[*]:numeric,colors[*])
  75. local lbres, vph, vpw, nboxes
  76. begin
  77.   getvalues map
  78.     "vpHeightF" : vph
  79.     "vpWidthF"  : vpw
  80.   end getvalues

  81.   nboxes = dimsizes(colors)
  82.    
  83.   lbres                    = True          ; labelbar only resources
  84.   lbres@lbAutoManage       = False          ; Necessary to control sizes
  85.   lbres@lbFillColors       = colors
  86.   lbres@vpWidthF           = 0.7 * vpw     ; labelbar width
  87.   lbres@vpHeightF          = 0.2 * vph     ; labelbar height
  88.   lbres@lbMonoFillPattern  = True          ; Solid fill pattern
  89.   lbres@lbLabelFontHeightF = 0.01          ; font height. default is small
  90.   lbres@lbOrientation      = "horizontal"
  91.   lbres@lbPerimOn          = False
  92.   lbres@lbLabelAlignment   = "InteriorEdges"
  93.   lbid = gsn_create_labelbar(wks,nboxes,""+arr,lbres)

  94.   amres                  = True
  95.   amres@amJust           = "TopCenter"
  96.   amres@amParallelPosF   =  0.0    ; Center
  97.   amres@amOrthogonalPosF =  0.6    ; Bottom
  98.   annoid = gsn_add_annotation(map,lbid,amres)
  99.   return(annoid)
  100. end
  101. ;============================================================
  102. ; PLOTS
  103. ;============================================================
  104.   
  105.   wks = gsn_open_wks("pdf","eofrasu")
  106.   gsn_define_colormap(wks,"rainbow+gray")     ; choose colormap
  107.   plot = new(neof,graphic)  
  108.   dum1 =new(neof,graphic)
  109.   map=new(neof,graphic)
  110. ;=================Set Map=================;
  111. res                         = True            
  112. res@tiMainString            = " "
  113. res@gsnMaximize             = True
  114. res@gsnDraw                 = False
  115. res@gsnFrame                = False

  116.   res@mpMinLatF               = 17.                        
  117.   res@mpMaxLatF               = 55.
  118.   res@mpMinLonF               = 72.
  119.   res@mpMaxLonF               = 136.

  120. res@mpFillOn                = True
  121. ; res@mpLandFillColor         =  100
  122. res@mpOutlineOn             = False  ; Use outlines from shapefile
  123. ;res@cnFillDrawOrder         = "PreDraw"
  124. res@mpDataBaseVersion       = "MediumRes"
  125. res@mpDataSetName           = "Earth..4"
  126. res@mpAreaMaskingOn         = True
  127. res@mpMaskAreaSpecifiers    = (/"China","Taiwan","Disputed area between India and China","India:Arunachal Pradesh"/)
  128. res@mpLandFillColor         = "white"
  129. res@mpInlandWaterFillColor  = "white"
  130. res@mpOceanFillColor        = "white"
  131. res@mpOutlineBoundarySets   = "NoBoundaries"
  132. res@vpXF            = 0.05   ;離屏幕左端的距離      
  133. res@vpWidthF        = 0.4    ;圖的寬度
  134. res@vpYF            = 0.2    ;離屏幕頂端的距離
  135. res@vpHeightF       = 0.3    ;圖的高度

  136.   res@mpGeophysicalLineThicknessF= 1.      ; double the thickness of geophysical boundaries
  137.   res@mpNationalLineThicknessF= 1.


  138.   res@pmTickMarkDisplayMode   = "Always"
  139.   ; panel plot only resources
  140.   resP                     = True         ; modify the panel plot
  141.   resP@gsnMaximize         = True         ; large format
  142.   resP@gsnPanelLabelBar    = True         ; add common colorbar
  143.   ; resP@lbLabelAutoStride   = True         ; auto stride on labels
  144.   resP@gsnPanelYWhiteSpacePercent = 2
  145.   resP@gsnPanelXWhiteSpacePercent = 2

  146.   ;*******************************************
  147. ; second plot
  148. ;*******************************************
  149. ; EOF time series  [bar form]

  150.   rts           = True
  151.   rts@gsnDraw   = False       ; don't draw yet
  152.   rts@gsnFrame  = False       ; don't advance frame yet
  153.   rts@gsnScale  = True        ; force text scaling               

  154.   rts@vpHeightF = 0.40        ; Changes the aspect ratio
  155.   rts@vpWidthF  = 0.85
  156.   rts@vpXF      = 0.10        ; change start locations
  157.   rts@vpYF      = 0.75        ; the plot
  158.    rts@trXMinF  = 1967
  159.    rts@trXMaxF  = 2014

  160.   rts@tiYAxisString = ""                    ; y-axis label      
  161.     resz                         = True
  162.     resz@xyLineColors            = "red"

  163. ; panel plot only resources
  164.   rtsP                      = True            ; modify the panel plot
  165.   rtsP@gsnMaximize          = True            ; large format
  166.   rtsP@txString             = "EOF Time Series for rasu"

  167.   year = ispan (1967,2014,1)
  168. ;****************************************************

  169.   do n=0,1
  170.   res@gsnLeftString  = "EOF "+(n+1)
  171.   res@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
  172.   ;res@tmXBLabelFontHeightF  = 0.005
  173.   ;res@tmYBLabelFontHeightF  = 0.005
  174.   res@gsnLeftStringFontHeightF = 0.01
  175.   res@gsnRightStringFontHeightF = 0.01
  176.   map(n)= gsn_csm_map(wks,res)   


  177.      ;=================Draw Map=================;

  178. cnres           = True
  179. cnres@china     = True        ; draw china map or not
  180. cnres@river     = True         ; draw changjiang&huanghe or not
  181. cnres@province  = True   ; draw province boundary or not
  182. cnres@nanhai    = False     ; draw nanhai or not
  183. cnres@diqu      = True
  184. chinamap = add_china_map(wks,map(n),cnres)
  185. ;***************************
  186. ; Plot rotated patterns
  187. ;*******************************************
  188.   npts = ndim
  189.   arr = (/-0.12,-0.08,-0.04,0,0.04,0.08,0.12/)
  190.                
  191.   narr = dimsizes(arr)
  192.   labels = new(narr+1,string)  ; Labels for legend.
  193.   RR   = eoff(:,n)  ; This is dummy data for determining
  194.    
  195. ;
  196.   num_distinct_markers = dimsizes(arr)+1        ; number of distinct markers
  197.   lat_new = new((/num_distinct_markers,dimsizes(RR)/),float,-99999)
  198.   lon_new = new((/num_distinct_markers,dimsizes(RR)/),float,-99999)
  199.   
  200. ;---Group the points according to which range they fall in.
  201.    do i = 0, num_distinct_markers-1
  202.      if (i.eq.0) then
  203.        indexes = ind(RR.lt.arr(0))
  204.      end if
  205.      if (i.eq.num_distinct_markers-1) then
  206.        indexes = ind(RR.ge.max(arr))
  207.      end if
  208.      if (i.gt.0.and.i.lt.num_distinct_markers-1) then      
  209.        indexes = ind(RR.ge.arr(i-1).and.RR.lt.arr(i))
  210.      end if
  211.    
  212.      ;index into range
  213.      if (.not.any(ismissing(indexes))) then
  214.        npts_range = dimsizes(indexes)   ; # of points in this range.
  215.       lat_new(i,0:npts_range-1) = lat(indexes)
  216.       lon_new(i,0:npts_range-1) = lon(indexes)
  217.      end if
  218.      delete(indexes)            ; Necessary b/c "indexes" may be a different
  219.                                 ; size next time.
  220.    end do

  221. ; Begin plotting section.
  222. ;==================================
  223.   gsres               = True
  224.   gsres@gsMarkerIndex = 16  
  225.   gsres@gsMarkerSizeF = 6. ; Increase marker size by a factor of 10.   
  226. ;---Get nice spacing through color map for marker colors
  227. getvalues wks
  228.     "wkColorMapLen" : clen     ; number of colors in color map
  229.   end getvalues

  230.   nstep = (clen-2)/narr
  231.   colors = ispan(3,clen-1,nstep)
  232. ;---Loop through each "bin" and attach the markers to the map.
  233.      ;draw eof
  234.     do i = 0, num_distinct_markers-1
  235.       if (.not.ismissing(lat_new(i,0)))
  236.       gsres@gsMarkerColor      = colors(i)
  237.       dumstr = unique_string("marker")
  238.       dum1(n) = gsn_add_polymarker(wks,map(n),lon_new(i,:),lat_new(i,:),gsres)
  239.       end if
  240.     end do
  241.        ;draw time series
  242.       rts@gsnLeftString  = "EOF "+(n+1)
  243.       rts@gsnRightString = sprintf("%5.1f", eof@pcvar(n )) +"%"
  244.       plot(n) = gsn_csm_xy (wks,year,eof_ts(n,:),rts)
  245.       draw(map(n))
  246.       frame(wks)
  247.     delete([/lat_new,lon_new/])

  248. end do
  249.   res_U                   = True
  250.   res_U@gsnFrame          = False
  251.   res_U@gsnPanelTop       = 0.90
  252.   res_U@gsnPanelBottom    = 0.45
  253.   res_U@gsnPanelLabelBar  = True
  254.   res_U@pmLabelBarWidthF  = 0.6
  255.   res_U@lbBoxEndCapStyle  = "TriangleBothEnds"     ; default is "RectangleEnds"
  256.   
  257.   res_L                   = True
  258.   res_L@gsnFrame          = False
  259.   res_L@gsnPanelTop       = 0.45
  260.   res_L@gsnPanelLabelBar  = True
  261.   res_L@pmLabelBarWidthF  = 0.6
  262.   res_L@lbBoxEndCapStyle  = "TriangleHighEnd"     ; Low end will have rectangle end

  263.   txres               = True
  264.   txres@txFontHeightF = 0.03
  265.   gsn_text_ndc(wks,"lbBoxEndCapStyle: triangle-end labelbars",0.5,0.95,txres)
  266.   
  267.   gsn_panel(wks,dum1,(/1,1/),res_U)
  268.   gsn_panel(wks,plot,(/1,1/),res_L)
  269.   
  270.   frame(wks)

  271. ;psres = True                                                               
  272. ;maximize_output(wks,psres)  ; calls draw and frame for you      


  273. end
  274.   
复制代码



密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2020-10-16 21:02:14 | 显示全部楼层
297.  gsn_panel(wks,plot,(/1,1/),res_L)改成
gsn_panel(wks,plot,(/1,2,5,3,1/),res_L)这种
(/1,2,5,3,1/)表明每行几张图
今天在这卡了好久,知道对你没用了,但是还是回一下
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-20 11:42:02 | 显示全部楼层
突然发现我是因为 resP@gsnPanelRowSpec  ; tell panel what order to plot
不小心设成True   这个设成true的话gsn_panel(wks,plot,(/1,2,5,3,1/),res_L),一共出12张图
否则gsn_panel(wks,plot,(/3,4/),resP),(/3,4/)就表明图几行几列。

你的脚本没细看但感觉可能是gsn_panel设置的问题。。。。?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表