Re: position of the value 0 in cnLevels to be represented by white colour.

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 14 2011 - 14:26:03 MDT

It looks to me as if your data set had a _FillValue set but somehow the attribute was not propagated. This makes the
data_min value into a value much less than the actual minimum of the real data, and accounts for the errors that
follow. The positive maximum value is totally overwhelmed by the minimum value, making all the level values
negative when using the initial automatic level selection that you are using as a starting point.
line:

ii = ind(levels.ge.0)

returns a missing value, since no values evaluate to True. (see the ind documentation) The missing value gets
propagated to num_neg and num_pos. In turn this means that the if tests:

if (num_neg .gt. 0)

and later:

if (num_pos .gt. 0)

both result in missing values, which are not allowed in if statement scalar logical expressions, causing the error
message:

fatal:The result of the conditional expression yields a missing value. NCL can not determine branch, see ismissing function

The immediate fix for this error is to change the if test condition to:

if (.not. ismissing(num_neg) .and. num_neg .gt. 0) then ....

However, the real fix is to ensure that the _FillValue is set for your data array such that min(data_array) ignores the fill value
when looking for the minimum value of the data.
At least this is the best I can make out without actually being able to execute your code.

 -dave

On Mar 13, 2011, at 12:42 AM, gibies george wrote:

