如何使用Python中的一些API计算供暖/制冷度日

问题描述 投票:0回答:2

我正在尝试使用 (Tbase - Ta) 公式计算加热/冷却度日 Tbase 通常为 65F 且 Ta = (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中我们需要使用上面的公式进行计算(Tbase - Ta

我的问题是两个 api 显示不同的结果(e.x)
当天的 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
}

python计算

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.x api web-services weather-api
2个回答
1
投票

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

更多详细信息请参见:https://www.weatherbit.io/blog/post/heating-and-cooling- Degree-days-weather-api-release


0
投票

您在计算第一个站的平均温度时犯了一个错误,而第二个站则错误地计算了 CDD 和 HDD。你不能拥有正的 HDD 和 CDD,所以我不知道他们是如何获得这些值的。

首站平均值为55.93F,HDD为9.07,CDD为0 每日平均值 = (62.44+49.42)/2 = 55.93F 硬盘=65-55.93

第二站的HDD为6.4,CDD为0。 硬盘=65-58.6

© www.soinside.com 2019 - 2024. All rights reserved.