爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8985|回复: 17

[作图] 求助求助,读grd文件算eof时间系数老出错

[复制链接]
发表于 2016-3-6 12:06:31 | 显示全部楼层 |阅读模式

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

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

x
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
;min_lat =  -10.0
; max_lat =40.0
  ;min_lon = 90.0
; max_lon = 160.0
  latS   =  -20
  latN   =  50
  lonL   =60
  lonR   =180
    neof   = 3        ; number of EOFs
  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
diri   = "H:/twentyc/"
  fili1   = "uchunelnino.grd"
   fili2   = "vchunelnino.grd"
    f1=fbindirread(diri+fili1,0,(/29,91,180/),"float")
    f2=fbindirread(diri+fili2,0,(/29,91,180/),"float")
     nlat  = 91                               ; YDEF
  mlon  = 180                              ; XDEF
  year  = 1878                            ; TDEF
  ntim  = 29                              ; time steps
  nmos  = 1
                                          ; not required
  time  = new (ntim, float  ,"No_FillValue") ; generate a "time" variable
;date  = new (ntim, integer,"No_FillValue") ; generate a "date" variable
   time = ispan(0,ntim-1,1)*1. + 1878
  ;n     = -1
  ;do nmo=1,nmos
    ; YRM= year*10000 + nmo*100
     ;ndm= days_in_month(year, nmo)  
    ;do ndy=1,ndm  
      ;n = n+1
       ;time(n) = n     
       ;date(n) = YRM + ndy                ; YYYYMMDD
    ;end do
  ;end do
  time!0         = "time"
  time@long_name = "time"
  time@units     = "yr"           ; "yyyy.fraction_of_year"
  time&time      = time
  ;date!0         = "time"
  ;date@long_name = "date"
; date@units     = "dy"
; date&time      = time
                                          ; generate lat/lon
  lon = ispan(0,mlon-1,1)*2. + 0.
  lon!0 = "lon"
  lon@long_name = "longitude"
  lon@units     = "degrees_east"
  lat = ispan(0,nlat-1,1)*2. -90.
  lat!0 = "lat"
  lat@long_name = "latitude"
  lat@units     = "degrees_north"

;time=ispan(1878,1906,1)
        ; lat=fspan(-90,90,91)
        ; lon=fspan(0,360,180)
        ;; time@units="years since 1878-03-01 00:00:0.0"
        ; lat@units="degrees_north"
        ; lon@units="degrees_east"     
      u=f1(:,:,:)
       v=f2(:,:,:)
         u!0="time"  
         u!1="lat"
         u!2="lon"
        u&time=time
         u&lat=lat
         u&lon=lon
         v!0="time"  
         v!1="lat"
         v!2="lon"
        v&time=time
         v&lat=lat
         v&lon=lon
   printVarSummary(u)  
   printVarSummary(v)
   ;YYYY   = cd_calendar(time,-1)
   s1 = uv2vr_cfd (u(:,:,:),v(:,:,:),lat,lon, 3)  
   s1=s1*1000000
   copy_VarMeta(u,s1)  
printVarSummary(s1)   
   s=dtrend_leftdim(s1,False)
  copy_VarMeta(s1,s)   
s = lonFlip(s)
printVarSummary(s)                              ; note the longitude coord
  rad    = 4.*atan(1.)/180.     
clat   =lat           
  clat   = sqrt( cos(rad*clat) )                ; gw for gaussian grid
; =================================================================
; weight all observations
; =================================================================
  wlh   = s                                  ; copy meta data
  wlh  = s*conform(s, clat, 1)
; wlh@long_name = "Wgt: "+wlh@long_name
; =================================================================
; Reorder (lat,lon,time) the *weighted* input data
; Access the area of interest via coordinate subscripting
; =================================================================
x      = wlh({lat|latS:latN},{lon|lonL:lonR},time|:)
  eof    = eofunc_Wrap(x, neof, optEOF)      
  eof_ts = eofunc_ts_Wrap (x, eof, optETS)
  printVarSummary( eof )                         ; examine EOF variables
  printVarSummary( eof_ts )
; =================================================================
; Normalize time series: Sum spatial weights over the area of used
; =================================================================
  dimx   = dimsizes( x )
  mln    = dimx(1)
sumWgt = mln*sum( lat(0:36) )
  eof_ts = eof_ts/sumWgt
