Re: setting major and minor lat/lon spacing

From: Kreienkamp Frank <Frank.Kreienkamp_at_nyahnyahspammersnyahnyah>
Date: Mon Jun 02 2014 - 05:54:29 MDT

Hello Mary,

if have tried your suggestion, but i failed.

As you can see in the attached file i have added the redefinition of the
function add_map_tickmarks. The interesting thing is, that the added
function (incl. the new lines 320 to 327 in the main program) do not
have any impact. Is it possible that i have missed some thing?

All i want to do, is to disable the additional labels due to the small
range (--> degree values only --> no additional minute-values).

I could live with those additional minute-values if those labels would
not change the hole picture. All my:
   amres1@amParallelPosF = -0.73
   amres1@amOrthogonalPosF = 0.88
have a different meaning with and without the additional minute-values
at the thick-marks.

Thanks in advance
Frank

Am Mittwoch, den 28.05.2014, 08:08 -0600 schrieb Mary Haley:
> Hi Frank,
>
> There are two types of map tickmarks that you can get with the gsn_xxxx scripts.
>
> The default map tickmarks, which don't have degree symbols, recognize the resources you're using.
>
> Under the hood, in the gsn_code.ncl script, these map tickmarks are created by hand, because at the time, we had no automatic way to get tickmarks on maps. This is the code that recognizes the gsnMajor/Minor resources,
>
> A few years later Dave created a way to get automatic tickmarks that give you the nice degree symbol. These are the tickmarks that you get when you set:
>
> res@pmTickMarkDisplayMode = "Always"
>
> These tickmarks are actually part of the TickMark object, and are not created by gsn_code.ncl,and hence they don't recognize any of the gsnMajor/Minor resources. These tickmarks are not very customizable unfortunately.
>
> If you want more custom tickmarks, see example mptick_9.ncl at:
>
> http://www.ncl.ucar.edu/Applications/mptick.shtml#ex9
>
> You will need to copy the "add_map_tickmarks" function to the top of your script, and then call it after you create your map, with something like:
>
> res@tmYLValues = ispan(51,53,1) ; this gives you tickmarks and labels at 51, 52, and 53
> res@tmXBValues = ispan(11,15,1) ; 11, 12, 13, 14, 15
>
> ;---Attach the new map tickmarks.
> map = add_map_tickmarks(wks,map,res)
>
>
> You can look at examples mptick_10 and mptick_11 for other methods.
>
> --Mary
>
> On May 27, 2014, at 11:26 PM, Kreienkamp Frank <Frank.Kreienkamp@dwd.de> wrote:
>
> > Hello,
> >
> > i have a map in stereographic projection (see attached png.file). The
> > system is automatically adding a setting for major and minor lat/lon
> > labels.
> >
> > Using the lines:
> > res@gsnMajorLatSpacing = 1
> > res@gsnMinorLatSpacing = 1
> > res@gsnMajorLonSpacing = 1
> > res@gsnMinorLonSpacing = 1
> > i try to change the default setting. Unfortunately i get the following
> > warnings and nothing happens.
> >
> > warning:gsnMajorLatSpacing is not a valid resource in map at this time
> > warning:gsnMajorLonSpacing is not a valid resource in map at this time
> > warning:gsnMinorLatSpacing is not a valid resource in map at this time
> > warning:gsnMinorLonSpacing is not a valid resource in map at this time
> > warning:gsnMajorLatSpacing is not a valid resource in
> > temp-develop_contour at this time
> > warning:gsnMajorLonSpacing is not a valid resource in
> > temp-develop_contour at this time
> > warning:gsnMinorLatSpacing is not a valid resource in
> > temp-develop_contour at this time
> > warning:gsnMinorLonSpacing is not a valid resource in
> > temp-develop_contour at this time
> >
> > What can i do to manually define the lat/lon label spacing? I want to
> > have only full degree labels 52 and 53°N.
> >
> > Thanks in advance
> > Frank
> >
> >
> >
> >
> >
> >
> > --
> > <temp-develop.ncl><temp-develop.png>_______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

 ;*************************************************
 ; NCL Graphics: polar_1.ncl
 ;
 ;************************************************
 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"
 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
 ;************************************************
   ;------------------------------------------------------------------------------
   ; This is a generic function that attaches tickmarks to a rectangular map.
   ;
   ; It allows you to explicitly indicate where you want tickmarks for any
   ; of the four axes.
   ;
   ; Use a separate resource list for this function. Depending on
   ; whether you want to set the bottom, top, left, right tickmarks,
   ; set the corresponding tmXBValues, tmXTValues, tmYLValues, and/or
   ; tmYRValues resources to indicate where you want map tickmarks
   ; and labels.
   ;
   ; You can also set other tm resources, like tmXBLabelFontHeightF,
   ; to control the size of the font.
   ;
   ;------------------------------------------------------------------------------
   undef("add_map_tickmarks")
   function add_map_tickmarks(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@vpXF = vpx
     bres@vpYF = vpy
     bres@vpWidthF = vpw
     bres@vpHeightF = vph
     bres@trXMinF = vpx
     bres@trXMaxF = vpx + vpw
     bres@trYMinF = vpy - vph
     bres@trYMaxF = vpy
     bres@tmEqualizeXYSizes = True
   
   ;---This resource the user can change in main code if desired.
     bres@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@tmYLMode = "Explicit"
       bres@tmYLValues = ylvalues
       bres@tmYLLabels = get_res_value(res2,"tmYLLabels",yllabels)
     else
       bres@tmYLOn = False
       bres@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@tmYROn = True
       bres@tmYRLabelsOn = True
       bres@tmYUseLeft = False
       bres@tmYRMode = "Explicit"
       bres@tmYRValues = yrvalues
       bres@tmYRLabels = get_res_value(res2,"tmYRLabels",yrlabels)
     else
       bres@tmYUseLeft = False
       bres@tmYROn = False
       bres@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@tmXTOn = True
       bres@tmXTLabelsOn = True
       bres@tmXUseBottom = False
       bres@tmXTMode = "Explicit"
       bres@tmXTValues = xtvalues
       bres@tmXTLabels = get_res_value(res2,"tmXTLabels",xtlabels)
     else
       bres@tmXUseBottom = False
       bres@tmXTOn = False
       bres@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@tmXBMode = "Explicit"
       bres@tmXBValues = xbvalues
       bres@tmXBLabels = get_res_value(res2,"tmXBLabels",xblabels)
     else
       bres@tmXBOn = False
       bres@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@gsnDraw = False
     bres@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
   
   ;----------------------------------------------------------------------
   ; MAIN CODE
   ;----------------------------------------------------------------------
 begin
 ;************************************************
 ; read in netCDF file
   a = addfile("temp-develop.nc","r")
   u = a->field(:,:)
   u@lat2d = a->lat(:,:) ; add 2d coordinate data
   u@lon2d = a->lon(:,:) ; add 2d coordinate data
 ;************************************************
 ; create plot
   wtype = "png"
 ;************************************************
 ; Set the pixel size of PNG image.
   wtype@wkWidth = 970
   wtype@wkHeight = 1000
   wks = gsn_open_wks(wtype,"temp-develop")
   res = True
   res@gsnMaximize = True
   res@gsnDraw = False
   res@gsnFrame = False
   res@mpProjection = "Stereographic"
   res@mpCenterLatF = 50 ; Centered over Germany
   res@mpCenterLonF = 10 ; Centered over Germany
   res@mpLimitMode = "Corners" ; choose range of map
   res@mpLeftCornerLatF = 53.7
   res@mpLeftCornerLonF = 11.0
   res@mpRightCornerLatF = 51.2
   res@mpRightCornerLonF = 15.0
   res@mpGridLatSpacingF = 1
   res@mpGridLonSpacingF = 1
   res@mpOutlineDrawOrder = "PostDraw" ; draw continental outline last
   res@mpFillDrawOrder = "PreDraw"
   res@mpDataBaseVersion = "HighRes" ; use finer database
   res@mpOutlineBoundarySets = "National"
   res@mpFillOn = False ; turns off continent gray
   res@mpLeftAngleF = 7
   res@mpRightAngleF = 8
   res@mpBottomAngleF = 6
   res@mpTopAngleF = 8
   res@mpMinLatF = 10.0
   res@pmTickMarkDisplayMode = "Always" ; Nicer tickmark labels
   res@mpGridAndLimbOn = True ; Turn on lat/lon grid
   res@mpGridLineDashPattern = 2 ; Dashed lines
   res@gsnLeftString = ""
 ;************************************************
 ; Plot will just be created, and not drawn yet.
   plot = gsn_csm_map(wks,res) ; Create plot
 ;************************************************
 ; putting tickmarks on all four axes.
   tmres = True
   tmres@tmYLValues = ispan(51,53,1)
   tmres@tmYRValues = ispan(51,53,1)
   tmres@tmXBValues = ispan(11,15,1)
   tmres@tmXTValues = ispan(11,15,1)
 ;---Attach the new map tickmarks.
   plot = add_map_tickmarks(wks,plot,tmres)
 ;************************************************
 ; adding color definition
   cmap = RGBtoCmap("/kp/kp05/fkreienk/data/VisTool/data/konstdat/Farben_rgb_temp.dat")
   gsn_define_colormap(wks,cmap)
 ;************************************************
 ; adding map
   res@cnFillOn = True ; color Fill
   res@cnFillMode = "RasterFill" ; Raster Mode
   res@cnLinesOn = False ; Turn off contour lines
   res@cnLevelSelectionMode = "AutomaticLevels"
   res@cnLabelBarEndStyle = "ExcludeOuterBoxes"
   res@gsnAddCyclic = False ; regional data: not cyclic
 ;************************************************
 ; Plot will just be created, and not drawn yet.
   plot = gsn_csm_contour_map(wks,u,res)
   amres1 = True
   txres = True
   txres@txFontHeightF = 0.01
   txres@txAngleF = 90 ; rotate text
   amres1@amParallelPosF = -0.73 ; This is the right edge of the plot.
   amres1@amOrthogonalPosF = 0.88 ; This is the bottom edge of the plot.
   amres1@amJust = "BottomLeft"
 ;************************************************
 ; adding title etc. information
   txid1 = gsn_create_text(wks, "data: tasmin_Beo_v2_Fill_day_1971_2000 (Jahr); task: Mean", txres)
   annoid1 = gsn_add_annotation(plot, txid1, amres1)
   txres@txAngleF = 0 ; derotate text
   txres@txFontHeightF = 0.018
   txid3 = gsn_create_text(wks, "[°C]", txres)
   amres1@amParallelPosF = 0.46 ; This is the right edge of the plot.
   amres1@amOrthogonalPosF = 0.705 ; This is the bottom edge of the plot.
   amres1@amJust = "CenterLeft"
   annoid1 = gsn_add_annotation(plot, txid3, amres1)
   txres@txAngleF = 90 ; derotate text
   txres@txFontHeightF = 0.01
   txid0 = gsn_create_text(wks, "VisTool (0.2.4) preliminary results, no warranty", txres)
   amres1@amParallelPosF = 0.71 ; This is the right edge of the plot.
   amres1@amOrthogonalPosF = 0.82 ; This is the bottom edge of the plot.
   amres1@amJust = "BottomLeft"
   annoid1 = gsn_add_annotation(plot, txid0, amres1)
   plres = True
   plres@gsLineColor = "black"
   plres@gsLineThicknessF = 2
   lines_id = gsn_add_shapefile_polylines(wks,plot,"/kp/kp05/fkreienk/data/VisTool/data/konstdat/ShapeFiles/DEU_adm1.shp",plres)
 ;************************************************
 ; Drawing plot
   draw(plot)
   frame(wks)
 
 ;************************************************
 ; adding DWD logo
   cmd = "composite -geometry 186x50+775+945 /kp/kp05/fkreienk/data/VisTool/data/konstdat/DWD-Logo-klein.jpg temp-develop.png temp-develop.png"
   system(cmd)
 end
Received on Mon Jun 2 05:54:50 2014

This archive was generated by hypermail 2.1.8 : Tue Jun 03 2014 - 11:40:09 MDT