### Author Topic: calculate average wind direction?  (Read 24217 times)

0 Members and 1 Guest are viewing this topic.

#### m77

• Forecaster
• Posts: 871
##### calculate average wind direction?
« on: August 18, 2010, 12:57:36 PM »
i saw that NOAA use arctan(u/v) to do this,

http://www.ndbc.noaa.gov/wndav.shtml

but can anyone run me through a basic eg please?

thanks

#### KeithBC

• Senior Contributor
• Posts: 162
##### Re: calculate average wind direction?
« Reply #1 on: August 18, 2010, 01:37:37 PM »
You have to do a vector addition to get the average direction.

Break down each individual wind speed/direction vector into an East-West component and a North/South component.  Assuming the direction is given in degrees clockwise from north, the north-south component is the cosine of the direction angle times the speed; the east/west component is the sine of the direction times the speed.
Cns = cos(Dir)*Spd
Cew = sin(Dir)*Spd

Add up all the north-south components.  Then separately, add up all the east/west components.

The average direction is the arctan of the east/west components divided by the north south components.
Dir = arctan(sum(Cew) / sum(Cew))

Gotchas to watch out for: Degrees versus radians.  Wind directions are usually given in degrees.  Trig functions are usually in radians.  Arctan functions usually get confused about quadrants.  If you have an arctan function that takes two parameters (rise and run), use it rather than one that takes a single value.  The two parameters  are then the east/west sum and the north/south sum.

#### m77

• Forecaster
• Posts: 871
##### Re: calculate average wind direction?
« Reply #2 on: August 18, 2010, 02:39:53 PM »
Ok so what if I get a north west 5mph and also a north east at 10 mph?

Can you please show me how to work that one?

i get 0.958 ????
« Last Edit: August 19, 2010, 02:52:09 AM by m77 »

#### KeithBC

• Senior Contributor
• Posts: 162
##### Re: calculate average wind direction?
« Reply #3 on: August 22, 2010, 01:17:51 PM »
Vector 1: NW @ 5
NS1 = 5 * cos(315) = 3.54
EW1 = 5 * sin(315) = -3.54

Vector 2: NE @ 10
NS2 = 10 * cos(45) = 7.07
EW2 = 10 * sin(45) = 7.07

TotalNS = NS1 + NS2 = 3.54 + 7.07 = 10.61
TotalEW = EW1 + EW2 = -3.54 + 7.07 = 3.54

Compute resultant vector:
Average Direction = atan(TotalEW / TotalNS) = atan(3.54 / 10.61) = 18.43

Note that I have given all angles in degrees.  In practice, you would have to convert to and from radians, since trig functions invariably use radian measure.  Also, a standard atan function will produce a quadrantal ambiguity that you will have to resolve yourself.  Some Microsoft products have an ATAN2 function which takes the rise and run separately, and can therefore resolve the ambiguity itself.  When I did this example in Excel, I used ATAN2(10.61, 3.54).

To be mathematically rigorous, you should divide the TotalNS and TotalEW by 2, since you want an average, not a total.  However, if you are only interested in the direction, you would be dividing both the numerator and denominator by the same amount, which is an unnecessary step.  The true vector average (with the division by 2) would only be necessary if you wanted a magnitude to go along with the direction.  In the case of wind, the result would be meaningless.

If the atan function returns a negative result, add 360 degrees to get a compass direction.
« Last Edit: August 22, 2010, 01:41:38 PM by KeithBC »

#### phanindra

• Member
• Posts: 1
##### Re: calculate average wind direction?
« Reply #4 on: January 07, 2014, 12:06:43 AM »
Hi KeithBC,

Firstly thank you for sparing your time..

I am having similar problem with the wind direction and current direction average..

I am applying same concept to both the parameters wind and current.. can it be done..??

please let me know the answer..as I am working on my M.Tech(Ocean Science) project..

I am having wind( & current) speed and direction with an interval of 1 hour daily for three years..
now I want daily average of both the wind(&current) direction, to observe the seasonal variations there after.