> Thank you Mary,
>
> It is helpful.
>
> But I could not get the reason for the following error:
>
> Here is the part of my script:
> _________________________________________________________________________
> print(data_min)
> print(data_max)
> if (data_min .gt. 0)
> resc@gsnSpreadColorStart = white
> resc@cnLevelSelectionMode = "ManualLevels"
> resc@cnMinLevelValF = 0
> end if
> if (data_max .lt. 0)
> resc@gsnSpreadColorEnd = white
> resc@cnLevelSelectionMode = "ManualLevels"
> resc@cnMaxLevelValF = 0
> end if
> if ((data_min .lt. 0) .and. (data_max .gt. 0))
> plot(ptn) = gsn_csm_contour_map(wkspnl,\
> data({region@latsouth:region@latnorth},{region@lonwest:region@loneast},j,pos),resc)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;; Retrieve contour levels
> getvalues plot@contour(ptn)
> "cnLevels" : levels
> end getvalues
>
> nlevels = dimsizes(levels)
> print(levels)
> print(" The data unit is " + unit + " : Do you need a change in unit ? ")
> ans = systemfunc("read var; echo $var")
> if (ans .eq. "yes") then
> print ("Enter the factor to be multiplied : ")
> factor = stringtofloat(systemfunc("read var; echo $var"))
> print ("Enter the new unit : ")
> data@unit = systemfunc("read var; echo $var")
> data = data*factor
> levels = levels/factor
> print(levels)
> end if
> ;;;; Create array containing fill indexes.
> colors = new(nlevels+1,integer)
> ii = ind(levels.ge.0)
> num_neg = ii(0)
> num_pos = nlevels-num_neg+1
> print(num_neg)
> print(num_pos)
> print(colors)
> if (num_neg .gt. 0)
> colors(0:num_neg-1) = ispan(2,51,tointeger(51/(num_neg-1)))
> end if
> print(colors)
> colors(num_neg) = 52
> print(colors)
> if (num_pos .gt. 0)
> colors(num_neg+1:) = ispan(53,103,tointeger(51/(num_pos-1)))
> end if
> print(colors)
> resc@cnFillColors= colors
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> end if
> _________________________________________________________________________
>
> Here is the output :
> _________________________________________________________________________
>
>
> Variable: data_min
> Type: float
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) -9.96921e+36
>
>
> Variable: data_max
> Type: float
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 44.79309
> warning:gsnScalarContour is not a valid resource in rain_tropics_dem_ecmwf_MeanError_contour at this time
>
>
> Variable: levels
> Type: float
> Total Size: 36 bytes
> 9 values
> Number of Dimensions: 1
> Dimensions and sizes: [9]
> Coordinates:
> (0) -9e+36
> (1) -8e+36
> (2) -7e+36
> (3) -6e+36
> (4) -5e+36
> (5) -4e+36
> (6) -3e+36
> (7) -2e+36
> (8) -1e+36
> (0) The data unit is mm/day : Do you need a change in unit ?
> yes
> (0) Enter the factor to be multiplied :
> 1e+36
> (0) Enter the new unit :
> 1e+36mm/day
>
>
> Variable: levels
> Type: float
> Total Size: 36 bytes
> 9 values
> Number of Dimensions: 1
> Dimensions and sizes: [9]
> Coordinates:
> (0) -9
> (1) -8
> (2) -7
> (3) -6
> (4) -5
> (5) -4
> (6) -3
> (7) -2
> (8) -1
>
>
> Variable: num_neg
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : -999
> (0) -999
>
>
> Variable: num_pos
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : -999
> (0) -999
>
>
> Variable: colors
> Type: integer
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : -999
> (0) -999
> (1) -999
> (2) -999
> (3) -999
> (4) -999
> (5) -999
> (6) -999
> (7) -999
> (8) -999
> (9) -999
> fatal:The result of the conditional expression yields a missing value. NCL can not determine branch, see ismissing function
> fatal:Execute: Error occurred at or near line 1993 in file script1.ncl
>
> fatal:Execute: Error occurred at or near line 2108 in file script1.ncl
>
> fatal:Execute: Error occurred at or near line 2589 in file script1.ncl
>
> fatal:Execute: Error occurred at or near line 2625 in file script1.ncl
>
> ________________________________________________________________________________________________
>
>
> On 10 March 2011 20:44, Mary Haley <haley@ucar.edu> wrote:
> Instead of
>
> getvalues plot(ptn)
>
> try
>
> getvalues plot@contour
>
> In the example I gave you, "plot" was a contour plot. In your case, it's a map. The contour plot is "attached" to the "plot" variable via the "contour" attribute.
>
> --Mary
>
> On Mar 10, 2011, at 6:23 AM, gibies george wrote:
>
>>
>>
>> On 10 March 2011 10:09, gibies george <gibies@tropmet.res.in> wrote:
>> Thank you Mary,
>>
>> This is exactly what I was looking for.
>>
>>
>> But the script
>>
>> plot(ptn) = gsn_csm_contour_map(wkspnl,\
>> data({region@latsouth:region@latnorth},{region@lonwest:region@loneast},j,pos),resc)
>> ;---Retrieve contour levels
>> getvalues plot(ptn)
>> "cnLevels" : levels ;;;; Here is line 1968 in file script1.ncl
>> end getvalues
>>
>> nlevels = dimsizes(levels)
>>
>> shows an error :
>>
>> warning:gsnScalarContour is not a valid resource in rain_tropics_dem_ecmwf_Climatology_contour at this time
>> warning:cnLevels is not a valid resource in map at this time
>> warning:NhlGetValues:Error retrieving cnLevels
>> fatal:Execute: Error occurred at or near line 1968 in file script1.ncl
>>
>>
>> On 10 March 2011 01:28, Mary Haley <haley@ucar.edu> wrote:
>> Gibies,
>>
>> Instead of using gsnSpreadXXXX, you will probably need to set the cnFillColors resource to an array of color indexes, so you can control which contour level gets which color index.
>>
>> If you are setting the contour levels yourself, then you should be able to determine what to set cnFillColors to.
>>
>> If you are letting NCL select the contour levels, then you will need to let NCL create the plot, and thn afterwards use "getvalues" to retrieve the "cnLevels" resource and construct cnFillColors based on those values.
>>
>> Something like this:
>>
>> . . .
>> plot = gsn_csm_contour_map(wks,data,res)
>>
>> ;---Retrieve contour levels
>> getvalues plot
>> "cnLevels" : levels
>> end getvalues
>>
>> nlevels = dimsizes(levels)
>>
>> ;---Create array containing fill indexes.
>> colors = new(nlevels+1,integer)
>> ii = ind(levels.ge.0)
>> num_neg = ii(0)
>> num_pos = nlevels-num_neg+1
>>
>> colors(0:num_neg-1) = ispan(2,51,toint(51/(num_neg-1)))
>> colors(num_neg:) = ispan(53,103,toint(51/(num_pos-1)))
>>
>> res@cnFillColors= colors
>> plot = gsn_csm_contour_map(wks,data,res)
>>
>>
>>
>> You will need to modify this based on whether you have a contour level exactly equal to 0 or not.
>>
>> --Mary
>>
>>
>> On Mar 9, 2011, at 3:51 AM, gibies george wrote:
>>
>>> Thank you Mary for the response.
>>>
>>> I am using gsn_csm_contour_map with "ViBlGrWhYeOrRe" colour-map
>>>
>>> I wish to have :
>>>
>>> the colours from 1 to 51 ie "ViBlGr" to be used for negative values.
>>> the colour 52 ie "White" to be used for zero.
>>> the colours from 53 to 103 ie "YeOrRe" to be used for positive values.
>>>
>>> I tried to manage it using gsnSpreadColorStart and gsnSpreadColorEnd in the cases when (data_min .gt. 0) or (data_max .lt. 0) but I don't know how to handle the case when (data_min .lt. 0) .and. (data_max .gt. 0) which i really want.
>>>
>>> I am afraid that I may not get full range of color map while using "gsn_contour_shade"
>>>
>>>
>>> On 9 March 2011 03:57, Mary Haley <haley@ucar.edu> wrote:
>>> Maybe "gsn_contour_shade" is what you're looking for:
>>>
>>> http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_contour_shade.shtml
>>>
>>>
>>>
>>>
>>> --Mary
>>>
>>> On Mar 8, 2011, at 5:47 AM, gibies george wrote:
>>>
>>>> How can I get the position of the value 0 in cnLevels while setting the resources for contour plot ?
>>>>
>>>> My requirement is as follows.
>>>>
>>>> I would like to get white to represent the value near to zero in contour interval irrespective of the data range.
>>>> ---------
>>>> ----------
>>>> -----------
>>>>
>>>> gsn_define_colormap(wkspnl,"ViBlGrWhYeOrRe")
>>>> white = 52
>>>> data_min = min(data)
>>>> data_max = max(data)
>>>>
>>>> if (data_min .gt. 0)
>>>> resc@gsnSpreadColorStart = white
>>>> resc@cnLevelSelectionMode = "ManualLevels"
>>>> resc@cnMinLevelValF = 0
>>>> end if
>>>>
>>>> if (data_max .lt. 0)
>>>> resc@gsnSpreadColorEnd = white
>>>> resc@cnLevelSelectionMode = "ManualLevels"
>>>> resc@cnMaxLevelValF = 0
>>>> end if
>>>>
>>>> if ((data_min .lt. 0) .and. (data_max .gt. 0))
>>>> ----------
>>>> ???????
>>>> ----------
>>>> end if
>>>> ----------------------
>>>> -----------------------
>>>> ----------------------
>>>>
>>>> How can I implement this?
>>>>
>>>>
>>>> --
>>>> Gibies George, CSIR-RF,
>>>> Seasonal Scale Prediction Group,
>>>> Climate and Global Modelling Division,
>>>> Indian Institute of Tropical Meteorology,
>>>> Dr. Homi Bhabha Road,
>>>> NCL (P. O.), Pashan,
>>>> Pune 411008, India.
>>>>
>>>> http://sites.google.com/site/gibiesge/
>>>>
>>>> Please Think about the environment. Save paper; Save Trees; and don't print this e-mail unless it is necessary.
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>>
>>>
>>> --
>>> Gibies George, CSIR-RF,
>>> Seasonal Scale Prediction Group,
>>> Climate and Global Modelling Division,
>>> Indian Institute of Tropical Meteorology,
>>> Dr. Homi Bhabha Road,
>>> NCL (P. O.), Pashan,
>>> Pune 411008, India.
>>>
>>> http://sites.google.com/site/gibiesge/
>>>
>>> Please Think about the environment. Save paper; Save Trees; and don't print this e-mail unless it is necessary.
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>>
>>
>> --
>> Gibies George, CSIR-RF,
>> Seasonal Scale Prediction Group,
>> Climate and Global Modelling Division,
>> Indian Institute of Tropical Meteorology,
>> Dr. Homi Bhabha Road,
>> NCL (P. O.), Pashan,
>> Pune 411008, India.
>>
>> http://sites.google.com/site/gibiesge/
>>
>> Please Think about the environment. Save paper; Save Trees; and don't print this e-mail unless it is necessary.
>>
>>
>>
>> --
>> Gibies George, CSIR-RF,
>> Seasonal Scale Prediction Group,
>> Climate and Global Modelling Division,
>> Indian Institute of Tropical Meteorology,
>> Dr. Homi Bhabha Road,
>> NCL (P. O.), Pashan,
>> Pune 411008, India.
>>
>> http://sites.google.com/site/gibiesge/
>>
>> Please Think about the environment. Save paper; Save Trees; and don't print this e-mail unless it is necessary.
>
>
>
>
> --
> Gibies George, CSIR-RF,
> Seasonal Scale Prediction Group,
> Climate and Global Modelling Division,
> Indian Institute of Tropical Meteorology,
> Dr. Homi Bhabha Road,
> NCL (P. O.), Pashan,
> Pune 411008, India.
>
> http://sites.google.com/site/gibiesge/
>
> Please Think about the environment. Save paper; Save Trees; and don't print this e-mail unless it is necessary.
> _______________________________________________
> 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 Mar 14 14:26:11 2011

This archive was generated by hypermail 2.1.8 : Wed Mar 16 2011 - 09:22:37 MDT