爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4099|回复: 10

[作图] ncl roef函数使用求助

[复制链接]
回帖奖励 10 金钱 回复本帖可获得 2 金钱奖励! 每人限 2 次
发表于 2016-10-22 15:16:14 | 显示全部楼层 |阅读模式

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

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

x
ncl里有个eof_varimax函数是求reof的,但运行时出现:fatal:(time) is not a named dimension in variable (eof_ts).fatal:["Execute.c":8575]:Execute: Error occurred at or near line 122 in file /home/fc/ncl/scripts/500reof.ncl
的报错.
求大神帮忙看看。
蓝色代码的地方是官网的函数使用说明
红色代码的地方就是报错地方
; ==============================================================
; eof_1.ncl
;
; Concepts illustrated:
;   - Calculating EOFs
;   - Using coordinate subscripting to read a specified geographical region
;   - Rearranging longitude data to span -180 to 180
;   - Calculating symmetric contour intervals
;   - Drawing filled bars above and below a given reference line
;   - Drawing subtitles at the top of a plot
;   - Reordering an array
; ==============================================================
; NCL V6.4.0 has new functions eofunc_n_Wrap and
; eofunc_ts_n_Wrap that allow you to calculate the EOFs without
; first having to first reorder the data. See eof_1_640.ncl.
; ==============================================================
; Calculate EOFs of the Sea Level Pressure over the North Atlantic.
; ==============================================================
; The slp.mon.mean file can be downloaded from:
; http://www.esrl.noaa.gov/psd/dat ... alysis.surface.html
; ==============================================================
; These files are loaded by default in NCL V6.2.0 and newer
; 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"
begin
; ==============================================================
; User defined parameters that specify region of globe and
; ==============================================================
  latS   =  0.
  latN   =  87.5
  lonL   =  -180.
  lonR   =  180.


  yrStrt = 1948
  yrLast = 1998


  season = "DJF"    ; choose Dec-Jan-Feb seasonal mean


  neof   = 3        ; number of EOFs
;   neof = nvar
  optEOF = True      
  optEOF@jopt = 0   ; This is the default; most commonly used; no need to specify.
;;optEOF@jopt = 1   ; **only** if the correlation EOF is desired


  optETS = False


; ==============================================================
; Open the file: Read only the user specified period
; ==============================================================
  f      = addfile ("/home/fc/data/slp.mon.mean.nc", "r")


  TIME   = f->time
  YYYY   = cd_calendar(TIME,-1)/100                 ; entire file
  iYYYY  = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)


  slp    = f->slp(iYYYY,:,:)
  printVarSummary(slp)                              ; variable overview


; ==============================================================
; dataset longitudes span 0=>357.5
; Because EOFs of the North Atlantic Oscillation are desired
; use the "lonFlip" (contributed.ncl) to reorder
; longitudes to span -180 to 177.5: facilitate coordinate subscripting
; ==============================================================
  slp    = lonFlip( slp )
  printVarSummary(slp)                              ; note the longitude coord


; ==============================================================
; compute desired global seasonal mean: month_to_season (contributed.ncl)
; ==============================================================
  SLP    = month_to_season (slp, season)
  nyrs   = dimsizes(SLP&time)
  printVarSummary(SLP)


; =================================================================
; create weights:  sqrt(cos(lat))   [or sqrt(gw) ]
; =================================================================
  rad    = 4.*atan(1.)/180.
  clat   = f->lat           
  clat   = sqrt( cos(rad*clat) )                 ; gw for gaussian grid


; =================================================================
; weight all observations
; =================================================================
  wSLP   = SLP                                   ; copy meta data
  wSLP   = SLP*conform(SLP, clat, 1)
  wSLP@long_name = "Wgt: "+wSLP@long_name


; =================================================================
; Reorder (lat,lon,time) the *weighted* input data
; Access the area of interest via coordinate subscripting
; =================================================================
  xw     = wSLP({lat|latS:latN},{lon|lonL:lonR},time|:)
  x      = wSLP(time|:,{lat|latS:latN},{lon|lonL:lonR})


;  eof      = eofunc_Wrap(xw, neof, optEOF)      
;  eof_ts   = eofunc_ts_Wrap (xw, eof, optETS)
ev = eofcor(xw,neof)
  option      = True
  option@jopt = 1
    eof = eofcor(xw,neof)
    eof_ts = eof_varimax(eof)


  printVarSummary( eof )                         ; examine EOF variables
  printVarSummary( eof_ts )


; =================================================================
; Normalize time series: Sum spatial weights over the area of used
; =================================================================
  dimxw  = dimsizes( xw )
  mln    = dimxw(1)
  sumWgt = mln*sum( clat({lat|latS:latN}) )
  eof_ts = eof_ts/sumWgt


; =================================================================
; Extract the YYYYMM from the time coordinate
; associated with eof_ts [same as SLP&time]
; =================================================================


  yyyymm = cd_calendar(eof_ts&time,-2)/100  
;;yrfrac = yyyymm_to_yyyyfrac(yyyymm, 0.0); not used here


