爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 13784|回复: 11

[作图] 热带SST的PC1与SST做回归并检验问题

[复制链接]

新浪微博达人勋

发表于 2017-4-4 01:55:46 | 显示全部楼层 |阅读模式

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

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

x
如图,我现在出的图填色是用student_t对回归检验的P值,不知道为什么会在陆地上有值,与原图差别较大?
其次想知道如何对t检验,负值填色冷色,正值填色暖色,我用的student_t 计算的值都是正值
代码如下(eof_ts的图并没有画出来)
希望得到解答,在这谢谢各位啦!!

  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. ; ==============================================================
  5. ; User defined parameters that specify region of globe and
  6. ; ==============================================================
  7. begin
  8.   latS   = -20.
  9.   latN   =  20.
  10.   yrStrt = 1979
  11.   yrLast = 1996

  12.   var    = "sst"
  13.   title  = "Regr.on SST's PC1"

  14.   ymStrt = yrStrt*100 +  1
  15.   ymLast = yrLast*100 + 12

  16.   neof   = 1                                  ; Leading EOF only
  17.   optEOF = True
  18.   optEOF@jopt = 1      
  19.   optETS = False

  20. ; ==============================================================
  21. ; Open the file: Read only the user specified period and level
  22. ; ==============================================================
  23.   f      = addfile ("/disk3/HadISST/HadISST_sst.nc","r")

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

  27.   x      = short2flt( f->sst(iYYYY,{latS:latN},:))
  28.   y      = short2flt(f->sst(iYYYY,:,:))
  29.   printVarSummary(x)                                ; (time, lat,lon)

  30. ; ==============================================================
  31. ; compute climatology and Anomalies
  32. ; ==============================================================
  33.   
  34.   xAnom=month_to_season(x, "DJF")
  35.   yAnom=month_to_season(y, "DJF")
  36.   ;xAnom=xAnom1/100.
  37.   ;copy_VarMeta(xAnom1, xAnom)
  38.   printVarSummary(xAnom)         
  39.   printMinMax(xAnom, True)

  40. ; =================================================================
  41. ; create weights:  sqrt(cos(lat))   [or sqrt(gw) ]
  42. ; =================================================================
  43.   rad    = get_r2d("float")
  44.   clat   = xAnom&latitude           
  45.   clat   = sqrt( cos(rad*clat) )                 ; gw for gaussian grid
  46.   printVarSummary(clat)

  47. ; =================================================================
  48. ; weight all observations
  49. ; =================================================================
  50.   xw     = xAnom*conform(xAnom, clat, 1)
  51.   copy_VarMeta(xAnom, xw)
  52.   xw@long_name = "Wgt: "+x@long_name

  53. ; =================================================================
  54. ; Reorder (lat,lon,time) the *weighted* input data
  55. ; Compute EOFs & Standardize time series
  56. ; =================================================================
  57.   eof    = eofunc_n_Wrap(xw, neof, optEOF, 0)      
  58.   eof    = -1*eof                                ; *special* match sign of CPC
  59.   eof_ts = eofunc_ts_n_Wrap (xw, eof, optETS, 0)


  60.   eof2    = eofunc_n_Wrap(yAnom, neof, optEOF, 0)      
  61.   eof2    = -1*eof2
  62.   printVarSummary( eof )                         ; examine EOF variables
  63.   printVarSummary( eof_ts )

  64.   eof_ts = dim_standardize_n( eof_ts, 0, 1)      ; normalize
  65.   printMinMax(eof_ts, False)
  66. ; =================================================================
  67. ; Regress
  68. ; =================================================================
  69.   yw2=yAnom(latitude|:,longitude|:,time|:)
  70.   tval =new((/180,360/),"float")
  71.   nxy  =new((/180,360/),"integer")
  72.   lon = lonGlobeF(360, "lon", "lon", "degrees_east")
  73.   tval!1= "lon"
  74.   tval&lon = lon
  75.   lat = latGlobeF(180, "lat", "lat", "degrees_north")
  76.   tval!0= "lat"
  77.   tval&lat = lat

  78.   lon = lonGlobeF(360, "lon", "lon", "degrees_east")
  79.   nxy!1= "lon"
  80.   nxy&lon = lon
  81.   lat = latGlobeF(180, "lat", "lat", "degrees_north")
  82.   nxy!0= "lat"
  83.   nxy&lat = lat
  84.   eof_regres = eof2                               ; create an array w meta data
  85.   do ne=0,neof-1
  86.      eof_regres(ne,:,:) = (/ regcoef(eof_ts(ne,:), yw2, tval,nxy) /)/100.
  87.   end do
  88.   df=16
  89.   tval=student_t(tval, df)
  90.   printVarSummary(tval)
  91.   printMinMax(tval, False)
  92.   printMinMax(eof_regres, False)
  93. ; =================================================================
  94. ; Extract the YYYYMM from the time coordinate
  95. ; associated with eof_ts [same as x&time]
  96. ; =================================================================

  97.   yyyymm = cd_calendar(eof_ts&time,-1)  
  98.   yrfrac = yyyymm_to_yyyyfrac(yyyymm, 0.0); not used here

  99. ;============================================================
  100. ; PLOTS
  101. ;============================================================
  102.   wks = gsn_open_wks("png","/disk1/dzz/study/ncl/TT/ssteof")         ; send graphics to PNG file
  103.   gsn_define_colormap(wks,"amwg256")
  104.   plot = new(neof,graphic)                ; create graphic array
  105.   plot2= new(neof,graphic)                                  ; only needed if paneling
  106. ; EOF patterns

  107.   res                      = True         
  108.   res@gsnDraw              = False        ; don't draw yet
  109.   res@gsnFrame             = False        ; don't advance frame yet

  110.   res@mpFillOn             = False        ; turn off map fill
  111.   res@mpOutlineOn          = True
  112.   res@mpMaxLatF            = 60
  113.   res@mpMinLatF            = -60
  114.   res@mpMaxLonF            = 360
  115.   res@mpMinLonF            = 0
  116.   res@mpCenterLonF         = 180
  117.   res@cnFillOn             = False         ; turn on color fill
  118.   res@cnLinesOn            = True
  119.   res@gsnContourNegLineDashPattern = 1
  120.   res@lbLabelBarOn         = True        ; turn off individual lb's
  121.   res@cnInfoLabelOn        = False
  122.   res@lbTitleOn            = False
  123.   res@cnLevelSelectionMode = "ManualLevels"
  124.   res@cnLevelSpacingF             = 0.3
  125.   ;res@cnFillPalette        = "amwg256"  
  126.   res@cnLineDrawOrder      ="PostDraw"
  127.   res@cnRasterSmoothingOn        = True                                  ; set symmetric plot min/max
  128.   ;symMinMaxPlt(eof_regres, 0.3, False, res)       ; contributed.ncl
  129. ; res@cnLevelSpacingF      = 0.3          ; *special* match CPC
  130.   res2                       = True
  131.   res2@gsnDraw               = False
  132.   res2@gsnFrame              = False
  133.   res2@cnFillOn              = True        ; turn on color fill
  134.   res2@cnLinesOn            = False       ; True is default
  135.   res2@cnLineLabelsOn       = False        ; True is default
  136.   res2@lbLabelBarOn         = False        ; turn off individual lb's
  137.   res2@cnLevelSelectionMode = "ExplicitLevels"
  138.   res2@cnLevels             = (/0.05,0.01/)
  139.   res2@cnFillColors         =  (/225,177,0/)
  140.   res2@cnInfoLabelOn        = False
  141.   res2@lbTitleOn            = False
  142.   res2@cnSmoothingOn        = True
  143. ; panel plot only resources

  144.   resP                     = True         ; modify the panel plot
  145.   resP@gsnMaximize         = True         ; large format
  146.   resP@gsnPanelLabelBar    = True         ; add common colorbar
  147.   ;resP@gsnPaperOrientation = "portrait"   ; force portrait

  148.   resP@txString            = title

  149. ;*******************************************
  150. ; first plot
  151. ;*******************************************
  152.   do n=0,neof-1
  153.      res@gsnLeftString  = "(c)1979-1996"
  154.      res@gsnRightString = ""
  155.      plot(n)=gsn_csm_contour_map(wks,eof_regres(n,:,:),res)
  156.      plot2(n)=gsn_csm_contour    (wks,tval,res2)  
  157.      overlay(plot, plot2)
  158.      draw(plot)
  159.      frame(wks)
  160.   end do
  161.   gsn_panel(wks,plot,(/neof,1/),resP)     ; now draw as one plot
  162. end
