[ncl-talk] Overlaying multiple polylines on top of contour map

Kelsey Mulder kelsey.mulder at manchester.ac.uk
Thu Jul 2 07:43:51 MDT 2015


Hello,

I’m trying to overlay multiple trajectory paths on top of relative vorticity contours using gsn_add_polyline. I have tried seemingly everything but can only either manage to get all the trajectories on a separate page from my wrf contour map (what happens with the script below) or to only get one trajectory to plot on my map. The NCL script is below  and my file of trajectories is attached. Any help would be greatly appreciated!


Kelsey Mulder


PhD Student, University of Manchester
School of Earth, Atmospheric and Environmental Sciences
Simon Building
Oxford Road
Manchester, M13 9PL
United Kingdom

Tel: +44 161 306 3911


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
;
; The WRF ARW input file.
; This needs to have a ".nc" appended, so just do it.
  a = addfile("./wrfout_d04_2011-11-29_12:00:00.nc","r")
; We generate plots, but what kind do we prefer?
;  type = "x11"
 type = "pdf"
; type = "ps"
; type = "ncgm"
  wks = gsn_open_wks(type,"abs_vort_traj")
  height = 500 ;height in meters
 gsn_define_colormap(wks,"BlueWhiteOrangeRed")

; Set some basic resources
  res = True
  res at MainTitle                   = "REAL-TIME WRF"
  res at gsnDraw    = False ;Don't draw yet!
  pltres = True
  mpres = True
  res at gsnFrame   = False ;don't advance frame yet!
mpres at mpGeophysicalLineColor = "Black"
mpres at mpGridLineColor = "Black"
mpres at mpLimbLineColor = "Black"
mpres at mpNationalLineColor = "Black"
mpres at mpPerimLineColor = "Black"
mpres at mpUSStateLineColor = "Black"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; What times and how many time steps are in the data set?
  times  = wrf_user_getvar(a,"times",-1) ; get times in the file
  ntimes = dimsizes(times)         ; number of times in the file
;print(times)
;exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;  do it = 0,ntimes-1,30             ; TIME LOOP
  do it = 539,539,5 ;Nothing and broken s
;  do it = 569,569,5 ;Bulging
;  do it = 149,149,5 ;core/gap
    print("Working on time: " + times(it) )
    res at TimeLabel = times(it)   ; Set Valid time to use on plots

  ; Get the data
    avo   = wrf_user_getvar(a,"avo",it)
    z     = wrf_user_getvar(a,"z",it)
    forig = wrf_user_getvar(a,"F",it)
    f     = forig*100000
    wstag = wrf_user_getvar(a,"W",it)      ; w in m/s
    w     = wrf_user_unstagger(wstag,"Z")

  ; Interpolate to pressure
    av_plane = wrf_user_intrp3d(avo,z,"h",height,0,False)
    rvo      = av_plane - f
    w_plane  = wrf_user_intrp3d(w,z,"h",height,0,False)
    copy_VarAtts(av_plane, rvo) ;copy variable attributes
;    rvo at description = "Relative Vorticity"

    ; Plotting options
      opts = res
      opts at cnFillOn = True
;      opts at gsnSpreadColorEnd = -3  ; End third from the last color in color map
      opts at ContourParameters = (/ -5000., 5000., 1000./)
      contour_a = wrf_contour(a,wks,rvo,opts)
      delete(opts)

      opts = res
      opts at cnFillOn = False
;      opts at gsnSpreadColorEnd = -3  ; End third from the last color in color map
      opts at ContourParameters = (/ 10., 20., 5./)
      opts at cnLineColor = "black"
;      opts at gsnContourNegLineDashPattern = 1     ; sets negative contours to dash patter
n 1
      contour_pos = wrf_contour(a,wks,w_plane,opts)
      delete(opts)

      opts = res
      opts at cnFillOn = False
;      opts at gsnSpreadColorEnd = -3  ; End third from the last color in color map
      opts at ContourParameters = (/ -20., -5., 5./)
      opts at cnLineColor = "grey50"
;      opts at gsnContourNegLineDashPattern = 1     ; sets negative contours to dash patter
n 1
      contour_neg = wrf_contour(a,wks,w_plane,opts)
      delete(opts)

    ; MAKE PLOTS
      plot = wrf_map_overlays(a,wks,(/contour_a,contour_pos,contour_neg/),pltres,mpres)
;      plot = wrf_map_overlays(a,wks,(/contour/),pltres,mpres)

;======================================
;Plot trajectory
;=======================================
   pltres at PanelPlot = True
;also read in trajectory location file so we can plot location
 hdata = readAsciiTable("./nothing_trajectories.txt",5,"float",0)
 maxtraj = 45
 dum = new(maxtraj,graphic)
 do ntraj=1,maxtraj,1
;ntraj = 1
heightdatastart = 61*(ntraj-1)
heightdataend = heightdatastart+60
 trajnumber = hdata(heightdatastart:heightdataend,0)
 timetraj   = hdata(heightdatastart:heightdataend,1)
 xlocation  = hdata(heightdatastart:heightdataend,2) ;in i units
 ylocation  = hdata(heightdatastart:heightdataend,3) ;in j units
 zlocation  = hdata(heightdatastart:heightdataend,4) ;in km


   loc = wrf_user_ij_to_ll(a,xlocation,ylocation,True)


 xpt = loc(0,:)
 ypt = loc(1,:)


      gsres = True
      first = True
      gsres at gsMarkerIndex  = 16           ; marker style (circle)
      gsres at gsMarkerSizeF  = 8.0          ; marker size
      gsres at gsMarkerColor  = "black"      ; maker color

; create a unique marker to indicate the start of the trajectory

      first at gsMarkerSizeF  = 15.0         ; marker size
      first at gsMarkerColor  = "black"     ; marker color

      res_lines                      = True
;      res_lines at gsLineThicknessF     = 3.           ; 3x as thick

    dum(ntraj-1) = gsn_add_polyline(wks,plot,xpt,ypt,res_lines)

end do ;end trajectory loop
      draw(plot)
      frame(wks)
  end do        ; END OF TIME LOOP

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150702/417abe54/attachment.html 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nothing_trajectories.txt
Url: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150702/417abe54/attachment.txt 


More information about the ncl-talk mailing list