Re: Label bar and constant field

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Tue Oct 16 2012 - 19:56:36 MDT

Hi Enrico,
Although I was able to get the "ForceAlways" option to work using a setvalues call on contour_tend right after this line:

  contour_tend = wrf_contour(a[it],wks, rain_tot_tend(it,:,:),opts_r) ; total (color)
  setvalues contour_tend
        "pmLabelBarDisplayMode" : "ForceAlways"
  end setvalues

it probably does not do what you want, because when the data are constant, it does not honor the explicit labels or colors.
Hopefully this can be corrected soon, but until then your only option is to manually create your own labelbar using gsn_create_labelbar.
It actually is not too hard. I have modified your original script to demonstrate a basic version. I am attaching it here. I also generated some
random data for the first frame just to see what the plot should look like when it has valid data.
 -dave

On Oct 16, 2012, at 12:40 PM, Enrico Benso wrote:

> Hi Dave,
>
> I tried pmLabelBarDisplayMode = "ForceAlways"
> but I get a lot of warnings and the label bar is not plotted even if precipitations are present:
>
> (0) Working on time: 2012-10-19_00:00:00
> warning:ContourPlotInitialize: scalar field is constant; ContourPlot not possible:[errno=1102]
> warning:ContourPlotSetValues: Data values out of range of levels set by EXPLICITLEVELS mode
> warning:lbPerimOn is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbLabelFontHeightF is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbAutoManage is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbLabelJust is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbLabelAutoStride is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbBoxMinorExtentF is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbTitleFontHeightF is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbTitleOn is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbTitleString is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbTitleJust is not a valid resource in /prec3h_contour.PlotManager at this time
> warning:lbTitleOffsetF is not a valid resource in /prec3h_contour.PlotManager at this time
>
>
> If this can help you, I attach here my script.
>
>
> ; Example script to produce plots for a WRF real-data run,
> ; with the ARW coordinate dynamics option.
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> ;load "./WRFUserARW.ncl"
>
> begin
> ;
> ; Make a list of all files we are interested in
> DATADir = "/home/vonjack/wrfems/runs/veneto/wrfprd/"
> FILES = systemfunc (" ls -1 " + DATADir + "*d02* ")
> numFILES = dimsizes(FILES)
> print("numFILES = " + numFILES)
> print(FILES)
> print (" ")
>
> ; We generate plots, but what kind do we prefer?
> ; type = "x11"
> ; type = "pdf"
> type = "png"
> ; type = "ncgm"
> ;type = "ps"
>
> type@wkWidth = 1024 ; default is 1024 by 1024
> type@wkHeight = 1024
> wks = gsn_open_wks(type,"img/prec3h")
>
>
> ; Set some basic resources
> res = True
> res@MainTitle = "www.avmeteo.it WRF 1.8Km"
> res@Footer = False
>
>
> pltres = True
> mpres = True
> mpres@mpOutlineOn = False
> mpres@mpGeophysicalLineColor = "Black"
> mpres@mpNationalLineColor = "Black"
> mpres@mpUSStateLineColor = "Black"
> mpres@mpGridLineColor = "Black"
> mpres@mpLimbLineColor = "Black"
> mpres@mpPerimLineColor = "Black"
> mpres@mpDataBaseVersion = "HighRes"
> mpres@mpGeophysicalLineThicknessF = 2
>
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> a = addfiles(FILES+".nc","r")
>
> times = wrf_user_getvar(a,"times",-1) ; get all times in the file
> ntimes = dimsizes(times) ; number of times in the file
>
>
> ; Get non-convective, convective and total precipitation
> rain_exp = wrf_user_getvar(a,"RAINNC",-1)
> rain_con = wrf_user_getvar(a,"RAINC",-1)
> rain_tot = rain_exp + rain_con
> rain_tot@description = "Precipitazioni accumulate (3h)"
>
> ; just creating new arrays here
> rain_exp_tend = rain_exp
> rain_con_tend = rain_con
> rain_tot_tend = rain_tot
> rain_exp_tend = 0.0
> rain_con_tend = 0.0
> rain_tot_tend = 0.0
> rain_exp_tend@description = "Explicit Precipitation Tendency"
> rain_con_tend@description = "Param Precipitation Tendency"
> rain_tot_tend@description = "Precipitazioni accumulate (3h)"
>
> ; Calculate tendency values
> ; We know our data is available every 3 hours, so setting tend_int to 1 gives
> ; tendencies for 3 hours, setting it to 2, gives 6hourly tendencies
> tend_int = 1
> rain_exp_tend(tend_int:ntimes-1:tend_int,:,:) = rain_exp(tend_int:ntimes-1:tend_int,:,:) - rain_exp(0:ntimes-2:tend_int,:,:)
> rain_con_tend(tend_int:ntimes-1:tend_int,:,:) = rain_con(tend_int:ntimes-1:tend_int,:,:) - rain_con(0:ntimes-2:tend_int,:,:)
> rain_tot_tend(tend_int:ntimes-1:tend_int,:,:) = rain_tot(tend_int:ntimes-1:tend_int,:,:) - rain_tot(0:ntimes-2:tend_int,:,:)
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> do it = tend_int,ntimes-1,tend_int ; Let's skip the first time as rain is 0 here
>
> print("Working on time: " + times(it) )
> res@TimeLabel = times(it) ; Set Valid time to use on plots
>
>
>
>
> ; Plotting options for Precipitation
> opts_r = res
> opts_r@UnitLabel = "mm"
> opts_r@cnLevelSelectionMode = "ExplicitLevels"
> opts_r@cnLevels = (/ .5, 1, 2, 5, 10, 15, 20, \
> 30, 40, 50, 60, 80, 100, 120, 150, 200, 250/)
> opts_r@cnFillColors = (/"0", "116","103", \
> "93","83", \
> "75","58","38", \
> "28","08","02","ForestGreen","Green","Chartreuse","Yellow","208","224","235"/)
> opts_r@cnInfoLabelOn = False
> opts_r@cnConstFLabelOn = False
> opts_r@cnFillOn = True
> opts_r@pmLabelBarDisplayMode = "ForceAlways"
>
>
>
>
> ; Precipitation Tendencies
> opts_r@SubFieldTitle = "da " + times(it-tend_int) + " a " + times(it)
>
> contour_tend = wrf_contour(a[it],wks, rain_tot_tend(it,:,:),opts_r) ; total (color)
> opts_r@cnFillOn = False
>
>
> delete(opts_r)
>
> pltres@PanelPlot = True
>
> ; MAKE PLOTS
>
>
> ; Total Precipitation Tendency + SLP
> plot = wrf_map_overlays(a[it],wks,contour_tend,pltres,mpres)
>
>
>
>
> shp_filename = "ITA_adm2.shp"
> f = addfile(shp_filename, "r") ; Open shapefile
> ;---Read data off shapefile
> segments = f->segments
> geometry = f->geometry
> segsDims = dimsizes(segments)
> geomDims = dimsizes(geometry)
> ;---Read global attributes
> geom_segIndex = f@geom_segIndex
> geom_numSegs = f@geom_numSegs
> segs_xyzIndex = f@segs_xyzIndex
> segs_numPnts = f@segs_numPnts
> numFeatures = geomDims(0)
> lines = new(segsDims(0),graphic) ; array to hold polylines
> plres = True ; resources for polylines
> plres@gsLineColor = "black" ; Default is foreground color
> plres@gsLineThicknessF = 2.0 ; Default is 1
> ;---Add polylines to plot
> lon = f->x
> lat = f->y
> segNum = 0 ; Counter for adding polylines
> do i=0, numFeatures-1
> startSegment = geometry(i, geom_segIndex)
> numSegments = geometry(i, geom_numSegs)
> do seg=startSegment, startSegment+numSegments-1
> startPT = segments(seg, segs_xyzIndex)
> endPT = startPT + segments(seg, segs_numPnts) - 1
> lines(segNum) = gsn_add_polyline(wks, plot, lon(startPT:endPT), \
> lat(startPT:endPT), plres)
> segNum = segNum + 1
> end do
> end do
> ;---Drawing the plot will draw the newly attached polylines.
> resP = True ; panel options
> resP@gsnMaximize = True ; maximize image
> draw(plot)
> frame(wks) ; Advanced frame.
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> end do ; END OF TIME LOOP
>
> end
>
>
>
>
>
>
>
> 2012/10/16 David Brown <dbrown@ucar.edu>
> Hi Enrico,
> There is a not-yet-documented setting for pmLabelBarDisplayMode called "ForceAlways" that will cause the LabelBar to appear even if the contour field is constant. Let us know if this does not work.
> -dave
>
>
> On Oct 15, 2012, at 1:57 PM, Enrico Benso wrote:
>
> >> Hello,
> >>
> >> I have a question about label bars.
> >> I use NCL to view my Wrf model output.
> >> When i try to display precipitations, and there si no rain in my small
> >> domain, I get a warning (constant scalar field).
> >> The problem is that in this case the label bar disappears, even if I
> >> set levels with Explicit Mode.
> >> Is there a way to avoid this?
> >>
> >> Thank You!
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Tue Oct 16 19:56:45 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT