Re: [lamptey@rumen.essc.psu.edu: Re: [ncl-talk] wind vector]

From: Matt Stumbaugh (Matt.Stumbaugh AT noaa.gov)
Date: Thu Mar 10 2005 - 17:58:45 MST


Ben,

I think you're best to start simple with gsn_vector. Just get one plot
before trying to make the panel.

http://ngwww.ucar.edu/ngdoc/ng/ug/ncl/gsun/examples/gsun03n.html

Attached is my version of a wind vector time series plot. This is more
complex than what I think you want but I'm still not understanding some
details of your problem. Here's what I did: calculated the wind speed
from (u,v), sorted the u/v arrays into velocity time series arrays
(speed bins X time) that correspond to the a unit velocity vector,
plotted the arrays, and then labeled the graph by speed (Y-axis) and
time (X-axis). The code is below.

I've thought about this a bit and without doing the problem, and not
knowing the dimensionality of your data, this is all I can really say.

Matt

;---------------------------------------------------------------\
; wxvx: scale_vx() \

undef("scale_vx")

procedure scale_vx(fn_wxnc:string, location_wxnc:string, \
figtype:string, time_start:integer, time_end:integer, \
maxY:float, speed_bin_size:float) \

local var_wxnc, fn_wxnc, f, res, n, m, plot_wx, wind_file, \
time_start, time_end, time_span, T, Time, time, \
spd_U, spd__V, speedU, speedV, \
velocity, max_ind, max_velocity, velocity_zero, sU, sV, \
bins_no, bins_array, bin1_present, \
sub_index, index_count, index_12, index1, index_array, max_ind, \
label_span, xValues, xLabels, maxY \

begin

;---------------------------------------------------------------\
; Get data

print("wxvx.ncl working...")

var_wxnc = location_wxnc+fn_wxnc+".nc"

f = addfile(var_wxnc,"r")

T = f->T
spd_U = f->spd_U
spd__V = f->spd__V
time = T
wind_file = f@source_file
speed = f->speed

sub_index = ind(T.le.time_end.and.T.ge.time_start)
Time = T(sub_index)
speedU = spd_U(sub_index)
speedV = spd__V(sub_index)
velocity = speed(sub_index)

delete(T)
delete(spd_U)
delete(spd__V)
delete(speed)

