Adding a "CANMETRICWX" standard unit system

171 views
Skip to first unread message

Chris Alemany

unread,
Aug 24, 2020, 11:37:18 PM8/24/20
to weewx-user
Hi All,

I'm trying to extend weewx so that there is a 4th option for unit systems called "CANMETRICWX" (Canadian Metric).

This would be the same as "METRIC" except rain values are in mm and pressure values are in kPa and eventually would also include a "Humidex" calculation as well.

I thought I had added everything I needed throughout the file system for the addition of the units system but I'm running into the following complaint on startup:

"AttributeError: module 'weewx' has no attribute 'CANMETRICWX'"

Not being familiar enough with python, I am stumped as to where I can add that attribute. Any help greatly appreciated.

Cheers

Chris

Tom Keffer

unread,
Aug 25, 2020, 10:35:17 AM8/25/20
to weewx-user
Hi, Chris

1. While the treatment of units is pretty modularized in weewx itself, many extensions make assumptions that there are only 3 unit systems ("If not this or this, then it must be that."). It may be too late to add a fourth unit system. It seems like it would be simpler to add kPa to the set of units, then use it in group_pressure.

2. As for your specific error, it's impossible to say much without some context. Are you forking weewx and adding to it? Or, trying to implement this as an extension? The module weewx has US, METRIC, and METRICWX defined. It does not have CANMATRIXWX. That would have to be added.

-tk

--
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/976de428-315e-4666-838c-fe5677759d4en%40googlegroups.com.

David VE3STI

