Skip to content

Commit

Permalink
HRDPS debugging (bcgov#3798)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgboss authored Jul 24, 2024
1 parent 2583c60 commit 72be42b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/app/weather_models/machine_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

0 comments on commit 72be42b

Please sign in to comment.