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

Home » Public Forums » archive » CONTOUR problem
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
CONTOUR problem [message #7115] Tue, 01 October 1996 00:00 Go to next message
Reginald Tang is currently offline  Reginald Tang
Messages: 1
Registered: October 1996
Junior Member
Hello,

I would appreciate helpful suggestions to a problem i've been having
with plotting contour lines in IDL.

I am plotting over a stereographic projection of the Northern hemisphere
centered on the North Pole and I am getting a weird "jump" of all levels
of the contour lines towards the pole around latitude -10 degrees. My
plot looks a bit like a pie-chart with a 10-degree slice taken out of
it. Otherwise, the plot is perfectly acceptable (as compared with output
using DISPLAA). I use the following statement:

CONTOUR, H, LON, LAT

where H is height data to be contoured and is a 36x16 array and LON is a
36-vector containing the longitude lines going from 0 to 180 and -170 to
-10. LAT is a 16-vector going from 90 (North pole) to 0 (Equator).

There are only 455 data points to be plotted, and their positions are
concentric and regularly spaced wrt longitude and latitude. however,
data from latitude 90 to 66 are spaced 20 degrees apart in longitude, as
opposed to 10 at lower latitudes than 66.

I've tried giving H, LON and LAT as three arrays of the same dimensions
to CONTOUR (an alternative suggested in the Reference) but this
inexplicably gave me a chaotic mess. A colleague and I have checked and
double-checked the contents of the parameters to make sure they are OK.

Any help, hints or clarifying questions will be appreciated. I hope it's
not a bug in IDL but just something i overlooked!

Reg
------------------
Environment Canada
4905 Dufferin
Downsview, Ontario
M3H 5T4
(416)739-4711
Re: Contour Problem [message #39072 is a reply to message #7115] Mon, 26 April 2004 06:22 Go to previous messageGo to next message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Christopher Lee wrote:
> On Fri, 23 Apr 2004 17:11:11 -0500, Jeff Patrick wrote:
>
>
>> I keep getting the following error in my code and I can't figure out why.
>> Any help would be appreciated.
>>
>> % Internal error: Triangulation is invalid.
>>

>
> There are identical points in the data, triangulate works (in a fluffy,
> wordy kind of way) by drawing circles which have the points on the
> circumference. If the points are identical, it can't work. (This would be
> my guess).
>
> There are colinear points which otherwise satisfy the Delauney
> Triangulation algorithm, (good luck finding these). The triangle will be
> 'flat', i.e not a triangle. If this is going to happen, it would most
> likely happen on the first three points, which are needed to bootstrap the
> algorithm.
>
Hello,
The GRID_INPUT (IDL 5.5+) can be used to fish out the duplicate data
triplets before the call to TRIANGULATE. See the DUPLICATES keywprd to
GRID_INPUT.

Ben
Re: Contour Problem [message #39078 is a reply to message #7115] Sat, 24 April 2004 04:39 Go to previous messageGo to next message
Christopher Lee is currently offline  Christopher Lee
Messages: 4
Registered: February 2001
Junior Member
On Fri, 23 Apr 2004 17:11:11 -0500, Jeff Patrick wrote:

> I keep getting the following error in my code and I can't figure out why.
> Any help would be appreciated.
>
> % Internal error: Triangulation is invalid.
>
> CONTOUR, X, Y, Z, IRREGULAR=1, ISOTROPIC=1, /CLOSED, /CELL_FILL, /OVERPLOT,
> .....
> each array is 32400 in size.
>
> Thank you,
>
> Jeff
> jeff.patrick@computer.org

Your getting the error because the contour function calls the triangulate
function internally, which throws an error on your data. If you can
separate the data from the Widget program, do it :) (save it to a file).

Then run TRIANGULATE on the data, if that throws an error, it probably
will, something is wrong with the data. e.g

There are identical points in the data, triangulate works (in a fluffy,
wordy kind of way) by drawing circles which have the points on the
circumference. If the points are identical, it can't work. (This would be
my guess).

There are colinear points which otherwise satisfy the Delauney
Triangulation algorithm, (good luck finding these). The triangle will be
'flat', i.e not a triangle. If this is going to happen, it would most
likely happen on the first three points, which are needed to bootstrap the
algorithm.

