Direction of Wind Vectors: A bug? [message #90287] |
Wed, 18 February 2015 10:32  |
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   |
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   |
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 #90306 is a reply to message #90289] |
Wed, 18 February 2015 14:23   |
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 #90343 is a reply to message #90287] |
Mon, 23 February 2015 07:28  |
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.")
|
|
|