爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
楼主: irides

[作图] ncl作风矢量的垂直剖面图,不知道问题出在哪里

[复制链接]
发表于 2018-3-23 11:08:33 | 显示全部楼层
请问最后的ncl程序能发出来分享一下吗
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2018-3-23 13:08:23 | 显示全部楼层
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/wrf/WRFUserARW.ncl"
begin
  a = addfile("~/urban_slope/wrfout_d04_2015-12-29_00_00_00.nc","r")
  wks = gsn_open_wks("png","uw_theta")

; Set some basic resources
  res = True
  res@Footer = False
  
  pltres = True
  ter_res = True
  opts_ter = ter_res
  opts_ter@gsnYRefLine = 0.0
  opts_ter@gsnAboveYRefLineColor = "black"
  opts_ter@gsnDraw = False
  opts_ter@gsnFrame = False
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  FirstTime = True
  FirstTimeMap = True
  times  = wrf_user_getvar(a,"times",-1) ; get times in the file
  ntimes = dimsizes(times)         ; number of times in the file
  mdims = getfilevardimsizes(a,"P") ; get some dimension sizes for the file
  nd = dimsizes(mdims)
  xlat = wrf_user_getvar(a, "XLAT",0)
  xlon = wrf_user_getvar(a, "XLONG",0)
  ter = wrf_user_getvar(a, "HGT",0)
;---------------------------------------------------------------
  do it = 16,39,1              ; TIME LOOP
  
;    it = 31
    print("Working on time: " + times(it) )
    res@TimeLabel = times(it)   ; Set Valid time to use on plots
   
    u = wrf_user_getvar(a,"ua",it)
;    v = wrf_user_getvar(a,"va",it)
    w = wrf_user_getvar(a,"wa",it)
    theta = wrf_user_getvar(a,"theta",it)
    z = wrf_user_getvar(a, "z",it)
    if ( FirstTime ) then                ; get height info for labels
      zmin = 0.
      zmax = 6.                          ; We are only interested in the first 6km
      nz   = floattoint(zmax + 1)
    end if
        opts_ter@trYMaxF = zmax*1000

;---------------------------------------------------------------
   do ip = 1, 3       ; we are doing 3 plots   
              
        plane = new(2,float)
        plane = (/106,104/)    ; pivot point is center of domain (x,y)
        opts = False
        if(ip .eq. 1) then
          angle = 90.
          X_plane = wrf_user_intrp2d(xlon,plane,angle,opts)
          X_desc = "longitude"
        end if
        if(ip .eq. 2) then
          angle = 0.
          X_plane = wrf_user_intrp2d(xlat,plane,angle,opts)
          X_desc = "latitude"
        end if
        if(ip .eq. 3) then
          angle = 45.
          X_plane = wrf_user_intrp2d(xlon,plane,angle,opts)
          X_desc = "longitude"
        end if
        theta_plane = wrf_user_intrp3d(theta,z,"v",plane,angle,opts)
        u_plane = wrf_user_intrp3d(u,z,"v",plane,angle,opts)
