[ncl-talk] Fw: map tickmarks

Chathurika chatu at scsio.ac.cn
Sun Mar 8 23:43:36 MDT 2020




-----Original Messages-----
From:Chathurika <chatu at scsio.ac.cn>
Sent Time:2020-03-09 13:40:37 (Monday)
To: ncl-talk at ucar.edu
Cc:
Subject: map tickmarks


Hello,


I draw the map in southern part of Sri Lanka. But tickmarks are wrong. It displays .3 instead .5. The drew map and code are attached herewith. Please help me to overcome this issue. 


Best Regards,
Chathu


;load "$NCARG_ROOT/lib/ncarg/database/rangs"


undef("add_map_tickmarks2")
function add_map_tickmarks2(wks,plot,res)
local res2, bres, vpx, vpy, vpw, vph, xndc, yndc, npts, n, j, nlat, \
nlon, delta, bot_lon, top_lon, lft_lat, rgt_lat, xblabels, xbvalues, \
xtlabels, xtvalues, yllabels, ylvalues, yrlabels, yrvalues, xfix, \
xlat, xlon, yfix, annoid, anno_str
begin
;---Make a copy of the original resource list.
  res2 = res


;---Retrieve edges of plot in NDC space.
  getvalues plot
     "vpXF"      :  vpx
     "vpYF"      :  vpy
     "vpWidthF"  :  vpw
     "vpHeightF" :  vph
  end getvalues


;---Turn off tickmarks associated with map. We want to add our own.
  setvalues plot
    "pmTickMarkDisplayMode" : "Never"
  end setvalues


;---Initialize resources for tickmark plot. User shouldn't change these.
  bres                          = True
  bres at vpXF                     = vpx
  bres at vpYF                     = vpy
  bres at vpWidthF                 = vpw
  bres at vpHeightF                = vph
  bres at trXMinF                  = vpx
  bres at trXMaxF                  = vpx + vpw
  bres at trYMinF                  = vpy - vph
  bres at trYMaxF                  = vpy
  bres at tmEqualizeXYSizes        = True


;---This resource the user can change in main code if desired.
  bres at gsnTickMarksPointOutward = get_res_value(res2,"gsnTickMarksPointOutward",True)


;
; NDC Points to scan on X and Y axes. These arrays will be used to
; find the closest NDC pair that gets us close to the location where
; we want a tickmark.
;
  npts = 100000   ; Increase to get closer match for tickmarks
  xndc = fspan(vpx,vpx+vpw,npts)
  yndc = fspan(vpy-vph,vpy,npts)


  n    = dimsizes(yndc) 
  xfix = new(n,float)
  yfix = new(n,float)
  xlon = new(n,float)
  xlat = new(n,float)
  delta = 0.001


;---Left axis tickmarks
  if(isatt(res2,"tmYLValues")) then
    lft_lat    = get_res_value(res2,"tmYLValues",-1)
    nlat       = dimsizes(lft_lat)
    ylvalues = new(nlat,float)
    yllabels = new(nlat,string)
    xfix  = vpx + 0.0001 ; Just a smidge into the plot to make sure we don't
                         ; get missing values returned.
;
; Loop across each left latitude value that we want a tickmark for,
; and try to find the closest X,Y NDC coordinate pair along this axis.
;
    NhlNDCToData(plot,xfix,yndc,xlon,xlat)
    do j=0,dimsizes(lft_lat)-1
      NhlNDCToData(plot,xfix,yndc,xlon,xlat)
      ii = minind(fabs(xlat-lft_lat(j)))
      if(.not.any(ismissing(ii)).and.fabs(xlat(ii)-lft_lat(j)).le.delta)
        yllabels(j) = fabs(lft_lat(j)) + ""
        ylvalues(j) = yndc(ii(0))
        if(lft_lat(j).lt.0) then
          yllabels(j) = yllabels(j) + "~S~o~N~S"
        end if
        if(lft_lat(j).gt.0) then
          yllabels(j) = yllabels(j) + "~S~o~N~N"
        end if
      end if
      delete(ii)
    end do
    bres at tmYLMode   = "Explicit"
    bres at tmYLValues = ylvalues
    bres at tmYLLabels = get_res_value(res2,"tmYLLabels",yllabels)
  else
    bres at tmYLOn       = False
    bres at tmYLLabelsOn = False
  end if


