Adding Dewpoint Depression and Wetbulb Formulas

53 views
Skip to first unread message

rich T

unread,
Nov 1, 2020, 3:58:51 PM11/1/20
to weewx-development
I want to add Dewpoint Depression and Wetbulb Formulas to the wxformulas.py file. So far this is what I have 

Dewpoint Depression:

def dewpointdepressF(t_F, rh):

    """Calculate dew point depression. 
    

    t_f: Temperature in Fahrenheit
    
    rh: relative humidity [0-100]
    
    Returns: Dewpoint Depression
    
    """

    if t_f is None or rh is None:
        return None
        
    dp_F = dewpointF(t_F, rh)
    dp_D = t_F - dp_F

    return dp_D if dp_D is not None else None

def dewpointdepressC(t_C, rh):

    """Calculate dew point depression. 
    

    t_C: temperature in degree Celsius
    
    rh: relative humidity [0-100]
    
    Returns: Dewpoint Depression
    
    """

    if t_C is None or rh is None:
        return None
        
    dp_C = dewpointC(t_C, rh)
    dp_D = t_C - dp_C

    return dp_D if dp_D is not None else None

Wetbulb:

def wetbulbF(t_F, rh):
    
    """Estimate the wetbulb temperature (1/3 method). 
    

    t_f: Temperature in Fahrenheit
    
    rh: relative humidity [0-100]
    
    dp_DwB: Dewpoint Depression divided by 3
    
    t_WbF: Wetbulb Temperature in Fahrenheit
    
    Returns: Wetbulb Temperature Estimation

    """

    if t_f is None or rh is None:
        return None
        
    dp_F = dewpointF(t_F, rh)
    dp_DwB = (t_F - dp_F) / 3
    t_WbF = t_F - dp_DwB

    return t_WbF if t_WbF is not None else None

def wetbulbC(t_C, rh):
    
    """Estimate the wetbulb temperature (1/3 method). 
    

    t_C: temperature in degree Celsius
    
    rh: relative humidity [0-100]
    
    dp_DwB: Dewpoint Depression divided by 3
    
    t_WbC: Wetbulb Temperature in Celsius
    
    Returns: Wetbulb Temperature Estimation

    """

    if t_C is None or rh is None:
        return None
        
    dp_C = dewpointC(t_C, rh)
    dp_DwB = (t_C - dp_C) / 3
    t_WbC = t_C - dp_DwB

    return t_WbC if t_WbC is not None else None

Does the coding look okay? I know I need to add two columns to the database, but what else would need to be updated to get the results in the database?

Rich


Tom Keffer

unread,
Nov 2, 2020, 7:44:03 AM11/2/20
to rich T, weewx-development
A problem is that you're doing arithmetic before checking for a "None" result. For example, 

    ...
    dp_F = dewpointF(t_F, rh)
    dp_D = t_F - dp_F

    return dp_D if dp_D is not None else None

If db_F is None, this will fail. Same problem with the other algorithms.

As for adding the results to the database, if you add the types through the xtypes system, they will become available throughout WeeWX. Follow the example in the Wiki. The biggest challenge will be checking that the units are right.

-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.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/0e328c83-7614-4448-8dd9-743929495d9bo%40googlegroups.com.

rich T

unread,
Nov 2, 2020, 4:34:31 PM11/2/20
to weewx-development
Thanks Tom.  Will give it a try.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages