WXforum.net

General Weather/Earth Sciences Topics => Weather Conditions Discussion => Topic started by: m77 on August 18, 2010, 12:57:36 PM

Title: calculate average wind direction?
Post by: m77 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
Title: Re: calculate average wind direction?
Post by: KeithBC 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.
Title: Re: calculate average wind direction?
Post by: m77 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 ????
Title: Re: calculate average wind direction?
Post by: KeithBC 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

Add components:
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.

[edit]If the atan function returns a negative result, add 360 degrees to get a compass direction.
Title: Re: calculate average wind direction?
Post by: phanindra 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.
Title: Re: calculate average wind direction?
Post by: SLOweather on January 07, 2014, 12:32:52 PM
I had an identical thread recently. Old Tele Man posted a dirrerent solution there (http://www.wxforum.net/index.php?topic=20772.msg199630#msg199630):

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) ]
Title: Re: calculate average wind direction?
Post by: KeithBC 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.
Title: Re: calculate average wind direction?
Post by: Red Dragon 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.
Title: Re: calculate average wind direction?
Post by: Jáchym 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);
}
Title: Re: calculate average wind direction?
Post by: waiukuweather 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
Title: Re: calculate average wind direction?
Post by: mcrossley 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.
Title: Re: calculate average wind direction?
Post by: drpjfitz on April 25, 2020, 01:22:23 AM
There are some good tidbits in this discussion, but the answers are incomplete. Remember, calculations require precision and details to be helpful.

Consider the following:

u           v      Speed   direction
 0.26       -2.99       3         355
-0.87       -9.96       10           5
-3.62     -13.52      14         15

Obviously, the average wind direction is 5 deg. But basic averaging by (355+5+15)/3 gives an answer of 125 deg, which is incorrect. The problem is that compass angles are circular and have a discontinuity for north winds where the angle in the northwest quadrant is from 270-360 deg and in the northeast quadrant is 0-90 deg.

One solution is a variant of the mean of circular quantities technique. The math technique is described at https://en.wikipedia.org/wiki/Mean_of_circular_quantities with meteorological details in Yamartino (1984). One does vector addition for each component, then performs an arctangent of the summed components ratio to get the average direction. This method has the following equations:

Step 1: Sum the sines and cosines of wind direction ϕ:

ssum=sum all sin⁡ϕ
scos=sum all cos⁡ϕ

Step 2: Compute the average

ϕ_avg=(180/pi)* atan2⁡(ssum,scos);             if ϕ_avg<0,then  ϕ_avg=ϕ_avg+360

For example, in the above example in radians mode:

ssum=sin{355*(pi/180)}+sin⁡{5*(pi/180)}+sin⁡{15*(pi/180)}=0.26
csum=cos⁡{355*(pi/180)}+cos⁡{5*(pi/180)}+cos⁡{15*(pi/180)}=2.96

Then the result for the average wind direction is:

ϕ_avg=180/pi*atan2⁡(0.26,2.96)=5 deg
Title: Re: calculate average wind direction?
Post by: d00m178 on December 17, 2021, 09:48:10 AM
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

Add components:
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.

[edit]If the atan function returns a negative result, add 360 degrees to get a compass direction.


hello.
Im checking this method for calculating average wind direction.
Im using Arduino so my code looks like this:

Code: [Select]
.....

void loop() {

........

  WD_curr = check_WD(); // current wind direction from sensor
  WS_curr = check_WS(); // current wind speed from sensor

  if (WS_curr != 0 ) {
      i++; 
      if ( WS_max < WS_curr ) { WS_max = WS_curr; }
      WS_summ = WS_summ + WS_curr;
      WS_mean = WS_summ / i;  // calculate average wind speed

// calculate average wind direction
      NS_curr = WS_curr * cos(WD_curr);
      EW_curr = WS_curr * sin(WD_curr);
      NS_summ = NS_summ + NS_curr;
      EW_summ = EW_summ + EW_curr;

      WD_mean = atan(EW_summ/NS_summ);

      Serial.print(F("WD_mean: ")); Serial.println(WD_mean, 3);

  } //end if


//print/send WS_mean WD_mean

} //end loop

