vector plot U,V not scaled equally?

From: Matt Stumbaugh (Matt.Stumbaugh AT noaa.gov)
Date: Fri Jul 08 2005 - 18:53:25 MDT

  • Next message: brownmc@uci.edu: "plotting data inside a state boundary"

    I'm having a difficult time figuring out the vectors (vc) and vector
    field (vf) resources. I want to produce a stick plot of winds. I've
    attached a simplified script (and below too) and plot. In reading the
    documentation and examples it isn't clear to me how to make the vectors
    be scaled to a reference frame that is different than that of the plot.
    That is to say I want U,V components to be scaled to a velocity
    reference frame that oriented to the X,Y directions but not of equal
    scaling. When I have a time series of these the only way I preserve the
    vector direction is by keeping the axes of equal length. This is then a
    formatting problem and not clean code either. And if mess with the view
    port, "...forget about it." There must be something I'm missing. Your
    help is greatly appreciated.

    Matt

    ;---------------------------------------------------------------;
    ; plotStx ;
    ;---------------------------------------------------------------;
    ; Author/Creation Date/Office:
    ; Description:
    ; Example:
    ; To develop:
    ; Update
    ;
    ;---------------------------------------------------------------\
       
    begin
        load "/sw/lib/ncarg/nclscripts/csm/gsn_code.ncl"
        load "/sw/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
        
        Uoc = (/10,10, 0, 0,-10,-10,-10,-10,10,10,10,10, 0, 0,-10,-10/)
        Voc = (/10,10,10,10, 0, 0,-10,-10,10,10,10,10, 0, 0,-10,-10/)
        Uoc_avg = Uoc
        Voc_avg = Voc
        
        ;---------------------------------------------------------------\
        ; Plotting
        
        plot_wx = "Wind_stick_plot"
        wks = gsn_open_wks("x11",plot_wx)
          
        res = True
        
        ; Vector Plot
        res@vpWidthF = 0.6
        res@vpHeightF=0.6
        ;res@gsnMaximize = True
        ;res@gsnPaperOrientation = "landscape"
        
        ; Title/Axis Labels
        res@tiYAxisString = ""
        res@tiXAxisString = "Local Time (Month, Day)"
        res@tiMainString = plot_wx
        res@tiXAxisFontHeightF = 0.015
        res@tiYAxisFontHeightF = 0.015
        
        ; Vector resources
        res@vcRefMagnitudeF = 10
        res@vcRefLengthF = .04
        res@vcMinFracLengthF = 0
        res@vcGlyphStyle = "LineArrow"
        res@vcLineArrowThicknessF = 2.5
        res@vcLineArrowHeadMaxSizeF = 0
        res@vcLineArrowHeadMinSizeF = 0
        res@vcPositionMode = "ArrowTail"
    ; res@vcVectorDrawOrder = "PostDraw"
        res@vcRefAnnoOn = True; Turns off reference vector box
        
        ; Tick Marks/Labels
        ; Y-Ticks
        res@tmYLLabelsOn = False
        res@tmYLOn = False
        res@tmYROn = False

        res@tmXTBorderOn = False
        res@tmXBBorderOn = False
        res@tmYLBorderOn = False
        res@tmYRBorderOn = False
        res@tmXBMinorOn = True
        res@tmXBMajorLengthF = 0.01
        res@tmXBLabelFontHeightF = 0.01
        
        col = dimsizes(Uoc)
        U = new((/col,col/),float)
        V = U
        U(3,:) = Uoc
        V(3,:) = Voc
        U(5,:) = Uoc_avg
        V(5,:) = Voc_avg
        vc = gsn_vector(wks,U,V,res)

    end


    ;---------------------------------------------------------------;
    ; plotCTSM ;
    ;---------------------------------------------------------------;
    undef("plotCTSM")
    procedure plotCTSM(figRAL:string,figtype:string,f_longwind:string,\
        fhours:integer, alongshore_heading:float, lb_angle:float, maxY:float,\
        year:integer, month:integer, day:integer, hour:integer, n:integer, \
        speedMet:float, dirMet:float, baro:float, Umet:float, Vmet:float, \
        Uoc:float, Voc:float, velOnAx:float, fvelOn:float, velAcAx:float, fvelAc:float, \
        across_heading:float)
        
    begin
        load "/sw/lib/ncarg/nclscripts/csm/gsn_code.ncl"
        load "/sw/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
        
        ;-- MetPlot in plotCTSM ---------------------------------------;
        bar = f_longwind+"_MetOceBar"
        wks = gsn_open_wks (figtype, bar)
        npanels = 6
        plot = new(npanels,graphic)
        resmo = True
        resmo@gsnFrame = False
        resmo@gsnDraw = False
        
        resmo@vpXF = 0.2 ; In page coordinates, where to start
        resmo@vpYF = 0.95;.8 ; the plot
        resmo@vpHeightF = 0.12;.1 ; Changes the aspect ratio
        resmo@vpWidthF = 0.65
        resmo@tiMainFontHeightF = 0.01
        resmo@tiMainPosition = "Left"
        resmo@tiMainJust = "topLeft"
        resmo@xyLineThicknessF = 2
    ; resmo@tiMainOffsetXF = 0.2
        resmo@tiYAxisFontHeightF = 0.008
        resmo@tiXAxisFontHeightF = 0.008
        resmo@tiYAxisString = "Velocity [knots]"
        
        xvals = ind(hour.eq.0)
        printVarSummary(xvals)
        tmXvals = n(xvals)
        time_labels = month(xvals)+"-"+day(xvals)
        resmo@tmXBMode = "Explicit"
        resmo@tmXBMinorOn = False
        resmo@tmYLMinorOn = False
        resmo@tmYRMinorOn = False

        ;
        ; Time X-Axis Labeling for bottom plot.
        ;
        resmo@tmXBOn = False
        resmo@tmXBLabelsOn = False
        resmo@tmXBValues = tmXvals
        resmo@tmXTMajorOutwardLengthF = 0
        resmo@tmXTMajorLengthF = 0.01
        resmo@tmXBMajorOutwardLengthF = 0
        resmo@tmXBMajorLengthF = 0.01
        resmo@tmXMajorGrid = True
        resmo@tmXMajorGridThicknessF = 1.0
        resmo@tmXMajorGridLineDashPattern = 2

        resmo@tmYRMajorLengthF = 0.02
        resmo@tmYLMajorOutwardLengthF = 0
        resmo@tmYLMajorLengthF = 0.02
        resmo@tmYLLabelFontHeightF = 0.008 ; default is 0.02
        
        resmo@trYMinF = -maxY ; bottom of Y-scale
        resmo@trYMaxF = maxY ; nominal top of Y-scale
        
        resL = resmo
        resL@tiYAxisString = "Velocity [knots]" ; axis string
        resL@tiMainString = "Meteorological Winds [Velocity (Solid) / Direction (Dashed)]" ; title
        resL@xyLineColors = "black"
        resL@xyDashPatterns= 0
        resL@trYMinF = 0
        
        resR = resmo
        resR@tiYAxisString = "Direction [From]" ; axis string
        resR@xyLineColors = "black"
        resR@xyDashPatterns= 1
        resL@trYMinF = 0
        resR@trYMaxF = 360
        
        plot(npanels - npanels) = gsn_csm_xy2(wks,n,speedMet,dirMet,resL,resR)
        
        resmo@pmLegendDisplayMode = "Always"
        resmo@pmLegendWidthF = .1
        resmo@pmLegendHeightF = .12
        resmo@pmLegendSide = "Right"
        resmo@lgOrientation = "vertical"
        resmo@lgAutoManage = False
        resmo@lgLabelFontHeightF = 0.007
        resmo@lgLabelOffsetF = 0.05
        resmo@lgPerimOn = False
        
        resmo@tmYMajorGrid = True
        resmo@tmYMajorGridThicknessF = 1.0
        resmo@tmYMajorGridLineDashPattern = 2
        resmo@xyMonoLineThickness = True ; all solid lines
    ; res@xyMarkLineMode = "Lines"
        
        resmo@xyLineColors = (/"blue","red"/)
        resmo@xyDashPatterns=(/1,0/)
        
        resmo@tiMainString = "Meteorological Winds [From]"
        resmo@xyExplicitLegendLabels = (/"East","North"/)
        plot(npanels - 5) = gsn_xy(wks,n,(/Umet,Vmet/),resmo)
        
        resmo@tiMainString = "Winds [Toward]"
        resmo@xyExplicitLegendLabels = (/"Eastward","Northward"/)
        plot(npanels - 4) = gsn_xy(wks,n,(/Uoc,Voc/),resmo)

        resmo@tiMainString = "Alongshore Velocity [Toward "+alongshore_heading+"~S~o~N~]"
        resmo@trYMinF = -maxY ; bottom of Y-scale
        resmo@trYMaxF = maxY ; nominal top of Y-scale
        resmo@xyExplicitLegendLabels = (/"Unfiltered",fhours+" Hour"/)
     
        plot(npanels - 3) = gsn_xy(wks,n,(/velOnAx,fvelOn/),resmo) ; add polyline

        resmo@tiMainString = "Across-shore Velocity [Toward "+across_heading+"~S~o~N~]"
        resmo@xyExplicitLegendLabels = (/"Unfiltered",fhours+" Hour"/)
     
        plot(npanels - 2) = gsn_xy(wks,n,(/velAcAx,fvelAc/),resmo) ; add polyline

        resmo@tiYAxisString = "Pressure [mb]"
        resmo@tiMainString = "Barometric Pressure"
        delete(resmo@xyLineColors)
        delete(resmo@xyDashPatterns)
        resmo@xyLineColors = "black"
        resmo@xyDashPatterns = 0
        delete(resmo@trYMinF)
        delete(resmo@trYMaxF)
        resmo@pmLegendDisplayMode = "Never"
        resmo@tiXAxisString = "LST Time (Month, Day)"
        resmo@tmXBOn = True
        resmo@tmXBLabelsOn = True
        resmo@tmXBLabels = time_labels
        resmo@tmXBLabelJust = "TopLeft"
        resmo@tmXBLabelAngleF = lb_angle
        resmo@tmXBLabelFontHeightF = 0.008
        plot(npanels-1) = gsn_xy(wks,n,baro,resmo)

        resP = True
        last = dimsizes(year) - 1
        panel_str = bar+".pdf, "+month(0)+"/"+day(0)+"/"+year(0)+" - "+month(last)+"/"+day(last)+"/"+year(last)+" (Local Time)"
        resP@gsnFrame = False
        resP@txString = panel_str
        resP@txFontHeightF = 0.01
        resP@gsnPanelBottom = 0.05
        resP@gsnMaximize = True
    ; resP@gsnRightString = bar
        gsn_panel(wks,plot,(/npanels,1/),resP)
        
        frame(wks)

        print("...plotCTSM work complete.")
    end

    ;---------------------------------------------------------------;
    ; plotWXvx ;
    ;---------------------------------------------------------------;
    ;
    ; v 2.0
    ; Matt Stumbaugh
    ; 2004/11/01
    ;
    ; Vector plot of NDBC wind data processed using rtNDBCscript.ncl.
    ;
    ; Example:
    ; plotWXvx(figtype, f_longwind, year, month, day, hour, n, speed, dirM, Umet, Vmet, Uoc, Voc, 25., 1.)
    ;
    ; To develop:
    ; - de-hardwire plot scaling. At present 25 knots and 1 bin per knot?
    ;
    ; Update
    ; 04-11-29: Component_knob 1,2 switch from speed to fabs(spd__V | spd_U), respectively.
    ; 04-12-23: Simplified labeling scheme to be determined by argument "maxY".
    ; Change workstation name so saved pdfs would be intelligently named.
    ; 05-07-06: Integrated wxvx.ncl into procedure plotWXvx() of rtNDBCplot.ncl for real-time
    ; wind analysis and processing to support GNOME trajectory modeling.
    ;
    ;---------------------------------------------------------------\

    undef("plotWXvx")

    procedure plotWXvx(figtype:string,f_longwind:string, year:integer, month:integer, \
        day:integer, hour:integer, n:integer, speed:float, \
        dirM:float, Umet:float, Vmet:float, Uoc:float, Voc:float, maxY:float, speed_bin_size:float)
        
    begin
        load "/sw/lib/ncarg/nclscripts/csm/gsn_code.ncl"
        load "/sw/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
        ;load "/sw/lib/ncarg/nclscripts/mrscode/rtNDBCfuncs.ncl"
        ;---------------------------------------------------------------\
        ; Get data
        
        print("plotWXvx is working...")
        velocity = speed
        speedU = Uoc
        speedV = Voc
        
        max_ind = ind(velocity.eq.max(velocity))
        
        ; 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)
                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)
                        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 = f_longwind+"_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 (knots)"
        res@tiXAxisString = "Local Time (Month, Day)"
        res@tiMainString = f_longwind+" Wind Vectors [Toward]"
        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
        xvals = ind(hour.eq.0)
        printVarSummary(xvals)
        tmXvals = n(xvals)
        time_labels = month(xvals)+"-"+day(xvals)
        
        res@tmXUseBottom = True
        res@tmXTBorderOn = True
        res@tmXTMinorOn = True
        res@tmXTMajorLengthF = 0.01
        res@tmXBMinorOn = True
        res@tmXBMajorLengthF = 0.01
        res@tmXBMode = "Explicit"
        res@tmXBValues = xvals
        res@tmXBLabels = time_labels
        res@tmXBLabelAngleF = 30
        res@tmXBLabelFontHeightF = 0.01
        
        vc = gsn_vector(wks,sU,sV,res)
        
        ;---------------------------------------------------------------\
        ; Output statistics STDOUT.
        
        max_velocity = max(velocity)
        maxY = maxY
        print("Maximum velocity= "+max_velocity+". Maximum Y-value = "+maxY)
        print("...wxvx.ncl work complete")

    end

    ;---------------------------------------------------------------;
    ; plotStx ;
    ;---------------------------------------------------------------;
    ; Author/Creation Date/Office:
    ; Description:
    ; Example:
    ; To develop:
    ; Update
    ;
    ;---------------------------------------------------------------\

    undef("plotStx")

    procedure plotStx(figtype:string,f_longwind:string, year:integer, month:integer, \
        day:integer, hour:integer, n:integer, speed:float, \
        dirM:float, Uoc:float, Voc:float, Uoc_avg:float, Voc_avg:float, maxY:float, speed_bin_size:float)
        
    begin
        load "/sw/lib/ncarg/nclscripts/csm/gsn_code.ncl"
        load "/sw/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

        print("plotStx() is working...")

        ;---------------------------------------------------------------\
        ; Plotting
        
        plot_wx = f_longwind+"_STX"
        wks = gsn_open_wks(figtype,plot_wx)
        
        print(Uoc+" "+Voc)
        
        res = True
        
        ; Vector Plot
    ; res@vpWidthF = 0.6
    ; res@vpHeightF=0.3
    ; res@gsnMaximize = True
    ; res@gsnPaperOrientation = "landscape"
        
        ; Title/Axis Labels
        res@tiYAxisString = ""
        res@tiXAxisString = "Local Time (Month, Day)"
        res@tiMainString = f_longwind+" Stick Plot [Toward]"
        res@tiXAxisFontHeightF = 0.015
        res@tiYAxisFontHeightF = 0.015
        
        ; Vector resources
        res@vcRefMagnitudeF = 10
        res@vcRefLengthF = .04
        res@vcMinFracLengthF = 0
        res@vcGlyphStyle = "LineArrow"
        res@vcLineArrowThicknessF = 2.5
        res@vcLineArrowHeadMaxSizeF = 0
        res@vcLineArrowHeadMinSizeF = 0
        res@vcPositionMode = "ArrowTail"
    ; res@vcVectorDrawOrder = "PostDraw"
        res@vcRefAnnoOn = True; Turns off reference vector box

        
        ; Tick Marks/Labels
        ; Y-Ticks
        res@tmYLLabelsOn = False
        res@tmYLOn = False
        res@tmYROn = False
        
        ;X-Ticks
        xvals = ind(hour.eq.0)
        printVarSummary(xvals)
        tmXvals = n(xvals)
        time_labels = month(xvals)+"-"+day(xvals)
        
        res@tmXUseBottom = True
        res@tmXTBorderOn = False
        res@tmXBBorderOn = False
        res@tmYLBorderOn = False
        res@tmYRBorderOn = False
        res@tmXTMinorOn = True
        res@tmXTMajorLengthF = 0.01
        res@tmXBMinorOn = True
        res@tmXBMajorLengthF = 0.01
        res@tmXBMode = "Explicit"
        res@tmXBValues = xvals
        res@tmXBLabels = time_labels
        res@tmXBLabelAngleF = 30
        res@tmXBLabelFontHeightF = 0.01
        
        col = dimsizes(Uoc)
        U = new((/col,col/),float)
        V = U
        avgwind = floattointeger(floor(col*5/10))
        fullwind = floattointeger(floor(col*6/10))
        U(fullwind,:) = Uoc
        V(fullwind,:) = Voc
        U(avgwind,:) = Uoc_avg
        V(avgwind,:) = Voc_avg
    ; res@vfYCEndIndex = fullwind+col/10
    ; res@vfYCStartIndex=avgwind - col/10
        vc = gsn_vector(wks,U,V,res)

    ; row = 5
    ; col = dimsizes(Uoc)
    ;
    ; U = new((/row,col/),float)
    ; V = U
    ;; avgwind = floattointeger(floor(col/3))
    ;; fullwind = floattointeger(floor(col*2/3))
    ; res@vfXArray = n
    ; res@vfYArray = (/0,1,2,3,4/)
    ; U(2,:) = Uoc
    ; V(2,:) = Voc
    ; U(3,:) = Uoc_avg
    ; V(3,:) = Voc_avg
    ; res@vfUMaxV = 20
    ; res@vfUMinV = -20
    ; res@vfVMaxV = 20
    ; res@vfVMinV = -20
    ; vc = gsn_vector(wks,U,V,res)

    end




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



    This archive was generated by hypermail 2b29 : Tue Jul 12 2005 - 14:14:12 MDT