爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 19465|回复: 32

[其他] 请大家进来看看帮帮忙,谢谢大家

[复制链接]

新浪微博达人勋

发表于 2014-8-11 21:38:45 | 显示全部楼层 |阅读模式

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

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

x
想用ncl绘制云水混合比时间高度图,这是我在wrfout里提取的头文件中对云水混合比的介绍float QCLOUD(Time, bottom_top, south_north, west_east) ;                QCLOUD:FieldType = 104 ;
                QCLOUD:MemoryOrder = "XYZ" ;
                QCLOUD:description = "Cloud water mixing ratio" ;
                QCLOUD:units = "kg kg-1" ;
                QCLOUD:stagger = "" ;
                QCLOUD:coordinates = "XLONG XLAT" ;
这个是从官网上copy的time_hight的脚本,修改了一下,
  slice   =w(Time|:,bottom_top|:,south_north|0, west_east|0)
  wks   = gsn_open_wks ("ps", "h_time")            ; open ps file
  gsn_define_colormap(wks,"BlWhRe")                ; choose colormap
  res                      = True                  ; plot mods desired

  res@cnFillOn             = True                  ; turn on color
  res@cnLinesOn            = False                 ; no contour lines
  res@gsnSpreadColors      = True                  ; use full range of colors
  res@lbLabelAutoStride    = True                  ; optimal labels

  res@cnLevelSelectionMode = "ManualLevels"       ; set manual contour levels
  res@cnMinLevelValF       = .001                  ; set min contour level
  res@cnMaxLevelValF       = .01                   ; set max contour level
  res@cnLevelSpacingF      = 0.0001                  ; set contour spacing

  plot = gsn_csm_pres_hgt (wks,slice,res)
end
每次运行都会提示gsn_csm_pres_hgt: Fatal: The first dimension of the input data must   have a coordinate variable called 'lev.'但是我的头文件里没有lev这个坐标啊,这该怎么办啊,有什么补救的方法或是什么方法还能画出时间-高度图吗。




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

新浪微博达人勋

发表于 2014-8-11 22:30:38 | 显示全部楼层
没有就自己添加吧!
首先,要把你的坐标顺序调整一下,把bottom_top换到最左边,即第一维;然后,要为第一维添加坐标变量,这个可以借助wrf_user_getvar。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-8-11 23:18:19 | 显示全部楼层
longlivehj 发表于 2014-8-11 22:30
没有就自己添加吧!
首先,要把你的坐标顺序调整一下,把bottom_top换到最左边,即第一维;然后,要为第一 ...

这个坐标顺序是直接换就行吗,要不要什么函数啥的.这个wrf_user_getvar在这里要怎么使用啊,它不是用来提取var的吗,怎么添加坐标变量啊,我刚接触ncl,比较菜,能具体一下怎么用吗
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-8-12 10:38:42 | 显示全部楼层
Maziy 发表于 2014-8-11 23:18
这个坐标顺序是直接换就行吗,要不要什么函数啥的.这个wrf_user_getvar在这里要怎么使用啊,它不是用来提 ...

1. http://www.ncl.ucar.edu/Document ... es.shtml#Subscripts,其中的named subscripting
2. http://www.ncl.ucar.edu/Document ... f_user_getvar.shtml,其中有个表格,包含了这个函数可以提取或者求取的所有变量,里面有pressure
3. http://www.ncl.ucar.edu/Document ... es.shtml#Dimensions,上下文里有添加坐标变量的介绍
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-8-12 15:20:04 | 显示全部楼层
longlivehj 发表于 2014-8-12 10:38
1. http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#Subscripts,其中的named  ...

我进行了修改,加入 lev    = wrf_user_getvar(f,"pressure",-1),然后在画图的程序之前加入

out!0="lev",修改了坐标 slice   =out(lev|:,Time|:,south_north|0,west_east|0)
但是运行的时候到一半的时候会出现

fatal:Subscript out of range, error in subscript #0
fatal:Execute: Error occurred at or near line 35 in file test.ncl
是哪里出错了吗
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-8-12 15:24:50 | 显示全部楼层
Maziy 发表于 2014-8-12 15:20
我进行了修改,加入 lev    = wrf_user_getvar(f,"pressure",-1),然后在画图的程序之前加入

out!0="l ...

