XType Unit Conversion

108 views
Skip to first unread message

Karen K

unread,
Jul 23, 2022, 4:15:17 PM7/23/22
to weewx-development
I wrote an XType extension, that calculates some value like this:

    def get_scalar(self, obs_type, record, db_manager, **option_dict):
        if obs_type!='myObsType': raise weewx.UnknownType(obs_type)
        # some calculation here
        return weewx.units.ValueTuple(x,'hPa','group_pressure')

get_scalar() returns a ValueTuple containing a unit. But it seems to me that the unit is ignored.

For example, if the function returns (20,'hPa','group_pressure'), then WeeWX reports 20 inHg.

Is that intended?

Tom Keffer

unread,
Jul 23, 2022, 5:54:47 PM7/23/22
to Karen K, weewx-development
Yes, that is what is intended. 

The ValueTuple can use any unit valid for group_pressure --- it has nothing to do with the final reporting unit, which is set under Units/Groups in weewx.conf or skin.conf. 




--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/acadc603-7df3-4a6c-bf7b-b1be8384665en%40googlegroups.com.

Karen K

unread,
Jul 24, 2022, 1:57:41 AM7/24/22
to weewx-development
Tom Keffer schrieb am Samstag, 23. Juli 2022 um 23:54:47 UTC+2:
The ValueTuple can use any unit valid for group_pressure --- it has nothing to do with the final reporting unit, which is set under Units/Groups in weewx.conf or skin.conf. 


I guess I described the issue too short.

If the value tuple return is (20,'hPa','group_pressure'), I would guess WeeWX should report 0,59059975 inHG, not 20 inHG, as it does.


Tom Keffer

unread,
Jul 24, 2022, 7:26:04 AM7/24/22
to Karen K, weewx-development
I see.

What is the context? Is the extension being used within [StdWXCalculate]?

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.

Karen K

unread,
Jul 25, 2022, 4:18:11 AM7/25/22
to weewx-development
Tom Keffer schrieb am Sonntag, 24. Juli 2022 um 13:26:04 UTC+2:
What is the context? Is the extension being used within [StdWXCalculate]?
 
Yes.

part of weewx.conf:
[StdRESTful]
    [[MQTT]]
        [[[inputs]]]
            [[[[myObsType]]]]
                units = hPa
[StdConvert]
    target_unit = US
[StdWXCalculate]
    [[Calculations]]
        myObsType = software



I calculated the value using my extension and output it by MQTT for testing. 

As an example: If the value, returned by the extension, is (20,'hPa','group_pressure') and the database unit is US and the output unit of MQTT is hPa, then the output is 677 to the MQTT broker. That means to me, that the value of 20 is not recognized as hPA (as sent in the value tuple) but as inHG.

If I add weewx.units.convertStd(...,record['usUnits']) at the end, then the correct value is output to MQTT. But it makes no sense to me to convert the value to the standard unit system if I return a value tuple. So I asked.


Tom Keffer

unread,
Jul 25, 2022, 7:54:51 PM7/25/22
to Karen K, weewx-development
If you look at the types calculated in wxxtypes.py you'll see that they do, in fact, call convertStd() before returning the value. 

I'm not sure why they do that rather than having it done in do_calculations() automatically. I recall having some good reason, but can't remember it now.

I'll look into it. In the meantime, you'll have to convert the value to whatever is used by the record.


-tk

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.

Karen K

unread,
Jul 26, 2022, 12:37:08 AM7/26/22
to weewx-development
Thank you very much.

Tom Keffer

unread,
Jul 31, 2022, 1:51:40 PM7/31/22
to weewx-development
Fixed in commit https://github.com/weewx/weewx/commit/52b8310b009c0231392d0cea4a6c65ad044df297

On Monday, July 25, 2022 at 9:37:08 PM UTC-7 kk44...@gmail.com wrote:
Thank you very much.

Reply all
Reply to author
Forward
0 new messages