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

Home » Public Forums » archive » Direction of Wind Vectors: A bug?
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
Direction of Wind Vectors: A bug? [message #90287] Wed, 18 February 2015 10:32 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Folks,

Someone was harassing my retirement reveries this morning by claiming
that cgDrawVectors was drawing vectors incorrectly, in the wrong
directions. He cited as evidence the output of the lovely NASA program,
PartVelVec.

Upon looking into this, I discovered that the two programs produce
vectors in exactly the same direction if the the plot they are being
output on has the same scale in the X and Y direction. (Other things,
such as vector length and whether the location specifies the end of the
vector or the middle, etc, are different, but irrelevant here.)

If the scale is different on the output plot, the two programs calculate
the end-point of the vector differently. As it happens (maybe you saw
this coming), I believe cgDrawVectors is doing things right and
PartVelVec is doing things wrong.

You will need a recent version of cgDrawVectors to test this. You can
download the latest here:

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

Unfortunately, I am only about 75% convinced cgDrawVectors is right. I
need reassurance from some IDL experts. God only knows how many papers
have been written using output from PartVelVec as supporting evidence!

Here is my thinking. Suppose you tell me at some spot on the Earth, the
wind is blowing 10 mph in the X direction and 10 mph in the Y direction.
Clearly, if I place, say, an arrow at that location, I will have to
point it at a 45 degree angle to the location I am standing on to
indicate the wind vector direction at that location.

OK, see, my confidence has already eroded to less than 50%, just by
writing what I have so far! :-(

As you can see from the test program below, cgDrawVectors preserves this
instantaneous vector angle (45 degrees) no matter what the plot scale,
while PartVelVec does not. But, I can also see someone explaining
PartVelVec by saying, "Look, forget the angle of the vector for a
moment. Walk from the starting point of this vector to the end of this
vector, and note the coordinates of the two points. Calculate the angle
from that. It is 45 degrees, even though it doesn't look like it on the
plot because the scale is screwed up."

So, here is my question. Are both of these programs "right"? If not, why
not? And, which would convey the "true wind direction" more convincingly
on a plot?

Here is the test program.

;*********************************************************** *****
Pro Vector_Bug
cgdisplay, wid=1, aspect=1.0, Title='Scale Same in XY'
cgplot, [-180, 180], [-180, 180], /NoData
partvelvec, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='red', length=.5
cgdrawvectors, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='blue', length=0.1

cgdisplay, wid=0, aspect=1.0, Title='Scale Different in XY'
cgplot, [-180, 180], [-90, 90], /NoData
partvelvec, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='red', length=.5
cgdrawvectors, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='blue', length=0.2
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: Direction of Wind Vectors: A bug? [message #90288 is a reply to message #90287] Wed, 18 February 2015 11:23 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Wednesday, February 18, 2015 at 1:32:50 PM UTC-5, David Fanning wrote:

> So, here is my question. Are both of these programs "right"? If not, why
> not? And, which would convey the "true wind direction" more convincingly
> on a plot?

I'd vote for the partvelvec.pro approach where the angle -- like everything else on the map -- is distorted by the unequal projections.

However, in a similar case I chose the opposite approach -- in my tvcircle.pro I have the comment

"TVCIRCLE always draws a circle --- even when in data coordinates and the X and Y data scales are unequal. (The X data scale is used to define the circle radius.) If this is not the behavior
you want, then use TVELLIPSE instead."


In any case, the behavior of the program should be documented (which partvelvec.pro currently isn't), and perhaps a keyword could be added to let the user choose which approach he wants.

--Wayne
Re: Direction of Wind Vectors: A bug? [message #90289 is a reply to message #90288] Wed, 18 February 2015 11:44 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
wlandsman writes:

>
> On Wednesday, February 18, 2015 at 1:32:50 PM UTC-5, David Fanning wrote:
>
>> So, here is my question. Are both of these programs "right"? If not, why
>> not? And, which would convey the "true wind direction" more convincingly
>> on a plot?
>
> I'd vote for the partvelvec.pro approach where the angle -- like everything else on the map -- is distorted by the unequal projections.
>
> However, in a similar case I chose the opposite approach -- in my tvcircle.pro I have the comment
>
> "TVCIRCLE always draws a circle --- even when in data coordinates and the X and Y data scales are unequal. (The X data scale is used to define the circle radius.) If this is not the behavior
> you want, then use TVELLIPSE instead."
>
>
> In any case, the behavior of the program should be documented (which partvelvec.pro currently isn't), and perhaps a keyword could be added to let the user choose which approach he wants.

I'm having a hard time wrapping my head around whether both approaches
are "right", or are they both "wrong." Or, maybe there is some other
combination. It would be easier (and maybe the right approach) to draw a
"stream line" instead of a vector. Then, at least you could visually see
the distortion.

In any case, I can't quite see where I would introduce the actions of
the proposed keyword. And, then, adding a real map projection is just...
Whew! I need another bottle of Tylenol. :-(

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: Direction of Wind Vectors: A bug? [message #90290 is a reply to message #90289] Wed, 18 February 2015 12:04 Go to previous messageGo to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
I saw this problem in the routine VELOVECT. I had to rewrite the code taking into account the aspect ratio of the output plot.

ra=(clip[3]-clip[1])/(clip[2]-clip[0])

x_step=0.01
y_step=0.01 * ra

I had to do the same in your routine windbarb. I assume that you are having the same problem here...
Re: Direction of Wind Vectors: A bug? [message #90291 is a reply to message #90290] Wed, 18 February 2015 12:09 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
nata writes:

> I saw this problem in the routine VELOVECT. I had to rewrite the code taking into account the aspect ratio of the output plot.
>
> ra=(clip[3]-clip[1])/(clip[2]-clip[0])
>
> x_step=0.01
> y_step=0.01 * ra
>
> I had to do the same in your routine windbarb. I assume that you are having the same problem here...

And you are just telling me about this now, after I've retired! Sigh...

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: Direction of Wind Vectors: A bug? [message #90294 is a reply to message #90291] Wed, 18 February 2015 12:25 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 02/18/15 15:09, David Fanning wrote:
>
> And you are just telling me about this now, after I've retired!
> Sigh...

To paraphrase Inigo Montoya: I do not think retired means what you think
it means.

cheers,

paulv
Re: Direction of Wind Vectors: A bug? [message #90296 is a reply to message #90294] Wed, 18 February 2015 12:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> To paraphrase Inigo Montoya: I do not think retired means what you think
> it means.

Trying to find the Like button to hit. (I've had plenty of time to learn
how to use Facebook lately.)

Dave
--
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: Direction of Wind Vectors: A bug? [message #90306 is a reply to message #90289] Wed, 18 February 2015 14:23 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
> I'm having a hard time wrapping my head around whether both approaches
> are "right", or are they both "wrong." Or, maybe there is some other
> combination. It would be easier (and maybe the right approach) to draw a
> "stream line" instead of a vector. Then, at least you could visually see
> the distortion.
>
> In any case, I can't quite see where I would introduce the actions of
> the proposed keyword. And, then, adding a real map projection is just...
> Whew! I need another bottle of Tylenol. :-(

OK, I've finally convinced myself Wayne was right all along. I can hear
the big sigh from NASA astronomy programmers from here in Colorado! :-)

With the help of the Arrow command to give me a better idea of which
direction I should be pointed in, I have revamped cgDrawVectors to
essentially point in the "data" direction. Now this is more or less
compatible with PartVelVec. I haven't tested this thoroughly with map
projections yet, but it appears it might even be slightly better than
PartVelVec with map projections. Or, maybe it's just my glazed eye
outlook on the subject.

In any case, I recommend everyone who cares about this kind of thing get
a new version of the cgDrawVectors program. You can find it here:

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

Here is my test program so you can see what the two programs are doing.
Be sure to download the new program before running it.

;*********************************************************** ***
Pro Vector_Bug
cgdisplay, wid=1, aspect=1.0, Title='Scale Same in XY'
cgplot, [-180, 180], [-180, 180], /NoData
partvelvec, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='red', length=.5
cgdrawvectors, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='blue', length=0.1
cgArrow, -45, 50, -25, 70, /Data, Color='Grn6', Thick=3
cgArrow, -45, -50, -25, -30, /Data, Color='Gold', Thick=3

cgdisplay, wid=0, aspect=1.0, Title='Scale Different in XY'
cgplot, [-180, 180], [-400, 400], /NoData
partvelvec, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='red', length=.5
cgdrawvectors, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='blue', length=0.2
cgArrow, -45, 50, -25, 70, /Data, Color='Grn6', Thick=3
cgArrow, -45, -50, -25, -30, /Data, Color='Gold', Thick=3

cgdisplay, wid=2, aspect=1.0, Title='Scale Different in XY on Map'
cgMap_Set, /Miller_Cylindrical, $
Position=[0.1, 0.1, 0.9, 0.9], LIMIT=[-70, -180, 70, 180]
;cgMap_Grid, /label
partvelvec, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='red', length=.5
; cgArrow, -45, 50, -25, 70, /Data, Color='Grn6', Thick=3
; cgArrow, -45, -50, -25, -30, /Data, Color='Gold', Thick=3

mapCoord = Obj_New('cgMap', 118, xrange=[-180, 180], $
yrange=[-70, 70], $
Position=[0.1, 0.1, 0.9, 0.9], /LatLon_Ranges)
mapCoord -> Draw
cgMap_Continents, Map=mapCoord, Color='grn5'
cgdrawvectors, [10,10], [10,10], [-45, -45], [50,-50], $
/over, veccolor='blue', length=0.2, Map=mapCoord
xy = mapCoord -> Forward([-45, -25], [50,70])
cgArrow, xy[0,0], xy[1,0], xy[0,1], xy[1,1], /Data, $
Color='grn6, Thick=3
xy = mapCoord -> Forward([-45, -25], [-50,-30])
cgArrow, xy[0,0], xy[1,0], xy[0,1], xy[1,1], /Data, $
Color='grn6, Thick=3
END
;*********************************************************

Cheers,

David

P.S. See you next year! ;-)

--
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: Direction of Wind Vectors: A bug? [message #90307 is a reply to message #90288] Wed, 18 February 2015 14:27 Go to previous messageGo to next message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 18.02.2015 20:23, wlandsman wrote:
> On Wednesday, February 18, 2015 at 1:32:50 PM UTC-5, David Fanning wrote:
>
>>> So, here is my question. Are both of these programs "right"? If not, why
>>> not? And, which would convey the "true wind direction" more convincingly
>>> on a plot?
> I'd vote for the partvelvec.pro approach where the angle -- like everything else on the map -- is distorted by the unequal projections.

I agree with Wayne. But this is realy just for equirectangular maps, I
guess...

Fabien
Re: Direction of Wind Vectors: A bug? [message #90309 is a reply to message #90307] Wed, 18 February 2015 14:44 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Fabien writes:

> I agree with Wayne. But this is realy just for equirectangular maps, I
> guess...

Well, I don't think Wayne is doing anything special for maps. I know
cgDrawVectors works "properly" for polar stereographic projections of
the poles, but this relies on using the cgMap object to set up the map
projection space. (Really simple, but people still tell me they won't
use or learn objects, so...)

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: Direction of Wind Vectors: A bug? [message #90343 is a reply to message #90287] Mon, 23 February 2015 07:28 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Someone was harassing my retirement reveries this morning by claiming
> that cgDrawVectors was drawing vectors incorrectly, in the wrong
> directions. He cited as evidence the output of the lovely NASA program,
> PartVelVec.

Having decided Wayne was doing the right thing, and still a bit
dissatisfied with how my cgDrawVectors algorithm was working, I spent
the weekend (the reason I retired!) completely gutting and rebuilding
cgDrawVectors. It now takes into account the scale of the plot in the X
and Y directions. What took me a while to work out is that the scale of
the plot on a map projection should always be 180x360, no matter what
portion of the map you are showing in the plot.

Making these changes, I can duplicate the PartVelVec results on every
test I've made, including tests with map projections using Map_Set and
the Map_Proj_Init methods (as implemented in cgMap_Set and cgMap). I've
tried various map projections, and all seems to be working correctly,
although additional testing on ALL map projections is probably
warranted.

While I was tearing things up, I decided to fix the code in cgArrow
(which was drawing the vectors) to make it more flexible and faster by
moving the code closer to the machine. You can now pass a vector of
colors to cgArrow, as well as a vector of arrows to draw, and you should
see significant speed-up of its vector drawing capability. Both programs
should be downloaded, as cgDrawVectors depends on cgArrow.

You can find the two new programs here:

http://www.idlcoyote.com/programs/cgarrow.pro
http://www.idlcoyote.com/programs/cgdrawvectors.pro

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: Interpolation
Next Topic: Errors when compiling routines with main-level programs

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

Current Time: Wed Oct 08 09:19:05 PDT 2025

Total time taken to generate the page: 0.00551 seconds