;---Right axis tickmarks
  if(isatt(res2,"tmYRValues")) then
    rgt_lat    = get_res_value(res2,"tmYRValues",-1)
    nlat       = dimsizes(rgt_lat)
    yrvalues = new(nlat,float)
    yrlabels = new(nlat,string)


    xfix  = vpx + vpw - 0.0001 ; Just a smidge into the plot to make sure we don't
                               ; get missing values returned.
;
; Loop across each right latitude value that we want a tickmark for,
; and try to find the closest X,Y NDC coordinate pair along this axis.
;
    do j=0,dimsizes(rgt_lat)-1
      NhlNDCToData(plot,xfix,yndc,xlon,xlat)
      ii = minind(fabs(xlat-rgt_lat(j)))
      if(.not.any(ismissing(ii)).and.fabs(xlat(ii)-rgt_lat(j)).le.delta)
        yrlabels(j) = fabs(rgt_lat(j)) + ""
        yrvalues(j) = yndc(ii(0))
        if(rgt_lat(j).lt.0) then
          yrlabels(j) = yrlabels(j) + "~S~o~N~S"
        end if
        if(rgt_lat(j).gt.0) then
          yrlabels(j) = yrlabels(j) + "~S~o~N~N"
        end if
      end if
      delete(ii)
    end do
    bres at tmYROn       = True
    bres at tmYRLabelsOn = True
    bres at tmYUseLeft   = False
    bres at tmYRMode     = "Explicit"
    bres at tmYRValues   = yrvalues
    bres at tmYRLabels   = get_res_value(res2,"tmYRLabels",yrlabels)
  else
    bres at tmYUseLeft   = False
    bres at tmYROn       = False
    bres at tmYRLabelsOn = False
  end if


;---Top axis tickmarks
  if(isatt(res2,"tmXTValues")) then
    top_lon    = get_res_value(res2,"tmXTValues",-1)
    nlon       = dimsizes(top_lon)
    xtvalues = new(nlon,float)
    xtlabels = new(nlon,string)


    yfix  = vpy - 0.0001 ; Just a smidge into the plot to make sure we don't
                         ; get missing values returned.
;
; Loop across each top longitude value that we want a tickmark for,
; and try to find the closest X,Y NDC coordinate pair along this axis.
;
    do j=0,dimsizes(top_lon)-1
      NhlNDCToData(plot,xndc,yfix,xlon,xlat)
      ii = minind(fabs(xlon-top_lon(j)))
      if(.not.any(ismissing(ii)).and.fabs(xlon(ii)-top_lon(j)).le.delta)
        xtlabels(j) = fabs(top_lon(j)) + ""
        xtvalues(j) = xndc(ii(0))
        if(top_lon(j).lt.0) then
          xtlabels(j) = xtlabels(j) + "~S~o~N~W"
        end if
        if(top_lon(j).gt.0) then
          xtlabels(j) = xtlabels(j) + "~S~o~N~E"
        end if
      end if
      delete(ii)
    end do
    bres at tmXTOn       = True
    bres at tmXTLabelsOn = True
    bres at tmXUseBottom = False
    bres at tmXTMode     = "Explicit"
    bres at tmXTValues   = xtvalues
    bres at tmXTLabels   = get_res_value(res2,"tmXTLabels",xtlabels)
  else
    bres at tmXUseBottom = False
    bres at tmXTOn       = False
    bres at tmXTLabelsOn = False
  end if


;---Bottom axis tickmarks
  if(isatt(res2,"tmXBValues")) then
    bot_lon    = get_res_value(res2,"tmXBValues",-1)
    nlon       = dimsizes(bot_lon)
    xbvalues = new(nlon,float)
    xblabels = new(nlon,string)


    yfix  = vpy-vph + 0.0001 ; Just a smidge into the plot to make sure 
                             ; we don't get missing values returned.