unread,
Aug 25, 2020, 11:03:42 AM8/25/20
to weewx-user
I'm not a programmer so I don't have helpful suggestions. But as a Canadian user, I hope that you figure this out. I use the "metric" option but think of wind speed in kph, not m/s, for example. I did get the Humidex added (a long time ago - I forget how I did it other than I know I didn't do the programming but found that someone else had already figured out and I just followed the instructions!)

Just as I type this, Tom's reply popped up.. Guess it won't be easy to add a new "Canadian option". The instructions for changing individual units is in the documentation but if you could make a "Canada-specific" set (cookbook style) that would be really useful for those of us who are users-but-not-programmers.

Keep us posted.

David

John Kline

unread,
Aug 25, 2020, 11:54:51 AM8/25/20
to weewx...@googlegroups.com
Remember that just because something is stored in the database in units that are not “Canadian”, that doesn’t mean you are stuck with that unit in reports or graphs.

My two cents is that you should be spending your time getting the units you want to see in the skin(s) you are using.

On Aug 25, 2020, at 8:03 AM, David VE3STI <david....@gmail.com> wrote:

I'm not a programmer so I don't have helpful suggestions. But as a Canadian user, I hope that you figure this out. I use the "metric" option but think of wind speed in kph, not m/s, for example. I did get the Humidex added (a long time ago - I forget how I did it other than I know I didn't do the programming but found that someone else had already figured out and I just followed the instructions!)
--
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.

Chris Alemany

unread,
Aug 25, 2020, 1:39:26 PM8/25/20
to weewx-user
Hi all,

Yes, I noticed last night when I was rooting around in all the various weewx files (I guess I was creating a “fork” as I was modifying the weewx bin files themselves, _ini_.py, units.py etc to add in the new system) for mentions of units, that many extensions seemed to make the same 3-way assumption on units. So perhaps that method is not worth the effort.

I’m not interested in having the database itself use Canadian Units (though extending it for Humidex readings would be useful), only that I’d be able to set the units as simply and widely as I can across all skins and extensions as I have multiple going at once.  Thought I was almost there. :)

Cheers for the suggestions,
Chris

You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/NO7igS5iBAo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/0913D44A-2766-4FB6-97B8-FE88BE3488D0%40johnkline.com.

John Kline

unread,
Aug 25, 2020, 2:08:45 PM8/25/20
to weewx...@googlegroups.com
You weren’t almost there as you were attempting to change the units stored in the database.

Have a look at the following for changing your reports.  You don’t have to change every report as you can set defaults for all reports.

On Aug 25, 2020, at 10:39 AM, Chris Alemany <chri...@gmail.com> wrote:

Hi all,

Chris Alemany

unread,
Aug 25, 2020, 2:34:06 PM8/25/20
to weewx...@googlegroups.com
Yes, thanks for that. I do change the units for some reports, unfortunately kilopascal does not exist as a selectable unit which is the crux of the issue, so I was looking at different ways of adding that unit and possibly Humidex as an available value as well. 

I’m going to take a peak at the aqi extension to see if I can use it as an example for what I need to do.

Cheers
Chris

John Kline

unread,
Aug 25, 2020, 2:59:04 PM8/25/20
to weewx...@googlegroups.com
Look here:


I did check the great resource in the sky (Wikipedia), and indeed Canada is an exception in that they use kPa.  It might be reasonable to add kPa to the weewx.units file itself, but Tom would be the decider on that.

Humidex might best be done with xtypes as it is derived from temperature and dew point.  I found xtypes less well documented, but I am using xtypes to derive aqi from pm2.5.  It’s fairly straightforward.

On Aug 25, 2020, at 11:34 AM, Chris Alemany <chri...@gmail.com> wrote:

Yes, thanks for that. I do change the units for some reports, unfortunately kilopascal does not exist as a selectable unit which is the crux of the issue, so I was looking at different ways of adding that unit and possibly Humidex as an available value as well. 

Tom Keffer

unread,
Aug 25, 2020, 6:09:38 PM8/25/20
to weewx-user
kPa should really be added to the pantheon of units. 

Created issue #596.

This is an easy one if someone wants to do a fork and tackle it. Don't forget to include tests.

-tk

gjr80

unread,
Aug 25, 2020, 8:00:20 PM8/25/20
to weewx-user
StdWXCalculate knows how to calculate humidex, in fact if you are running WeeWX 3.2.0 or later chances are humidex is already appearing in your loop packets and archive records (provided its pre-reqs outTemp and outHumidity exist in the loop packet/archive record) it's just not saved to database due to humidex not being in your database schema. However, field humidex (and humidex1) exist in the wview_extended schema which was introduced in WeeWX v4.0.0 and this has been  the default schema for new installs since WeeWX 4.0.0 (note upgrades continue to use the schema that was in use before the upgrade so if upgrading WeeWX 3.x to WeeWX 4.x you will not be changed to the wview_extended schema). In terms of units I understand that humidex is technically a unitless number but it is effectively interpreted as a temperature, humidex was added to group_temperature as of WeeWX 3.5.0 so normal WeeWX unit conversions/formatting of humidex is available.

In summary, if you are using WeeWX 4.x and the wview_extended schema chances are you will see humidex appear in your database and it can then be used in reports/plots just as any other observation.

Gary

Chris Alemany

unread,
Aug 26, 2020, 12:45:21 AM8/26/20
to weewx-user
OH! That’s exciting!
I believe I’m still using the default schema from wview plus a value in there for stormRain. Definitely haven’t changed anything since 4.x as I only just upgraded.
I’ll look for a good way to double check the schema type and then upgrade to the new-improved schema if needed.

Thanks for the heads up on that!

Cheers
Chris

Chris Alemany

unread,
Aug 26, 2020, 3:01:46 AM8/26/20
to weewx...@googlegroups.com
I’ve extended the database and filled in all the calculations for the past 14 years. Very nice to have all that extra data!

I’ll see if I can figure out how to add the kPa but if someone smarter than me gets to it first, I won’t complain. :) Thank you Tom for your blessing! 

Thank you all for your quick help and advice.
Cheers
Chris

Cameron D

unread,
Aug 27, 2020, 4:25:37 AM8/27/20
to weewx-user
HI Chris,
in Australia we have a similar situation but I have found customising the reports to be sufficient. I have used METRICWX as the database units from the start, so I can read sensible numbers there.
I suppose our main difference is standardising on hectoPascals for pressure, but that happens to be the same as mbar, so I have simply used that in the reports.

Cameron.

Graham Eddy

unread,
Aug 27, 2020, 5:09:30 AM8/27/20
to weewx...@googlegroups.com
same here. except i started with METRICWX with speed changed to km/h, then moved to METRIC with rain changed to mm

Tom Keffer

unread,
Aug 27, 2020, 8:11:02 AM8/27/20
to weewx-user
Fixed in commit 90c9b64

Chris Alemany

unread,
Aug 27, 2020, 10:23:20 AM8/27/20
to weewx...@googlegroups.com
Thank you Tom!  Millions of Canadians rejoice that we can use our own unit. :)

Reply all
Reply to author
Forward
0 new messages