;        v_plane = wrf_user_intrp3d(v,z,"v",plane,angle,opts)
        w_plane = wrf_user_intrp3d(w,z,"v",plane,angle,opts)
        ter_plane = wrf_user_intrp2d(ter,plane,angle,opts)
        print("Max terrain height in plot " + max(ter_plane))
        
        theta_plane2 = theta_plane
        w_plane2 = w_plane
        cross_dims = dimsizes(theta_plane2)
        rank = dimsizes(cross_dims)
        iz_do = 25                    
        do iz = 0,24
          iz_do = iz_do-1
          do ix = 0,cross_dims(rank-1)-1
            if ( ismissing(theta_plane2(iz_do,ix)) ) then
              theta_plane2(iz_do,ix) = theta_plane2(iz_do+1,ix)
            end if
            if ( ismissing(w_plane2(iz_do,ix)) ) then
              w_plane2(iz_do,ix) = w_plane2(iz_do+1,ix)
            end if
          end do
        end do

      ; Find the index where 6km is - only need to do this once
        if ( FirstTime ) then
          zz = wrf_user_intrp3d(z,z,"v",plane,angle,opts)
          b = ind(zz(:,0) .gt. zmax*1000. )
          zmax_pos = b(0) - 1
          if ( abs(zz(zmax_pos,0)-zmax*1000.) .lt. abs(zz(zmax_pos+1,0)-zmax*1000.) ) then
            zspan = b(0) - 1
          else
            zspan = b(0)
          end if
          delete(zz)
          delete(b)
          FirstTime = False
        end if
      ; X-axis lables
      dimsX = dimsizes(X_plane)
      xmin  = X_plane(0)
      xmax  = X_plane(dimsX(0)-1)
      xspan = dimsX(0)-1
      nx    = floattoint( (xmax-xmin)/2 + 1)
      ;---------------------------------------------------------------
        
      ; Options for XY Plots
        opts_xy                         = res
        opts_xy@tiXAxisString           = X_desc
        opts_xy@tiYAxisString           = "Height (km)"
        opts_xy@cnMissingValPerimOn     = True
        opts_xy@cnMissingValFillColor   = 0
        opts_xy@cnMissingValFillPattern = 11
        opts_xy@tmXTOn                  = False
        opts_xy@tmYROn                  = False
        opts_xy@tmXBMode                = "Explicit"
        opts_xy@tmXBValues              = fspan(0,xspan,6)                    ; Create tick marks
        opts_xy@tmXBLabels              = sprintf("%.1f",fspan(xmin,xmax,6))  
        opts_xy@tmXBLabelFontHeightF    = 0.015
        opts_xy@tmYLMode                = "Explicit"
        opts_xy@tmYLValues              = fspan(0,zspan,nz)                    ; Create tick marks
        opts_xy@tmYLLabels              = sprintf("%.1f",fspan(zmin,zmax,nz))  ; Create labels
        opts_xy@tiXAxisFontHeightF      = 0.020
        opts_xy@tiYAxisFontHeightF      = 0.020
        opts_xy@tmXBMajorLengthF        = 0.02
        opts_xy@tmYLMajorLengthF        = 0.02
        opts_xy@tmYLLabelFontHeightF    = 0.015
        opts_xy@PlotOrientation         = w_plane@Orientation

      ; Plotting options for RH
        opts_theta = opts_xy
        opts_theta@pmLabelBarOrthogonalPosF = -0.18
        opts_theta@cnFillOn                = True
        opts_theta@cnLevelSelectionMode = "ExplicitLevels"
        opts_theta@cnLevels = (/286,287,288,289,290,292,294,296,300,304,308,312/)

      ; Plotting options for Temperature
        ;opts_vec = opts_xy
        vcres = opts_xy
        vcres@vcGlyphStyle       = "LineArrow"
        vcres@vcPositionMode     = "ArrowTail"
        vcres@vcRefAnnoOn        = True
        vcres@vcMinDistanceF     = 0.03
        vcres@vcRefMagnitudeF    = 8.
        vcres@vcLineArrowThicknessF = 3.0
        vcres@vcMapDirection        = False
        vcres@vcFillArrowsOn     = True
        vcres@vcRefLengthF       = 0.02
        vcres@vcFillArrowHeadXF  = 0.2
        vcres@vcFillArrowHeadYF  = 0.2
        vcres@vcFillArrowHeadInteriorXF = 0.15
        ;opts_vec@cnInfoLabelZone = 1
        ;opts_vec@cnInfoLabelSide = "Top"
        ;opts_vec@cnInfoLabelPerimOn = True
        ;opts_vec@cnInfoLabelOrthogonalPosF = -0.00005
        ;opts_vec@ContourParameters  = (/ 5. /)
