爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
楼主: yunqicainiao

[作图] ncl绘制台风路径

  [复制链接]
发表于 2017-3-11 21:37:25 | 显示全部楼层
kangyan195730 发表于 2017-3-11 16:16
我用的这个脚本,wrf是逐小时输出的,提示错误该修改哪里,弄了好久
Dimension sizes on right hand sid ...

我是每三个小时输出一个wrfout文件,要不你把整个脚本都贴出来我再看看
密码修改失败请联系微信:mofangbao
发表于 2017-3-11 21:41:00 | 显示全部楼层
fanxiqing 发表于 2017-3-11 21:37
我是每三个小时输出一个wrfout文件,要不你把整个脚本都贴出来我再看看

; Plot storm stracks from wrfout files.

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/wrf/WRF_contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin   
  date=(/0912,0913,0914,0915,0916,0917,0918,0919,0920,0921,0922,0923,1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018/)
  ndate = dimsizes(date)
  sdate = sprinti("%4.0i",date)

; Experiment name (for legend)
  EXP = (/"EXP_I"/)                ; (/"EXP_I","EXP_II","EXP_III"/)
  nexp = dimsizes(EXP)

  a=addfile("wrfout_d01_2006-08-09_12:00:00.nc","r")
  lat2d = a->XLAT(0,:,:)
  lon2d = a->XLONG(0,:,:)
  dimll = dimsizes(lat2d)
  nlat  = dimll(0)
  mlon  = dimll(1)

  slp = wrf_user_getvar(a,"slp",0)
  dims = dimsizes(slp)

; Array for track
  time = new(ndate,string)
  imin = new(ndate,integer)
  jmin = new(ndate,integer)
  smin = new(ndate,integer)

  fs = systemfunc("ls wrfout*00")
  nfs= dimsizes(fs)
  if(nfs .ne. ndate) then
     print("Check input data:"+nfs+" .ne. "+ndate)
  end if

  do ifs=0,nfs-1
    f = addfile(fs(ifs)+".nc","r")
    time(ifs)=wrf_user_list_times(f)
; print(time(ifs))
    slp2d = wrf_user_getvar(f,"slp",0)

; We need to convert 2-D array to 1-D array to find the minima.
    slp1d     = ndtooned(slp2d)
    smin(ifs) = minind(slp1d)

; Convert the index for 1-D array back to the indeces for 2-D array.
    minij     = ind_resolve(ind(slp1d.eq.min(slp2d)),dims)
    imin(ifs) = minij(0,0)
    jmin(ifs) = minij(0,1)

;   print(time(ifs)+" : "+min(slp2d)+" ("+imin(ifs)+","+jmin(ifs)+")")
  end do

; Graphics section

  wks=gsn_open_wks("png","track")              ; Open PS file.
  gsn_define_colormap(wks,"BlGrYeOrReVi200")  ; Change color map.

  res                     = True
  res@gsnDraw             = False             ; Turn off draw.
  res@gsnFrame            = False             ; Turn off frame advance.
  res@gsnMaximize         = True              ; Maximize plot in frame.

  res@tiMainString = "Typhoon Saomai"       ; Main title

  wrf_mapres_c(a,res,0)                          ; Set up map resources
                                              ;    (plot options)
  plot = gsn_csm_map(wks,res)                 ; Create a map.

; Set up resources for polymarkers.
  gsres                = True
  gsres@gsMarkerIndex  = 16                  ; filled dot
  ;gsres@gsMarkerSizeF = 0.005               ; default - 0.007
  colors   = (/5,160,40/)

; Set up resources for polylines.
  res_lines                      = True
  res_lines@gsLineThicknessF     = 3.           ; 3x as thick

  dot  = new(ndate,graphic)    ; Make sure each gsn_add_polyxxx call
  line = new(ndate-1,graphic)    ; is assigned to a unique variable.

