[ncl-talk] Zooming Functions Clarification

Mary Haley haley at ucar.edu
Thu Apr 21 11:58:30 MDT 2016


I think you need to subscript your data arrays too.

If you look at that olr.ncl script that I pointed you to earlier:

http://www2.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/NCL/Examples/SPECIAL/olr.ncl

You'll see this code; note the "olr_zoom" below.  This is the variable
that's plotted, and not the original "olr":

; We are interested in a zoomed area with the SW corner at 20N;90W,
; and the NE corner at 30N;80W
; So get the XY points of these points
  lats = (/  20.0,  30.0 /)
  lons = (/ -93.0, -80.0 /)
  loc = wrf_user_ll_to_ij(a, lons, lats, True)

; loc(0,;) is west-east (x) ; loc(1,:) is south-north (y)
; subtract one since we want to use it as an index in NCL
  x_start = loc(0,0) - 1
  x_end   = loc(0,1) - 1
  y_start = loc(1,0) - 1
  y_end   = loc(1,1) - 1

  mpres1 at ZoomIn = True        ; set up map info for zoomed area
  mpres1 at Xstart = x_start
  mpres1 at Ystart = y_start
  mpres1 at Xend = x_end
  mpres1 at Yend = y_end

  olr = wrf_user_getvar(a,"OLR",-1)              ; get olr
  olr_zoom = olr(:,y_start:y_end,x_start:x_end)  ; create a zoomed area

You need to do something similar for your "tc" variable.

--Mary

On Thu, Apr 21, 2016 at 9:52 AM, Illston, Bradley G. <illston at ou.edu> wrote:

> Mary and Will,
>
>
>
> Thank you so much for the help. I am getting closer, but things still seem
> a bit off after close inspection. My code is below. If I do not zoom (e.g.
> comment out mpres at ZoomIn = True), I get the following image:
>
>
>
> http://res.mesonet.org/~billston/phd/images/ncl-talk/original.png
>
>
>
> If I zoom, I get the following image:
>
>
>
> http://res.mesonet.org/~billston/phd/images/ncl-talk/zoomed.png
>
>
>
> While the “map” does zoom in, the WRF 2m air temperature field does not.
> You can see this by looking at the contour shapes in the NW corner, for
> example. I think my code is getting very close, but just missing one final
> piece. Any ideas? Thank you so much for your assistance.
>
>
>
> Cheers,
>
> Brad Illston
>
>
>
>
>
> 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/wrf/WRFUserARW.ncl"
>
>
>
> begin
>
>
>
> ;---Define colormap. First is background color, second is foreground color
>
>   colors = (/(/255, 255, 255/),(/0, 0, 0/),(/255, 255, 255/),(/088, 164,
> 074/),(/047,124,062/),(/055, 072,
> 114/),(/095,129,183/),(/094,165,212/),(/116,196,205/),(/135,099,162/),(/128,076,144/)/)
> / 255.
>
>
>
> ;---Open WRF output file
>
>   a = addfile(wrf_filename,"r")
>
>
>
>   print("  NetCDF file = "+wrf_filename)
>
>   print("  Output image = "+output_png)
>
>
>
>
>
>
>
>    global_attnames = getvaratts(a) ;-- retrieve the  global attributes
> from input file
>
>    do i=0,dimsizes(global_attnames)-1
>
>       print(global_attnames(i) + " = " + a@$global_attnames(i)$) ;--
> print global attribute contents
>
>    end do
>
>
>
>
>
>
>
> ;---Read temperature at first time step
>
>   tc = wrf_user_getvar(a,"T2",0)
>
>   tc at long_name = "2m Air Temperature"
>
>   tc at units = "C"
>
>   tc=tc-273.15
>
>   wks = gsn_open_wks("png",output_png)
>
>   gsn_define_colormap(wks,"WhiteBlueGreenYellowRed")                ;
> choose colormap
>
> ; gsn_define_colormap(wks,colors)
>
>
>
> ;---Resources for filled contour plot
>
>   res                      = True
>
>
>
>   res at cnFillOn             = True
>
>   res at cnLinesOn            = False
>
>   res at gsnMaximize          = True
>
>
>
>   res at tiMainString         = run_length + " Run (" + year + ") - " +
> run_date + " " + end_time + " UTC"
>
>   res at Footer               = False
>
>   res at FieldTitle           = "2m Air Temperature"
>
>   res at lbTitleOn            = True
>
>   res at lbTitleString        = ""
>
>   res at NoHeaderFooter       = True            ; Switch headers and footers
> off
>
>
>
>   res at cnLevelSelectionMode = "ExplicitLevels"
>
>   res at cnLevels             =
> (/10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25/)
>
> ; res at ContourParameters = (/10,25,1/)      ; Contour levels
>
>
>
>   contour = wrf_contour(a,wks,tc,res)        ; Create contour plot
>
>
>
>   pltres                      = True         ; Basic overlay plot options
>
>   pltres at PanelPlot            = True         ; Tells wrf_map_overlays not
> to remove overlays
>
>
>
>   mpres                       = True         ; Set map options
>
>   mpres at mpOutlineOn           = True         ; Turn on map outlines
>
>   mpres at mpFillOn              = False        ; Turn off map fill
>
>   mpres at mpDataBaseVersion     = "Ncarg4_1"
>
>   mpres at mpDataSetName         = "Earth..2"   ; For counties
>
>   mpres at mpOutlineBoundarySets = "GeophysicalAndUSStates"
>
>   mpres at mpOutlineSpecifiers   = (/"Land", "Oklahoma:counties"/)
>
>   mpres at tiMainString          = run_length + " Run (" + year + ") - " +
> run_date + " " + end_time + " UTC"
>
>   mpres at gsnMaximize           = True
>
>
>
>
>
> ; We are interested in a zoomed area so get the XY points of these points
>
>   lats = (/  35.0,  36.0 /)
>
>   lons = (/ -98.2, -96.8 /)
>
>   loc = wrf_user_ll_to_ij(a, lons, lats, True)
>
> ; loc(0,;) is west-east (x) ; loc(1,:) is south-north (y)
>
> ; subtract one since we want to use it as an index in NCL
>
>   x_start = loc(0,0) - 1
>
>   x_end   = loc(0,1) - 1
>
>   y_start = loc(1,0) - 1
>
>   y_end   = loc(1,1) - 1
>
>
>
> ;  mpres at ZoomIn = True        ; set up map info for zoomed area
>
>   mpres at Xstart = x_start
>
>   mpres at Ystart = y_start
>
>   mpres at Xend = x_end
>
>   mpres at Yend = y_end
>
>
>
> ;---Create the contours over the WRF map (nothing will be drawn yet).
>
>   plot = wrf_map_overlays(a,wks,contour,pltres,mpres)
>
>
>
> ;---Plot OKC Boundary
>
>
>
>   lnres                    = True
>
>   lnres at gsLineColor        = "gray25"
>
>   lnres at gsLineThicknessF   = 2.0
>
>
>
>   okc_shp   =
> gsn_add_shapefile_polylines(wks,plot,"resources/OKCCityLimit_outline.shp",lnres)
>
>
>
>   polyres                  = True
>
>   polyres at gsMarkerIndex    = 1 ; Filled circle
>
>   polyres at gsMarkerSizeF    = 0.03
>
>
>
>   mesonet_points =
> gsn_add_shapefile_polymarkers(wks,plot,"resources/ok_mesonet_sites_active_20151014.shp",polyres)
>
>   micronet_points =
> gsn_add_shapefile_polymarkers(wks,plot,"resources/OKC_Micronet.shp",polyres)
>
>
>
>   draw(plot)       ; This will draw the map and the shapefile outlines.
>
>   frame(wks)       ; Advance the frame
>
>
>
> end
>
> *From:* Mary Haley [mailto:haley at ucar.edu]
> *Sent:* Thursday, April 14, 2016 1:41 PM
> *To:* Illston, Bradley G. <illston at ou.edu>
> *Cc:* ncl-talk at ucar.edu; Will Hobbs <will.hobbs at utas.edu.au>
> *Subject:* Re: [ncl-talk] Zooming Functions Clarification
>
>
>
> ​Hi Brad,
>
>
>
> There are a few problems with the script in general.
>
>
>
> First, as Will pointed out, you are trying to set map resources when you
> create a contour plot. This is why you are getting errors.
>
>
>
> But, I do see that later you are calling wrf_map_overlays, which is where
> you want to apply the map resources​. However, with the wrf_xxxx plotting
> scripts, you have to be careful about zooming in on the data when it's
> being done over a map.  The wrf_map_overlays procedure assumes that you are
> using the map projection that's provided on the WRF output file, and hence
> it doesn't really know anything about the lat/lon coordinates of your data.
>
>
>
> If you then try to zoom in on your WRF data without telling NCL what part
> of your data actually corresponds to the area you are zooming in on, then
> your results are likely going to be incorrect.
>
>
>
> wrf_map_overlays recognizes a special "ZoomIn" resource that allows you to
> do map zooming. Please see the "olr.ncl" example at:
>
>
>
>
> http://www2.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/NCL/Examples/SPECIAL/olr.htm
>
>
>
> The scripts on the "WRF debug" page also show how to use ZoomIn:
>
>
>
> http://www.ncl.ucar.edu/Applications/wrfdebug.shtml
>
>
>
> If you don't want to use the wrf_contour/wrf_map_overlays plotting
> scripts, then you can plot your WRF data with gsn_csm_contour_map.  We have
> some examples of this, and also show how to zoom in on your data.  See
> wrf_gsn_3.ncl at:
>
>
>
> http://www.ncl.ucar.edu/Applications/wrfgsn.shtml
>
>
>
> --Mary
>
>
>
>
>
> On Wed, Apr 13, 2016 at 9:47 PM, Will Hobbs <will.hobbs at utas.edu.au>
> wrote:
>
> Brad
>
>
>
> I'm not a WRF user so any suggestion here is just a guess. However, have
> you tried setting the resources trYMinF, trYMaxF etc instead of mpMaxLatF
> etc.
>
>
>
> I would guess that wrf_contour() is not a map plotting function, so it
> wouldn't recognise the mp resources. As long as the array that you're
> plotting has lat/lon coordinate dimensions the bounds set by the 'tr'
> resources should work fine.
>
>
>
> Hope that helps
>
>
>
> Will
>
>
>
>
>
> *From: *<Illston>, "Bradley G." <illston at ou.edu>
> *Date: *Thursday, 14 April 2016 1:16 PM
> *To: *"ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
> *Subject: *[ncl-talk] Zooming Functions Clarification
>
>
>
> NCL Users,
>
>
>
> I am one to try and figure my problems on their own, but I am a bit
> stumped after working on this for a few days. I am trying to zoom my map in
> to a set of bounding latitudes and longitudes in my domain to no avail. I
> kept trying various iterations utilizing ZoomIn or mpMinLatF/mpMinLonF/etc.
> I am not sure when you should use one and when you would use the other.
> Below is my latest script that works, but not zoomed in. When I run it, I
> get the following warnings:
>
>
>
> warning:mpLimitMode is not a valid resource in
> /tair_24hr_2011_2008091502_contour at this time
>
> warning:mpMinLonF is not a valid resource in
> /tair_24hr_2011_2008091502_contour at this time
>
> warning:mpMaxLonF is not a valid resource in
> /tair_24hr_2011_2008091502_contour at this time
>
> warning:mpMinLatF is not a valid resource in
> /tair_24hr_2011_2008091502_contour at this time
>
> warning:mpMaxLatF is not a valid resource in
> /tair_24hr_2011_2008091502_contour at this time
>
>
>
> Am I mixing various gsn functions that is causing a confusion? Is there a
> preferred one for plotting basic WRF output (in NetCDF format) to a PNG
> file? Any thoughts? Thank you so much.
>
>
>
> Cheers,
>
> Brad Illston
>
>
>
> 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/wrf/WRFUserARW.ncl"
>
>
>
> begin
>
>
>
> ;---Define colormap. First is background color, second is foreground color
>
>   colors = (/(/255, 255, 255/),(/0, 0, 0/),(/255, 255, 255/),(/088, 164,
> 074/),(/047,124,062/),(/055, 072,
> 114/),(/095,129,183/),(/094,165,212/),(/116,196,205/),(/135,099,162/),(/128,076,144/)/)
> / 255.
>
>
>
> ;---Open WRF output file
>
>   a = addfile(wrf_filename,"r")
>
>
>
>   print("  NetCDF file = "+wrf_filename)
>
>   print("  Output image = "+output_png)
>
>
>
> ;---Read temperature at first time step
>
>   tc = wrf_user_getvar(a,"T2",0)
>
>   tc at long_name = "2m Air Temperature"
>
>   tc at units = "C"
>
>   tc=tc-273.15
>
>   wks = gsn_open_wks("png",output_png)
>
>   gsn_define_colormap(wks,"WhiteBlueGreenYellowRed")                ;
> choose colormap
>
> ; gsn_define_colormap(wks,colors)
>
>
>
> ;---Resources for filled contour plot
>
>   res                      = True
>
>
>
>   res at cnFillOn             = True
>
>   res at cnLinesOn            = False
>
>   res at gsnMaximize          = True
>
>
>
>   res at tiMainString         = run_length + " Run (" + year + ") - " +
> run_date + " " + end_time + " UTC"
>
>   res at Footer               = False
>
>   res at FieldTitle           = "2m Air Temperature"
>
>   res at lbTitleOn            = True
>
>   res at lbTitleString        = ""
>
>  res at NoHeaderFooter       = True            ; Switch headers and footers
> off
>
>
>
>   res at cnLevelSelectionMode = "ExplicitLevels"
>
>   res at cnLevels             =
> (/10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25/)
>
> ; res at ContourParameters = (/10,25,1/)      ; Contour levels
>
>
>
>   res at mpLimitMode            = "LatLon"
>
>   res at mpMinLatF              =   35
>
>   res at mpMinLonF              =  -98
>
>   res at mpMaxLatF              =   36
>
>   res at mpMaxLonF              =  -97
>
>
>
>   contour = wrf_contour(a,wks,tc,res)        ; Create contour plot
>
>
>
>   pltres                      = True         ; Basic overlay plot options
>
>   pltres at PanelPlot            = True         ; Tells wrf_map_overlays not
> to remove overlays
>
>
>
>   mpres                       = True         ; Set map options
>
>   mpres at mpOutlineOn           = True         ; Turn on map outlines
>
>   mpres at mpFillOn              = False        ; Turn off map fill
>
>   mpres at mpDataBaseVersion     = "Ncarg4_1"
>
>   mpres at mpDataSetName         = "Earth..2"   ; For counties
>
>   mpres at mpOutlineBoundarySets = "GeophysicalAndUSStates"
>
>   mpres at mpOutlineSpecifiers   = (/"Land", "Oklahoma:counties"/)
>
>   mpres at tiMainString          = run_length + " Run (" + year + ") - " +
> run_date + " " + end_time + " UTC"
>
>   mpres at gsnMaximize           = True
>
>
>
> ;---Create the contours over the WRF map (nothing will be drawn yet).
>
>   plot = wrf_map_overlays(a,wks,contour,pltres,mpres)
>
>
>
> end
>
>
>
> University of Tasmania Electronic Communications Policy (December, 2014).
> This email is confidential, and is for the intended recipient only.
> Access, disclosure, copying, distribution, or reliance on any of it by
> anyone outside the intended recipient organisation is prohibited and may be
> a criminal offence. Please delete if obtained in error and email
> confirmation to the sender. The views expressed in this email are not
> necessarily the views of the University of Tasmania, unless clearly
> intended otherwise.
>
>
> _______________________________________________
> 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/20160421/d208ea11/attachment.html 


More information about the ncl-talk mailing list