复制代码


Regression of the winter mean SST onto the simultaneous normalized PC1 of the tropical SST

Regression of the winter mean SST onto the simultaneous normalized PC1 of the tropical SST

原文献的图

原文献的图
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-4-6 15:38:42 | 显示全部楼层
解决啦,主要是tval的经纬信息(lat,lon)与eof_regres的经纬信息(latitude,longitude)不一致,我统一改成(latitude,longitude)就可以了,但是不知道NCL为什么会这么识别
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

发表于 2017-4-4 09:13:28 | 显示全部楼层
填色图错位了180度吧
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2017-4-4 01:58:01 | 显示全部楼层
另:EOF是(20S,20N)SST对其做EOF1,回归是全球SST与以上EOF1求得的标准化时间序列做的相关(再次感谢所有解答的人)
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-4-4 11:16:13 | 显示全部楼层
cos函数必须对应的是弧度吧,你用get_r2d函数将弧度值转化成度之后,再应用cos函数是错的吧?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-4-4 12:08:34 | 显示全部楼层
talkd 发表于 2017-4-4 09:13
填色图错位了180度吧

哦 对对 这个倒是没注意,谢谢提醒!!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-4-4 12:11:17 | 显示全部楼层
rpf 发表于 2017-4-4 11:16
cos函数必须对应的是弧度吧,你用get_r2d函数将弧度值转化成度之后,再应用cos函数是错的吧?

这个函数我是在官网计算EOF上看到的,不过我觉得 直接用eofunc函数来计算就可以,这个自带权重计算这几行不懂是为什么
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-4-10 16:59:13 | 显示全部楼层
学习了,谢谢大家讨论
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-1-3 17:11:25 | 显示全部楼层

亲 修改的部分可以一下吗
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-1-3 17:17:11 | 显示全部楼层

亲 修改的部分可以贴一下吗
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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