Re: PolyMarkers Question

From: Adam Phillips (asphilli AT cgd.ucar.edu)
Date: Mon Apr 25 2005 - 14:57:53 MDT


Hi Sarav,

The question about binning with polymarkers has come up before,
unfortunately there isn't an example of this in the NCL Applications
polygon section, yet. (http://www.ncl.ucar.edu/Applications/polyg.shtml)

Mary Haley had previously written an example that shows how to do this,
I modified it slightly to be more generic. That script is attached here
as markers.ncl. This script will draw markers that have been binned over
a preexisting map. The colormap, the colors to be used, and the setting
of the bins are done at the top of the program under the options section.

You cannot draw a black outline around each marker though (as in your
example). Mary came up with an idea to use gsn_add_polygon to duplicate
that feature. I took the markers.ncl script and modified it so that
polygons are drawn instead of markers, allowing one to use the gsEdge
resources to draw a black boundary around the diamond, and then setting
gsFillColor to color the interior of the polygon. This script is
attached here as polygonfill.ncl, and the resulting plot is attached as
polygonfill.jpg.

Let me know if you see any problems with the scripts, I believe these
two will be likely added to the ncl webpage soon...

Adam

Saravanan Arunachalam wrote:
> Hi,
>
> Can one enable coloring of polymarkers with NCL, just like you would for
> contouring, i.e. different colors for chosen bins. I looked through the
> documentation section of polymarkers, but didnt find this capability.
>
> Please see a plot at the link below, that was produced from a different
> software. The diamonds on these plots indicate not only the locations of
> observed stations, but also the magnitude of the observed values, i.e.
> the diamonds are colored using the same color-bin that are used for the
> tile-plot (represents the modeled data).
>
> ftp://ftp.unc.edu/pub/empd/sarav/tileplot_obsoverlay.png
>
> This type of plot helps in comparing model predictions compared to
> observations on the same plot.
>
> Thanks.
>
> Sarav Arunachalam
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk@ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli@ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD                                   fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin ;-------Options-------- arr = (/0.,5.,10.,15.,20.,23.,26./) ; bin settings (bin0=<0., bin1=0.:4.999, etc.) colormap = "BlWhRe" ; colormap to use colors = (/10,30,38,48,56,66,74,94/) ; marker colors, dimsizes must be = dimsizes(arr)+1 ;--------------------------- print("Setting up data") npts = 100 ;number of points lat = random_uniform( 25., 50.,npts) ; Create some dummy latitude lon = random_uniform(235.,290.,npts) ; and longitude data that ; will contain the position of ; our markers. R = random_uniform(-1.2,35.,npts) ; This is dummy data for determining ; how to color the markers. ;------------------------------ ; Create X and Y arrays to hold the points for each range and initialize ; them to missing values. We want to use num_distinct_markers ; different colors, so we need num_distinct_markers sets of X and ; Y points. ; num_distinct_markers = dimsizes(arr)+1 ; number of distinct markers lat_new = new((/num_distinct_markers,dimsizes(R)/),float,-999) lon_new = new((/num_distinct_markers,dimsizes(R)/),float,-999) ; ; Group the points according to which range they fall in. ; do i = 0, num_distinct_markers-1 if (i.eq.0) then indexes = ind(R.lt.arr(0)) end if if (i.eq.num_distinct_markers-1) then indexes = ind(R.ge.max(arr)) end if if (i.gt.0.and.i.lt.num_distinct_markers-1) then indexes = ind(R.ge.arr(i-1).and.R.lt.arr(i)) end if if (.not.any(ismissing(indexes))) then npts_range = dimsizes(indexes) ; # of points in this range. lat_new(i,0:npts_range-1) = lat(indexes) lon_new(i,0:npts_range-1) = lon(indexes) end if delete(indexes) ; Necessary b/c "indexes" may be a different size next time. end do ;================================================================================= wks = gsn_open_wks("ps","markers") ; Open a workstation. gsn_define_colormap(wks,colormap) nc1 = NhlNewColor(wks,.8,.8,.8) ; add light gray to colormap, for continents mapres = True mapres@gsnMaximize = True ; Maximize plot in frame. mapres@gsnFrame = False ; Don't advance the frame mapres@mpMinLatF = 25. mapres@mpMaxLatF = 50. mapres@mpMinLonF = 235. mapres@mpMaxLonF = 290. mapres@mpFillColors = (/-1,-1,103,-1/) ;assign light gray to land masses map = gsn_csm_map(wks,mapres) ; ; Create a logical variable to hold the marker resources. These ; markers are different than the XY markers, because they are not ; associated with an XY plot. You can put these markers on any plot. ; gsres = True gsres@gsMarkerIndex = 16 ; ; Loop through each grouping of markers, and draw them one set at ; a time assigning the proper color and size with gsn_marker. ; do i = 0, num_distinct_markers-1 if (.not.ismissing(lat_new(i,0))) gsres@gsMarkerColor = colors(i) gsres@gsMarkerThicknessF = 0.7*(i+1) gsn_polymarker(wks,map,lon_new(i,:),lat_new(i,:),gsres) end if end do frame(wks) ; Advance the frame. end

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin ;-------Options-------- arr = (/0.,5.,10.,15.,20.,25.,30./) ; bin settings (bin0=<0., bin1=0.:4.999, etc.) colormap = "BlWhRe" ; colormap to use colors = (/10,30,38,48,56,66,74,94/) ; marker colors, dimsizes must be = dimsizes(arr)+1 delta = .5 ; degrees of lat/lon from center of diamond->edge ;--------------------------- print("Setting up data") npts = 100 ;number of points lat = random_uniform( 25., 50.,npts) ; Create some dummy latitude lon = random_uniform(235.,290.,npts) ; and longitude data that ; will contain the position of ; our polygons. R = random_uniform(-1.2,35.,npts) ; This is dummy data for determining ; how to color the interior of the polygons. ;------------------------------ ; Create X and Y arrays to hold the points for each range and initialize ; them to missing values. We want to use num_distinct_markers ; different colors, so we need num_distinct_markers sets of X and ; Y points. ; num_distinct_markers = dimsizes(arr)+1 ; number of distinct markers lat_new = new((/num_distinct_markers,dimsizes(R)/),float,-999) lon_new = new((/num_distinct_markers,dimsizes(R)/),float,-999) ; ; Group the points according to which range they fall in. ; do i = 0, num_distinct_markers-1 if (i.eq.0) then indexes = ind(R.lt.arr(0)) end if if (i.eq.num_distinct_markers-1) then indexes = ind(R.ge.max(arr)) end if if (i.gt.0.and.i.lt.num_distinct_markers-1) then indexes = ind(R.ge.arr(i-1).and.R.lt.arr(i)) end if if (.not.any(ismissing(indexes))) then npts_range = dimsizes(indexes) ; # of points in this range. lat_new(i,0:npts_range-1) = lat(indexes) lon_new(i,0:npts_range-1) = lon(indexes) end if delete(indexes) ; Necessary b/c "indexes" may be a different size next time. end do ;================================================================================= wks = gsn_open_wks("ps","polygonfill") ; Open a workstation. gsn_define_colormap(wks,colormap) nc1 = NhlNewColor(wks,.8,.8,.8) ; add light gray to colormap, for continents mapres = True mapres@gsnMaximize = True ; Maximize plot in frame. mapres@gsnFrame = False ; Don't advance the frame mapres@mpMinLatF = 25. mapres@mpMaxLatF = 50. mapres@mpMinLonF = 235. mapres@mpMaxLonF = 290. mapres@gsnDraw = False mapres@mpFillColors = (/-1,-1,103,-1/) ;assign light gray to land masses map = gsn_csm_map(wks,mapres)

polyres = True ; set polygon resources polyres@gsEdgesOn = True polyres@gsEdgeColor = "black" polyres@gsEdgeThicknessF = 5.

lonpt = new(5,float) ; for polygon drawing latpt = new(5,float) ; for polygon drawing dum = new(num(.not.ismissing(ndtooned(lat_new))),graphic) cntr = 0 do gg = 0, num_distinct_markers-1 ; loop over each polygon bin if (.not.ismissing(lat_new(gg,0))) do hh = 0,num(.not.ismissing(lat_new(gg,:)))-1 lonpt(0:4:2) = lon_new(gg,hh) ; set polygon specific coordinates lonpt(1) = lon_new(gg,hh)+delta lonpt(3) = lon_new(gg,hh)-delta latpt(0:4:2) = lat_new(gg,hh)-delta latpt(1:3:2) = lat_new(gg,hh) latpt(2) = lat_new(gg,hh)+delta polyres@gsFillColor = colors(gg) dum(cntr) = gsn_add_polygon(wks,map,lonpt,latpt,polyres) cntr = cntr+1 end do end if end do draw(wks) frame(wks) ; Advance the frame. end


polygonfill.jpg

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



This archive was generated by hypermail 2b29 : Mon Apr 25 2005 - 15:52:21 MDT