Author Topic: How to average wind direction?  (Read 3973 times)

0 Members and 1 Guest are viewing this topic.

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
How to average wind direction?
« on: November 18, 2013, 04:37:23 PM »
Some of my stations update the web server every minute with current data. That can make a scattery polar plot of directions. I've already sampled the data to plot fewer dots on the polar graph, but it's still not as clear as I'd like it to be.

VWS seems to apply some smoothing to wind direction data.

I thought about doing a 10 minute degrees average, but that has a problem. If you have 5 samples of data at around 315 degrees each  (NW), and 5 samples at around 45 degrees (NE), the average will be 180 degrees (South), when the average is clearly 0 degrees (north).

I have a couple of thoughts, but I wanted to see what other ideas people have.

Offline Murry Conarroe

  • Contributor
  • ***
  • Posts: 143
    • Wildwood Weather
Re: How to average wind direction?
« Reply #1 on: November 19, 2013, 01:00:37 PM »
Murry

Offline Scott216

  • Senior Member
  • **
  • Posts: 62
Re: How to average wind direction?
« Reply #2 on: October 15, 2014, 10:49:53 AM »
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) ]

This doesn't seem to work for me.  Maybe I'm doing something wrong.  If I have 10 reading:
9x 195 degrees
1x 170 degrees

The signed compliment for the nine 195 degree reading is: -(360-195) = -165
The signed compliment for the one 170 degree reading is: 170
If I add them up  (-165 x 9) + 170 = -1315
The average = -1315/10 = -131.5
Converting the negative value that back to 0-360 degree range: 360 - 131.5 = 228.5 degrees
But the average is really 192.5 degrees


Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: How to average wind direction?
« Reply #3 on: October 15, 2014, 01:23:23 PM »
Unfortunately, I think the method posted by Old Tele man is not correct. The calculation is not so simple. You have to use arctan of the results. The formulae are relatively complex, but can be easily written as a macro or function.

Hopefully this helps:

http://www.laketyersbeach.net.au/windaveraging.html

Offline Scott216

  • Senior Member
  • **
  • Posts: 62
Re: How to average wind direction?
« Reply #4 on: October 15, 2014, 02:28:23 PM »
Unfortunately, I think the method posted by Old Tele man is not correct. The calculation is not so simple. You have to use arctan of the results. The formulae are relatively complex, but can be easily written as a macro or function.

Hopefully this helps:

http://www.laketyersbeach.net.au/windaveraging.html
I tried the arctan method and I had some problems with that also where it didn't always return the right result.  I'll have to look at it again.  Thanks for the link, maybe that will help.

Offline Murry Conarroe

  • Contributor
  • ***
  • Posts: 143
    • Wildwood Weather
Re: How to average wind direction?
« Reply #5 on: October 15, 2014, 03:16:16 PM »
If doing this in PHP, try
Code: [Select]
function avgWind($directionArray) {
//Expects: An array containing wind direction in degrees
//Returns: Average wind direction
  $directionArray = array_filter($directionArray);
  if (0 == count($directionArray)){
      return("");
  } 
  $sinsum = 0; $cossum = 0;
 
  foreach ($directionArray as $value) {
    $sinsum += sin(deg2rad($value));
    $cossum += cos(deg2rad($value));
  }
  return ((rad2deg(atan2($sinsum, $cossum)) + 360) % 360);
}
Murry

Offline Scott216

  • Senior Member
  • **
  • Posts: 62
Re: How to average wind direction?
« Reply #6 on: October 15, 2014, 08:47:14 PM »
I figured it out.  I was using atan() when I should have been using atan2().  Here's the C code from my Arduino:

Code: [Select]
// Calculate average of wind direction
// Because wind direction goes from 359 to 0, use vector averaging to determine direction
int avgWindDir(uint16_t windDir)
{
  const byte ARYSIZE = 30;     // number of elements in arrays
  const float DEG2RAD = 3.14156 / 180.0; // convert degrees to radian
  static float dirNorthSouth[ARYSIZE];
  static float dirEastWest[ARYSIZE];
  static byte c = 0; // array counter
 
  if ( c == ARYSIZE )
  { c = 0; }
 
  windDir = windDir + 1; // convert range from 0-359 to 1 to 360

  dirNorthSouth[c] = cos(windDir * DEG2RAD);
  dirEastWest[c++] = sin(windDir * DEG2RAD);
 
  // Get array totals
  float sumNorthSouth = 0.0;
  float sumEastWest =   0.0;
  for (byte i = 0; i < ARYSIZE; i++)
  {
    sumNorthSouth += dirNorthSouth[i];
    sumEastWest +=   dirEastWest[i];
  }
 
  // use atan2() with average vector
  float avgWindDir = atan2( (sumEastWest/(float) ARYSIZE), (sumNorthSouth/(float) ARYSIZE));
  avgWindDir = avgWindDir / DEG2RAD;  // convert radians back to degrees
 
  if ( avgWindDir < 0 )
  { avgWindDir += 360; }
 
  int windDirection = (int)avgWindDir % 360; // atan2() result can be > 360, so use modulus to just return remainder
  windDirection = windDirection - 1; // convert range back to 0-359

  return g_windDirection;


Offline Randall Kayfes

  • Weather - Photography - Astronomy - Computer Admin
  • Forecaster
  • *****
  • Posts: 1949
    • Arizona Kaymann
Re: How to average wind direction?
« Reply #7 on: December 07, 2014, 11:00:13 AM »
Thinking outside the box

Supporting Data:



Offline PaulMy

  • Forecaster
  • *****
  • Posts: 5509
    • KomokaWeather
Re: How to average wind direction?
« Reply #8 on: December 07, 2014, 12:25:47 PM »
I like those "boxes".  Very nice representation.
 
Paul