爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 16354|回复: 16

NCL 脚本,hadisst海温数据,EOF分解,画 北半球 PDO问题?

[复制链接]

新浪微博达人勋

发表于 2014-3-10 15:59:38 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 guizi 于 2014-3-10 15:59 编辑

最近两天在用  ncl  对  HADISST 做EOF 分解
遇到个 神器错误,并且用ncl 老遇到神器错误,

这个 不解就是  加拿大北部,巴芬岛 那块的数据有问题,把范围选小点 就可以,
下面的脚本,发过一次,ncl脚本,稍作修改,就贡献在ncl 板块了


脚本如下
;************************************************
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/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/skewt_func.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/wind_rose.ncl"
;************************************************
begin
;*************  set up  some parameter        *********   
  lonL   = 100
  lonR   = 240

  latB   = -10
  latT   = 40

  yrStrt = 1950
  yrLast = 2013
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  neof = 8
;************  open files and  read the data ***********  
  f     = addfile("../HadISST_sst.nc","r")
  time   = f->time                   ; days since 0000-09-01 00:00:00
  YYYY   = cd_calendar(time,-1)/100                 ; entire file
  iYYYY  = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;  sst  = f->sst(iYYYY,{latT:latB},:)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  g_sst  = f->sst(iYYYY,:,:)
  g1_sst = lonPivot(g_sst,0.5)
  sst    = g1_sst(:,{latB:latT},{lonL:lonR})
;*************  deal with the data     *****

  sst    = where(abs(sst).gt.500,sst@_FillValue,sst)

  printVarSummary(sst)
  printMinMax(sst,True)
  
  f_sst   = sst

  printVarSummary(f_sst)
  printMinMax(f_sst,True)

  ntime   = dimsizes(sst&time)
  ny      = dimsizes(sst&latitude)
  nx      = dimsizes(sst&longitude)
;******************************************************


  copy_VarCoords(sst,f_sst)
;  printVarSummary(f_sst)

;  y_sst = dtrend_msg_n(f_sst&time,f_sst,True,False,0)
;  copy_VarCoords(sst,y_sst)

  y_sst = dtrend_leftdim(f_sst,False)
;  printVarSummary(y_sst)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   temp   = y_sst
   nt     = ntime/12
   print(nt)
   month  = 12
   temp_mon  = new((/month,nt,ny,nx/),float)
   temp_d    = new((/ntime,ny,nx/),float)

   do imon=0,month-1
      temp_mon(imon,:,:,:) =  dim_rmvmean_n_Wrap(temp(imon:ntime-1:12,:,:),0)
   end do

   do it=0,nt-1
   do imon=0,month-1
      temp_d(it*12+imon,:,:)  =  temp_mon(imon,it,:,:)
   end do
   end do
      copy_VarCoords(temp,temp_d)


;~~~~~~~~~~~~~~~~~~~~~~~~~~~
  x    = temp_d
  printVarSummary(x)

;*******************************************
;  EOF
;*******************************************
  X = x(latitude|:,longitude|:,time|:)              ; Space x Time

  optEof = True
  eof    = eofunc_Wrap( X, neof, optEof)
  eof_ts = eofunc_ts_Wrap( X, eof, False)

  printVarSummary(eof)
  printVarSummary(eof_ts)

  yyyymm = cd_calendar(eof_ts&time,-2)/100
  year   = yyyymm/100


;*******************************************
;  plots
;*******************************************
  wks = gsn_open_wks("pdf","pdo_eof")
  gsn_define_colormap(wks,"posneg_1")     ; choose colormap
