Why I can not get the correct marker sizes?

From: xiang lin <leo.aries.g_at_nyahnyahspammersnyahnyah>
Date: Sun Aug 19 2012 - 01:15:46 MDT

Hi, all

       I made a classified post map using NCL, Here below is my scripts (
derived from the example in the
http://ncl.ucar.edu/Applications/Scripts/polyg_8.ncl).

I can not get the correct gsmarker sizes as described in the scripts (as
seen in the attached ps file). Anyone can give me some instruction? Thank!

; *****************************************************
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"

begin

data_path = "/data1/Antarctic_Data/Antarctic_station.temp_1979-2011/"

sta_name =
(/"Amundsen_Scott","Bellingshausen","Casey","Davis","Dumont_Durville","Faraday_Vernadsky","Halley","Mawson","Mirny","Neumayer_1982-2011","Novolazarevskaya",\
            "Orcadas","Rothera","Scott_Base","Syowa"/)

; ****************** read the AAO index series
********************************************
data =
 asciiread("/data1/Antarctic_Data/AAO_monthly_197901-201112.txt",(/33*12,3/),"float")
vars = (/"DJF","MAM","JJA","SON","ANN"/)
xx = data(:,2)
xx!0 = "time"
xx&time= fspan(1979.08,2012.,33*12)

y = new((/5,33/),"float")
y(4,:) = month_to_annual(xx,1)
y(0,:) = month_to_season(xx,"DJF")
y(1,:) = month_to_season(xx,"MAM")
y(2,:) = month_to_season(xx,"JJA")
y(3,:) = month_to_season(xx,"SON")
printVarSummary(y)
y!0 = "nvars"
delete(data)

; calculate the correlation
ccr = new((/14,5/),"float")
do i = 0,13

   data_filename = data_path + sta_name(i) + ".txt"
   print(" " + data_filename)

   data = asciiread(data_filename, (/33,14/),"float")
   x = data(:,1:12)
   xy = ndtooned(x)
   xy!0 = "time"
   z = new((/5,33/),"float")
   z(4,:) = data(:,13)
   z(0,:) = month_to_season(xy,"DJF")
   z(1,:) = month_to_season(xy,"MAM")
   z(2,:) = month_to_season(xy,"JJA")
   z(3,:) = month_to_season(xy,"SON")

   ccr(i,:) = escorc(y,z)

end do

opt = True
opt@fout = "Corr_AAO.vs.stationTemp.dat"
ftmx = "5f8.3"
write_matrix(ccr, ftmx, opt)

; plot ********************************

; -------Options--------

  arr = (/-0.45,-0.35,0.,0.35,0.45/) ; bin settings (bin0 = < 0.,
                                         ; bin1 = 0.:4.999, etc.)
  colors = (/"blue","blue","blue","red","red","red"/) ; marker colors,
dimsizes must
                                        ; be equal to dimsizes(arr)+1
* sizes = (/3,2,1,1,2,3/)*0.006*
  labels = new(dimsizes(arr)+1,string) ; Labels for legend.

  npts = 14
  lat = asciiread("14stations_lat.txt",-1,"float")
  lon = asciiread("14stations_lon.txt",-1,"float")
  data1 = asciiread("Corr_AAO.vs.stationTemp.dat",(/14,5/),"float")
  R = data1(:,1)
  season = "MAM"

; ------------------------------
; 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. At the
; same time, create the label that we will use later in the legend.
;
  do i = 0, num_distinct_markers-1
    if (i.eq.0) then
      indexes = ind(R.lt.arr(0))
      labels(i) = "x < " + arr(0)
    end if
    if (i.eq.num_distinct_markers-1) then
      indexes = ind(R.ge.max(arr))
      labels(i) = "x >= " + 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))
      labels(i) = arr(i-1) + " <= x < " + arr(i)
    end if
;
; Now that we have the set of indexes whose values fall within
; the given range, take the corresponding lat/lon values and store
; them, so later we can color this set of markers with the appropriate
; color.
;
    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

;===========================================================================
; Begin plotting section.
;
  wks = gsn_open_wks("eps","Corr_AAO.vs.Antarctic.StationTemp_" + season )
    ; Open a workstation and
  gsn_define_colormap(wks,"WhViBlGrYeOrRe") ; define a different
colormap.

  nc1 = NhlNewColor(wks,.8,.8,.8) ; Add light gray to colormap,
                                         ; for continents.
;
; Set up some map resources
;
  mpres = True
  mpres@gsnMaximize = True ; Maximize plot in frame.
  mpres@gsnFrame = False ; Don't advance the frame
;
; Zoom in on United States.
;
 ; mpres@mpMinLatF = 25.
 ; mpres@mpMaxLatF = 50.
 ; mpres@mpMinLonF = 235.
 ; mpres@mpMaxLonF = 290.

  mpres@gsnPolar = "SH"
  mpres@mpMaxLatF = -50

; mpres@mpFillColors = (/-1,-1,nc1,-1/) ;assign light gray to land masses

; mpres@tiMainString = "Dummy station data colored and~C~sized according to
range of values"
  mpres@tiMainString = "Correlation: AAO vs Temperature (" + season + ")"
   map = gsn_csm_map(wks,mpres)

; Create logical variables to hold the marker and text 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 ; Use filled dots for markers.

  txres = True
  txres@txFontHeightF = 0.015

;
; Loop through each grouping of markers, and draw them one set at
; a time, assigning the proper color and size with gsn_marker.
;
; At the same time, draw a legend showing the meaning of the markers.
;

  xleg = (/0.07,0.07,0.32,0.32,0.57,0.57,0.82,0.82/) ; Location of
  xtxt = (/0.16,0.16,0.44,0.44,0.66,0.66,0.91,0.91/) ; legend markers
  yleg = (/0.22,0.17,0.22,0.17,0.22,0.17,0.22,0.17/) - 0.03 ; and text
  ytxt = (/0.22,0.17,0.22,0.17,0.22,0.17,0.22,0.17/) - 0.03 ; strings.

  do i = 0, num_distinct_markers-1
      print(" " + lat_new(i,0))
      if (.not.ismissing(lat_new(i,0)))
      gsres@gsMarkerColor = colors(i)
* gsres@gsMarkerSizeF = sizes(i)*
      gsn_polymarker(wks,map,lon_new(i,:),lat_new(i,:),gsres)
      end if
; Add marker and text for the legend.
;
      gsn_polymarker_ndc(wks, xleg(i),yleg(i),gsres)
      gsn_text_ndc (wks,labels(i),xtxt(i),ytxt(i),txres)
    ; end if
  end do

  frame(wks) ; Advance the frame.

end

Leo

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

Received on Sun Aug 19 01:16:00 2012

This archive was generated by hypermail 2.1.8 : Thu Aug 23 2012 - 16:16:15 MDT