Chris.
Re: Contour Problem [message #39212 is a reply to message #7115] Mon, 26 April 2004 11:14 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Jeff Patrick wrote:
> I've checked the latitude and longitude and do not see any duplicate data,
> so I guess my next question is what data type (int, single, double, etc.) is
> Contour looking for? I could see that it may think there is duplicate data
> if it is rounding the values I'm sending it. Also does Contour use the

Near-duplicates are just as bad as duplicates, and there doesn't have to
be any explicit rounding to make that true. 'b' is a duplicate of 'c'
for practical purposes, if you need to calculate "a/(b-c)" for values of
'a', 'b', and 'c' for which b-c is so close to 0 that the calculation
would overflow.
Re: Contour Problem [message #39217 is a reply to message #39078] Mon, 26 April 2004 09:04 Go to previous messageGo to next message
Jeff Patrick is currently offline  Jeff Patrick
Messages: 4
Registered: April 2004
Junior Member
I've checked the latitude and longitude and do not see any duplicate data,
so I guess my next question is what data type (int, single, double, etc.) is
Contour looking for? I could see that it may think there is duplicate data
if it is rounding the values I'm sending it. Also does Contour use the
value stored in the zero (0) index of the array (it seems that other IDL
function may not)?

Thanks for the help on this,

Jeff

"Christopher Lee" <lc@127.0.0.1> wrote in message
news:pan.2004.04.24.11.39.58.346601@127.0.0.1...
> On Fri, 23 Apr 2004 17:11:11 -0500, Jeff Patrick wrote:
>
>> I keep getting the following error in my code and I can't figure out
why.
>> Any help would be appreciated.
>>
>> % Internal error: Triangulation is invalid.
>>
>> CONTOUR, X, Y, Z, IRREGULAR=1, ISOTROPIC=1, /CLOSED, /CELL_FILL,
/OVERPLOT,
>> .....
>> each array is 32400 in size.
>>
>> Thank you,
>>
>> Jeff
>> jeff.patrick@computer.org
>
> Your getting the error because the contour function calls the triangulate
> function internally, which throws an error on your data. If you can
> separate the data from the Widget program, do it :) (save it to a file).
>
> Then run TRIANGULATE on the data, if that throws an error, it probably
> will, something is wrong with the data. e.g
>
> There are identical points in the data, triangulate works (in a fluffy,
> wordy kind of way) by drawing circles which have the points on the
> circumference. If the points are identical, it can't work. (This would be
> my guess).
>
> There are colinear points which otherwise satisfy the Delauney
> Triangulation algorithm, (good luck finding these). The triangle will be
> 'flat', i.e not a triangle. If this is going to happen, it would most
> likely happen on the first three points, which are needed to bootstrap the
> algorithm.
>
> Chris.
Re: CONTOUR problem [message #62121 is a reply to message #7115] Wed, 27 August 2008 07:09 Go to previous messageGo to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 27, 9:02 am, xiao <littledd...@gmail.com> wrote:
> On Aug 27, 3:06 am, Wox <nom...@hotmail.com> wrote:
>
>
>
>> On Tue, 26 Aug 2008 16:21:05 -0700 (PDT), xiao <littledd...@gmail.com>
>> wrote:
>
>>> HI~ everyone~ i use the contour pro to display a 2Darray named s11.
>>> And I wrote it like this:
>
>>> CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],ytitl e='Viewing
>>> zenith angle',xtitle='Relative azimuth angle',/C_LABELS
>
>>> But the xrange and yrange do not work and it only labeled on line in
>>> the image , Any one see where the problem is ?
>
>>> Thank you very much~
>
>> nlevels=5
>> CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],xstyl e=1,ystyle=1,ytitle='Viewing
>> zenith angle',xtitle='Relative azimuth
>> angle',C_LABELS=replicate(1,nlevels)
>
>> To know how many levels there are (nlevels), you must set the LEVELS
>> keyword yourself., otherwise make nlevels big enough.
>
> Thanks , it works. but the xrange still does not work......

Btw, how can I set the intervals of the contour ?
thanx
Re: CONTOUR problem [message #62122 is a reply to message #7115] Wed, 27 August 2008 07:02 Go to previous messageGo to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 27, 3:06 am, Wox <nom...@hotmail.com> wrote:
> On Tue, 26 Aug 2008 16:21:05 -0700 (PDT), xiao <littledd...@gmail.com>
> wrote:
>
>> HI~ everyone~ i use the contour pro to display a 2Darray named s11.
>> And I wrote it like this:
>
>> CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],ytitl e='Viewing
>> zenith angle',xtitle='Relative azimuth angle',/C_LABELS
>
>> But the xrange and yrange do not work and it only labeled on line in
>> the image , Any one see where the problem is ?
>
>> Thank you very much~
>
> nlevels=5
> CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],xstyl e=1,ystyle=1,ytitle='Viewing
> zenith angle',xtitle='Relative azimuth
> angle',C_LABELS=replicate(1,nlevels)
>
> To know how many levels there are (nlevels), you must set the LEVELS
> keyword yourself., otherwise make nlevels big enough.

Thanks , it works. but the xrange still does not work......
Re: CONTOUR problem [message #62128 is a reply to message #7115] Wed, 27 August 2008 01:06 Go to previous messageGo to next message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Tue, 26 Aug 2008 16:21:05 -0700 (PDT), xiao <littledddna@gmail.com>
wrote:

> HI~ everyone~ i use the contour pro to display a 2Darray named s11.
> And I wrote it like this:
>
> CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],ytitl e='Viewing
> zenith angle',xtitle='Relative azimuth angle',/C_LABELS
>
> But the xrange and yrange do not work and it only labeled on line in
> the image , Any one see where the problem is ?
>
> Thank you very much~

