[ncl-talk] vectors won't draw

Mary Haley haley at ucar.edu
Thu Dec 3 14:29:42 MST 2015


Mira,

This is a rather complicated piece of code and it's hard to tell where the
problem might be. In the future, please try to provide a cleaner script
that shows the problem.  Even better, if you can provide a clean script and
the data file, then we can run the script here and debug your problem much
quicker.

Usually when people say that data is not showing up on a map, my first
thought is that the lat/lon coordinates are either missing, or out-of-range
of the map limits provided.

It looks like you do have lat/lon coordinates attached to diff_u and
diff_v, so you are probably okay there.

Since this is a vector plot, the next thing might be one of your vector
resources.  I recommend drawing your vector plot with the barest number of
resources set, so you can make sure that your data is even valid.

Try commenting out these resources and see if you get some vectors:

vcres at vcRefMagnitudeF = 10.0                    ; define vector ref mag
vcres at vcRefLengthF = 0.045                      ; define length of vec ref
]vcres at vcMinDistanceF = 0.017

I don't know which of your vector plots is causing the problem, because I
just don't have time to go through your code and follow where "u" and "v"
get used in various calculations. But, you should use "printMinMax" on
various calculated variables to make sure they look okay.

Sometimes a seemingly simple change to your code can cause all missing
values to be returned, or values outside of a range you might be expecting.

If you continue to have problems that you can't solve, then please email
ncl-talk again, but include a cleaner script, and the data file if you can.


--Mary





On Wed, Dec 2, 2015 at 8:13 PM, <mberdahl at envsci.rutgers.edu> wrote:

