首页 > 解决方案 > 如何使用python中的一些api计算加热/冷却度日

问题描述

我正在尝试使用 (T base - T a ) 公式T base通常为 65F 和T a = (high_temp + low_temp)/2计算加热/冷却度日

(前任)

high_temp = 96.5F low_temp=65.21F then 
mean=(high_temp + low_temp)/2
result = mean - 65

65 是平均室温
,如果结果 > 65,则为制冷度日(cdd),否则为采暖度日(hdd)

我从两个 api 获取天气数据

weatherbit中提供cdd和hdd数据,但在darksky中我们需要使用上面的公式(T base - T a)计算

我的问题是两个 api 都显示不同的结果(例如)
darksky json 响应天

{
"latitude": 47.552758,
"longitude": -122.150589,
"timezone": "America/Los_Angeles",
"daily": {
    "data": [
          {
            "time": 1560927600,
            "summary": "Light rain in the morning and overnight.",
            "icon": "rain",
            "sunriseTime": 1560946325,
            "sunsetTime": 1561003835,
            "moonPhase": 0.59,
            "precipIntensity": 0.0057,
            "precipIntensityMax": 0.0506,
            "precipIntensityMaxTime": 1561010400,
            "precipProbability": 0.62,
            "precipType": "rain",
            "temperatureHigh": 62.44,
            "temperatureHighTime": 1560981600,
            "temperatureLow": 48,
            "temperatureLowTime": 1561028400,
            "apparentTemperatureHigh": 62.44,
            "apparentTemperatureHighTime": 1560981600,
            "apparentTemperatureLow": 46.48,
            "apparentTemperatureLowTime": 1561028400,
            "dewPoint": 46.61,
            "humidity": 0.75,
            "pressure": 1021.81,
            "windSpeed": 5.05,
            "windGust": 8.36,
            "windGustTime": 1560988800,
            "windBearing": 149,
            "cloudCover": 0.95,
            "uvIndex": 4,
            "uvIndexTime": 1560978000,
            "visibility": 4.147,
            "ozone": 380.8,
            "temperatureMin": 49.42,
            "temperatureMinTime": 1561010400,
            "temperatureMax": 62.44,
            "temperatureMaxTime": 1560981600,
            "apparentTemperatureMin": 47.5,
            "apparentTemperatureMinTime": 1561014000,
            "apparentTemperatureMax": 62.44,
            "apparentTemperatureMaxTime": 1560981600
           }
        ]
    },
    "offset": -7
}

蟒蛇计算

response = result.get("daily").get("data")[0]
low_temp = response.get("temperatureMin")
hi_temp = response.get("temperatureMax")
mean = (hi_temp + low_temp)/2
#65 is normal room temp
print(65-mean)

这里的平均值是 6.509999999999998
65 - 平均值 = 58.49
hdd 是 58.49所以cdd 是 0

Weatherbit json响应中的同一日期是:

{
 "threshold_units": "F",
 "timezone": "America/Los_Angeles",
 "threshold_value": 65,
 "state_code": "WA",
 "country_code": "US",
 "city_name": "Newcastle",
 "data": [
   {
     "rh": 68,
     "wind_spd": 5.6,
     "timestamp_utc": null,
     "t_ghi": 8568.9,
     "max_wind_spd": 11.4,
     "cdd": 0.4,
     "dewpt": 46.9,
     "snow": 0,
     "hdd": 6.7,
     "timestamp_local": null,
     "precip": 0.154,
     "t_dni": 11290.6,
     "temp_wetbulb": 53.1,
     "t_dhi": 1413.9,
     "date": "2019-06-20",
     "temp": 58.6,
     "sun_hours": 7.6,
     "clouds": 58,
     "wind_dir": 186
   }
 ],
 "end_date": "2019-06-21",
 "station_id": "727934-94248",
 "count": 1,
 "start_date": "2019-06-20",
 "city_id": 5804676
}

这里hdd 是 6.7cdd 是 0.4

你能解释一下他们是如何得到这个结果的吗?

标签: python-3.xapiweb-servicesweather-api

解决方案


您需要使用每小时数据来计算 HDD 和 CDD,然后将它们平均得到每日值。

更多细节在这里:https ://www.weatherbit.io/blog/post/heat-and-cooling-degree-days-weather-api-release


推荐阅读