#### SLOweather

• Forecaster
• Posts: 3386
##### Re: calculate average wind direction?
« Reply #5 on: January 07, 2014, 12:32:52 PM »
I had an identical thread recently. Old Tele Man posted a dirrerent solution there:

Quote
Use the "signed-complement" value technique, ie: "...how many degrees left(-) or right(+) of True North (0º)..." for each reading, not its actual value:

-(360º-315º) = -45º x 5 = -225º, where n = 5
-(0-45) = +45º x 5 = +225º, where n = 5; total n = 5+5 = 10

AVGº = (-225º + 225º)/10 = (0º/10) = 0º [ NOTE: do error checking for ZERO-value BEFORE performing division by number of samples (n = 10) ]

#### KeithBC

• Senior Contributor
• Posts: 162
##### Re: calculate average wind direction?
« Reply #6 on: January 07, 2014, 02:00:00 PM »
Hi KeithBC,

Firstly thank you for sparing your time..

I am having similar problem with the wind direction and current direction average..

I am applying same concept to both the parameters wind and current.. can it be done..??

please let me know the answer..as I am working on my M.Tech(Ocean Science) project..

I am having wind( & current) speed and direction with an interval of 1 hour daily for three years..
now I want daily average of both the wind(&current) direction, to observe the seasonal variations there after.
The solution is just a general vector addition.  It has nothing to do with wind per se.  It applies any time you are averaging several directions.

While a vector addition makes sense for the average direction, it does not make sense for an average speed, at least in the context of wind or ocean currents.  If you have a wind from the east at 60 and another from the west at 50, the average direction would be from the east, but the average speed would not be 10, which is what a vector addition would give you.  For speeds, you need to average the speeds as a straight numerical average, separately from the direction vectors.

#### Red Dragon

• Member
• Posts: 28
##### Re: calculate average wind direction?
« Reply #7 on: March 14, 2017, 09:05:07 PM »
You have to do a vector addition to get the average direction.

Break down each individual wind speed/direction vector into an East-West component and a North/South component.  Assuming the direction is given in degrees clockwise from north, the north-south component is the cosine of the direction angle times the speed; the east/west component is the sine of the direction times the speed.
Cns = cos(Dir)*Spd
Cew = sin(Dir)*Spd

Add up all the north-south components.  Then separately, add up all the east/west components.

The average direction is the arctan of the east/west components divided by the north south components.
Dir = arctan(sum(Cew) / sum(Cew))

Gotchas to watch out for: Degrees versus radians.  Wind directions are usually given in degrees.  Trig functions are usually in radians.  Arctan functions usually get confused about quadrants.  If you have an arctan function that takes two parameters (rise and run), use it rather than one that takes a single value.  The two parameters  are then the east/west sum and the north/south sum.

I tried writing some code to do this but my results are ether 0-90 or 270-360.

#### Jáchym

• Meteotemplate Developer
• Forecaster
• Posts: 8567
##### Re: calculate average wind direction?
« Reply #8 on: March 14, 2017, 09:13:11 PM »
This is what I use in Meteotemplate, you just pass it the array with the directions (in deg, 0-360) and it works fine:

Code: [Select]
`function avgWind(\$directions) {   \$sinSum = 0;   \$cosSum = 0;   foreach (\$directions as \$value) { \$sinSum += sin(deg2rad(\$value)); \$cosSum += cos(deg2rad(\$value));   }   return ((rad2deg(atan2(\$sinSum, \$cosSum)) + 360) % 360); }`

#### waiukuweather

• Forecaster
• Posts: 624
##### Re: calculate average wind direction?
« Reply #9 on: March 14, 2017, 10:43:16 PM »
you want to also weight the wind direction by windspeed as well i.e as a vector

#### mcrossley

• Forecaster
• Posts: 314
##### Re: calculate average wind direction?
« Reply #10 on: March 15, 2017, 06:53:11 AM »
I tried writing some code to do this but my results are ether 0-90 or 270-360.
You need to use atan2() to obtain the results for all the quadrants.
Mark