Re: Visualizing NARR storm motion vectors

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri, 7 Nov 2008 09:31:05 -0700 (MST)

Jamie,

I think you need to turn off draw and frame for the vector plot
as you did for the contour plot:

     resvctr_at_gsnFrame = False
     resvctr_at_gsnDraw = False

Then, after the "overlay" call, you need to draw the base
plot, because "overlay" doesn't do any drawing:

     overlay(plot,vctrplot)
     draw(plot)
     gsn_polymarker(wks,plot,lon,lat,polyres)
     frame(wks)

I recommend using "gsn_add_polymarker" instead of "gsn_polymarker", so
that you can attach it to the plot:

     overlay(plot,vctrplot)
     dum1 = gsn_add_polymarker(wks,plot,lon,lat,polyres)
     draw(plot)
     frame(wks)

This way, if you redraw "plot" later, the polymarker will be
drawn with it.

--Mary

On Thu, 6 Nov 2008, Jamie Lahowetz wrote:

> Thanks for the replies. Its almost there. I seem to have trouble with this
> type of stuff.
> The speed show up well but there is no map background and there is a second
> page that only has the polymarker. strange yes. Any ideas?
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> ;############################
>
> begin
>
> fili =
> "/home/jlahowet/THOR/test2/narr/u-v_comp/narr-a_221_20080522_1800_000.grb"
> f = addfile (fili, "r")
>
> ;############################
> ; Print
> ;############################
>
> names = getfilevarnames(f)
> print(names)
> atts = getfilevaratts(f,names(0))
> dims = getfilevardims(f,names(0))
> print(atts)
> print(dims)
>
> ;############################
> ; Variables
> ;############################
>
> upt = f->USTM_221_HTGY
> vpt = f->VSTM_221_HTGY
> lat2d = f->gridlat_221
> lon2d = f->gridlon_221
>
> upt_at_lat2d = lat2d
> upt_at_lon2d = lon2d
> vpt_at_lat2d = lat2d
> vpt_at_lon2d = lon2d
>
> ;############################
> ; Calculations for Vectors
> ;############################
>
> speed = sqrt(upt(:,:)^2+vpt(:,:)^2)
>
> ;############################
>
> ;wks = gsn_open_wks("x11","vectors")
> wks = gsn_open_wks("pdf","vectors")
> gsn_define_colormap(wks,"gui_default")
>
> ;############################
> ; Resources
> ;############################
>
> res = True
> res_at_tiMainString = "Native Lambert Conformal"
>
> res_at_mpLimitMode = "Corners"
> res_at_mpLeftCornerLatF = 37.0
> res_at_mpLeftCornerLonF = -103.0
> res_at_mpRightCornerLatF = 40.0
> res_at_mpRightCornerLonF = -98.0
>
> res_at_mpProjection = "LAMBERTCONFORMAL"
> res_at_mpLambertParallel1F = lon2d_at_Latin1
> res_at_mpLambertParallel2F = lon2d_at_Latin2
> res_at_mpLambertMeridianF = lat2d_at_Lov
>
> ; print(lon2d_at_Latin1)
> ; print(lon2d_at_Latin2)
> ; print(lon2d_at_Lov)
>
> res_at_pmTickMarkDisplayMode = "Always"
> res_at_mpFillOn = False
> res_at_mpOutlineDrawOrder = "PostDraw"
> res_at_mpOutlineBoundarySets = "GeophysicalAndUSStates"
> res_at_mpGridAndLimbOn = True
>
> res_at_tfDoNDCOverlay = False
>
> res_at_cnFillOn = True
> res_at_cnLinesOn = False
> res_at_gsnSpreadColors = True
> res_at_gsnAddCyclic = False
> res_at_gsnFrame = False
> res_at_gsnDraw = False
>
> resvctr = True
>
> resvctr_at_vcRefMagnitudeF = 4.0
> resvctr_at_vcRefLengthF = 0.045
> resvctr_at_vcRefAnnoOrthogonalPosF = -1.0
> resvctr_at_vcRefAnnoArrowLineColor = "black"
> resvctr_at_vcRefAnnoArrowUseVecColor = False
>
> resvctr_at_vcGlyphStyle = "CurlyVector"
> resvctr_at_vcLineArrowColor = "red"
> resvctr_at_vcLineArrowThicknessF = 2.0
> resvctr_at_vcVectorDrawOrder = "PostDraw"
> resvctr_at_vcMinDistanceF = 0.05
>
> ;############################
>
> ; plot = gsn_csm_contour_map(wks,speed,res)
>
> ;############################
> ; Contour
> ;############################
>
> ;cnres = True
> ;cnres_at_tfDoNDCOverlay = True ; don't transform
> ;cnres_at_cnInfoLabelOn = False ; turn off info label
> ;cnres_at_cnLineLabelsOn = True ; turn off line labels
> ;cnres_at_tiMainString = "Contour on Contour: Native Grid" ;
> title
> ;cnres_at_gsnDraw = False ; don't draw yet
> ;cnres_at_gsnFrame = False ; don't advance frame
> yet
>
> ;############################
>
> ;plotcn = gsn_contour(wks,vpt,cnres)
> ;overlay(plot,plotcn)
>
> ;############################
> ; Plot marker
> ;############################
>
> lon = -101.210212707520
> lat = 39.2006416320801
> eps = 1e-3 ; or some small value
>
> polyres = True
> polyres_at_gsMarkerIndex = 16
> polyres_at_gsMarkerSizeF = 7.0
> ;polyres_at_gsMarkerColor = "black"
> ;draw(plot)
> ;gsn_polymarker(wks,plot,lon,lat,polyres)
>
> ;############################
> ; lat/lon Grid
> ;############################
>
> ;gridres = True
> ;gridres_at_gsMarkerIndex = 2
> ;gridres_at_gsMarkerSizeF = 10.0
> ;gridres_at_gsMarkerColor = "white"
> ;gsn_polymarker(wks,plot,ndtooned(lon2d),ndtooned(lat2d),gridres)
>
> ;############################
> ; Text Resources
> ;############################
>
> ;textres = True
> ;textres_at_txFontHeightF = 0.007 ; May need to change this
> ;textres_at_txFontColor = "black"
>
> ;############################
> ; Grid numbers
> ;############################
>
> ;nlat = dimsizes(lat2d(:,0)) ; Get dimension sizes
> ;nlon = dimsizes(lon2d(0,:)) ; of the lat/lon dimensions.
>
> ;do i=0,nlat-1
> ; do j=0,nlon-1
> ; text_string = (i+1)+","+(j+1) ; "1,1", "1,2", etc.
> ; gsn_text(wks,plot,text_string,lon2d(i,j),lat2d(i,j),textres)
> ; if( (lat2d(i,j)-eps).le.lat.and.lat.le.(lat2d(i,j)+eps).and.\
> ; (lon2d(i,j)-eps).le.lon.and.lon.le.(lon2d(i,j)+eps)) then
> ; vpt_text = ndtooned(vpt) + ""
> ; gsn_text(wks,plot,vpt_text,lon2d(i,j),lat2d(i,j),textres)
> ; end if
> ; end do
> ;end do
>
> plot = gsn_csm_contour_map(wks,speed,res)
> vctrplot = gsn_csm_vector(wks,upt,vpt,resvctr)
> overlay(plot,vctrplot)
> gsn_polymarker(wks,plot,lon,lat,polyres)
> frame(wks)
>
> end
>
>
>
> On Thu, Nov 6, 2008 at 11:04 AM, Adam Phillips <asphilli_at_cgd.ucar.edu>wrote:
>
>> Hi Jamie,
>>
>> You have 2 draw(plot) lines in your code:
>>
>> polyres_at_gsMarkerColor = "black"
>> draw(plot)
>> gsn_polymarker(wks,plot,lon,lat,polyres)
>>
>> and then
>>
>> overlay(plot,vctrplot)
>> draw(plot)
>> gsn_polymarker(wks,plot,lon,lat,polyres)
>>
>>
>> You should definitely delete the first draw(plot) line. Also, the order
>> that you should use for your plot calls and gsn_polymarker calls is:
>>
>> 1) plot = gsn_csm_contour_map(wks,speed,res)
>> 2) vctrplot = gsn_csm_vector(wks,upt,vpt,resvctr)
>> 3) overlay(plot,vctrplot)
>> 4) gsn_polymarker(wks,plot,lon,lat,polyres)
>> 5) frame(wks)
>>
>> Finally, note that you can use gsn_csm_vector_scalar_map to plot the
>> vectors over a scalar field (wind speed in your case).
>>
>> http://www.ncl.ucar.edu/Applications/vector.shtml#ex1
>>
>> Adam
>>
>>
>> Jamie Lahowetz wrote:
>>
>>> Hello,
>>> I have been trying to visualized NARR storm vectors but am getting
>>> confused. I want one output (I get two right now and dont know why) and I'm
>>> just not sure if I have coded it right.
>>>
>>>
>>>
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load
>>> "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>> ;############################
>>>
>>> begin
>>>
>>> fili =
>>> "/home/jlahowet/THOR/test2/narr/u-v_comp/narr-a_221_20080522_1800_000.grb"
>>> f = addfile (fili, "r")
>>>
>>> ;############################
>>> ; Print
>>> ;############################
>>>
>>> names = getfilevarnames(f)
>>> print(names)
>>> atts = getfilevaratts(f,names(0))
>>> dims = getfilevardims(f,names(0))
>>> print(atts)
>>> print(dims)
>>>
>>> ;############################
>>> ; Variables
>>> ;############################
>>>
>>> upt = f->USTM_221_HTGY
>>> vpt = f->VSTM_221_HTGY
>>> lat2d = f->gridlat_221
>>> lon2d = f->gridlon_221
>>> upt_at_lat2d = lat2d
>>> upt_at_lon2d = lon2d
>>> vpt_at_lat2d = lat2d
>>> vpt_at_lon2d = lon2d
>>>
>>> ;############################
>>> ; Calculations for Vectors
>>> ;############################
>>>
>>> speed = sqrt(upt(:,:)^2+vpt(:,:)^2)
>>>
>>> ;############################
>>>
>>> ;wks = gsn_open_wks("x11","vectors")
>>> wks = gsn_open_wks("pdf","vectors")
>>> gsn_define_colormap(wks,"gui_default")
>>>
>>> ;############################
>>> ; Resources
>>> ;############################
>>>
>>> res = True
>>> res_at_tiMainString = "Native Lambert Conformal"
>>>
>>> res_at_mpLimitMode = "Corners"
>>> res_at_mpLeftCornerLatF = 37.0
>>> res_at_mpLeftCornerLonF = -103.0
>>> res_at_mpRightCornerLatF = 40.0
>>> res_at_mpRightCornerLonF = -98.0
>>>
>>> res_at_mpProjection = "LAMBERTCONFORMAL"
>>> res_at_mpLambertParallel1F = lon2d_at_Latin1
>>> res_at_mpLambertParallel2F = lon2d_at_Latin2
>>> res_at_mpLambertMeridianF = lat2d_at_Lov ; print(lon2d_at_Latin1)
>>> ; print(lon2d_at_Latin2)
>>> ; print(lon2d_at_Lov)
>>> res_at_pmTickMarkDisplayMode = "Always"
>>> res_at_mpFillOn = False res_at_mpOutlineDrawOrder
>>> = "PostDraw" res_at_mpOutlineBoundarySets = "GeophysicalAndUSStates"
>>> res_at_mpGridAndLimbOn = True
>>> res_at_tfDoNDCOverlay = False
>>>
>>> res_at_cnFillOn = True res_at_cnLinesOn
>>> = False res_at_gsnSpreadColors = True
>>> res_at_gsnAddCyclic = False res_at_gsnFrame
>>> = False
>>> res_at_gsnDraw = False
>>> resvctr = True
>>> resvctr_at_vcRefMagnitudeF = 4.0
>>> resvctr_at_vcRefLengthF = 0.045
>>> resvctr_at_vcRefAnnoOrthogonalPosF = -1.0
>>> resvctr_at_vcRefAnnoArrowLineColor = "black"
>>> resvctr_at_vcRefAnnoArrowUseVecColor = False
>>>
>>> resvctr_at_vcGlyphStyle = "CurlyVector"
>>> resvctr_at_vcLineArrowColor = "red"
>>> resvctr_at_vcLineArrowThicknessF = 2.0
>>> resvctr_at_vcVectorDrawOrder = "PostDraw"
>>> resvctr_at_vcMinDistanceF = 0.05
>>>
>>> ;############################
>>> plot = gsn_csm_contour_map(wks,speed,res)
>>> ;############################
>>> ; Contour
>>> ;############################
>>>
>>> ;cnres = True
>>> ;cnres_at_tfDoNDCOverlay = True ; don't transform
>>> ;cnres_at_cnInfoLabelOn = False ; turn off info
>>> label
>>> ;cnres_at_cnLineLabelsOn = True ; turn off line
>>> labels
>>> ;cnres_at_tiMainString = "Contour on Contour: Native Grid" ;
>>> title
>>> ;cnres_at_gsnDraw = False ; don't draw yet
>>> ;cnres_at_gsnFrame = False ; don't advance
>>> frame yet
>>> ;############################
>>> ;plotcn = gsn_contour(wks,vpt,cnres)
>>> ;overlay(plot,plotcn)
>>>
>>> ;############################
>>> ; Plot marker
>>> ;############################
>>>
>>> lon = -101.24
>>> lat = 38.87
>>> eps = 1e-3 ; or some small value
>>> polyres = True
>>> polyres_at_gsMarkerIndex = 16
>>> polyres_at_gsMarkerSizeF = 7.0
>>> polyres_at_gsMarkerColor = "black"
>>> draw(plot)
>>> gsn_polymarker(wks,plot,lon,lat,polyres)
>>> ;############################
>>> ; lat/lon Grid
>>> ;############################
>>>
>>> ;gridres = True
>>> ;gridres_at_gsMarkerIndex = 2
>>> ;gridres_at_gsMarkerSizeF = 10.0
>>> ;gridres_at_gsMarkerColor = "white"
>>> ;gsn_polymarker(wks,plot,ndtooned(lon2d),ndtooned(lat2d),gridres)
>>> ;############################
>>> ; Text Resources
>>> ;############################
>>> ;textres = True
>>> ;textres_at_txFontHeightF = 0.007 ; May need to change this
>>> ;textres_at_txFontColor = "black"
>>>
>>> ;############################
>>> ; Grid numbers
>>> ;############################
>>>
>>> ;nlat = dimsizes(lat2d(:,0)) ; Get dimension sizes
>>> ;nlon = dimsizes(lon2d(0,:)) ; of the lat/lon dimensions.
>>>
>>> ;do i=0,nlat-1
>>> ; do j=0,nlon-1
>>> ; text_string = (i+1)+","+(j+1) ; "1,1", "1,2", etc.
>>> ; gsn_text(wks,plot,text_string,lon2d(i,j),lat2d(i,j),textres)
>>> ; if( (lat2d(i,j)-eps).le.lat.and.lat.le.(lat2d(i,j)+eps).and.\
>>> ; (lon2d(i,j)-eps).le.lon.and.lon.le.(lon2d(i,j)+eps)) then
>>> ; vpt_text = ndtooned(vpt) + ""
>>> ; gsn_text(wks,plot,vpt_text,lon2d(i,j),lat2d(i,j),textres)
>>> ; end if
>>> ; end do
>>> ;end do
>>>
>>> vctrplot = gsn_csm_vector(wks,upt,vpt,resvctr)
>>> overlay(plot,vctrplot)
>>> draw(plot)
>>> gsn_polymarker(wks,plot,lon,lat,polyres)
>>>
>>> frame(wks)
>>>
>>> end
>>>
>>> --
>>> Jamie Ryan Lahowetz
>>> University of Nebraska - Lincoln
>>> Graduate Student - Geosciences
>>> 402.304.0766
>>> jlahowe2_at_bigred.unl.edu <mailto:jlahowe2_at_bigred.unl.edu>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>> --
>> --------------------------------------------------------------
>> Adam Phillips asphilli_at_ucar.edu
>> National Center for Atmospheric Research tel: (303) 497-1726
>> ESSL/CGD/CAS fax: (303) 497-1333
>> P.O. Box 3000
>> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>>
>
>
>
> --
> Jamie Ryan Lahowetz
> University of Nebraska - Lincoln
> Graduate Student - Geosciences
> 402.304.0766
> jlahowe2_at_bigred.unl.edu
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 07 2008 - 09:31:05 MST

This archive was generated by hypermail 2.2.0 : Fri Nov 07 2008 - 13:41:15 MST