Hello everyone
I have implemented the wetbulp.py file in my weewx. But now I have noticed 
that after creating the column in the database, the value is not saved. 
Could it be that this line is missing in "wetbulb.py"? If so, what would it 
have to look like for it to work?
Thx
[email protected] schrieb am Donnerstag, 17. Dezember 2020 um 22:09:09 
UTC+1:

> thank you, i will do this in database.
>
> gjr80 schrieb am Donnerstag, 17. Dezember 2020 um 21:26:28 UTC+1:
>
>> Yes, that will be it. Loading and calculating for a day will be 
>> straightforward, though it will involve a lot of complex calculations being 
>> done each time you call the aggregate (and this will occur each time you 
>> run the report, so potentially every archive interval minutes). On the 
>> other hand, adding wet bulb to the database will involve one complex 
>> calculation every archive interval and any time you use an aggregate it is 
>> a simple hit on the database. In this case I think it may be better to add 
>> wet bulb to the database.
>>
>> Gary
>>
>> On Friday, 18 December 2020 at 06:14:05 UTC+10 [email protected] wrote:
>>
>>> No, i just adjustet the vaporpressure.py example.
>>>
>>> But i see what you mean, i have to calculate it by my own, this means i 
>>> have to load all data for a day and calculate it.
>>> im not shure i can do this.
>>> i quess its easyer and better to do this in the database. 
>>>
>>> gjr80 schrieb am Donnerstag, 17. Dezember 2020 um 20:37:57 UTC+1:
>>>
>>>> Hi,
>>>>
>>>> When you wrote your xtype extension what methods did you implement? Did 
>>>> you implement get_aggregate()?
>>>>
>>>> Gary
>>>>
>>>> On Friday, 18 December 2020 at 02:41:34 UTC+10 [email protected] wrote:
>>>>
>>>>> Hi
>>>>> i made a xtype extension for a wetbulp temperaur. this worsks fine 
>>>>> with the $current tag and the image generator.
>>>>>
>>>>> with tag $day.wetbulp_t.min the chetagenerator rise no error but 
>>>>> whrites  $day.wetbulp_t.min    in the file...
>>>>>
>>>>> do i have do add wetbulp_t in database for get this to work?
>>>>>
>>>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/f75db5a1-631b-42b6-ba93-40c6701f2de3n%40googlegroups.com.
#
#    Copyright (c) 2020 Tom Keffer <[email protected]>
#
#    See the file LICENSE.txt for your full rights.
#
"""This example shows how to extend the XTypes system with a new type, wetbulp_t, the vapor
pressure of water.

REQUIRES WeeWX V4.2 OR LATER!

To use:
    1. Stop weewxd
    2. Put this file in your user subdirectory.
    3. In weewx.conf, subsection [Engine][[Services]], add WetbulptemperureService to the list
    "xtype_services". For example, this means changing this

        [Engine]
            [[Services]]
                xtype_services = weewx.wxxtypes.StdWXXTypes, weewx.wxxtypes.StdPressureCooker, weewx.wxxtypes.StdRainRater

    to this:

        [Engine]
            [[Services]]
                xtype_services = weewx.wxxtypes.StdWXXTypes, weewx.wxxtypes.StdPressureCooker, weewx.wxxtypes.StdRainRater, user.wetbulp.wetbulpService



    4. Restart weewxd

"""
import math

import weewx
import weewx.units
import weewx.xtypes
from weewx.engine import StdService
from weewx.units import ValueTuple


class WetBulp(weewx.xtypes.XType):

    def __init__(self, algorithm='simple'):
        # Save the algorithm to be used.
        self.algorithm = algorithm.lower()

    def get_scalar(self, obs_type, record, db_manager):
        # We only know how to calculate 'vapor_p'. For everything else, raise an exception UnknownType
        if obs_type != 'wetbulp_t':
            raise weewx.UnknownType(obs_type)

        # We need outTemp in order to do the calculation.
        if 'outTemp' not in record or record['outTemp'] is None:
            raise weewx.CannotCalculate(obs_type)

        # We have everything we need. Start by forming a ValueTuple for the outside temperature.
        # To do this, figure out what unit and group the record is in ...
        unit_and_group = weewx.units.getStandardUnitType(record['usUnits'], 'outTemp')
        # ... then form the ValueTuple.
        outTemp_vt = ValueTuple(record['outTemp'], *unit_and_group)

        # Both algorithms need temperature in Celsius, so let's make sure our incoming temperature
        # is in that unit. Use function convert(). The results will be in the form of a ValueTuple
        outTemp_C_vt = weewx.units.convert(outTemp_vt, 'degree_C')
        # Get the first element of the ValueTuple. This will be in Celsius:
        outTemp_C = outTemp_C_vt[0]



        # We need outHumidity in order to do the calculation.
        if 'outHumidity' not in record or record['outHumidity'] is None:
            raise weewx.CannotCalculate(obs_type)

        # We have everything we need. Start by forming a ValueTuple for the outside humidity.
        # To do this, figure out what unit and group the record is in ...
        unit_and_group = weewx.units.getStandardUnitType(record['usUnits'], 'outHumidity')
        # ... then form the ValueTuple.
        outHumidity_vt = ValueTuple(record['outHumidity'], *unit_and_group)

        # Algorithms need humidity in percent, so let's make sure our incoming humidity
        # is in that unit. Use function convert(). The results will be in the form of a ValueTuple
        
        #outHumidity_P_vt = weewx.units.convert(outTemp_vt, 'group_percent')
        # Get the first element of the ValueTuple. This will be in Percent:
        outHumidity_P = outHumidity_vt[0]
        
        

        # Now we can use the formula. Results will be in degree celcius. Create a ValueTuple out of it:
        w_b = ValueTuple(-5.809 + 0.058 * outHumidity_P + 0.697 * outTemp_C + 0.003 * outHumidity_P * outTemp_C, 'degree_C', 'group_temperature')


        # We have the wetbulp temeratur as a ValueTuple. Convert it back to the units used by
        # the incoming record and return it
        return weewx.units.convertStd(w_b, record['usUnits'])


class wetbulpService(StdService):
    """ WeeWX service whose job is to register the XTypes extension wetbulp with the
    XType system.
    """

    def __init__(self, engine, config_dict):
        super(wetbulpService, self).__init__(engine, config_dict)

        # Get the desired algorithm. Default to "simple".
        try:
            algorithm = config_dict['WetBulp']['algorithm']
        except KeyError:
            algorithm = 'simple'

        # Instantiate an instance of VaporPressure:
        self.vp = WetBulp(algorithm)
        # Register it:
        weewx.xtypes.xtypes.append(self.vp)

    def shutDown(self):
        # Remove the registered instance:
        weewx.xtypes.xtypes.remove(self.vp)


# Tell the unit system what group our new observation type, 'vapor_p', belongs to:
weewx.units.obs_group_dict['wetbulp_t'] = "group_temperature"

Reply via email to