;============================================================
; PLOTS
;============================================================
  wks = gsn_open_wks("png","reof500")         ; send graphics to PNG file
  plot = new(neof,graphic)                ; create graphic array
                                          ; only needed if paneling
; EOF patterns


  res                      = True         
  res@gsnDraw              = False        ; don't draw yet
  res@gsnFrame             = False        ; don't advance frame yet
  res@gsnAddCyclic         = False        ; plotted dataa are not cyclic

  res@mpFillOn             = False        ; turn off map fill
  res@mpMinLatF            = latS         ; zoom in on map
  res@mpMaxLatF            = latN
  res@mpMinLonF            = lonL
  res@mpMaxLonF            = lonR
  res@cnFillOn             = False         ; turn on color fill
  res@cnLinesOn            = True        ; True is default
res@cnLineLabelInterval       = 1        ; True is default
;  res@cnFillPalette        = "BlWhRe"     ; set color map
;  res@lbLabelBarOn         = True       ; turn off individual lb's
  res@cnLineColor = "red"
res@gsnContourLineThicknessesScale =1.5
res@gsnContourNegLineDashPattern = 1
res@cnInfoLabelOn = False
res@mpOutlineOn             = True  ; 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@mpNationalLineColor     = "black"        ;guojie yan se
res@mpGeophysicalLineColor  = "black"     ; kao shui diyu yan se
res@mpCenterLonF = 180
                                          ; set symmetric plot min/max
  symMinMaxPlt(eof, 16, False, res)       ; contributed.ncl


; panel plot only resources
  resP                     = True         ; modify the panel plot
  resP@gsnMaximize         = True         ; large format
  resP@gsnPanelLabelBar    = True         ; add common colorbar


  yStrt                    = yyyymm(0)/100
  yLast                    = yyyymm(nyrs-1)/100
  resP@txString            = "SLP: "+season+": "+yStrt+"-"+yLast


;*******************************************
; first plot
;*******************************************
  do n=0,neof-1
     res@gsnLeftString  = "EOF "+(n+1)
     res@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
     plot(n)=gsn_csm_contour_map_ce(wks,eof(n,:,:),res)
  end do
  gsn_panel(wks,plot,(/neof,1/),resP)     ; now draw as one plot


;*******************************************
; 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               


; these four rtsources allow the user to stretch the plot size, and
; decide exactly where on the page to draw it.


  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@tiYAxisString = "Pa"                    ; y-axis label      


  rts@gsnYRefLine           = 0.              ; reference line   
  rts@gsnXYBarChart         = True            ; create bar chart
  rts@gsnAboveYRefLineColor = "red"           ; above ref line fill red
  rts@gsnBelowYRefLineColor = "blue"          ; below ref line fill blue


; panel plot only resources
  rtsP                      = True            ; modify the panel plot
  rtsP@gsnMaximize          = True            ; large format
  rtsP@txString             = "SLP: "+season+": "+yStrt+"-"+yLast


  year = yyyymm/100


; create individual plots
  do n=0,neof-1
     rts@gsnLeftString  = "EOF "+(n+1)
     rts@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
     plot(n) = gsn_csm_xy (wks,year,eof_ts(n,:),rts)


  end do
  gsn_panel(wks,plot,(/neof,1/),rtsP)     ; now draw as one plot


end
















slp.mon.mean.nc

18.05 MB, 下载次数: 0, 下载积分: 金钱 -5

密码修改失败请联系微信:mofangbao
发表于 2016-10-22 19:06:46 | 显示全部楼层

回帖奖励 +2 金钱

必须要有mixed Julian/Gregorian date属性才能用cd_calender,自己看函数属性吧。错误提示已经很清楚了
密码修改失败请联系微信:mofangbao
发表于 2016-10-22 19:25:03 | 显示全部楼层

回帖奖励 +2 金钱

跟着来学习的~正在研究NCL
密码修改失败请联系微信:mofangbao
发表于 2016-10-22 21:30:00 | 显示全部楼层

回帖奖励 +2 金钱

同为跟着来学习的~
密码修改失败请联系微信:mofangbao
发表于 2016-10-23 10:02:13 | 显示全部楼层

回帖奖励 +2 金钱

为楼主呼吁一下,有此类大神赶紧帮解决一下啊~
密码修改失败请联系微信:mofangbao
发表于 2017-2-23 14:35:15 | 显示全部楼层

回帖奖励 +2 金钱

楼主reof已经做出来了吗?有计算reof的时间系数?(ncl)
密码修改失败请联系微信:mofangbao
发表于 2019-11-1 20:18:29 | 显示全部楼层

回帖奖励 +2 金钱

来学习学习学习学习学习学习学习学习
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

发表于 2020-3-29 19:14:39 | 显示全部楼层

回帖奖励 +2 金钱

{:5_275:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

 成长值: 0
发表于 2020-6-6 11:15:29 | 显示全部楼层

回帖奖励 +2 金钱

学习了学习了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

 成长值: 0
发表于 2020-6-6 11:18:27 | 显示全部楼层

回帖奖励 +2 金钱

学习了学习了{:5_213:}{:5_213:}
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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