; Loop through each date and add polylines to the plot.
  do i = 0,ndate-2   
     res_lines@gsLineColor  = colors(0)
     xx=(/lon2d(imin(i),jmin(i)),lon2d(imin(i+1),jmin(i+1))/)
     yy=(/lat2d(imin(i),jmin(i)),lat2d(imin(i+1),jmin(i+1))/)
     line(i) = gsn_add_polyline(wks,plot,xx,yy,res_lines)
  end do

  lon1d = ndtooned(lon2d)
  lat1d = ndtooned(lat2d)

; Loop through each date and add polymarkers to the plot.
  do i = 0,ndate-1
     print("dot:"+lon1d(smin(i))+","+lat1d(smin(i)))
     gsres@gsMarkerColor  = colors(0)
     dot(i)=gsn_add_polymarker(wks,plot,lon1d(smin(i)),lat1d(smin(i)),gsres)
  end do

; Date (Legend)
  txres               = True
  txres@txFontHeightF = 0.009
  txres@txFontColor   = colors(0)

  txid1 = new(ndate,graphic)
; Loop through each date and draw a text string on the plot.
  do i = 0, ndate-1
     txres@txJust = "CenterRight"
     ix = smin(i) - 15
    ; ix = smin(i)
     print("Eye:"+ix)
     if(i.eq.1) then
        txres@txJust = "CenterLeft"
        ix = ix + 31
     end if
     txid1(i) = gsn_add_text(wks,plot,sdate(i),lon1d(ix),lat1d(ix),txres)
  end do

; Add marker and text for legend. (Or you can just use "pmLegend" instead.)
  txres@txJust = "CenterLeft"

  txid2 = new(nexp,graphic)
  pmid2 = new(nexp,graphic)
  do i = 0,nexp-1
    gsres@gsMarkerColor  = colors(i)
     txres@txFontColor    = colors(i)
     ii = ((/129,119,109/))  ; ilat
     jj = ((/110,110,110/))  ; jlon
     ji = ii*mlon+jj         ; col x row
     pmid2(i) = gsn_add_polymarker(wks,plot,lon1d(ji(i)),lat1d(ji(i)),gsres)
     txid2(i) = gsn_add_text(wks,plot,EXP(i),lon1d(ji(i)+2),lat1d(ji(i)),txres)
  end do

  draw(plot)
  frame(wks)
end
密码修改失败请联系微信:mofangbao
发表于 2017-3-11 21:42:58 | 显示全部楼层
kangyan195730 发表于 2017-3-11 21:41
; Plot storm stracks from wrfout files.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl ...

方便把你的脚本分享下,修改下看我的逐小时能不能出图
密码修改失败请联系微信:mofangbao
发表于 2017-3-11 21:43:02 | 显示全部楼层
kangyan195730 发表于 2017-3-11 21:41
; Plot storm stracks from wrfout files.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl ...

方便把你的脚本分享下,修改下看我的逐小时能不能出图
密码修改失败请联系微信:mofangbao
发表于 2017-3-13 06:17:03 | 显示全部楼层
把 fs = systemfunc("ls wrfout*00")引号里面改成“ls /home/.../wrfout_d01*”试试
密码修改失败请联系微信:mofangbao
发表于 2017-3-13 06:17:21 | 显示全部楼层
kangyan195730 发表于 2017-3-11 21:43
方便把你的脚本分享下,修改下看我的逐小时能不能出图

把 fs = systemfunc("ls wrfout*00")引号里面改成“ls /home/.../wrfout_d01*”试试
密码修改失败请联系微信:mofangbao
发表于 2017-4-5 09:05:42 | 显示全部楼层
都试试看,谢谢
密码修改失败请联系微信:mofangbao
发表于 2017-5-10 21:11:39 | 显示全部楼层
谢谢分享,正用的到!
密码修改失败请联系微信:mofangbao
发表于 2017-5-16 18:43:04 | 显示全部楼层
太棒啦,谢谢
密码修改失败请联系微信:mofangbao
发表于 2017-5-20 11:47:06 | 显示全部楼层
谢谢分享,一直在找这个。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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