;
; Loop across each bottom longitude value that we want a tickmark for,
; and try to find the closest X,Y NDC coordinate pair along this axis.
;
    do j=0,dimsizes(bot_lon)-1
      NhlNDCToData(plot,xndc,yfix,xlon,xlat)
      ii = minind(fabs(xlon-bot_lon(j)))
      if(.not.any(ismissing(ii)).and.fabs(xlon(ii)-bot_lon(j)).le.delta)
        xblabels(j) = fabs(bot_lon(j)) + ""
        xbvalues(j) = xndc(ii(0))
        if(bot_lon(j).lt.0) then
          xblabels(j) = xblabels(j) + "~S~o~N~W"
        end if
        if(bot_lon(j).gt.0) then
          xblabels(j) = xblabels(j) + "~S~o~N~E"
        end if
      end if
      delete(ii)
    end do
    bres at tmXBMode   = "Explicit"
    bres at tmXBValues = xbvalues
    bres at tmXBLabels = get_res_value(res2,"tmXBLabels",xblabels)
  else
    bres at tmXBOn       = False
    bres at tmXBLabelsOn = False
  end if


;
; Now that we are done figuring out where to put tickmarks, and
; what labels to use, get any "tm" resources that might have been
; set by the user, and create a blank plot with thes new tickmarks.
;


;---Get rest of user resources that were set with "tm".
  bres = get_res_eq(res2,"tm")


  bres = True   ; Above call will set bres to True if no "tm" resources, so
                ; make sure it is True still.


  bres at gsnDraw  = False
  bres at gsnFrame = False


;
; Create blank plot with new tickmarks (don't use gsn_csm_blank_plot, 
; because it wants to scale the size of your X and Y axes.)
;
  blank  = gsn_blank_plot(wks,bres)


;
; Attach new tickmarks to original plot. This will allow resizing
; if desired. The default is to attach one plot to the center of
; the other one. These two plots are already the same size.
;
  annoid = gsn_add_annotation(plot,blank,False)


;
; Be sure to return the annotation id, otherwise the
; tickmarks will disappear.
;
  anno_str = unique_string("annoid")
  plot@$anno_str$ = annoid


  return(plot)
end


;;;;........................................




begin


 setfileoption("nc", "MissingToFillValue", False)


fY=addfile("bathy_indianO.nc","r")
vNames = getfilevarnames (fY)
print(vNames)




topo=fY->TOPO2(0,{4:11},{76:86})


printVarSummary(topo)




f1 = addfile("UV_hr_mean-150-02.nc", "r")
Vn1 = getfilevarnames(f1)
print(Vn1)


zonal =f1->zonal(:,1)
printVarSummary(zonal)


depth=f1->lev
print(depth)




merid =f1->merid(:,1)


printVarSummary(merid)
latitude =f1->lat
print(latitude)


printVarSummary(latitude)
longitude =f1->lon
print(longitude)
printVarSummary(longitude)




f2 = addfile("UV_hr_mean-150-05.nc", "r")
Vn2 = getfilevarnames(f2)
print(Vn2)


east =f2->zonal(:,1)




printVarSummary(east)
north =f2->merid(:,1)


printVarSummary(north)
lat =f2->lat
print(lat)


printVarSummary(lat)


lon =f2->lon
print(lon)
printVarSummary(lon)


f3 = addfile("UV_hr_mean-75-05.nc", "r")
Vn3 = getfilevarnames(f2)
print(Vn3)


east3 =f3->zonal(:,1)




printVarSummary(east3)
north3 =f3->merid(:,1)


printVarSummary(north3)
lat3 =f3->lat


printVarSummary(lat)
lon3 =f3->lon


printVarSummary(lon3)




print(lon3(99))
print(lat3(99))




wks=gsn_open_wks("png", "chathu-150")


res=True
res at gsnMaximize=True
res at vpWidthF=2.5
res at vpHeightF=2


res at gsnDraw=False
res at gsnFrame=False




res at tiMainString=""
res at gsnLeftString=""




res at cnFillOn=True
res at cnFillPalette="MPL_terrain"
res at cnLinesOn=True
res at cnInfoLabelOn=False
res at cnLineLabelsOn=True
res at cnLineLabelPlacementMode="constant"
res at cnConstFLabelFontHeightF=0.005


res at tmXBLabelJust="CenterCenter"
res at tmXBLabelAngleF=0.
res at lbLabelBarOn = False




res at gsnAddCyclic=False




res at pmTickMarkDisplayMode = "Always"






res at mpPerimOn=False
res at mpGridAndLimbOn        = False 






