爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 9389|回复: 16

数组有值,却无法出图

[复制链接]

新浪微博达人勋

发表于 2014-12-4 12:59:21 | 显示全部楼层 |阅读模式

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

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

x
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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
begin
in=addfile("/home/zssapr/IOP10/2014072400/wrfout01/02/wrfout_d01_2014-07-24-00_f02.nc","r")
;************get variables***********************************
  UA = wrf_user_getvar(in, "ua",-1)
  VA = wrf_user_getvar(in, "va",-1)
  p = wrf_user_getvar(in, "pressure",-1)
  lat2d = in->XLAT(0,:,:)
  lon2d = in->XLONG(0,:,:)
  lat2d@units = "degrees_north"
  lon2d@units = "degrees_east"
  lat  =in->XLAT(0,:,0)
  lon  =in->XLONG(0,0,:)
  ua2 = wrf_user_intrp3d(UA,p,"h",900,0.,False)
  va2 = wrf_user_intrp3d(VA,p,"h",900,0.,False)
  T =in->Times
  scale=1.e05
  wks = gsn_open_wks("ps","flow")
;********************define  dv********************************
  dv = new ( dimsizes(ua2), typeof(ua2), ua2@_FillValue )
  dv@long_name  = "divengence"
  dv@units      = "scaled"
  dv = uv2dv_cfd (ua2,va2,lat,lon, 2)*scale
  copy_VarCoords(ua2,dv)
;************res for all******************************
  res                     =True
  res@gsnLeftString  = ""
  res@gsnRightString = ""
  res@pmTickMarkDisplayMode = "Always"
;************************res for contour plot************
  gsn_define_colormap( wks ,"BlueWhiteOrangeRed")
  dvMask=mask(dv,dv.gt.0,False)
  div_res =res
  div_res@cnFillOn=True
  div_res@gsnAddCyclic = False
  div_res@gsnSpreadColors  = True
  div_res@cnLevelSelectionMode = "ManualLevels"        ; set manual contour levels
   div_res@cnMinLevelValF       = -50                  ; set min contour level
   div_res@cnMaxLevelValF       = 50                 ; set max contour level
   div_res@cnLevelSpacingF      =   2.
  div_res@cnInfoLabelOn = False
  div_res@cnLineLabelsOn      = False
  div_res@cnLinesOn   =False
  div_res@lbAutoManage         = False
; Turn various features on and off.
  div_res@lbPerimOn            = False
  div_res@lbTitleOn            = True
  div_res@lbTitleString        ="div(1.e10-5)"
  div_res@lbOrientation         = "Vertical"
  div_res@lbTitleExtentF        = 0.1
  div_res@lbTitleFontHeightF    = 0.01
  div_res@lbTitlePosition       = "Right"
  div_res@lbTitleDirection     = "Across"
  div_res@lbTitleAngleF        = 90.                               ; title angle
  div_res@pmLabelBarDisplayMode = "Always"
  div_res@pmLabelBarHeightF     = 0.4
  div_res@pmLabelBarWidthF      = 0.05
  div_res@pmLabelBarSide        = "Right"
  contour_div = wrf_contour(in,wks, dv(0,:,:), div_res)
end
上面的脚本是求散度的,printVarSummary(dv)为:
**************************************************
Variable: dv
Type: float
Total Size: 469504 bytes
            117376 values
Number of Dimensions: 3
Dimensions and sizes:        [1] x [south_north | 448] x [west_east | 262]
Coordinates:
Number Of Attributes: 3
  units :        scaled
  long_name :        divengence
  _FillValue :        9.96921e+36
**************************************************
print(dv),dv的数值也是正常,但是在出图时发现,所出的图图像大小只有2kb。把div_res设为False,则可以出图,但是图像(没有值,等值线也很奇怪)如下:
QQ截图20141204125422.png
将wrf_contour换为gsn_csm_contour后ncl运行超过5min,我终止了,没有等下去。
之前重来没有遇见这种情况,请问这是为什么呢。。。。谢谢!

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-4 20:52:33 | 显示全部楼层
wrf_contour只创建contour,要通过gsnDraw=True强制绘图。
仔细看wrf_contour的帮助和给出的例子。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-12-5 10:09:03 | 显示全部楼层
longlivehj 发表于 2014-12-4 20:52
wrf_contour只创建contour,要通过gsnDraw=True强制绘图。
仔细看wrf_contour的帮助和给出的例子。

