utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:weatherlink-python 作者: beamerblvd 项目源码 文件源码
def calculate_thw_index(temperature, relative_humidity, wind_speed):
    """
    Uses the air temperature, relative humidity, and wind speed (THW = temperature-humidity-wind) to calculate a
    potentially more accurate "felt-air temperature." This is not as accurate, however, as the THSW index, which
    can only be calculated when solar radiation information is available. It uses `calculate_heat_index` and then
    applies additional calculations to it using the wind speed. As such, it returns `None` for input temperatures below
    70 degrees Fahrenheit. The additional calculations come from web forums rumored to contain the proprietary
    Davis Instruments THW index formulas.

    hi is the heat index as calculated by `calculate_heat_index`
    WS is the wind speed in miles per hour

    :param temperature: The temperature in degrees Fahrenheit
    :type temperature: int | long | decimal.Decimal
    :param relative_humidity: The relative humidity as a percentage (88.2 instead of 0.882)
    :type relative_humidity: int | long | decimal.Decimal
    :param wind_speed: The wind speed in miles per hour
    :type wind_speed: int | long | decimal.Decimal

    :return: The THW index temperature in degrees Fahrenheit to one decimal place, or `None` if the temperature is
                less than 70F
    :rtype: decimal.Decimal
    """
    hi = calculate_heat_index(temperature, relative_humidity)
    WS = _as_decimal(wind_speed)

    if not hi:
        return None
    return hi - (THW_INDEX_CONSTANT * WS).quantize(ONE_TENTH, rounding=decimal.ROUND_CEILING)


# noinspection PyPep8Naming
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号