[ncl-talk] Overlay a box and a marker over WRF field

Rabah Hachelaf hachelaf at sca.uqam.ca
Wed May 27 20:01:49 MDT 2015


Thanks Mary,

It works.

Rabah

2015-05-27 14:49 GMT-04:00 Mary Haley <haley at ucar.edu>:

> ​When you use gsn_add_xxxx versus gsn_xxxxx, then in order to see the
> "added" feature, you must draw the plot object after you've added the
> feature.  I.e.
>
> pid = gsn_add_polymarker(wks,plot,lon,lat,mkres)
> draw(plot)
> frame(wks)
>
> When you just use gsn_polymarker, then the marker is drawn the minute you
> call that procedure, and it is *not* attached to the plot.
>
> --Mary
>>
> On Wed, May 27, 2015 at 11:26 AM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
> wrote:
>
>> But without the dot marker in the center of the domain !!!
>>
>> 2015-05-27 13:22 GMT-04:00 Rabah Hachelaf <hachelaf at sca.uqam.ca>:
>>
>> Thanks Rick and others,
>>>
>>> It works now.
>>>
>>>
>>> Rabah
>>>
>>> 2015-05-27 13:06 GMT-04:00 Rick Brownrigg <brownrig at ucar.edu>:
>>>
>>> Hi,
>>>>
>>>> If you set the resources as recommended by Karin (which you have not
>>>> done in your attached script), and you use gsn_add_polymarker() rather than
>>>> gsn_polymarker(), you'll get what you are after.  Note that
>>>> gsn_add_polymarker, like gsn_add_polyline, is a function, not a procedure,
>>>> so you must assign the return value to some (arbitrary) variable.
>>>>
>>>> Rick
>>>>
>>>>
>>>> On Wed, May 27, 2015 at 9:27 AM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
>>>> wrote:
>>>>
>>>>> @ Katin,
>>>>>
>>>>> Thanks for your replay, but your suggestion does'nt change any things.
>>>>> @ Alex,
>>>>>
>>>>> Attached you find my geo_em, namelist.wps and the ncl script that i
>>>>> use.
>>>>>
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Rabah
>>>>>
>>>>> 2015-05-27 6:47 GMT-04:00 Karin Meier-Fleischer <
>>>>> meier-fleischer at dkrz.de>:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> take a look at the web page
>>>>>> https://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_map_overlays.shtml
>>>>>>
>>>>>> —>
>>>>>>
>>>>>> If you want to use gsn_add_poly*xxxx* routines (like
>>>>>> *gsn_add_polymarker*
>>>>>> <https://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_polymarker.shtml>)
>>>>>> to add primtives to a WRF plot, then you need to set:
>>>>>>
>>>>>> plt_res at PanelPlot = True
>>>>>> plt_res at FramePlot = False
>>>>>>
>>>>>> *before* you call *wrf_map_overlays*. Then, call the appropriate
>>>>>> gsn_add_poly*xxxx* routine to attach the desired primitives, and
>>>>>> finally call *draw*
>>>>>> <https://www.ncl.ucar.edu/Document/Functions/Built-in/draw.shtml>(plot)
>>>>>> and *frame*
>>>>>> <https://www.ncl.ucar.edu/Document/Functions/Built-in/frame.shtml>(wks)
>>>>>> to draw the plot with the attached primitives and advance the frame.
>>>>>>
>>>>>> Bye,
>>>>>> Karin
>>>>>>
>>>>>>
>>>>>>
>>>>>> Am 27.05.2015 um 05:51 schrieb Alex Schaefer <
>>>>>> alexander.schaefer at mines.sdsmt.edu>:
>>>>>>
>>>>>> Rabah,
>>>>>>
>>>>>> So if you don’t put them both both res and pltres you still end up
>>>>>> with 2 plots?
>>>>>>
>>>>>> It might also be worth trying to use the gsn_add_polymarker as
>>>>>> opposed to using the gsn-polymarker. gsn_polymarker might have the frame
>>>>>> internally built. The gsn_add_polymarker does return an identifier so you
>>>>>> would do it similar to your polyline call:
>>>>>>
>>>>>> pm_id = gsn_add_polymarker(wks,plot,npres at ref_lon,npres at ref_lat
>>>>>> ,mpres)
>>>>>>
>>>>>> If this doesn’t work can you attach your geo_em file and script and I
>>>>>> will see if I can see what is going on.
>>>>>>
>>>>>> -Alex
>>>>>>
>>>>>>
>>>>>>
>>>>>> On May 26, 2015, at 7:06 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
>>>>>> wrote:
>>>>>>
>>>>>> Hi Alex ,
>>>>>>
>>>>>> When i add
>>>>>>  opts at gsnDraw = False
>>>>>>  opts at gsnFrame = False
>>>>>>  or
>>>>>>  res at gsnDraw = False
>>>>>>  res at gsnFrame = False
>>>>>>
>>>>>> and also
>>>>>>
>>>>>>  pltres at gsnDraw = False
>>>>>>  pltres at gsnFrame = False
>>>>>>
>>>>>> I get only grid with the box and the marker like attached.
>>>>>>
>>>>>>
>>>>>>
>>>>>> 2015-05-26 20:47 GMT-04:00 Alex Schaefer <
>>>>>> alexander.schaefer at mines.sdsmt.edu>:
>>>>>>
>>>>>>> Rabah,
>>>>>>>
>>>>>>> Where in your script did you add the resources suggested by Jared?
>>>>>>>
>>>>>>> Since you have a bunch of different resource objects you will need
>>>>>>> to set it in each going into plots controlling plot resources. For you this
>>>>>>> should include res or opts and likely pltres.
>>>>>>>
>>>>>>> -Alex
>>>>>>>
>>>>>>>
>>>>>>> On May 26, 2015, at 6:36 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Jared,
>>>>>>>
>>>>>>> Thanks for your reponse,
>>>>>>>
>>>>>>> But add
>>>>>>>
>>>>>>>
>>>>>>> res at gsnDraw = False
>>>>>>> res at gsnFrame = False
>>>>>>>
>>>>>>> doesn't change any things.
>>>>>>>
>>>>>>> Rabah
>>>>>>>
>>>>>>>
>>>>>>> 2015-05-26 18:34 GMT-04:00 Jared Lee <jaredlee at ucar.edu>:
>>>>>>>
>>>>>>>> Hi Rabah,
>>>>>>>>
>>>>>>>> I believe what you're missing is these two lines where you set
>>>>>>>> other 'res' resources:
>>>>>>>>
>>>>>>>> res at gsnDraw = False
>>>>>>>> res at gsnFrame = False
>>>>>>>>
>>>>>>>> By default they're both set to True, which would give you two
>>>>>>>> separate images. If you set both to false you should get a single plot with
>>>>>>>> your polymarker overlaid.
>>>>>>>>
>>>>>>>> Hope that helps.
>>>>>>>>
>>>>>>>> Jared
>>>>>>>>
>>>>>>>> On Tue, May 26, 2015 at 4:21 PM, Rabah Hachelaf <
>>>>>>>> hachelaf at sca.uqam.ca> wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hello NCL users,
>>>>>>>>>
>>>>>>>>> I am using the script below to plot a box and a marker dot over
>>>>>>>>> topography field from WRF outputs,
>>>>>>>>>
>>>>>>>>> My problem is i can not get one figure, i get two separate figures
>>>>>>>>> like attached.
>>>>>>>>>
>>>>>>>>> Any suggestion to solve this.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ;   Example script - plot terrain (using some basic WRF scripts)
>>>>>>>>> ;   Overwrite basic map background settings
>>>>>>>>> ;   November 2008
>>>>>>>>>
>>>>>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>>>>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>>>>>>>>>
>>>>>>>>> begin
>>>>>>>>>
>>>>>>>>>   a = addfile("../geo_em.d02.nc","r")           ; Open a file
>>>>>>>>>   filename = "../namelist.wps"
>>>>>>>>>
>>>>>>>>>   npres= True
>>>>>>>>>   npres at ref_lat   = stringtofloat(systemfunc("grep ref_lat    "
>>>>>>>>> +filename+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
>>>>>>>>>   npres at ref_lon   = stringtofloat(systemfunc("grep ref_lon    "
>>>>>>>>> +filename+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
>>>>>>>>>
>>>>>>>>>  type = "png"
>>>>>>>>>   wks = gsn_open_wks(type,"plt_geo_6")         ; Create a plot
>>>>>>>>> workstation
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>   opts = True                                  ; Set some Basic
>>>>>>>>> Plot options
>>>>>>>>>   opts at MainTitle = "GEOGRID FIELDS"
>>>>>>>>>   opts at InitTime = False                        ; Do not plot time
>>>>>>>>> or footers
>>>>>>>>>   opts at Footer = False
>>>>>>>>>
>>>>>>>>>   ter = wrf_user_getvar(a,"HGT_M",0)           ; Read the variable
>>>>>>>>> to memory
>>>>>>>>>   lon = a->XLONG_U(0,:,:)
>>>>>>>>>   lat = a->XLAT_U(0,:,:)
>>>>>>>>>  printVarSummary(lat)
>>>>>>>>>
>>>>>>>>>  print (lat(0,0)+", "+lon(0,0)+",0,")
>>>>>>>>>  print (lat(0,60)+", "+lon(0,60)+",0,")
>>>>>>>>>  print (lat(59,60)+", "+lon(59,60)+",0,")
>>>>>>>>>  print (lat(59,0)+", "+lon(59,0)+",0")
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>   res = opts                                   ; Use basic options
>>>>>>>>> for this field
>>>>>>>>>   res at cnFillOn = True                          ; Create a color
>>>>>>>>> fill plot
>>>>>>>>>   res at ContourParameters = (/ 0., 1000., 50. /) ; Set the levels
>>>>>>>>>
>>>>>>>>>   contour = wrf_contour(a,wks,ter,res)
>>>>>>>>>
>>>>>>>>>   pltres = True                                ; Set plot options
>>>>>>>>>   mpres = True                                 ; Set map options
>>>>>>>>>   mpres at mpGeophysicalLineColor      = "Black"  ; Overwrite basic
>>>>>>>>> map settings
>>>>>>>>>   mpres at mpGridLineColor             = "Black"
>>>>>>>>>   mpres at mpLimbLineColor             = "Black"
>>>>>>>>>   mpres at mpNationalLineColor         = "Black"
>>>>>>>>>   mpres at mpPerimLineColor            = "Black"
>>>>>>>>>   mpres at mpUSStateLineColor          = "Black"
>>>>>>>>>      mpres at mpProjection = "LambertConformal"
>>>>>>>>>        mpres at mpLambertParallel1F = 30
>>>>>>>>>        mpres at mpLambertParallel2F = 60
>>>>>>>>>        mpres at mpLambertMeridianF = -98
>>>>>>>>>        mpres at mpGridSpacingF     = 0.25
>>>>>>>>> ;************************************************
>>>>>>>>> ; add the box
>>>>>>>>> ;************************************************
>>>>>>>>> ;************************************************
>>>>>>>>>  ypts = (/ lat(10,10), lat(10,50), lat(49,50),  lat(49,10),
>>>>>>>>>  lat(10,10)/)
>>>>>>>>>  xpts = (/ lon(10,10), lon(10,50), lon(49,50),  lon(49,10),
>>>>>>>>>  lon(10,10)/)
>>>>>>>>> ;************************************************
>>>>>>>>>
>>>>>>>>>   resp                  = True                      ; polyline
>>>>>>>>> mods desired
>>>>>>>>>   resp at gsLineColor      = "black"                     ; color of
>>>>>>>>> lines
>>>>>>>>>   resp at gsLineThicknessF = 2.0                       ; thickness
>>>>>>>>> of lines
>>>>>>>>> ;  resp at gsLineLabelString= "test"                    ; adds a
>>>>>>>>> line label string
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>   plot = wrf_map_overlays(a,wks,(/contour/),pltres,mpres) ; Plot
>>>>>>>>> field over map background
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>   dum = new(4,graphic)
>>>>>>>>>   do i = 0 , 3
>>>>>>>>>     dum(i)=gsn_add_polyline(wks,plot,xpts(i:i+1),ypts(i:i+1),resp)
>>>>>>>>>
>>>>>>>>>   end do
>>>>>>>>> ;*********************************************************
>>>>>>>>>   mpres at gsMarkerColor = "Black"
>>>>>>>>>   mpres at gsMarkerIndex = 16
>>>>>>>>>   mpres at gsMarkerSizeF = 0.005
>>>>>>>>>   gsn_polymarker(wks,plot,npres at ref_lon,npres at ref_lat,mpres)
>>>>>>>>>
>>>>>>>>>   draw(plot)
>>>>>>>>>   frame(wks)
>>>>>>>>>
>>>>>>>>> end
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> ------------------------------
>>>>>>>>> Cordialement,
>>>>>>>>> Best regards,
>>>>>>>>> Rabah Hachelaf
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> ncl-talk mailing list
>>>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> ===============================
>>>>>>>> Jared A. Lee, Ph.D.
>>>>>>>> Project Scientist I
>>>>>>>> Research Applications Laboratory
>>>>>>>> National Center for Atmospheric Research
>>>>>>>> Boulder, Colorado, USA
>>>>>>>>
>>>>>>>> Email: jaredlee at ucar.edu (w)
>>>>>>>> Phone: 303.497.8485 (w)
>>>>>>>> Web: https://staff.ucar.edu/users/jaredlee
>>>>>>>> ===============================
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> ncl-talk mailing list
>>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> ------------------------------
>>>>>>> Cordialement,
>>>>>>> Best regards,
>>>>>>> Rabah Hachelaf
>>>>>>>  _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> ------------------------------
>>>>> Cordialement,
>>>>> Best regards,
>>>>> Rabah Hachelaf
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> ------------------------------
>>> Cordialement,
>>> Best regards,
>>> Rabah Hachelaf
>>>
>>
>>
>>
>> --
>> ------------------------------
>> Cordialement,
>> Best regards,
>> Rabah Hachelaf
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>


-- 
------------------------------
Cordialement,
Best regards,
Rabah Hachelaf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150527/a25b7516/attachment.html 


More information about the ncl-talk mailing list