;
; This will not be necessary in V6.1.0 and later. Named colors can
; be used without having to first add them to the color map.
;
  dum = NhlNewColor(wks,0.7,0.7,0.7)      ; add gray to color table

  plot = new(neof,graphic)                ; create graphic array
                                          ; only needed if paneling
  res                      = True
  res@gsnDraw              = False        ; don't draw yet
  res@gsnFrame             = False        ; don't advance frame yet
  res@gsnSpreadColors      = True         ; spread out color table
  res@gsnSpreadColorEnd    = -2           ; don't use added gray
  res@gsnAddCyclic         = False        ; data not cyclic


  res@mpCenterLonF         = 190.         ; defailt is 0 [GM]
  res@mpMinLatF            = min(x&latitude)
  res@mpMaxLatF            = max(x&latitude)
  res@mpMinLonF            = min(x&longitude)
  res@mpMaxLonF            = max(x&longitude)
  res@mpFillDrawOrder      = "PostDraw"

  res@cnFillOn             = True         ; turn on color fill
  res@cnLinesOn            = True         ; 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


  resP@txString            = "Kaplan_sst (Pierce)"
  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(0:3),(/2,2/),resP)     ; draw all 'neof' as one plot

;*******************************************
; time series (principal component) plot
;*******************************************
  eof_ts@long_name = "Amplitude"

  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 resources 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@gsnYRefLine           = 0.              ; reference line
  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

;  year = cd_calendar(eof_ts&time,1)


  resP@txString            = "KAplan_sst: Pierce"
  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(0:3),(/2,2/),rtsP)        ; draw all 'neof' as one plot

end




自己还有 上面的结果还是不好看,主要在 时间系数的  坐标问题
QQ图片20140310155547.jpg   图正常, QQ图片20140310155552.jpg




要是 这么设   QQ图片20140310155559.jpg ,图不正常,坐标正常 QQ图片20140310155604.jpg

谁还有个好的法子撒???

?????

QQ图片20140310155201.jpg
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-3-10 16:40:35 | 显示全部楼层
本帖最后由 longlivehj 于 2014-3-10 16:44 编辑

举个例子,如果是日数据,时间单位days since 0000-09-01 00:00:00。那么,cd_calendar之前,6月30日和7月1日之间,时间坐标相差1;cd_cadendar之后,630和701之间,时间坐标相差71。这就是你时间系数图出现“神器错误”的原因。

这种情况,可以通过tmXBMode、tmXBValues和tmXBLabels属性来手动设置坐标;也可以用time_axis_labels过程来设置。

ncl官方网页上有相关实例。time_labels
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-3-10 20:33:29 | 显示全部楼层
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-3-12 10:31:25 | 显示全部楼层
你也做PDO啊,我也做PDO,研究了大半年了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-3-13 13:52:03 | 显示全部楼层
楼主的问题最后解决了么?可以分享一下么?我也遇到了一样的问题
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-9 13:53:12 | 显示全部楼层
请问下楼主,你的HADISST数据是在哪儿下的呢?我只下载到txt格式,下面有个nc格式的无法下载(自动回复:请不要使用迅雷等下载工具,点我查看下载帮助),求助啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-6-1 21:30:54 | 显示全部楼层
你好,用你的脚本运行之后,出现图中的错误,能不能帮忙看看是什么原因?谢谢啦~~~~
$DTQZGBLT{B}}UDTJ)3PGYX.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-1 20:33:01 | 显示全部楼层
sweet33 发表于 2015-4-9 13:53
请问下楼主,你的HADISST数据是在哪儿下的呢?我只下载到txt格式,下面有个nc格式的无法下载(自动回复:请 ...

同求问啊!!!你现在会了吗
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-1 20:33:12 | 显示全部楼层
sweet33 发表于 2015-4-9 13:53
请问下楼主,你的HADISST数据是在哪儿下的呢?我只下载到txt格式,下面有个nc格式的无法下载(自动回复:请 ...

同求问啊!!!你现在会了吗
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-1 20:33:27 | 显示全部楼层
sweet33 发表于 2015-4-9 13:53
请问下楼主,你的HADISST数据是在哪儿下的呢?我只下载到txt格式,下面有个nc格式的无法下载(自动回复:请 ...

同求问啊!!!你现在会了吗
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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