Re: polygon error

From: DONG Li <dongli_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 15 2010 - 19:56:56 MST

Dear Mary,

One more question~ I want to fill those polygons according to the values that in them, so I write:
-----------------------------------
gsn_define_colormap(wks, "WhBlReWh")
cmap = gsn_retrieve_colormap(wks)
...
numLevel = dimsizes(cmap(:,0))-1
cnLevels = new(numLevel, float)
cnLevels = fspan(1.0, 1.5, numLevel)
...
do i = 0, n-1
    ...
    polyRes@gsFillColor = GetFillColor(cnLevels, cmap, q(i))
    ...
end do
-----------------------------------
But NCL complains:

(0) Not enough colors in colormap for number of contour levels

What should I do?

Cheers,

DONG Li

On 2010-11-15, at 下午11:53, Mary Haley wrote:

> Dear Dong Li,
>
> The problem is that you have longitude values that start small, -127 to -146 and then they jump suddenly to 179. NCL is basically filling in the outside of the circle, based on the large values you gave it. It has no way of knowing that you want the short distance.
>
> To fix this, use the "where" function to add 360 to all longitude values less than 360:
>
> lonPoint = where(lonPoint.lt.0,lonPoint+360,lonPoint)
>
> --Mary
>
> On Nov 14, 2010, at 6:08 PM, DONG Li wrote:
>
>> Dear Mary,
>>
>> My real NCL script needs some data which is too large for transferring. Here is a small script for debugging, you can use the following vertices:
>>
>> -127.338600 -87.929138
>> -146.644073 -86.213120
>> 179.307693 -85.080284
>> 144.447769 -85.944191
>> 112.320877 -87.895256
>>
>> --------------------------------
>> #!/bin/bash
>>
>> echo "Input the coordinates of the vertices:"
>> lon1=go
>> n=-1
>> while [ $lon1 ]; do
>> read lon1 lat1
>> lon=$lon,$lon1
>> lat=$lat,$lat1
>> n=$[$n+1]
>> done
>> lon=${lon%%,}
>> lon=${lon##,}
>> lat=${lat%%,}
>> lat=${lat##,}
>> echo "Input the angle of viewpoint:"
>> read angle
>>
>> ncl 1> /dev/null <<-EOF
>> 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
>>
>> numPoint = ${n}
>> lonPoint = (/${lon}/)
>> latPoint = (/${lat}/)
>>
>> lonMin = min(lonPoint)
>> lonMax = max(lonPoint)
>> latMin = min(latPoint)
>> latMax = max(latPoint)
>>
>> lonCenter = (lonMin+lonMax)/2
>> latCenter = (latMin+latMax)/2
>>
>> wks = gsn_open_wks("x11", "spherical_polygon")
>>
>> mapRes = True
>> mapRes@gsnDraw = False
>> mapRes@gsnFrame = False
>> mapRes@mpGreatCircleLinesOn = True
>> mapRes@mpGridAndLimbOn = True
>> mapRes@mpGridLineColor = "Background"
>> mapRes@mpProjection = "Satellite"
>> mapRes@mpCenterLonF = lonCenter
>> mapRes@mpCenterLatF = latCenter
>> mapRes@mpLimitMode = "Angles"
>> mapRes@mpLeftAngleF = ${angle}
>> mapRes@mpRightAngleF = ${angle}
>> mapRes@mpBottomAngleF = ${angle}
>> mapRes@mpTopAngleF = ${angle}
>>
>> map = gsn_csm_map(wks, mapRes)
>>
>> textRes = True
>> textRes@txFontHeightF = 0.01
>> textRes@txFont = "helvetica-bold"
>>
>> do i = 0, numPoint-1
>> text = gsn_add_text(wks, map, sprinti("%d", i+1), lonPoint(i)-0.5, latPoint(i)-0.5, textRes)
>> end do
>>
>> draw(map)
>>
>> edgeRes = True
>> edgeRes@gsLineThicknessF = 0.5
>> edgeRes@gsLineColor = "blue"
>>
>> lon = new(2, float)
>> lat = new(2, float)
>>
>> do i = 0, numPoint-1
>> j = i-1
>> if (i .eq. 0) then
>> j = numPoint-1
>> end if
>> lon(0) = lonPoint(j)
>> lon(1) = lonPoint(i)
>> lat(0) = latPoint(j)
>> lat(1) = latPoint(i)
>> gsn_polyline(wks, map, lon, lat, edgeRes)
>> end do
>>
>> vertexRes = True
>> vertexRes@gsMarkerIndex = 1
>> vertexRes@gsMarkerSizeF = 0.01
>> vertexRes@gsMarkerColor = "red"
>>
>> gsn_polymarker(wks, map, lonPoint, latPoint, vertexRes)
>>
>> if (True) then
>> fillRes = True
>> fillRes@gsFillsOn = True
>> fillRs@gsFillColor = "red"
>>
>> gsn_polygon(wks, map, lonPoint, latPoint, res)
>> end if
>>
>> frame(wks)
>>
>> end
>> EOF
>>
>> --------------------------------
>>
>> Thanks for help!
>>
>> DONG Li
>>
>> On 2010-11-15, at 上午6:21, Mary Haley wrote:
>>
>>> Dear DONG LI,
>>>
>>> It's possible that you are running into a different problem. Can you provide us with a short NCL script that shows the problem so we can run it here?
>>>
>>> Thanks,
>>>
>>> --Mary
>>>
>>> On Nov 14, 2010, at 7:56 AM, DONG Li wrote:
>>>
>>>> Dear all,
>>>>
>>>> I want to display a Voronoi diagram on the sphere, and each cell has a value. So I need to plot a lot of filled polygons. But I observed that some polygons have been wrongly filled, that is the entire map has been filled except the polygons! I searched out the mail list, and found some one has already encountered such problem:
>>>>
>>>> http://www.ncl.ucar.edu/Support/talk_archives/2009/0109.html,
>>>>
>>>> and "Mary Haley" said "This problem has been fixed and will be in the 5.1.0 release. It had
>>>> to do with floating point precision in some low-level map code." But I am using 5.2.1, why such a problem still exist? The following are an example of problematic polygon:
>>>>
>>>> -127.338600 -87.929138
>>>> -146.644073 -86.213120
>>>> 179.307693 -85.080284
>>>> 144.447769 -85.944191
>>>> 112.320877 -87.895256
>>>> -127.338600 -87.929138
>>>>
>>>> Thanks for help!
>>>>
>>>> DONG Li
>>>>
>>>> _______________________________________________
>>>> 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
Received on Mon Nov 15 19:57:09 2010

This archive was generated by hypermail 2.1.8 : Wed Nov 17 2010 - 13:14:26 MST