res at mpOutlineOn= True
  res at mpOutlineBoundarySets       = "NoBoundaries"   ; turn on country boundaries
  res at mpOutlineSpecifiers      = (/"Continents"/)


  res at mpGeophysicalLineColor      = "Black"       ; color of cont. outlines
  res at mpGeophysicalLineThicknessF = 2.5          ; thickness of outlines




res at mpFillDrawOrder="Draw"
res at mpLimitMode="Corners"
res at mpLeftCornerLatF=5
res at mpRightCornerLatF=8
res at mpLeftCornerLonF=79
res at mpRightCornerLonF=83


res at mpProjection="Mercator"




  
res at mpDataSetName = "Earth..4"                 ; choose most recent boundaries
res at mpDataBaseVersion     = "HighRes"


res at mpGeophysicalLineThicknessF= 2.5
res at mpNationalLineThicknessF= 2.5 
delete(res at mpOutlineSpecifiers)
 res at mpOutlineSpecifiers = (/"Sri Lanka (Ceylon)"/)






plot=gsn_csm_contour_map(wks, topo, res)


txres=True
txres at txFontHeightF=0.012
txres at txFont="helvetica-bold"
txres at txJust="TopLeft"


chres = True
  chres at gsMarkerIndex=1
  chres at gsMarkerSizeF=0.08
  chres at gsMarkerColor="salmon"
chres at tfPolyDrawOrder = "PostDraw"
  chres at gsLineColor="salmon"
  chres at gsLineThicknessF=9.0
  chres at gsFillColor="black"




plres = True
  plres at gsMarkerIndex=1
  plres at gsMarkerSizeF=0.08
  plres at gsMarkerColor="red"
plres at tfPolyDrawOrder = "PostDraw"
  plres at gsLineColor="red"
  plres at gsLineThicknessF=9.0
  plres at gsFillColor="black"


dum6 = gsn_add_polyline(wks, plot, lon3, lat3, chres)
dum2 = gsn_add_polyline(wks, plot, longitude, latitude, plres)
dum3 = gsn_add_polyline(wks, plot, lon, lat, plres)




  mkres               = True
  mkres at gsMarkerIndex = 16     ; Filled circle
  mkres at gsMarkerSizeF = 0.025
  mkres at gsMarkerColor  = "turquoise1"
dum4 = gsn_add_polymarker(wks, plot, longitude(0), latitude(0) ,mkres)
  mres               = True
  mres at gsMarkerIndex = 16     ; Filled circle
  mres at gsMarkerSizeF = 0.025
  mres at gsMarkerColor  = "yellow"
  mres at tfPolyDrawOrder = "PostDraw"
dum5 = gsn_add_polymarker(wks, plot, lon(41), lat(41), mres)


  cres               = True
  cres at gsMarkerIndex = 16     ; Filled circle
  cres at gsMarkerSizeF = 0.025
  cres at gsMarkerColor  = "seagreen1"
  cres at tfPolyDrawOrder = "PostDraw"
dum7 = gsn_add_polymarker(wks, plot, lon3(99), lat3(99), cres)


cres=True
cres at txFontColor="black"
cres at txFontThicknessF=0.6
cres at txFontHeightF=0.025




sl=gsn_add_text(wks, plot, "Sri Lanka", 81.2, 7.3, cres)


in=gsn_add_text(wks, plot, "Indian Ocean", 82.3, 5.25, cres)


draw(plot)
frame(wks)


end










best regards,
Chathu
--


Wickramage Chathurika Hemamali
Msc in Physical Oceanography
State Key Laboratory of Tropical Oceanography
South China Sea Institute of Oceanology
University of Chinese Academy of Science
China


Specialized in Oceanography and Marine Geology (Bachelor)
University of Ruhuna
Matara
Sri Lanka


Email : wickramagechathurika at rocketmail.com
chatu at scsio.ac.cn

--


Wickramage Chathurika Hemamali
Msc in Physical Oceanography
State Key Laboratory of Tropical Oceanography
South China Sea Institute of Oceanology
University of Chinese Academy of Science
China


Specialized in Oceanography and Marine Geology (Bachelor)
University of Ruhuna
Matara
Sri Lanka


Email : wickramagechathurika at rocketmail.com
chatu at scsio.ac.cn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200309/35f9274b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chathu-150.000002.png
Type: image/png
Size: 37953 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200309/35f9274b/attachment.png>


More information about the ncl-talk mailing list