but sometime I receive negative results for wind direction.
you already advised
Quote
If the atan function returns a negative result, add 360 degrees to get a compass direction.
what it means?

I need check if it negative and add to WD_mean variable 360?
like this?
Code: [Select]
if (WD_mean < 0) {
   WD_mean = WD_mean + 360
}


or probably I can use atan2 function?

please advice
Title: Re: calculate average wind direction?
Post by: Randall Kayfes on January 24, 2022, 06:20:52 PM
It is almost as if we are talking Wind Runs and direction...
Title: Re: calculate average wind direction?
Post by: sky_watcher on January 24, 2022, 07:21:33 PM
you want to also weight the wind direction by windspeed as well i.e as a vector
This and average wind speed is always an interesting topic, and many will disagree with my perspective.

Some things I read (https://www.scadacore.com/2014/12/19/average-wind-direction-and-wind-speed/) say that both wind direction and wind speed should be vector calculations.

If makes sense that if you do a vector wind speed, you should do a vector wind direction, HOWEVER, according to the WMO when discussing average wind speed "Perhaps the simplest example is a mechanical rotation-counting register on a cup anemometer commonly used to measure the passage of wind during a chosen averaging time interval." That is, Wind Run distance reading divided by time giving speed.

This means that averaging wind speed should NOT include the direction. That is, if the wind blows for the same period of time from East and then the West at 20kph, the WMO definition of average wind speed is  NOT 0kph, it is 20kph.

I couldn't find any reference in the WMO docs for calculating average wind direction and I don't recall ever calculating it many decades ago when I was  Radio technical Officer/Weather Observer with the Australian Bureau of Meteorology, so IMO, if average wind speed does not take into account direction, neither should wind direction.

If you calculate the vectors, what you are calculating is where you would expect a leaf blown by the wind to end up on average. In that case, the East/West example gives the correct answer of where a leaf would end up if blown East and then West for the same periods of time and the same speed.

Title: Re: calculate average wind direction?
Post by: sky_watcher on January 24, 2022, 09:39:01 PM
so IMO, if average wind speed does not take into account direction, neither should wind direction.
Oops! That should say "if average wind speed does not take into account direction, neither should wind direction take speed into account."
Title: Re: calculate average wind direction?
Post by: Randall Kayfes on February 23, 2022, 05:13:58 PM
Sky_Watcher brings up an interesting argument and I would tend to agree. The information spider graphed gives two completely different stories to tell:

YTD Wind Direction by Run:
(https://blogger.googleusercontent.com/img/a/AVvXsEiz4fR46bng9BSLCSgLz_mL8ccRTJnX3vNdu30-WD7TvZHTpVBtYi2s020FvE4bYL5XqSIHgAf8ie7QWFMb4BwfhTjCQIW0vYHRkBTC2n9LiJYGtc2Yb54xhwYAr2JOeVyoxuRqUH1Hneq7F632_Pu1NRxM2sg5h0aZWbdRTZFXE-lZ7m6-ZbjJScumNQ=w640-h517)

YTD Wind Direction by Time:
(https://blogger.googleusercontent.com/img/a/AVvXsEiUbPDVzMEgq6NICoIqVkSO-ygQsNXN-nXgnn7IO_bLEsU6Q1WdHsetorewQRR5YKgXO4Ss6CNa0Btf9gOIl1bPV965fOvrC91OaCXvIQ844GF-JaBYpNitiFt2xzi64z98lIRzl8S-t85SU4KGB0PuHPHMafiVx-F0nhlmrZzDEDUkoK7jWg0xkl0RHg=w640-h456)

For me a constant all-day (time) wind is more informative vs. one strong gust (run)...
But which graph is more "accurate" is way beyond my education...