# [ncl-talk] problem about Plotting r,theta data

Mary Haley haley at ucar.edu
Wed Apr 26 08:22:37 MDT 2017

```Hello,

I'm not sure I understand. You said you didn't have any data from 355 to 0,
so I believe that's exactly what the plot is showing you.

When you plot data over a global map, we sometimes see this kind of thing
because the longitude point doesn't go all the way from -180 to 180, or
from 0 to 360. In that case, we set a special resource:

res at gsnAddCyclic = True

which simply creates a new data array that has more more element in the
longitude direction (nlat x (nlon+1)) and we copy the first data point at
the first longitude point to the end of this array, so you are effectively
closing the gap.

gsnAddCyclic is only for map plots, but you could do something similar for
your contour plot.  Here's what the "add cyclic point" code looks like:

dims = dimsizes(pr)
ny   = dims(0)
mx   = dims(1)
mx1  = mx+1

pr_cyclic           = new((/ny, mx1/),typeof(pr))
pr_cyclic(:,0:mx-1) = pr             ; pass everything

pr_cyclic(:,mx)     = (/ pr(:,0) /)  ; value only

You will need to do the same thing for x and y, so I suggest making a
function, like "make _cyclic" and calling it for pr, x, and y.

By the way, if you have NCL V6.1.0 or later, You don't need to use
NhlNewColor. You can now use named colors directly. So, instead of this:

cnres at cnMissingValFillColor = NhlNewColor(wks,.7,.7,.7)

you can use this:

cnres at cnMissingValFillColor = "gray"

You can see all the named colors at:

http://www.ncl.ucar.edu/Document/Graphics/named_colors.shtml

--Mary

On Mon, Apr 24, 2017 at 2:46 AM, wen <wenguanhuan at 163.com> wrote:

>
>
>
> hi all,
>    I am ploting r-theta data. Theta is from 0 to 355 at an interval of 5.
> However, the there is blank at the angular of 355-0. Do anybody know why.
> My script is attached bellow.
> ;***********************************************
> ;
> ; Concepts illustrated:
> ;   - Plotting radar (r,theta) data
> ;   - Adding shading or color fill to areas on a contour plot with missing
> data
> ;   - Drawing raster contours
> ;   - Drawing cell-filled contours
> ;   - Using triangular meshes to create contours
> ;***********************************************
>
> begin
> pi       =  4.0*atan(1.)
>   deg2rad  =  pi/180.
>   rad2deg  =  45./atan(1.)
>
>
>   a = 6371.
>
>   r = ispan(0,500,10)
>   theta  = ispan(0,355,5)
>
>   y = conform_dims((/dimsizes(r),dimsizes(theta)/),r,0)*cos(
>   x = conform_dims((/dimsizes(r),dimsizes(theta)/),r,0)*sin(
>
> ;  x = r*sin(theta*deg2rad)
>
>
>
> ;print(lat+" "+lon )
>
>   tcnum = systemfunc("cut -d ' ' -f 1 land_tcnum_time.dat")
> ltime = systemfunc("cut -d ' ' -f 2 land_tcnum_time.dat")
>
>  i = 3
>
>  tcdir = "land_gd_tc/"
>  tcfile = tcnum(i)+".dat"
>  tmp = asciiread(tcdir+tcfile,-1,"integer")
>  ntime = dimsizes(tmp)/6
>  data = onedtond(tmp,(/ntime,6/))
>
>  index = ind(ltime(i).eq.data(:,0))
>  lat0 = data(index,2)*0.01
>  lon0 = data(index,3)*0.01
>
>  a0 = a*cos(lat0*deg2rad)
>
>
>   lat = y/(a*deg2rad)+lat0
>   lon = x/(a0*deg2rad)+lon0
>
>
>  fd = "/gza/g3/wengh/TC/TRMM/"+tcnum(i)+"/"
>  fn = systemfunc("ls "+fd+"3B42."+str_get_cols(ltime(i),0,7)+"."+str_get_
> cols(ltime(i),8,9)+"*.HDF")
>  f = addfile(fn,"r")
>  pre = f->precipitation
>
>  latgrid = fspan(-49.875,49.875,400)
>  longrid = fspan(-179.875,179.875,1440)
>
>  pre!0 = "lon"
>  pre!1 = "lat"
>
>  pre&lon = longrid
>  pre&lat = latgrid
>
>
> pr = new((/dimsizes(r),dimsizes(theta)/),typeof(pre))
>
> do i=0,dimsizes(r)-1
>  do j=0,dimsizes(theta)-1
>   nlat = ind_nearest_coord(lat(i,j),latgrid,0)
>   nlon = ind_nearest_coord(lon(i,j),longrid,0)
>   pr(i,j) = (/pre(nlon,nlat)/)
>  end do
> end do
>
>
> ;print(pr(0,0)+" "+x(0,0)+" "+y(0,0))
>
> ;exit
>
>
> graphicname = get_script_prefix_name()
> wks = gsn_open_wks("eps" ,graphicname)
> ;gsn_define_colormap(wks,"gui_default")
> gsn_define_colormap(wks,"precip2_15lev")
> ;gsn_define_colormap(wks,"precip2_17lev")
> colors = ispan(4,17,1)
> ;colors(0) = 2
>
>
>   cnres                   = True
> ;  cnres at gsnMaximize       = True
>
>   cnres at sfXArray          = x
>   cnres at sfYArray          = y
>   cnres at cnFillOn          = True
>   cnres at cnLinesOn         = False
> ;  cnres at cnFillMode        = "RasterFill"      ; this mode is fastest
>   cnres at trGridType        = "TriangularMesh"
>   cnres at lbLabelAutoStride = True
> ;  contour = gsn_csm_contour(wks,pr,cnres)
>
> ; The CellFill mode is slower but draws more outlying data
> ; and lets you fill in the missing value arrays, giving a good
> ; sense of the circular extent of the plot.
>
>   cnres at cnFillMode            =  "CellFill"
>   cnres at cnMissingValFillColor = NhlNewColor(wks,.7,.7,.7)
>   cnres at cnLevelSelectionMode = "ExplicitLevels"     ; set manual contour
> levels
>   cnres at cnLevels       = ispan(1,13,1)               ; set min contour
> level
>   cnres at cnFillColors   = colors
>
>
>   contour = gsn_csm_contour(wks,pr,cnres)
> end
>
>
> --
> Best regards,
> Guanhuan Wen
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170426/da8d17db/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ??1.png
Type: image/png
Size: 255529 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170426/da8d17db/attachment.png
```