out!0="lev"后,有out&lev=lev么?
实在不行,把脚本贴上来。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-8-12 15:49:52 | 显示全部楼层
longlivehj 发表于 2014-8-12 15:24
out!0="lev"后,有out&lev=lev么?
实在不行,把脚本贴上来。

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/wrf/WRFUserARW.ncl"

begin
f      = addfile("./WRFV3/test/em_quarter_ss/wrfout_d01_0001-01-01_00:00:00.nc","r")
w      = wrf_user_getvar(f,"QCLOUD",-1)
xlat   = wrf_user_getvar(f,"XLAT",-1)
xlong  = wrf_user_getvar(f,"XLONG",-1)
lev    = wrf_user_getvar(f,"pressure",-1)

ntimes = dimsizes(w(:,0,0,0))
wbt    = dimsizes(w(0,:,0,0))
wsn    = dimsizes(w(0,0,:,0))
wwe    = dimsizes(w(0,0,0,:))
out    = new((/wbt,ntimes,wsn,wwe/),"float",0)
do it = 0,ntimes-1
do bt = 0,wbt-1
chu    = w(it,bt,0,0)
yy     = 0
xx     = 0
   do sn = 0,wsn-1
    do we = 0,wwe-1
     if(w(it,bt,sn,we).gt.chu) then
       chu=w(it,bt,sn,we)
      yy = sn
       xx = we
     end if
   end do
   end do
out(it,bt,0,0)= w(it,bt,yy,xx)
print(it)
end do
end do

out!0="lev"
out&lev=lev





slice   =out(lev|:,Time|:,south_north|0,west_east|0)
;================================================
; plot
;================================================
  wks   = gsn_open_wks ("pdf", "h_time")            ; open ps file
  gsn_define_colormap(wks,"BlWhRe")                ; choose colormap
  res                      = True                  ; plot mods desired  res@cnFillOn             = True                  ; turn on color
  res@cnLinesOn            = False                 ; no contour lines

;---This resource not needed in V6.1.0
  res@gsnSpreadColors      = True                  ; use full range of colors

;---This resource defaults to True in NCL V6.1.0
  res@lbLabelAutoStride    = True                  ; optimal labels

  res@cnLevelSelectionMode = "ManualLevels"       ; set manual contour levels
  res@cnMinLevelValF       = .001                  ; set min contour level
  res@cnMaxLevelValF       = .01                   ; set max contour level
  res@cnLevelSpacingF      = 0.0001                  ; set contour spacing

  plot = gsn_csm_pres_hgt (wks,slice,res)
end

这个是我的脚本,还是提示fatal:Subscript out of range, error in subscript #0
fatal:Execute: Error occurred at or near line 35 in file test.ncl

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

新浪微博达人勋

 楼主| 发表于 2014-8-12 17:10:46 | 显示全部楼层
longlivehj 发表于 2014-8-12 15:24
out!0="lev"后,有out&lev=lev么?
实在不行,把脚本贴上来。

我把35行那个错误改过了,然后运行后出现了这个错误
fatal:Coordinate variables must have one dimension only
fatal:No coordinate variable exists for dimension (lev) in variable (out)
fatal:Execute: Error occurred at or near line 41 in file test.ncl
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-8-12 17:16:19 | 显示全部楼层
Maziy 发表于 2014-8-12 15:49
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/c ...

大概改了一下,红色标出来了。另外,4层循环太麻烦,可以用dim_max_n_Wrap一次解决。

;out    = new((/wbt,ntimes,wsn,wwe/),"float",0)
out = w
do it = 0,ntimes-1
do bt = 0,wbt-1
chu    = w(it,bt,0,0)
yy     = 0
xx     = 0
   do sn = 0,wsn-1
    do we = 0,wwe-1
     if(w(it,bt,sn,we).gt.chu) then
       chu=w(it,bt,sn,we)
      yy = sn
       xx = we
     end if
   end do
   end do
out(it,bt,0,0)= w(it,bt,yy,xx)
print(it)
end do
end do

out!1="lev"
out&lev=lev

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

新浪微博达人勋

 楼主| 发表于 2014-8-13 16:31:48 | 显示全部楼层
longlivehj 发表于 2014-8-12 17:16
大概改了一下,红色标出来了。另外,4层循环太麻烦,可以用dim_max_n_Wrap一次解决。

;out    = new(( ...

我修改过后还是不行啊,:No coordinate variable exists for dimension (lev) in variable (out)
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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