fix: BrightSky with None humidity data (#555)

Make the BrightSky weather forecast more robust for the case that BrightSky
does not provide relative humidity data for a certain location.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte 2025-05-22 11:15:48 +02:00 committed by GitHub
parent ccd2f5307c
commit 9959cb14a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,7 @@ format, enabling consistent access to forecasted and historical weather attribut
import json
from typing import Dict, List, Optional, Tuple, Union
import numpy as np
import pandas as pd
import pvlib
import requests
@ -228,6 +229,11 @@ class WeatherBrightSky(WeatherProvider):
end_datetime=self.end_datetime,
interval=to_duration("1 hour"),
)
if any(x is None or isinstance(x, float) and np.isnan(x) for x in temperature):
# We can not calculate PWAT
debug_msg = f"Innvalid temperature '{temperature}'"
logger.debug(debug_msg)
return
key = WeatherDataRecord.key_from_description("Relative Humidity (%)")
assert key
humidity = self.key_to_array(
@ -236,6 +242,11 @@ class WeatherBrightSky(WeatherProvider):
end_datetime=self.end_datetime,
interval=to_duration("1 hour"),
)
if any(x is None or isinstance(x, float) and np.isnan(x) for x in humidity):
# We can not calculate PWAT
debug_msg = f"Innvalid humidity '{humidity}'"
logger.debug(debug_msg)
return
data = pvlib.atmosphere.gueymard94_pw(temperature, humidity)
pwat = pd.Series(
data=data,