Average Wind Dir in toservice

25 views
Skip to first unread message

Freman

unread,
Mar 20, 2012, 11:52:32 PM3/20/12
to py...@googlegroups.com
Is there any way to get the average wind direction (over the past hour) in the toService live view?

Jim Easterbrook

unread,
Mar 21, 2012, 1:59:07 PM3/21/12
to py...@googlegroups.com
On 21/03/12 03:52, Freman wrote:
> Is there any way to get the average wind direction (over the past hour)
> in the toService live view?

Not without writing a function to compute it in toservice.py, a bit like
'rain_hour' but rather more complicated.

To get any useful answer you need to take account of the wind speed as
well as direction. If most of the last hour had no wind but the vane
rested in one position, the average wind might still be from a
completely different direction. Have a look at Process.py where I do a
vector sum to get an average direction.
--
Jim Easterbrook <http://www.jim-easterbrook.me.uk/>

Message has been deleted

Freman

unread,
Mar 26, 2012, 9:05:45 AM3/26/12
to py...@googlegroups.com
It is all good. I decided to do the averaging in my daemon - it's done over the last 30 entries which equates to less than 30 minutes but it's enough for my purposes.

I do take into account the wind direction and speed.

here's the code in javascript (nodejs) but I can port it to any language you would like to try it in.

function avg(array) {
        var sum = 0;
        for (i in array) {
                sum += parseFloat(array[i]);
        }
        return sum / array.length;
}

function calc_average_wind_dir(data) {
// Store a number of U's and V's
        u_comp.push(-1 * (data.windspeedms * Math.sin(data.winddir * Math.PI/180)));
        v_comp.push(-1 * (data.windspeedms * Math.cos(data.winddir * Math.PI/180)));
// Store a number of wind speeds (for future use, not used atm)
        ws.push(data.windspeedms);

// Dispose of any entries older than 30
        while (u_comp.length > 30) {
                u_comp.shift();
                v_comp.shift();
                ws.shift();
        }

// Calculate the average u and v
        var u_avg = avg(u_comp);
        var v_avg = avg(v_comp);

// Calculate the average wind direction
        var avg_wd;

        if (u_avg > 0) {
                avg_wd = 90 - 180 / Math.PI * Math.atan(v_avg / u_avg) + 180;
        }
        else if (u_avg < 0) {
                avg_wd = 90 - 180 / Math.PI * Math.atan(v_avg / u_avg);
        }
        else {
                if (v_avg < 0) {
                        avg_wd = 360;
                }
                else if (v_avg > 0) {
                        avg_wd = 180;
                }
                else {
                        avg_wd = 0;
                }
        }

        return avg_wd
}

(I admit it's based on pseudo code I found via google, no idea where now though)
Reply all
Reply to author
Forward
0 new messages