; =================================================================
; Extract the YYYYMM from the time coordinate
; associated with eof_ts [same as SLP&time]
; =================================================================
  yyyy = cd_calendar(eof_ts&time,-2)/100
  ;yyyymm = cd_calendar(time,-2)/100  
;;yrfrac = yyyymm_to_yyyyfrac(yyyymm, 0.0); not used here
;============================================================
; PLOTS
;============================================================
  wks = gsn_open_wks("ps","eofvor29")
  gsn_define_colormap(wks,"BlWhRe")       ; choose colormap
  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
;---This resource not needed in V6.1.0
  res@gsnSpreadColors      = True         ; spread out color table
  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             = True         ; turn on color fill
  res@cnLinesOn            = False        ; True is default
;res@cnLineLabelsOn       = False        ; True is default
  res@lbLabelBarOn         = False        ; turn off individual lb's
                                          ; 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
  resP@lbLabelAutoStride   = True         ; auto stride on labels
yStrt                    = yyyy(0)
  yLast                    = yyyy(ntim-1)
; yStrt                    = 1878
; yLast                    = 1906
;resP@txString            = "lh: "+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 = ""                    ; 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             = "lh: "+season+": "+yStrt+"-"+yLast
  ;year1 = 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
空间场没什么大问题,但是时间场出错: eofs.png 1111.png
我知道是eof_ts这块出错了,但是因为是grd的我也不知道应该怎么改,就自己试了好久还是出错,希望做过这方面的大神指点一下吧

  
  



密码修改失败请联系微信:mofangbao
 楼主| 发表于 2016-3-6 12:12:17 | 显示全部楼层
菜鸟一只,一直在试。。。也想过把grd的转成nc,但是也遇到错,各种受挫{:eb303:}{:eb303:}
密码修改失败请联系微信:mofangbao
发表于 2016-3-6 16:47:17 | 显示全部楼层
subtropical 发表于 2016-3-6 12:12
菜鸟一只,一直在试。。。也想过把grd的转成nc,但是也遇到错,各种受挫

ncl有一个命令直接转成netcdf格式的
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2016-3-6 16:59:01 | 显示全部楼层
andrewsoong 发表于 2016-3-6 16:47
ncl有一个命令直接转成netcdf格式的

你说的是cdo吗,我上午试了,说找不到这个命令。。。。这不是ncl自带的。。。
密码修改失败请联系微信:mofangbao
发表于 2016-3-6 17:02:21 | 显示全部楼层
subtropical 发表于 2016-3-6 16:59
你说的是cdo吗,我上午试了,说找不到这个命令。。。。这不是ncl自带的。。。

大哥,我说的是NCL !!!
http://www.ncl.ucar.edu/Document/Tools/ncl_convert2nc.shtml
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2016-3-6 17:12:03 | 显示全部楼层
andrewsoong 发表于 2016-3-6 17:02
大哥,我说的是NCL !!!
http://www.ncl.ucar.edu/Document/Tools/ncl_convert2nc.shtml

好的好的,非常感谢,我好好看看,谢谢大侠{:eb511:}
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2016-3-6 19:29:37 | 显示全部楼层
andrewsoong 发表于 2016-3-6 17:02
大哥,我说的是NCL !!!
http://www.ncl.ucar.edu/Document/Tools/ncl_convert2nc.shtml

您好,我看了,但是没有grd转nc的。。。
ncl_convert2nc converts one or more GRIB1, GRIB2, HDF 4, HDF-EOS 2, HDF-EOS 5, netCDF, and/or shapefile files to netCDF formatted files.
难道grd和这些都一样吗,换一下就行了吗
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2016-3-6 19:41:04 | 显示全部楼层
plot(n) = gsn_csm_xy (wks,year,eof_ts(n,:),rts)改成 plot(n) = gsn_csm_xy (wks,time,eof_ts(n,:),rts)就可以出图了,但是总觉得grd方式还是不太对,希望大神指导一下
密码修改失败请联系微信:mofangbao
发表于 2016-3-6 19:48:43 | 显示全部楼层
subtropical 发表于 2016-3-6 19:29
您好,我看了,但是没有grd转nc的。。。
ncl_convert2nc converts one or more GRIB1, GRIB2, HDF 4, HD ...

grd就是grib
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2016-3-6 19:50:55 | 显示全部楼层

哦哦,谢谢,我真是知道的太少了。。。。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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