nlevels=5
CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],xstyl e=1,ystyle=1,ytitle='Viewing
zenith angle',xtitle='Relative azimuth
angle',C_LABELS=replicate(1,nlevels)

To know how many levels there are (nlevels), you must set the LEVELS
keyword yourself., otherwise make nlevels big enough.
Re: CONTOUR problem [message #62210 is a reply to message #7115] Wed, 27 August 2008 08:02 Go to previous messageGo to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 27, 10:00 am, Wox <nom...@hotmail.com> wrote:
> On Wed, 27 Aug 2008 07:41:23 -0700 (PDT), xiao <littledd...@gmail.com>
> wrote:
>
>> Sorry, another question....why i always get red as the back ground
>> color when i use this statement?
>
>> !P.background=255 i thought it should be white.... :(
>
> The quick answer would be:
>
> device,decomposed=0
> !P.background=255
> CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],color =0,xstyle=1,ystyle=1,ytitle='Viewing
> zenith angle',xtitle='Relative azimuth angle',C_LABELS=replicate(1,10)
>
> => note the xstyle,ystyle and color keywords

THanks~ I got it ~ :)
Re: CONTOUR problem [message #62211 is a reply to message #7115] Wed, 27 August 2008 08:00 Go to previous messageGo to next message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Wed, 27 Aug 2008 07:41:23 -0700 (PDT), xiao <littledddna@gmail.com>
wrote:

> Sorry, another question....why i always get red as the back ground
> color when i use this statement?
>
> !P.background=255 i thought it should be white.... :(

The quick answer would be:

device,decomposed=0
!P.background=255
CONTOUR,s11,rangle,vangle,xrange=[0,180],yrange=[0,90],color =0,xstyle=1,ystyle=1,ytitle='Viewing
zenith angle',xtitle='Relative azimuth angle',C_LABELS=replicate(1,10)

=> note the xstyle,ystyle and color keywords
Re: CONTOUR problem [message #62212 is a reply to message #7115] Wed, 27 August 2008 07:51 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> Sorry, another question....why i always get red as the back ground
> color when i use this statement?
>
> !P.background=255 i thought it should be white.... :(

http://www.dfanning.com/color_tips/colorchp3.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: CONTOUR problem [message #62214 is a reply to message #7115] Wed, 27 August 2008 07:41 Go to previous messageGo to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 27, 9:16 am, xiao <littledd...@gmail.com> wrote:
> On Aug 27, 9:14 am, David Fanning <n...@dfanning.com> wrote:
>
>> xiao writes:
>>> Btw, how can I set the intervals of the contour ?
>
>> http://www.dfanning.com/tips/nlevels.html
>
>> Cheers,
>
>> David
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Thank you ,David :)
Sorry, another question....why i always get red as the back ground
color when i use this statement?

!P.background=255 i thought it should be white.... :(
Re: CONTOUR problem [message #62217 is a reply to message #7115] Wed, 27 August 2008 07:16 Go to previous messageGo to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 27, 9:14 am, David Fanning <n...@dfanning.com> wrote:
> xiao writes:
>> Btw, how can I set the intervals of the contour ?
>
> http://www.dfanning.com/tips/nlevels.html
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thank you ,David :)
Re: CONTOUR problem [message #62218 is a reply to message #62121] Wed, 27 August 2008 07:14 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> Btw, how can I set the intervals of the contour ?

http://www.dfanning.com/tips/nlevels.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: CONTOUR problem [message #62219 is a reply to message #62122] Wed, 27 August 2008 07:13 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> Thanks , it works. but the xrange still does not work......

Set the [XY]Style keywords to 1 to force exact axis scaling.
This is, IMHO, almost always necessary when using the CONTOUR
command. You can find more information about the anemic
CONTOUR command here:

http://www.dfanning.com/documents/tips.html#Graphics2d

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Contour Problem [message #77036 is a reply to message #7115] Mon, 25 July 2011 11:13 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Alexa writes:

> I think this is probably a pretty easy problem but I could get help
> that'd be great.
>
> I'm making a contour plot and and I want to change the values of the
> axes so I'm doing
>
> x=[-6, 0]
> y=[-3, 1]
>
> Contour, x, y, z
>
> But I get an error that says that x and y need to be 2D arrays, but
> aren't those already 2D arrays? Do I have the syntax wrong?

Well, usually the syntax of the Contour plot is like this:

Contour, z, x, y

Maybe you want something like this:

s = Size(z, /Dimensions)
x = Scale_Vector(Findgen(s[0]), -6, 0)
y = Scale_Vector(Findgen(s[1]), -3, 1)
Contour, z, x, y

You can find Scale_Vector here:

http://www.idlcoyote.com/programs/scale_vector.pro

You might need other routines from the Coyote Library, too.
It is best to download the whole thing.

http://www.idlcoyote.com/code_tips/installcoyote.php

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Contour Problem
Next Topic: TIMEGEN bug (not the pre-6.4 bug that Fanning describes)

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

Current Time: Wed Oct 08 15:09:57 PDT 2025

Total time taken to generate the page: 0.17010 seconds