comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » cgContour and NaN values
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
cgContour and NaN values [message #86117] Tue, 08 October 2013 10:58 Go to next message
limiqt is currently offline  limiqt
Messages: 27
Registered: October 2013
Junior Member
Dear all,
I am having some trouble using contour with data which has NaN values. My valid range of data is -1 to 1. I have also change the NaN to -999. In that case the -999 appear as the same color as -1. I would like that the NaN values appear as white. Please, Could you tell me what I am doing wrong? (I am following a example I found at http://www.idlcoyote.com/graphics_tips/contourcolors.php but Im sure i missed somthing)

my data is [192,145]

data
minval=-1.
maxval=1.
data=cgScaleVector(data, minval, maxval, /NaN)

cgwindow
ncontours = 10
cgLoadCT, 22, /Brewer, /Reverse, NColors=ncontours
clevels = cgScaleVector(Findgen(ncontours+1), minval, maxval, /NaN)
colors = Bindgen(ncontours+1) + 1B
cgContour, data, lons, lats, Levels=clevels, C_Colors=colors, /Fill, missing=!Values.F_Nan, Position=[0.125, 0.125, 0.925, 0.8], /AddCmd
cgColorbar, NColors=ncontours, Range=[minval,maxval], Divisions=10, $
Bottom=1, Ticklen=0.001, /AddCmd

Thanks
Lim.
Re: cgContour and NaN values [message #86119 is a reply to message #86117] Tue, 08 October 2013 11:55 Go to previous messageGo to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
With the caveat that I haven't tested, this, I spot your code specifies missing=!Values.F_Nan . I'd either change that to -999, or else leave your missing values as !values.f_nan . I'd try that.

Andy

On Tuesday, October 8, 2013 1:58:09 PM UTC-4, Lim wrote:
> Dear all,
>
> I am having some trouble using contour with data which has NaN values. My valid range of data is -1 to 1. I have also change the NaN to -999. In that case the -999 appear as the same color as -1. I would like that the NaN values appear as white. Please, Could you tell me what I am doing wrong? (I am following a example I found at http://www.idlcoyote.com/graphics_tips/contourcolors.php but Im sure i missed somthing)
>
>
>
> my data is [192,145]
>
>
>
> data
>
> minval=-1.
>
> maxval=1.
>
> data=cgScaleVector(data, minval, maxval, /NaN)
>
>
>
> cgwindow
>
> ncontours = 10
>
> cgLoadCT, 22, /Brewer, /Reverse, NColors=ncontours
>
> clevels = cgScaleVector(Findgen(ncontours+1), minval, maxval, /NaN)
>
> colors = Bindgen(ncontours+1) + 1B
>
> cgContour, data, lons, lats, Levels=clevels, C_Colors=colors, /Fill, missing=!Values.F_Nan, Position=[0.125, 0.125, 0.925, 0.8], /AddCmd
>
> cgColorbar, NColors=ncontours, Range=[minval,maxval], Divisions=10, $
>
> Bottom=1, Ticklen=0.001, /AddCmd
>
>
>
> Thanks
>
> Lim.
Re: cgContour and NaN values [message #86124 is a reply to message #86119] Wed, 09 October 2013 01:44 Go to previous messageGo to next message
limiqt is currently offline  limiqt
Messages: 27
Registered: October 2013
Junior Member
Thanks Andy.

The code works (i think) changing the NaN to -999. and by explicitly defining the color table. It does not work using NaN. It does not work following the color table as in the example I mentioned (http://www....)

mindata=Min(datax)
maxdata=Max(datax)
data=cgScaleVector(datax, mindata, maxdata)
;print, mindata
;print, maxdata

;cgwindow
ncolors = 8
;cgLoadCT,0
TVLCT, cgColor(['blu8', 'blu6', 'blu4', 'blu2', 'red2', 'red4','red6', 'red8', 'white'], /Triple), 1
clevels=[-1,-0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1]
colors = Bindgen(ncolors+1) + 1B
cgContour, data, lons, lats, Levels=clevels, C_Colors=colors, /Fill, $
Position=[0.125, 0.125, 0.925, 0.8];, /AddCmd
cgColorbar, NColors=ncolors, Range=[-1,1], Divisions=ncolors, $
Bottom=1, Ticklen=0.001;, /AddCmd



On Tuesday, October 8, 2013 2:55:47 PM UTC-4, AMS wrote:
> With the caveat that I haven't tested, this, I spot your code specifies missing=!Values.F_Nan . I'd either change that to -999, or else leave your missing values as !values.f_nan . I'd try that.
>
>
>
> Andy
>
>
>
> On Tuesday, October 8, 2013 1:58:09 PM UTC-4, Lim wrote:
>
>> Dear all,
>
>>
>
>> I am having some trouble using contour with data which has NaN values. My valid range of data is -1 to 1. I have also change the NaN to -999. In that case the -999 appear as the same color as -1. I would like that the NaN values appear as white. Please, Could you tell me what I am doing wrong? (I am following a example I found at http://www.idlcoyote.com/graphics_tips/contourcolors.php but Im sure i missed somthing)
>
>>
>
>>
>
>>
>
>> my data is [192,145]
>
>>
>
>>
>
>>
>
>> data
>
>>
>
>> minval=-1.
>
>>
>
>> maxval=1.
>
>>
>
>> data=cgScaleVector(data, minval, maxval, /NaN)
>
>>
>
>>
>
>>
>
>> cgwindow
>
>>
>
>> ncontours = 10
>
>>
>
>> cgLoadCT, 22, /Brewer, /Reverse, NColors=ncontours
>
>>
>
>> clevels = cgScaleVector(Findgen(ncontours+1), minval, maxval, /NaN)
>
>>
>
>> colors = Bindgen(ncontours+1) + 1B
>
>>
>
>> cgContour, data, lons, lats, Levels=clevels, C_Colors=colors, /Fill, missing=!Values.F_Nan, Position=[0.125, 0.125, 0.925, 0.8], /AddCmd
>
>>
>
>> cgColorbar, NColors=ncontours, Range=[minval,maxval], Divisions=10, $
>
>>
>
>> Bottom=1, Ticklen=0.001, /AddCmd
>
>>
>
>>
>
>>
>
>> Thanks
>
>>
>
>> Lim.
Re: cgContour and NaN values [message #86127 is a reply to message #86124] Wed, 09 October 2013 16:05 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
NaNs are handled a particular way by Contour:
http://www.exelisvis.com/docs/CONTOUR_Procedure.html

In particular, the line:
"Note that the IEEE floating-point value NaN is also treated as missing data."
might explain some of the problems you're having.

May I gently a different way of defining the "color table" using the palette keyword, since you're using Coyote graphics:

(My apologies for not adopting this example to fit yours - this is an example from some notes I've developed : https://www.dropbox.com/s/c8so8daw70tpe5v/contour_notes.pdf)

nLev = 5
l_levels = DINDGEN(5)*50 + 100
l_ticks = [STRING(l_levels, FORMAT='(F5.1)'), ' ']

colors = ['blue', 'red', 'green', 'yellow', 'orange']
rgb = cgCOLOR(colors, /TRIPLE)

cgContour, data, lons, lats, LEVELS = l_levels, PALETTE=rgb, /FILL, POSITION=[0.1, 0.1, 0.8, 0.9]

cgCOLORBAR, /VERTICAL, /RIGHT, NCOLORS = nLev, PALETTE = rgb, DIVISIONS = nLev, POSITION = [0.85, 0.1, 0.9, 0.9], TICKNAMES = l_ticks
Re: cgContour and NaN values [message #86138 is a reply to message #86117] Thu, 10 October 2013 07:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Lim writes:

> I am having some trouble using contour with data which has NaN values. My valid range of data is -1 to 1. I have also change the NaN to -999. In that case the -999 appear as the same color as -1. I would like that the NaN values appear as white. Please, Could you tell me what I am doing wrong? (I am following a example I found at http://www.idlcoyote.com/graphics_tips/contourcolors.php but Im sure i missed somthing)

It is almost *never* a good idea to try filled contours with missing
data. The results are always unsatisfactory. But, if you have to, you
have to. I would try something like this.

data = dist(192,145)
data[50:60,75:79] = !Values.F_NaN
minval=-1.
maxval=1.
nanIndices = Where(Finite(data) EQ 0, count)
data=cgScaleVector(data, minval, maxval, /NaN)
IF count GT 0 THEN data[nanIndices] = minval - 1
cgWindow
ncontours = 10
cgLoadCT, 22, /Brewer, /Reverse, NColors=ncontours+1, Bottom=2
TVLCT, cgColor('white', /Triple), 1
clevels = [minval-1, cgScaleVector(Findgen(ncontours+1), $
minval, maxval)]
colors = Bindgen(ncontours+1) + 1B
cgContour, data, lons, lats, Levels=clevels, C_Colors=colors, /Fill, $
missing=!Values.F_Nan, Position=[0.125, 0.125, 0.925, 0.8], /AddCmd
cgColorbar, NColors=ncontours, Range=[minval,maxval], Divisions=10, $
Bottom=2, Ticklen=0.001, /AddCmd
END


Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cgContour and NaN values [message #86169 is a reply to message #86138] Tue, 15 October 2013 19:54 Go to previous message
limiqt is currently offline  limiqt
Messages: 27
Registered: October 2013
Junior Member
Hi David and Philip.
Thank you very much for your precisse assistance.

Lim

On Thursday, October 10, 2013 10:16:46 AM UTC-4, David Fanning wrote:
> Lim writes:
>
>
>
>> I am having some trouble using contour with data which has NaN values. My valid range of data is -1 to 1. I have also change the NaN to -999. In that case the -999 appear as the same color as -1. I would like that the NaN values appear as white. Please, Could you tell me what I am doing wrong? (I am following a example I found at http://www.idlcoyote.com/graphics_tips/contourcolors.php but Im sure i missed somthing)
>
>
>
> It is almost *never* a good idea to try filled contours with missing
>
> data. The results are always unsatisfactory. But, if you have to, you
>
> have to. I would try something like this.
>
>
>
> data = dist(192,145)
>
> data[50:60,75:79] = !Values.F_NaN
>
> minval=-1.
>
> maxval=1.
>
> nanIndices = Where(Finite(data) EQ 0, count)
>
> data=cgScaleVector(data, minval, maxval, /NaN)
>
> IF count GT 0 THEN data[nanIndices] = minval - 1
>
> cgWindow
>
> ncontours = 10
>
> cgLoadCT, 22, /Brewer, /Reverse, NColors=ncontours+1, Bottom=2
>
> TVLCT, cgColor('white', /Triple), 1
>
> clevels = [minval-1, cgScaleVector(Findgen(ncontours+1), $
>
> minval, maxval)]
>
> colors = Bindgen(ncontours+1) + 1B
>
> cgContour, data, lons, lats, Levels=clevels, C_Colors=colors, /Fill, $
>
> missing=!Values.F_Nan, Position=[0.125, 0.125, 0.925, 0.8], /AddCmd
>
> cgColorbar, NColors=ncontours, Range=[minval,maxval], Divisions=10, $
>
> Bottom=2, Ticklen=0.001, /AddCmd
>
> END
>
>
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: scopes
Next Topic: Yet another user with poly_fit problems

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:34:01 PDT 2025

Total time taken to generate the page: 0.02188 seconds