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

0 Members and 1 Guest are viewing this topic.

Offline m77

  • Forecaster
  • *****
  • Posts: 878
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
Weatherlink ip, Vantage Vue,

Offline 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.

Offline m77

  • Forecaster
  • *****
  • Posts: 878
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 »
Weatherlink ip, Vantage Vue,

Offline 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

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.
« Last Edit: August 22, 2010, 01:41:38 PM by KeithBC »

Offline 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.

Offline SLOweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 3457
    • http://www.sloweather.com
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) ]

Offline 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.

Offline Red Dragon

  • Member
  • *
  • Posts: 34
    • Weather Chipmunk
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.

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8604
    • Meteotemplate
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);
}

Offline waiukuweather

  • Forecaster
  • *****
  • Posts: 1064
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

Offline mcrossley

  • Forecaster
  • *****
  • Posts: 910
    • Wilmslow Astro
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

Offline drpjfitz

  • Member
  • *
  • Posts: 1
Re: calculate average wind direction?
« Reply #11 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
« Last Edit: April 25, 2020, 01:35:11 AM by drpjfitz »

Offline d00m178

  • Member
  • *
  • Posts: 3
Re: calculate average wind direction?
« Reply #12 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

Offline Randall Kayfes

  • Weather - Photography - Astronomy - Computer Admin
  • Forecaster
  • *****
  • Posts: 1930
    • Arizona Kaymann
Re: calculate average wind direction?
« Reply #13 on: January 24, 2022, 06:20:52 PM »
It is almost as if we are talking Wind Runs and direction...



Offline sky_watcher

  • Contributor
  • ***
  • Posts: 124
Re: calculate average wind direction?
« Reply #14 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 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.

“The more a man knows, the more willing he is to learn. The less a man knows, the more positive he is that he knows everything...” ― Robert G. Ingersoll

Offline sky_watcher

  • Contributor
  • ***
  • Posts: 124
Re: calculate average wind direction?
« Reply #15 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."
“The more a man knows, the more willing he is to learn. The less a man knows, the more positive he is that he knows everything...” ― Robert G. Ingersoll

Offline Randall Kayfes

  • Weather - Photography - Astronomy - Computer Admin
  • Forecaster
  • *****
  • Posts: 1930
    • Arizona Kaymann
Re: calculate average wind direction?
« Reply #16 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:


YTD Wind Direction by Time:


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...
« Last Edit: February 23, 2022, 05:16:54 PM by Randall Kayfes »



 

anything