From 9959cb14a4a57d723e206311de36db984b0a65a8 Mon Sep 17 00:00:00 2001 From: Bobby Noelte Date: Thu, 22 May 2025 11:15:48 +0200 Subject: [PATCH] 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 --- src/akkudoktoreos/prediction/weatherbrightsky.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/akkudoktoreos/prediction/weatherbrightsky.py b/src/akkudoktoreos/prediction/weatherbrightsky.py index b638a61..e24c854 100644 --- a/src/akkudoktoreos/prediction/weatherbrightsky.py +++ b/src/akkudoktoreos/prediction/weatherbrightsky.py @@ -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,