下面是刚测试的脚本:
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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
begin
in=addfile("/home/zssapr/IOP10/2014072400/wrfout01/02/wrfout_d01_2014-07-24-00_f02.nc","r")
;************get variables***********************************
; lat2d =  wrf_user_getvar(in, "lat",0)
; lon2d = wrf_user_getvar(in, "lon",0)
  UA = wrf_user_getvar(in, "ua",-1)
  VA = wrf_user_getvar(in, "va",-1)
  p = wrf_user_getvar(in, "pressure",-1)
  lat2d = in->XLAT(0,:,:)
  lon2d = in->XLONG(0,:,:)
  lat2d@units = "degrees_north"
  lon2d@units = "degrees_east"
  lat  =in->XLAT(0,:,0)
  lon  =in->XLONG(0,0,:)
  ua2 = wrf_user_intrp3d(UA,p,"h",900,0.,False)
  va2 = wrf_user_intrp3d(VA,p,"h",900,0.,False)
  T =in->Times
  scale=1.e05
  wks = gsn_open_wks("ps","flow")
;*********************wrf grid to  rectilinear grid**********
  ; nlat=448
   ;lat  = latGau(nlat, "lat", "latitude", "degrees_north")
   ;lon = fspan(115,120,262) ; create longitudes or read from file
  ; UA2  = rcm2rgrid_Wrap(lat2d,lon2d,ua2,lat,lon,1)
  ; VA2  = rcm2rgrid_Wrap(lat2d,lon2d,va2,lat,lon,1)
  ; print(UA2)  
;printVarSummary(UA2)
;*****************div******************
  dv = new ( dimsizes(ua2), typeof(ua2), ua2@_FillValue )
  dv@long_name  = "divengence"
  dv@units      = "scaled"
  dv = uv2dv_cfd (ua2,va2,lat,lon, 2)*scale
  copy_VarCoords(ua2,dv)
  printVarSummary(dv)
;************res for all******************************
  res                     =True
  res@gsnFrame       = True
  res@gsnDraw        = True
  res@gsnLeftString  = ""
  res@gsnRightString = ""
  res@pmTickMarkDisplayMode = "Always"
;************************res for contour plot************
  gsn_define_colormap( wks ,"BlueWhiteOrangeRed")
  dvMask=mask(dv,dv.gt.0,False)
  div_res =res
  div_res@cnFillOn=True
  div_res@gsnAddCyclic = False
  div_res@gsnSpreadColors  = True
  div_res@cnLevelSelectionMode = "ManualLevels"        ; set manual contour levels
  div_res@cnMinLevelValF       = -20                  ; set min contour level
  div_res@cnMaxLevelValF       = 20                 ; set max contour level
  div_res@cnLevelSpacingF      =   2.

  div_res@cnInfoLabelOn = False
  div_res@cnLineLabelsOn      = False
  div_res@cnLinesOn   =False
  div_res@lbAutoManage         = False
; Turn various features on and off.
  div_res@lbPerimOn            = False
  div_res@lbTitleOn            = True
  div_res@lbTitleString        ="div(1.e10-5)"
  div_res@lbOrientation         = "Vertical"
  div_res@lbTitleExtentF        = 0.1
  div_res@lbTitleFontHeightF    = 0.01
  div_res@lbTitlePosition       = "Right"
  div_res@lbTitleDirection     = "Across"
  div_res@lbTitleAngleF        = 90.                               ; title angle
  div_res@pmLabelBarDisplayMode = "Always"
  div_res@pmLabelBarHeightF     = 0.4
  div_res@pmLabelBarWidthF      = 0.05
  div_res@pmLabelBarSide        = "Right"
  print(ua2(0,:,:)+"  "+dv(0,:,:))