;Contour terrain cross section
        contour_ter = gsn_csm_xy(wks,X_plane,ter_plane,opts_ter)

      ; Get the contour info for the rh and temp
        vector = wrf_vector(a,wks,u_plane(0:zmax_pos,:),w_plane(0:zmax_pos,:)*20.,vcres)
        contour_theta = wrf_contour(a,wks,theta_plane(0:zmax_pos,:),opts_theta)
        vector2 = wrf_vector(a,wks,u_plane(0:zmax_pos,:),w_plane2(0:zmax_pos,:)*20.,vcres)
        contour_theta2 = wrf_contour(a,wks,theta_plane2(0:zmax_pos,:),opts_theta)
      ;---------------------------------------------------------------
  ; MAKE PLOTS         
        if (FirstTimeMap) then
          lat_plane = wrf_user_intrp2d(xlat,plane,angle,opts)
          lon_plane = wrf_user_intrp2d(xlon,plane,angle,opts)
          mpres = True
          pltres = True
          pltres@FramePlot = False
          optsM = res
          optsM@NoHeaderFooter = True
          optsM@cnFillOn = True
          optsM@lbTitleOn = False
          optsM@cnLevelSelectionMode = "ExplicitLevels"
          optsM@cnLevels = (/0,2,100,300,500,700,1000,1500,2000,2500,3000,3500,4000,4500,5000,5600/)
          contour  = wrf_contour(a,wks,ter,optsM)
          plot = wrf_map_overlays(a,wks,(/contour/),pltres,mpres)
          lnres = True
          lnres@gsLineThicknessF = 3.0
          lnres@gsLineColor = "Red"
          gsn_polyline(wks,plot,(/lon_plane(0),lon_plane(217)/),(/30.67,30.67/),lnres)         
;          gsn_polyline(wks,plot,(/104.41,104.41/),(/lat_plane(0),lat_plane(211)/),lnres)
         
          frame(wks)
          delete(lon_plane)
          delete(lat_plane)
          pltres@FramePlot = True
       end if
       ;plot = wrf_overlays(a,wks,(/contour_rh,contour_tc/),pltres)
       ;plot = wrf_overlays(a,wks,(/contour_rh,contour_tc,contour_ter/),pltres)
       plot = wrf_overlays(a,wks,(/contour_theta2,contour_ter,vector/),pltres)
  ; Delete options and fields, so we don't have carry over
        delete(opts_xy)
        delete(vcres)
        delete(opts_theta)
        delete(w_plane)
        delete(theta_plane)
        delete(w_plane2)
        delete(theta_plane2)
        delete(X_plane)
        delete(ter_plane)
;    end do  ; make next cross section
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    FirstTimeMap = False
  end do        ; END OF TIME LOOP
end

完全是按照之前的网址改的,具体还要自己调整,希望能帮助到你
密码修改失败请联系微信:mofangbao
发表于 2018-4-25 15:12:19 | 显示全部楼层
谢谢,不过我最后运行出来有错
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2018-4-25 17:00:41 | 显示全部楼层
sdhjdfjsb 发表于 2018-4-25 15:12
谢谢,不过我最后运行出来有错

肯定是我的代码和你的数据哪里不匹配了吧,你还是自己找找吧
密码修改失败请联系微信:mofangbao
发表于 2018-5-8 14:28:20 | 显示全部楼层
在u_plane = wrf_user_intrp3d(u,z,"v",plane,angle,opts)显示左右维度部队称怎么调?
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2018-5-8 14:48:04 | 显示全部楼层
刀客白刃 发表于 2018-5-8 14:28
在u_plane = wrf_user_intrp3d(u,z,"v",plane,angle,opts)显示左右维度部队称怎么调?

什么叫左右纬度不对称?
密码修改失败请联系微信:mofangbao
发表于 2018-5-8 14:51:24 | 显示全部楼层
irides 发表于 2018-5-8 14:48
什么叫左右纬度不对称?

左右变量维数不一致
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2018-5-8 15:02:10 | 显示全部楼层
刀客白刃 发表于 2018-5-8 14:51
左右变量维数不一致

去ncl网站看看这个插值函数要求的维数是多少,你的数据的纬度又是多少,应该是你的数据纬度多了或者少了
密码修改失败请联系微信:mofangbao
发表于 2018-5-24 22:05:36 | 显示全部楼层
irides 发表于 2018-3-23 13:08
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm ...

请问是因为四个值的那种剖面出错所以最后用两个值和角度了是吗??我搞了两天实在没办法用那个四个值的函数。。。就是好像就只是剖了一个点,所以想问问呢
密码修改失败请联系微信:mofangbao
发表于 2018-5-24 22:05:40 | 显示全部楼层
irides 发表于 2018-3-23 13:08
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm ...

请问是因为四个值的那种剖面出错所以最后用两个值和角度了是吗??我搞了两天实在没办法用那个四个值的函数。。。就是好像就只是剖了一个点,所以想问问呢
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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