From 72be42b663a4fd5925d3adf198502605f0c53b3a Mon Sep 17 00:00:00 2001 From: dgboss Date: Wed, 24 Jul 2024 09:07:29 -0700 Subject: [PATCH] HRDPS debugging (#3798) --- api/app/weather_models/machine_learning.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/app/weather_models/machine_learning.py b/api/app/weather_models/machine_learning.py index c7d06fa15..57762de47 100644 --- a/api/app/weather_models/machine_learning.py +++ b/api/app/weather_models/machine_learning.py @@ -6,6 +6,7 @@ from typing import List from logging import getLogger from sklearn.linear_model import LinearRegression +import math import numpy as np from sqlalchemy.orm import Session from app.weather_models import SCALAR_MODEL_VALUE_KEYS @@ -263,8 +264,12 @@ def predict_precipitation(self, model_precipitation: float, timestamp: datetime) if model_precipitation is None: logger.warning('model precipitation for %s was None', timestamp) return None + if math.isnan(model_precipitation): + logger.warning("model precipitation for %s was NaN", timestamp) + return None hour = timestamp.hour predicted_precip_24h = self.regression_models_v2._precip_model.predict(hour, [[model_precipitation]]) if predicted_precip_24h is None or len(predicted_precip_24h) == 0: + # No data to return return None return max(0, predicted_precip_24h[0])