爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6807|回复: 5

利用where函数截取区域海温资料的问题

[复制链接]
发表于 2015-4-23 17:45:23 | 显示全部楼层 |阅读模式

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

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

x
我想要截取热带地区中东太平洋的海温,其他地方需要设置成缺测,我看到官网where函数有这样一个例子正好是可以满足我的要求的,但是我直接使用的时候发现出错,想请教一下到底是要怎么使用这个函数截取海温资料?或者有没有其他方法可以达到这个目的?
QQ图片20150423165513.png

出错信息

出错信息
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2015-4-23 17:45:43 | 显示全部楼层
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"

begin

;************************************************
; Specify geographical region and time span (year-month start and end
;************************************************

  latS     = -90               
  latN     =  90
  lonL     = -180
  lonR     = 180
   ;
;************************************************
; Read from netCDF file: variable is type short...unpack
;************************************************
   diri   = "E:/data/"
   fili   = "HadISST_sst.nc"
   f      = addfile(diri+fili,"r")
   x      = short2flt( f->sst(1,{latS:latN},{lonL:lonR}) )
   x =lonFlip(x)
   printVarSummary(x)                            ; [time| 720]x[lat| 91]x[lon| 180]
  
   x@lat2d = f->latitude    ; 2D coordinate arrays
    x@lon2d = f->longitude

    latMin  = -20
    latMax  =  60
    lonMin  = 110
    lonMax  = 270
   
    x = where((x@lat2d.ge.latMin .and. x@lat2d.le.latMax  .and. \
               x@lon2d.ge.lonMin .and. x@lon2d.le.lonMax), x, x@_FillValue)
   wks  = gsn_open_wks("png","E:/ENSO/20150423/01")
    colors=read_colormap_file("BlWhRe")
      res                       = True   

   res@gsnMaximize           = False             ; make large
   
   res@cnFillOn              = True             ; turn on color
   res@cnLinesOn             = False            ; turn off contour lines
   res@cnLineLabelsOn        = False            ; turn off contour line labels
;;res@cnFillMode            = "RasterFill"
;  res@mpFillOn              = False            ; turn off default background gray
   res@mpCenterLonF          =180
    res@mpMinLatF=-90
    res@mpMaxLatF=90
    res@mpMinLonF=0
    res@mpMaxLonF=360
    res@gsnLeftString=""
    res@gsnRightString=""
resep=res
   resep@tiMainString          = "CP La Nina"  
resep@cnLevelSelectionMode  = "ManualLevels"   ; set manual contour levels
  resep@cnMinLevelValF        =  -2           ; set min contour level
  resep@cnMaxLevelValF        =  2      ; set max contour level
resep@cnLevelSpacingF       =   0.2          ; set contour interval
resep@cnFillPalette        =colors(18:82,:)


;   resep@gsnCenterString       =yearep(i)-1+"/"+yearep(i)
  
  plot = gsn_csm_contour_map_ce(wks,x,resep)
end
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2015-4-23 17:48:45 | 显示全部楼层
后面我又试了一下把where语句改成 xelsat=where(xelsat&latitude.gt.latMin,xelsat,xelsat@_FillValue)显示错误fatal:where:condition variable (parameter 1) dimension mismatch with parameter2
密码修改失败请联系微信:mofangbao
发表于 2015-4-23 18:59:35 | 显示全部楼层
例子里坐标变量是二维的,你数据的坐标变量是一维的!
密码修改失败请联系微信:mofangbao
发表于 2015-4-23 19:08:50 | 显示全部楼层
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"

begin

;************************************************
; Specify geographical region and time span (year-month start and end
;************************************************

  latS     = -90               
  latN     =  90
  lonL     = -180
  lonR     = 180
   ;
;************************************************
; Read from netCDF file: variable is type short...unpack
;************************************************
   diri   = "E:/data/"
   fili   = "HadISST_sst.nc"
   f      = addfile(diri+fili,"r")
   x      = short2flt( f->sst(1,{latS:latN},{lonL:lonR}) )
   x =lonFlip(x)
   printVarSummary(x)                            ; [time| 720]x[lat| 91]x[lon| 180]
  
   x@lat2d = conform(x, f->latitude, 0)    ; 2D coordinate arrays
    x@lon2d = conform(x, f->longitude, 1)


    latMin  = -20
    latMax  =  60
    lonMin  = 110
    lonMax  = 270
   
    x = where((x@lat2d.ge.latMin .and. x@lat2d.le.latMax  .and. \
               x@lon2d.ge.lonMin .and. x@lon2d.le.lonMax), x, x@_FillValue)
   wks  = gsn_open_wks("png","E:/ENSO/20150423/01")
    colors=read_colormap_file("BlWhRe")
      res                       = True   

   res@gsnMaximize           = False             ; make large
   
   res@cnFillOn              = True             ; turn on color
   res@cnLinesOn             = False            ; turn off contour lines
   res@cnLineLabelsOn        = False            ; turn off contour line labels
;;res@cnFillMode            = "RasterFill"
;  res@mpFillOn              = False            ; turn off default background gray
   res@mpCenterLonF          =180
    res@mpMinLatF=-90
    res@mpMaxLatF=90
    res@mpMinLonF=0
    res@mpMaxLonF=360
    res@gsnLeftString=""
    res@gsnRightString=""
resep=res
   resep@tiMainString          = "CP La Nina"  
resep@cnLevelSelectionMode  = "ManualLevels"   ; set manual contour levels
  resep@cnMinLevelValF        =  -2           ; set min contour level
  resep@cnMaxLevelValF        =  2      ; set max contour level
resep@cnLevelSpacingF       =   0.2          ; set contour interval
resep@cnFillPalette        =colors(18:82,:)


;   resep@gsnCenterString       =yearep(i)-1+"/"+yearep(i)
  
  plot = gsn_csm_contour_map_ce(wks,x,resep)
end

密码修改失败请联系微信:mofangbao
 楼主| 发表于 2015-4-23 19:51:13 | 显示全部楼层

实在是太感谢了!
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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