Calculating average wind direction when aggregate is higher than your archive period.

205 views
Skip to first unread message

James Taylor

unread,
Oct 16, 2022, 9:35:08 AM10/16/22
to weewx-user
Hello

Following on from https://github.com/weewx/weewx/issues/798, I've been trying to replicate and understand weewx behaviour when it comes to using get_series and get_aggregate.

So if you are trying to aggregate winddir for graphing purposes, you want to get a wind vector which I understand

Here is my example where my data is being archived every 300 seconds

(time_start_vt, time_stop_vt, obs_vt) = weewx.xtypes.get_series( obs_lookup, x_domain, db_lookup(data_binding=binding), aggregate_type, aggregate_interval)

obs_lookup is windDir
Start time is 1665440100 and end time is 1665442800
x_domain entries are 1665440100 and 1665442800
aggregate_type is avg
aggregate_interval is 300
([355.0, 355.0, 355.0, 355.480837630687, 0.0, 0.0, 0.0, 0.0, 4.249651034454402], 'degree_compass', 'group_direction')
aggregate_interval is 900
([355.0, 118.49361254356234, 1.416550344818134], 'degree_compass', 'group_direction')

I can see for the second group it is returning an average rather than a vector value of around 358.5, but trying to understand how we should be coding it.

If I can change to aggregate of vecdir or vecavg I get a UnknownType error

Any help will be appreciated here.

James

Tom Keffer

unread,
Oct 17, 2022, 9:05:37 AM10/17/22
to weewx...@googlegroups.com
Calculating the vector averaged direction requires a vector, so the observation type is 'wind', which is a vector, not 'windDir'. The aggregation that returns direction from a vector is 'vecdir', so, you want:

(start_ts, stop_ts, dirs) = weewx.xtypes.get_series('wind', x_domain, db_lookup(data_binding=binding), 'vecdir', aggregate_interval)

Unfortunately, 'wind' appears only in the daily summaries. This means aggregate_interval must be multiples of one day. This restriction could be relaxed should someone want to write the necessary xtypes extension. 



--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/2ed7f92d-c030-45df-a241-2abde9c647een%40googlegroups.com.

James Taylor

unread,
Oct 17, 2022, 9:51:41 AM10/17/22
to weewx-user
Thanks Tom for coming back to me and makes sense now on how 'wind' fits into it all.

bell...@gmail.com

unread,
Oct 17, 2022, 4:52:43 PM10/17/22
to weewx-user
I'm still trying to wrap my head around wind data in WeeWX... Does that mean that in the Seasons skin, the weekwinddir, monthwindir, and yearwinddir plots are not a vector average? If yearwinddir plot was something like below, would it generate a vector average?
        [[[yearwinddir]]]
            yscale = 0.0, 360.0, 45.0
            line_type = None
            marker_type = box
            marker_size = 2
            #[[[[windDir]]]]
            [[[[wind]]]]
                aggregate_type = vecdir
When I changed the yearwinddir plot to the above, it ran and I got what looked like a different plot.
Thanks. rich

Tom Keffer

unread,
Oct 18, 2022, 7:53:57 PM10/18/22
to weewx...@googlegroups.com
You're right that the wind direction plots that come with the Seasons skin are not very useful. They might make sense for short time periods that do not use aggregation, but not for longer periods. Unfortunately, the way vecdir is set up now, aggregation intervals have to be multiples of a day. Hence, your example works, but it won't for plots with shorter aggregation intervals.

I've created Issue #800 to track.

Tom Keffer

unread,
Oct 22, 2022, 5:26:27 PM10/22/22
to weewx...@googlegroups.com
Fixed with commit 407602c, to appear in V4.9.

James Taylor

unread,
Oct 24, 2022, 2:54:37 PM10/24/22
to weewx-user
Cool.

Just need to find a way to upgrade sqlite3 on Raspberry PI.    The packaged version is 3.34.1 on is Raspbian 11 (Bullseye) and this is wanting at least 3.35.

James

Tom Keffer

unread,
Oct 24, 2022, 3:39:19 PM10/24/22
to weewx...@googlegroups.com
That's unfortunate. Bullseye has been out for a while, so I had just assumed that it had 3.35.

I think sqlite maintains their own repository. You could try upgrading from that.

James Taylor

unread,
Oct 24, 2022, 4:52:35 PM10/24/22
to weewx-user
Yes, I was surprised.  Hopefully Debian 12 ( Bookworm) when it comes along in 2023 has a newer version as standard

I just upgraded to the latest version, which I would only recommend for those that are comfortable with this sort of thing.   It didn't actually take that long to compile on my Pi4

mkdir sqlite && cd sqlite
tar xvfz sqlite-autoconf-3390400.tar.gz
cd sqlite-autoconf-3390400
./configure
make
sudo make install
/usr/local/bin/sqlite3 --version # returns 3.39.4 2022-09-29

You also need to replace /usr/lib/arm-linux-gnueabihf/libsqlite3.so.0.8.6 with the version compiled under sqlite-autoconf-3390400/.libs/, so python3 will start using the newer instance (Note if somebody is reading this, it is at their risk and understand the consequencies

# python3 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.39.4


However it is now working using the example from my original email

obs_lookup is wind

Start time is 1665440100 and end time is 1665442800
x_domain entries are 1665440100 and 1665442800
archive is <weewx.manager.DaySummaryManager object at 0xb2c55a60>
aggregate_type is vecdir
aggregate_interval is 900
([1665440100, 1665441000, 1665441900], 'unix_epoch', 'group_time')
([355.0, 357.7404188153435, 2.124825517227194], 'degree_compass', 'group_direction')

James

Tom Keffer

unread,
Oct 24, 2022, 5:08:48 PM10/24/22
to weewx...@googlegroups.com
Thanks for checking this, James!

Nice to have a Debian whiz on board!

James Taylor

unread,
Oct 24, 2022, 5:34:49 PM10/24/22
to weewx-user
No problems

I wish!  My day job is mainly working with Red Hat and its derivatives (Rocky / CentOS)

James

James Taylor

unread,
Oct 25, 2022, 9:34:05 AM10/25/22
to weewx-user
Given the update, I have just backed out to sqlite3 (3.34.1) and upgraded to weewx 4.9.1 and I can see I'm getting the same result with the changes.   Excellent coding Tom.

# python3 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.34.1

obs_lookup is wind
Start time is 1665440100 and end time is 1665442800
x_domain entries are 1665440100 and 1665442800
archive is <weewx.manager.DaySummaryManager object at 0xb2d298f8>

aggregate_type is vecdir
aggregate_interval is 900
([1665440100, 1665441000, 1665441900], 'unix_epoch', 'group_time')
([355.0, 357.7404188153435, 2.124825517227194], 'degree_compass', 'group_direction')
Reply all
Reply to author
Forward
0 new messages