> Hi all,
>
> I have a strange problem where I have a working script and plot with
> vectors overlaid on a filled contour.  However, when I make a slight
> change to how I calculate u and v (I average over levels instead of just
> choosing a single level), the vectors won't plot.  Below I have the
> dysfunctional script where I've commented the section where I just use u
> and v at 500mb, and attempt to calculate the average of the u and v over
> the troposphere (1000 - 200 mb).  I'll also copy the variable summaries
> below.
> Any help is appreciated.
> Thanks,
> Mira
>
>
>
> My script is:
>
>
> 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/csm/shea_util.ncl"
> ;************************************************
> begin
> ;************************************************
> ; read in netCDF file s
> ;************************************************
> a = addfile("uwnd.mon.mean.alllevels.nc","r") ; u winds
> b = addfile("vwnd.mon.mean.alllevels.nc","r") ; v winds
>
> c = addfile("../PrecipitableWater/pr_wtr.eatm.mon.mean.nc","r") ;
> precipitable water content
>
> ;************************************************
> ; read in pwonal [u] and meridional [v] winds (July)
> ;************************************************
>
> ;;;;;; If I just want one level
> ;u = a->uwnd(0:803,{500},{45:90},{270:357.5})
> ;v = b->vwnd(0:803,{500},{45:90},{270:357.5}) ; Get u, v, time (1),level
> (1000hpa),latitude(-90:90) and lonitude(0:360) data.
>
> ;; If I want an average of the levels in the troposphere for instance.
> u_trop = a->uwnd(0:803,{1000:200},{45:90},{270:357.5})
> v_trop = b->vwnd(0:803,{1000:200},{45:90},{270:357.5}) ; Get u, v, time
> (1),level (1000 to 200 hpa),latitude(-90:90) and lonitude(0:360) data.
> u = dim_avg_n(u_trop,1) ;==> take the average over levels 200mb - 1000mb
> (troposphere)
> v = dim_avg_n(v_trop,1) ;==> take the average over levels 200mb - 1000mb
> (troposphere)
> ;; name the dimensions
> u!0 = "time"
> u!1 = "lat"
> u!2 = "lon"
> v!0 = "time"
> v!1 = "lat"
> v!2 = "lon"
>
> pw = c->pr_wtr(0:803,{45:90},{270:357.5})  ; get precipitable water content
>
>
> printVarSummary(u)
> printVarSummary(v)
> printVarSummary(pw)
>
> ; Calculate the seasonal averages.
> uDJF = month_to_season(u, "DJF")
> vDJF = month_to_season(v, "DJF")
> pwDJF = month_to_season(pw, "DJF")
>
> printVarSummary(uDJF)
> printVarSummary(vDJF)
> printVarSummary(pwDJF)
>
> ; from the matlab script i wrote: findExtremeYrs, i pulled out the extreme
> years (> or < 1std) that i want to average and plot here.
>
>
> ;ans = 7 (longitude of IL)
> ;yearList_hi =1966        1967        1968        1969        1974
> 1975        1983        1994        1995        2005
> ;yearList_lo =1963        1964        1985        1987        1991
> 1992        1996        2002   2003    2006      2009
>
>
> ; this data starts at 1948 (this is index 0), so 1953=5, 1963=15 etc.
>
>
> uDJF_lon_hi = uDJF((/18,19,20,21,26,27,35,46,47,57/),:,:)
> uDJF_lon_lo = uDJF((/15,16,37,38,42,43,47,53,54,57,60/),:,:)
>
> vDJF_lon_hi = vDJF((/18,19,20,21,26,27,35,46,47,57/),:,:)
> vDJF_lon_lo = vDJF((/15,16,37,38,42,43,47,53,54,57,60/),:,:)
>
> pwDJF_lon_hi = pwDJF((/18,19,20,21,26,27,35,46,47,57/),:,:)
> pwDJF_lon_lo = pwDJF((/15,16,37,38,42,43,47,53,54,57,60/),:,:)
>
>
> uAvgTime_hi = dim_avg_n_Wrap(uDJF_lon_hi,0)
> uAvgTime_lo = dim_avg_n_Wrap(uDJF_lon_lo,0)
>
> printVarSummary(uAvgTime_hi)
> printVarSummary(uAvgTime_lo)
>
> vAvgTime_hi = dim_avg_n_Wrap(vDJF_lon_hi,0)
> vAvgTime_lo = dim_avg_n_Wrap(vDJF_lon_lo,0)
>
> printVarSummary(vAvgTime_hi)
> printVarSummary(vAvgTime_lo)
>
> pwAvgTime_hi = dim_avg_n_Wrap(pwDJF_lon_hi,0)
> pwAvgTime_lo = dim_avg_n_Wrap(pwDJF_lon_lo,0)
>
> printVarSummary(pwAvgTime_hi)
> printVarSummary(pwAvgTime_lo)
>
> ; dirty way to copy metadata over first.
> diff_u = uAvgTime_hi;
> diff_v = vAvgTime_hi;
> diff_pw = pwAvgTime_hi;
>
> diff_u = uAvgTime_lo - uAvgTime_hi
> diff_v = vAvgTime_lo - vAvgTime_hi
> diff_pw = pwAvgTime_lo - pwAvgTime_hi
>
> printVarSummary(diff_u)
> printVarSummary(diff_v)
> printVarSummary(diff_pw)
>
> ;************************************************
> ; create plot
> ;************************************************
> wks = gsn_open_wks("eps","Panel_lon_pw_500")            ; open a ps file
> gsn_define_colormap(wks,"temp1")
>
> plot = new(3,graphic)                           ; create a plot array
>
> ;---- set common resources for all plots
> res                     = True
> res at gsnDraw             = False                 ; dont draw
> res at gsnFrame            = False                 ; dont advance frame
> res at cnInfoLabelOn       = False                 ; trn off cn info label
> res at gsnAddCyclic = False                        ; has to do with wrapping
> the lonitude at 0/360
> res at cnFillPalette = "matlab_jet"
> ;************************************************
> ; Choose a subregion
> ;************************************************
> res at mpMaxLatF = 90                              ;maximum latitude
> res at mpMinLatF = 45                              ;minimum latitude
> ;res at mpMaxLonF = 357.5                  ;       ;maximum lonitude
> ;res at mpMinLonF = 270                            ;minimum lonitude
> res at mpMaxLonF = 0
> res at mpMinLonF = -90
> ;res at mpFillBoundarySets = AllBoundaries
> res at mpOutlineBoundarySets = "National"
> res at mpOutlineOn = True
> res at mpOutlineDrawOrder = "PostDraw"
>
> mpid = gsn_csm_map(wks,res)
> mpid2 = gsn_csm_map(wks,res)
> mpid3 = gsn_csm_map(wks,res)
>
> ;***********************************************
> ; ----wind  vector plot
> ;***********************************************
> vcres = res
> vcres at vcRefAnnoOrthogonalPosF = -1.0            ; move ref vector up
> vcres at vcRefMagnitudeF = 10.0                    ; define vector ref mag
> vcres at vcRefLengthF = 0.045                      ; define length of vec ref
> vcres at vcGlyphStyle = "CurlyVector"              ; turn on curly vectors
> vcres at vcMinDistanceF = 0.017
> vcres at mpFillOn = False                          ; turn off gray fill
> vcres at mpOutlineBoundarySets = "National"        ; turn on country
> boundaries
> ;vcres at mpFillBoundarySets = AllBoundaries
> vcres at mpGeophysicalLineColor = "Navy"           ; color of cont. outlines
> vcres at mpGeophysicalLineThicknessF = 1.5         ; thickness of outlines
> vcres at gsnRightString = ""                       ; turn off thue units
> string
>
> ;vcres at gsnLeftString = "DJF High lon"
> ; was previously winds_hi =
> gsn_csm_vector_map_ce(wks,uAvgTime_hi,vAvgTime_hi,vcres)
> winds_hi = gsn_csm_vector(wks,uAvgTime_hi,vAvgTime_hi,vcres)
> ;vcres at gsnLeftString = "DJF Low lon"
> winds_lo = gsn_csm_vector(wks,uAvgTime_lo,vAvgTime_lo,vcres)
> ;vcres at gsnLeftString = "Difference of High - Low"
> winds_diff = gsn_csm_vector(wks, diff_u, diff_v,vcres)
> ;************************************************
> ;---- geopotential height filled contour plot
> ;***********************************************
> pwfres                      = res
> pwfres at cnFillOn             = True
> ;pwfres at cnLevelSelectionMode = "ExplicitLevels
> ;pwfres at cnLevels             = ispan(-20,90,5)
> pwfres at lbLabelFontHeightF   = 0.015
> pwfres at lbOrientation        = "Vertical"
> pwfres at pmLabelBarOrthogonalPosF = -0.005
> pwfres at cnFillPalette = "BlWhRe"
> pwfres at cnLinesOn = False ; turn off contour lines
> pwfres at cnLevelSelectionMode = "ManualLevels"            ;set manual
> contour levels
> pwfres at cnMinLevelValF =0.                               ; set min contour
> level
> pwfres at cnMaxLevelValF = 20.                             ; set max contour
> level
> pwfres at cnLevelSpacingF = 2 ; set contour spacing
>
> contour_pwf_hi = gsn_csm_contour(wks,pwAvgTime_hi,pwfres)
> contour_pwf_lo = gsn_csm_contour(wks,pwAvgTime_lo,pwfres)
>
>
> plot(0) = gsn_csm_contour(wks,pwAvgTime_hi,pwfres)
> plot(1) = gsn_csm_contour(wks,pwAvgTime_lo,pwfres)
>
> delete(pwfres at cnLevelSpacingF)          ;<== delete resource before
> resetting
> pwfres at cnLevelSelectionMode = "AutomaticLevels"         ; set back to
> automatic
> levels for third panel.
>
> contour_pwf_diff = gsn_csm_contour(wks,diff_pw,pwfres)
> plot(2) = gsn_csm_contour(wks,diff_pw,pwfres)
>
> ;overlay(plot(0),winds_hi)
> overlay(mpid,plot(0))
> overlay(mpid,winds_hi)
>
> ;overlay(plot(1),winds_lo)
> overlay(mpid2,plot(1))
> overlay(mpid2,winds_lo)
>
> ;overlay(plot(2),winds_diff)
> overlay(mpid3,plot(2))
> overlay(mpid3,winds_diff)
>
> ;draw(mpid)
> ;frame(wks)
>
> ;************************************************
> ; create panel
> ;************************************************
> resP = True                                     ; modify the panel plot
> resP at txString = "lon 500mb"
> gsn_panel(wks,(/mpid,mpid2,mpid3/),(/3,1/),resP)                ; now draw
> as one plot;
>
>
> end
>
>
>
>
>
> varPrintSummaries are below:
>
> Variable: v
> Type: float
> Total Size: 2199744 bytes
>             549936 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 804] x [lat | 19] x [lon | 36]
> Coordinates:
>             time: [1297320..1883904]
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 14
>   level :       500
>   long_name :   Monthly mean v wind
>   units :       m/s
>   precision :   2
>   least_significant_digit :     1
>   var_desc :    v-wind
>   dataset :     CDC Derived NCEP Reanalysis Products
>   level_desc :  Multiple levels
>   statistic :   Mean
>   parent_stat : Other
>   missing_value :       -9.96921e+36
>   valid_range : ( -125, 160 )
>   actual_range :        ( -68.57001, 68.56999 )
>   _FillValue :  -9.96921e+36
>
>
>
> Variable: pw
> Type: float
> Total Size: 2199744 bytes
>             549936 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 804] x [lat | 19] x [lon | 36]
> Coordinates:
>             time: [1297320..1883904]
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 15
>   long_name :   Monthly Mean of Precipitable Water Content
>   valid_range : ( -102.2, 102.2 )
>   units :       kg/m^2
>   add_offset :   0
>   scale_factor :         1
>   missing_value :       -9.96921e+36
>   precision :   2
>   least_significant_digit :     1
>   var_desc :    Precipitable Water Content
>   dataset :     CDC Derived NCEP Reanalysis Products
>   level_desc :  Surface
>   statistic :   Mean
>   parent_stat : Other
>   actual_range :        ( -3.971937, 69.0658 )
>   _FillValue :  -9.96921e+36
>
> Variable: uDJF
> Type: float
> Total Size: 183312 bytes
>             45828 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 67] x [lat | 19] x [lon | 36]
> Coordinates:
>             time: [1297320..1875888]
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 15
>   level :       500
>   long_name :   DJF: Monthly mean u wind
>   units :       m/s
>   precision :   2
>   least_significant_digit :     1
>   var_desc :    u-wind
>   dataset :     CDC Derived NCEP Reanalysis Products
>   level_desc :  Multiple levels
>   statistic :   Mean
>   parent_stat : Other
>   missing_value :       -9.96921e+36
>   valid_range : ( -125, 160 )
>   actual_range :        ( -68.04001, 124.4 )
>   _FillValue :  -9.96921e+36
>   NMO : 0
>
>
> Variable: vDJF
> Type: float
> Total Size: 183312 bytes
>             45828 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 67] x [lat | 19] x [lon | 36]
> Coordinates:
>             time: [1297320..1875888]
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 15
>   level :       500
>   long_name :   DJF: Monthly mean v wind
>   units :       m/s
>   precision :   2
>   least_significant_digit :     1
>   var_desc :    v-wind
>   dataset :     CDC Derived NCEP Reanalysis Products
>   level_desc :  Multiple levels
>   statistic :   Mean
>   parent_stat : Other
>   missing_value :       -9.96921e+36
>   valid_range : ( -125, 160 )
>   actual_range :        ( -68.57001, 68.56999 )
>   _FillValue :  -9.96921e+36
>   NMO : 0
>
>
> Variable: uAvgTime_hi
> Type: float
> Total Size: 2736 bytes
>             684 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 19] x [lon | 36]
> Coordinates:
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 16
>   NMO : 0
>   _FillValue :  -9.96921e+36
>   actual_range :        ( -68.04001, 124.4 )
>   valid_range : ( -125, 160 )
>   missing_value :       -9.96921e+36
>   parent_stat : Other
>   statistic :   Mean
>   level_desc :  Multiple levels
>   dataset :     CDC Derived NCEP Reanalysis Products
>   var_desc :    u-wind
>   least_significant_digit :     1
>   precision :   2
>   units :       m/s
>   long_name :   DJF: Monthly mean u wind
>   level :       500
>   average_op_ncl :      dim_avg_n over dimension(s): time
>
> Variable: uAvgTime_lo
> Type: float
> Total Size: 2736 bytes
>             684 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 19] x [lon | 36]
> Coordinates:
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 16
>   NMO : 0
>   _FillValue :  -9.96921e+36
>   actual_range :        ( -68.04001, 124.4 )
>   valid_range : ( -125, 160 )
>   missing_value :       -9.96921e+36
>   parent_stat : Other
>   statistic :   Mean
>   level_desc :  Multiple levels
>   dataset :     CDC Derived NCEP Reanalysis Products
>   var_desc :    u-wind
>   least_significant_digit :     1
>   precision :   2
>   units :       m/s
>   long_name :   DJF: Monthly mean u wind
>   level :       500
>   average_op_ncl :      dim_avg_n over dimension(s): time
>
>
> Variable: vAvgTime_hi
> Type: float
> Total Size: 2736 bytes
>             684 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 19] x [lon | 36]
> Coordinates:
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 16
>   NMO : 0
>   _FillValue :  -9.96921e+36
>   actual_range :        ( -68.57001, 68.56999 )
>   valid_range : ( -125, 160 )
>   missing_value :       -9.96921e+36
>   parent_stat : Other
>   statistic :   Mean
>   level_desc :  Multiple levels
>   dataset :     CDC Derived NCEP Reanalysis Products
>   var_desc :    v-wind
>   least_significant_digit :     1
>   precision :   2
>   units :       m/s
>   long_name :   DJF: Monthly mean v wind
>   level :       500
>   average_op_ncl :      dim_avg_n over dimension(s): time
>
> Variable: vAvgTime_lo
> Type: float
> Total Size: 2736 bytes
>             684 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 19] x [lon | 36]
> Coordinates:
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 16
>   NMO : 0
>   _FillValue :  -9.96921e+36
>   actual_range :        ( -68.57001, 68.56999 )
>   valid_range : ( -125, 160 )
>   missing_value :       -9.96921e+36
>   parent_stat : Other
>   statistic :   Mean
>   level_desc :  Multiple levels
>   dataset :     CDC Derived NCEP Reanalysis Products
>   var_desc :    v-wind
>   least_significant_digit :     1
>   precision :   2
>   units :       m/s
>   long_name :   DJF: Monthly mean v wind
>   level :       500
>   average_op_ncl :      dim_avg_n over dimension(s): time
>
> Variable: diff_u
> Type: float
> Total Size: 2736 bytes
>             684 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 19] x [lon | 36]
> Coordinates:
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 16
>   average_op_ncl :      dim_avg_n over dimension(s): time
>   level :       500
>   long_name :   DJF: Monthly mean u wind
>   units :       m/s
>   precision :   2
>   least_significant_digit :     1
>   var_desc :    u-wind
>   dataset :     CDC Derived NCEP Reanalysis Products
>   level_desc :  Multiple levels
>   statistic :   Mean
>   parent_stat : Other
>   missing_value :       -9.96921e+36
>   valid_range : ( -125, 160 )
>   actual_range :        ( -68.04001, 124.4 )
>   _FillValue :  -9.96921e+36
>   NMO : 0
>
> Variable: diff_v
> Type: float
> Total Size: 2736 bytes
>             684 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat | 19] x [lon | 36]
> Coordinates:
>             lat: [45..90]
>             lon: [270..357.5]
> Number Of Attributes: 16
>   average_op_ncl :      dim_avg_n over dimension(s): time
>   level :       500
>   long_name :   DJF: Monthly mean v wind
>   units :       m/s
>   precision :   2
>   least_significant_digit :     1
>   var_desc :    v-wind
>   dataset :     CDC Derived NCEP Reanalysis Products
>   level_desc :  Multiple levels
>   statistic :   Mean
>   parent_stat : Other
>   missing_value :       -9.96921e+36
>   valid_range : ( -125, 160 )
>   actual_range :        ( -68.57001, 68.56999 )
>   _FillValue :  -9.96921e+36
>   NMO : 0
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151203/b4bbfcfc/attachment.html 


More information about the ncl-talk mailing list