max_ind = ind(velocity.eq.max(velocity))
;print(max_ind+", "+velocity(max_ind)+", "+speedU(max_ind)+",
"+speedV(max_ind))

; Sort velocity data into bins.
wks_maxY = maxY+speed_bin_size
bins_no = floattointeger(wks_maxY/speed_bin_size)
bins_array = fspan(0,maxY,bins_no)

sU = new((/bins_no,dimsizes(speedU)/),"float")
sU = 0
sV = sU

velocity_zero =ind(velocity.eq.0)
index_count = 0

; Sort u,v velocity data by bins of wind speed (u+v)
bin1_present = 0
do m=1,(bins_no-1)
    if any(velocity.le.bins_array(m).and.velocity.gt.bins_array(m-1))
        index =
ind(velocity.le.bins_array(m).and.velocity.gt.bins_array(m-1))
        sU(m,index) = speedU(index)
        sV(m,index) = speedV(index)
        ;print(dimsizes(index)+" velocities recorded in
"+bins_array(m-1)+" - "+bins_array(m))
        index_count = dimsizes(index) + index_count

        ; Keeping track of all data that falls in a speed bin.
        if m.gt.1
            if bin1_present.eq.1
                index_12 = catIndex(index1,index)
                ; see mrsFunction.ncl function "index_12 =
catIndex(index1,index2)"
                delete(index1)
                index1 = index_12
                delete(index_12)
            else
                index1 = index
                bin1_present = 1
            end if
        else ; that is, if m is equal to 1...
            index1 = index
            bin1_present = 1
        end if
        delete(index)
    else
        ;print("No velocities recorded between "+bins_array(m-1)+" -
"+bins_array(m))
    end if
end do

index_array = index1

; Sort indices
qsort(index_array)

;---------------------------------------------------------------\
; Plotting

plot_wx = fn_wxnc+"_arrow"
wks = gsn_open_wks(figtype,plot_wx)

res = True

; Vector Plot
res@vpWidthF = 0.6
res@vpHeightF=0.3
res@vcRefAnnoOn = False ; Turns off reference vector box
res@gsnMaximize = True
res@gsnPaperOrientation = "landscape"

; Title/Axis Labels
res@tiYAxisString = "Velocity ("+velocity@units+")"
res@tiXAxisString = "Time (Julian Days)"
res@tiMainString = wind_file
res@tiXAxisFontHeightF = 0.015
res@tiYAxisFontHeightF = 0.015

; Vector resources
res@vcRefMagnitudeF = 20
res@vcRefLengthF = .02
res@vcMinFracLengthF = 1.0
res@vcGlyphStyle = "LineArrow"
res@vcLineArrowThicknessF = 2
res@vcLineArrowHeadMaxSizeF = 0.006
res@vcLineArrowHeadMinSizeF = 0.006
res@vcPositionMode = "ArrowHead"

; Tick Marks/Labels
; Y-Ticks
res@tmYLBorderOn = True
res@tmYRBorderOn = True
res@tmYLLabelsOn = True
res@tmYLMode = "Explicit"

res@tmYLValues = fspan(0,dimsizes(bins_array),dimsizes(bins_array)+1)
res@tmYLLabels = fspan(0,wks_maxY,dimsizes(bins_array)+1)
res@tmYLLabelFontHeightF = 0.01
res@tmYLMinorOn = False
res@tmYLMajorLengthF = 0.01
res@tmYRMajorLengthF = 0.01

;X-Ticks
res@tmXUseBottom = True
res@tmXTBorderOn = True
res@tmXTMinorOn = True
res@tmXTMajorLengthF = 0.01
res@tmXBMinorOn = True
res@tmXBMajorLengthF = 0.01
res@tmXBMode = "Explicit"

time_span = time_end-time_start
label_span= time_span*24
xLabels = ispan(time_start,time_end,1)
xValues = ispan(0,label_span,24)
res@tmXBValues = xValues
res@tmXBLabels = xLabels
res@tmXBLabelAngleF = 30
res@tmXBLabelFontHeightF = 0.01

vc = gsn_vector(wks,sU,sV,res)

;system("mv "+"plot_wx".pdf"+location_wxnc)

;---------------------------------------------------------------\
; Output statistics STDOUT.

max_velocity = max(velocity)
maxY = maxY
print("Maximum velocity= "+max_velocity+". Maximum Y-value = "+maxY)
print("...")
print("...wxvx.ncl work complete")
print("...")

end

Benjamin Lamptey wrote:

>----- Forwarded message from Benjamin Lamptey <lamptey@rumen.essc.psu.edu> -----
>
>Date: Thu, 10 Mar 2005 18:42:06 -0500
>From: Benjamin Lamptey <lamptey@rumen.essc.psu.edu>
>To: Matt Stumbaugh <Matt.Stumbaugh@noaa.gov>
>Cc: Benjamin Lamptey <lamptey@essc.psu.edu>
>Subject: Re: wind vector
>In-Reply-To: <4230CB00.5030304@noaa.gov>
>User-Agent: Mutt/1.4.2.1i
>
>On Thu, Mar 10, 2005 at 02:32:32PM -0800, Matt Stumbaugh wrote:
>
>
>>Benjamin,
>>
>>What kind of wind vector do you want to plot? Overlaid on a map, in a
>>time series, or something else? I have some code that could help with
>>the time series plot. Regardless, I think it would help others help you
>>if you include your code and elaborate on the type of plot you want.
>>
>>Matt
>>Matt,
>>
>>
>For now, I want to plot seasonal winds (DJF and JJA). Later on I shall overlay them
>on maps.
>
>code snippet
>;
>;
> mres@pmTickMarkDisplayMode = "Always"
> mres@tfDoNDCOverlay = True
> mres@gsnAddCyclic = False ; regional data
> mres@gsnFrame = False ; don't advance frame yet
> mres@gsnDraw = False ; don't draw yet
> mres@lbLabelBarOn = False ; no individual label bar
>
> mres@vcRefAnnoOrthogonalPosF = -1.0
> mres@vcRefMagnitudeF = 10.0
> mres@vcRefLengthF = 0.045
> mres@vcGlyphStyle = "CurlyVector"
> mres@vcMinDistanceF = 0.017
>
> plot = new(4,graphic) ; create a plot array
> mres@gsnLeftString = "DJF 1000mb U wind"
> plot(0) = gsn_csm_vector_map_ce(wks,ua1_noag_DJF,va1_noag_DJF,mres)
>
> mres@gsnLeftString = "JJA 1000mb U wind"
> plot(1) = gsn_csm_vector_map_ce(wks,ua1_noag_JJA,va1_noag_JJA,mres)
>
> :
> :
> :
>
>Thanks
>Ben
>
>
>
>
>
>
>
>
>
>
>
>>Benjamin Lamptey wrote:
>>
>>
>>
>>>Hello,
>>>I wish to plot the wind vector. My data is from a binary file. I wish to
>>>make a panel plot.
>>>
>>>I am following the example at
>>>"http://www.cgd.ucar.edu/csm/support/CSM_Graphics/Scripts/vector_3.ncl".
>>>
>>>I keep getting the following error
>>>-----------
>>>warning:gsnTickMarksOn is not a valid resource in map at this time
>>>warning:Attempt to reference attribute (tickmarks) which is undefined
>>>fatal:Execute: Error occurred at or near line 5350 in file
>>>/opt/local/ncarg_4.3.0/lib/ncarg/nclscripts/csm/gsn_csm.ncl
>>>
>>>fatal:Execute: Error occurred at or near line 291
>>>---------------
>>>
>>>The only resource I have in my script that has to do with tickmarks is
>>>
>>>mres@pmTickMarkDisplayMode = "Always" (I think)
>>>
>>>I should be grateful if someone could point out what I might be doing
>>>wrong. That is, which resource is generating the erro message.
>>>
>>>Thanks
>>>
>>>
>>>
>>>
>>>Benjamin L. Lamptey Phone: (814) 865-9911 (office)
>>>Pennstate (EMS Environment Institute) (814) 237-8193 (home)
>>>2217 Earth-Engineering Sciences Bldg Fax : (814) 865-3191
>>>University Park, PA 16802 WWW:http://www.essc.psu.edu/~lamptey
>>>
>>>
>>>
>>>_______________________________________________
>>>ncl-talk mailing list
>>>ncl-talk@ucar.edu
>>>http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>>
>>>
>
>
>




_______________________________________________
ncl-talk mailing list
ncl-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Fri Mar 11 2005 - 08:46:43 MST