utils.py 文件源码

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

项目:weatherlink-python 作者: beamerblvd 项目源码 文件源码
def calculate_wind_chill(temperature, wind_speed):
    """
    Uses the air temperature and wind speed to calculate the wind chill, the purpose of which is to represent a
    "felt-air temperature" close to what a human actually feels given the temperature and wind speed. This index does
    not take into account the humidity or solar radiation, and so is not the most accurate measure of a true
    "feels-like" temperature. For that, see `calculate_thw_index` and `calculate_thsw_index`. The algorithm used and
    its constants are sourced from the chart at http://www.srh.noaa.gov/ssd/html/windchil.htm, and the function is
    tested against the same chart. In this algorithm:

    T is the temperature in degrees Fahrenheit
    WS is the wind speed in miles per hour

    This function returns `None` if the input temperature is above 40F.

    :param temperature: The temperature in degrees Fahrenheit
    :type temperature: int | long | decimal.Decimal
    :param wind_speed: The wind speed in miles per hour
    :type wind_speed: int | long | decimal.Decimal

    :return: The wind chill temperature in degrees Fahrenheit to one decimal place, or `None` if the temperature is
                higher than 40F
    :rtype: decimal.Decimal
    """
    if temperature > WIND_CHILL_THRESHOLD:
        return None

    T = temperature
    WS = _as_decimal(wind_speed)

    if WS == ZERO:  # No wind results in no chill, so skip it
        return T

    V = WS ** WC_V_EXP
    wind_chill = (
        WC_C1 + (WC_C2 * T) - (WC_C3 * V) + (WC_C4 * T * V)
    ).quantize(ONE_TENTH, rounding=decimal.ROUND_FLOOR)

    return T if wind_chill > T else wind_chill


# noinspection PyPep8Naming
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号