contour_div = wrf_contour(in,wks, dv(0,:,:), div_res)
end------------------------------------------------------------------------
这个脚本按照您的意思修改了,gsnDraw、gsnFrame=True,但输出的图像只有2kb,是空白;将wrf_contour改为gsn_csm_contour后,ncl运行迟迟不结束,将红色部分注释掉后,出图,但图像如下:
QQ截图20141205100712.png

我print(dv)输出过了,dv是正常有值的,有少部分缺测值(9.96921e+36),但绘出的图像是这种情况。。。。这是怎么回事?
谢谢!困惑我半天了。。。。

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-5 11:18:00 来自手机 | 显示全部楼层
先看看数据范围,再设置红色部分。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-12-5 13:50:47 | 显示全部楼层
longlivehj 发表于 2014-12-5 11:18
先看看数据范围,再设置红色部分。

红色部分如果设置,ncl会一直运行5min以上,我不得不终止,出不了图。。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-5 20:58:37 | 显示全部楼层
追风的阳光 发表于 2014-12-5 10:09
下面是刚测试的脚本:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/ ...

labelbar显示数据很大啊,你确定算对了?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-12-5 21:45:07 | 显示全部楼层
longlivehj 发表于 2014-12-5 20:58
labelbar显示数据很大啊,你确定算对了?

我print出dv,除了缺测值,其他都是正常的。。。。。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-12-5 21:46:10 | 显示全部楼层
longlivehj 发表于 2014-12-5 20:58
labelbar显示数据很大啊,你确定算对了?

截取的一部分:
(0,36,46)        10.41775
(0,36,47)        12.60727
(0,36,48)        -7.212826
(0,36,49)        -11.61587
(0,36,50)        9.770587
(0,36,51)        14.06386
(0,36,52)        0.4245035
(0,36,53)        -6.727871
(0,36,54)        -2.598933
(0,36,55)        1.835732
(0,36,56)        2.119976
(0,36,57)        0.2940474
(0,36,58)        1.841637
(0,36,59)        5.475983
(0,36,60)        4.274001
(0,36,61)        3.184008
(0,36,62)        5.549555
(0,36,63)        5.356657
(0,36,64)        -1.543052
(0,36,65)        -5.094163
(0,36,66)        -1.507116
(0,36,67)        2.516322
(0,36,68)        4.984159
(0,36,69)        5.740543
(0,36,70)        5.914805
(0,36,71)        4.282104
(0,36,72)        2.012356
(0,36,73)        0.6987128
(0,36,74)        1.54446
(0,36,75)        -0.9440516
(0,36,76)        -2.808898
(0,36,77)        5.547362
(0,36,78)        16.68004
(0,36,79)        14.77696
(0,36,80)        -1.028149
(0,36,81)        -15.48636
(0,36,82)        -14.04939
(0,36,83)        -5.27437
(0,36,84)        -2.485497
(0,36,85)        -6.280032
(0,36,86)        -6.677418
(0,36,87)        4.806983
(0,36,88)        15.79461
(0,36,89)        11.32165
(0,36,90)        11.88749
(0,36,91)        10.3312
(0,36,92)        4.881011
(0,36,93)        2.329093
(0,36,94)        -7.455531
(0,36,95)        -22.06524
(0,36,96)        -24.99107
(0,36,97)        -14.22649
(0,36,98)        1.550279
(0,36,99)        14.38659
(0,36,100)        20.59286
(0,36,101)        19.71161
(0,36,102)        20.81037
(0,36,103)        24.68879
(0,36,104)        27.91078
(0,36,105)        21.80719
(0,36,106)        23.80427
(0,36,107)        23.71424
(0,36,108)        2.538875
(0,36,109)        -9.295198
(0,36,110)        -7.343812
(0,36,111)        0.2961792
(0,36,112)        -1.329385
(0,36,113)        -16.10124
(0,36,114)        4.777144
(0,36,115)        31.68072
(0,36,116)        28.99237
(0,36,117)        -5.722231
(0,36,118)        -23.50173
(0,36,119)        -34.16319
(0,36,120)        -21.49144
(0,36,121)        -10.42239
(0,36,122)        -8.254757
(0,36,123)        -9.466222
(0,36,124)        -18.54029
(0,36,125)        -26.08821
(0,36,126)        -17.09283
(0,36,127)        -5.341873
(0,36,128)        -1.865331
(0,36,129)        -2.680391
(0,36,130)        -0.3907287
(0,36,131)        3.706665
(0,36,132)        9.014683
(0,36,133)        12.94897
(0,36,134)        15.32157
(0,36,135)        14.72888
(0,36,136)        9.348233
(0,36,137)        2.649416
(0,36,138)        -2.468593
(0,36,139)        -5.68165
(0,36,140)        -6.483833
(0,36,141)        -4.668987
(0,36,142)        -1.880095
(0,36,143)        -0.5712144
(0,36,144)        -1.021974
(0,36,145)        -1.493999
(0,36,146)        -1.041826
(0,36,147)        -0.12794
(0,36,148)        0.6458191
(0,36,149)        0.4220457
(0,36,150)        -0.488728
(0,36,151)        -1.117953
(0,36,152)        -1.824883
(0,36,153)        -2.559983
(0,36,154)        -2.273945
(0,36,155)        -1.607019
(0,36,156)        -1.899688
(0,36,157)        -2.967448
(0,36,158)        -3.275625
(0,36,159)        -1.987227
(0,36,160)        0.006070353
(0,36,161)        1.407083
(0,36,162)        1.642427
(0,36,163)        1.664886
(0,36,164)        2.341256
(0,36,165)        2.859246
(0,36,166)        2.822493
(0,36,167)        2.747557
(0,36,168)        2.972009
(0,36,169)        3.379853
(0,36,170)        3.715621
(0,36,171)        3.941442
(0,36,172)        3.888077
(0,36,173)        3.148376
(0,36,174)        2.339262
(0,36,175)        2.083087
(0,36,176)        1.619912
(0,36,177)        1.880175
(0,36,178)        4.51799
(0,36,179)        7.243457
(0,36,180)        6.597273
(0,36,181)        3.220625
(0,36,182)        1.157393
(0,36,183)        1.398552
(0,36,184)        1.741587
(0,36,185)        1.043015
(0,36,186)        -0.9162912
(0,36,187)        -3.157164
(0,36,188)        -4.406868
(0,36,189)        -4.633029
(0,36,190)        -5.189426
(0,36,191)        -6.295824
(0,36,192)        -6.886153
(0,36,193)        -7.404253
(0,36,194)        -7.838412
(0,36,195)        -6.625958
(0,36,196)        -5.446036
(0,36,197)        -4.430144
(0,36,198)        0.4930134
(0,36,199)        2.758697
(0,36,200)        -9.179914
(0,36,201)        -21.9382
(0,36,202)        -21.38926
(0,36,203)        2.022467
(0,36,204)        32.55787
(0,36,205)        37.93518
(0,36,206)        3.590774
(0,36,207)        -25.65604
(0,36,208)        -11.84365
(0,36,209)        -15.48114
(0,36,210)        4.775383
(0,36,211)        12.04913
(0,36,212)        10.23102
(0,36,213)        9.96921e+36
(0,36,214)        9.96921e+36
(0,36,215)        9.96921e+36
(0,36,216)        9.96921e+36
(0,36,217)        9.96921e+36
(0,36,218)        9.96921e+36
(0,36,219)        9.96921e+36
(0,36,220)        9.96921e+36
(0,36,221)        9.96921e+36
(0,36,222)        9.96921e+36
(0,36,223)        36.81085
(0,36,224)        -4.792445
(0,36,225)        -8.685954
(0,36,226)        -1.071934
(0,36,227)        -2.62576
(0,36,228)        -3.41757
(0,36,229)        -1.648707
(0,36,230)        -1.129312
(0,36,231)        -0.6290731
(0,36,232)        0.3765376
(0,36,233)        0.6919138
(0,36,234)        0.7079865
(0,36,235)        1.161438
(0,36,236)        1.504287
(0,36,237)        1.267602
(0,36,238)        0.7591608
(0,36,239)        0.3051673
(0,36,240)        -0.06043775
(0,36,241)        -0.2000503
(0,36,242)        -0.08028388
(0,36,243)        0.06172989
(0,36,244)        0.1269343
(0,36,245)        0.1587189
(0,36,246)        0.1205433
(0,36,247)        -0.1195195
(0,36,248)        -0.5094345
(0,36,249)        -0.7083871
(0,36,250)        -0.4296952
(0,36,251)        0.2277481
(0,36,252)        0.9508814
(0,36,253)        1.554778
(0,36,254)        1.956787
(0,36,255)        2.10919
(0,36,256)        2.061061
(0,36,257)        1.938333
(0,36,258)        1.873867
(0,36,259)        1.684683
(0,36,260)        1.414943
(0,36,261)        1.446143
(0,37,0)        -12.42044
(0,37,1)        -10.34898
(0,37,2)        3.549121
(0,37,3)        8.211284
(0,37,4)        -4.873518
(0,37,5)        -1.679845
(0,37,6)        5.072357
(0,37,7)        13.07932
(0,37,8)        6.509898
(0,37,9)        -7.286056
(0,37,10)        -12.62248
(0,37,11)        -5.53533
(0,37,12)        -9.111698
(0,37,13)        -6.479018
(0,37,14)        -15.82322
(0,37,15)        -21.95579
(0,37,16)        -4.815626
(0,37,17)        1.564235
(0,37,18)        0.2874533
(0,37,19)        -0.1344686
(0,37,20)        -2.707752
(0,37,21)        -9.913095
(0,37,22)        -6.780851
(0,37,23)        27.67099
(0,37,24)        18.45952
(0,37,25)        -5.115317
(0,37,26)        0.4716913
(0,37,27)        -6.707717
(0,37,28)        -18.74351
(0,37,29)        12.26185
(0,37,30)        35.87117
(0,37,31)        2.411878
(0,37,32)        -15.25924
(0,37,33)        -5.209439
(0,37,34)        2.584346
(0,37,35)        1.247666
(0,37,36)        -5.228837
(0,37,37)        -7.487504
(0,37,38)        -8.727258
(0,37,39)        -5.770546
(0,37,40)        8.327007
(0,37,41)        15.96851
(0,37,42)        9.934938
(0,37,43)        -6.296731
(0,37,44)        -9.094782
(0,37,45)        -14.02572
(0,37,46)        -8.547671
(0,37,47)        -3.884375
(0,37,48)        -0.04780681
(0,37,49)        13.20093
(0,37,50)        13.30284
(0,37,51)        10.47247
(0,37,52)        0.3511147
(0,37,53)        -2.080057
(0,37,54)        -1.574177
(0,37,55)        -3.557766
(0,37,56)        -3.085521
(0,37,57)        0.6814659
(0,37,58)        5.219105
(0,37,59)        5.609985
(0,37,60)        2.424458
(0,37,61)        1.676961
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-5 21:47:59 | 显示全部楼层
追风的阳光 发表于 2014-12-5 21:45
我print出dv,除了缺测值,其他都是正常的。。。。。

printVarSummary和printMinMax结果贴出来
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-12-5 21:54:59 | 显示全部楼层
longlivehj 发表于 2014-12-5 21:47
printVarSummary和printMinMax结果贴出来

Variable: dv
Type: float
Total Size: 469504 bytes
            117376 values
Number of Dimensions: 3
Dimensions and sizes:        [1] x [south_north | 448] x [west_east | 262]
Coordinates:
Number Of Attributes: 3
  units :        scaled
  long_name :        divengence
  _FillValue :        9.96921e+36
(0)         
(0)        divengence: min=-137.763   max=1.28247e+38
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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