Skip to content

Commit

Permalink
More checks for np.float64
Browse files Browse the repository at this point in the history
  • Loading branch information
conbrad committed Jan 27, 2025
1 parent 0e04dfa commit 285f592
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions api/app/jobs/common_model_fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def accumulate_nam_precipitation(nam_cumulative_precip: float, prediction: Model
if prediction.prediction_timestamp.hour % nam_accumulation_interval == 0:
# If we're on an 'accumulation interval', update the cumulative precip
cumulative_precip = current_precip

cumulative_precip = cumulative_precip.item() if isinstance(cumulative_precip, np.float64) else cumulative_precip
current_precip = current_precip.item() if isinstance(current_precip, np.float64) else current_precip

return (cumulative_precip, current_precip)


Expand Down Expand Up @@ -262,7 +266,8 @@ def _process_prediction(
if prediction.tmp_tgl_2 is None:
logger.warning("tmp_tgl_2 is None for ModelRunPrediction.id == %s", prediction.id)
else:
station_prediction.tmp_tgl_2 = prediction.tmp_tgl_2
temp = prediction.tmp_tgl_2.item() if isinstance(prediction.tmp_tgl_2, np.float64) else prediction.tmp_tgl_2
station_prediction.tmp_tgl_2 = temp

Check warning on line 270 in api/app/jobs/common_model_fetchers.py

View check run for this annotation

Codecov / codecov/patch

api/app/jobs/common_model_fetchers.py#L269-L270

Added lines #L269 - L270 were not covered by tests

# 2020 Dec 10, Sybrand: Encountered situation where rh_tgl_2 was None, add this workaround for it.
# NOTE: Not sure why this value would ever be None. This could happen if for whatever reason, the
Expand All @@ -272,13 +277,15 @@ def _process_prediction(
logger.warning("rh_tgl_2 is None for ModelRunPrediction.id == %s", prediction.id)
station_prediction.rh_tgl_2 = None
else:
station_prediction.rh_tgl_2 = prediction.rh_tgl_2
rh = prediction.rh_tgl_2.item() if isinstance(prediction.rh_tgl_2, np.float64) else prediction.rh_tgl_2
station_prediction.rh_tgl_2 = rh

Check warning on line 281 in api/app/jobs/common_model_fetchers.py

View check run for this annotation

Codecov / codecov/patch

api/app/jobs/common_model_fetchers.py#L280-L281

Added lines #L280 - L281 were not covered by tests
# Check that apcp_sfc_0 is None, since accumulated precipitation
# does not exist for 00 hour.
if prediction.apcp_sfc_0 is None:
station_prediction.apcp_sfc_0 = 0.0
station_prediction.apcp_sfc_0 = float(0.0)

Check warning on line 285 in api/app/jobs/common_model_fetchers.py

View check run for this annotation

Codecov / codecov/patch

api/app/jobs/common_model_fetchers.py#L285

Added line #L285 was not covered by tests
else:
station_prediction.apcp_sfc_0 = prediction.apcp_sfc_0.item() if isinstance(prediction.apcp_sfc_0, np.float64) else prediction.apcp_sfc_0
apcp = prediction.apcp_sfc_0.item() if isinstance(prediction.apcp_sfc_0, np.float64) else prediction.apcp_sfc_0
station_prediction.apcp_sfc_0 = apcp

Check warning on line 288 in api/app/jobs/common_model_fetchers.py

View check run for this annotation

Codecov / codecov/patch

api/app/jobs/common_model_fetchers.py#L287-L288

Added lines #L287 - L288 were not covered by tests
# Calculate the delta_precipitation and 24 hour precip based on station's previous prediction_timestamp
# for the same model run
self.session.flush()
Expand All @@ -287,10 +294,12 @@ def _process_prediction(

# Get the closest wind speed
if prediction.wind_tgl_10 is not None:
station_prediction.wind_tgl_10 = prediction.wind_tgl_10
wind_tgl_10 = prediction.wind_tgl_10.item() if isinstance(prediction.wind_tgl_10, np.float64) else prediction.wind_tgl_10
station_prediction.wind_tgl_10 = wind_tgl_10

Check warning on line 298 in api/app/jobs/common_model_fetchers.py

View check run for this annotation

Codecov / codecov/patch

api/app/jobs/common_model_fetchers.py#L297-L298

Added lines #L297 - L298 were not covered by tests
# Get the closest wind direcion
if prediction.wdir_tgl_10 is not None:
station_prediction.wdir_tgl_10 = prediction.wdir_tgl_10
wdir_tgl_10 = prediction.wdir_tgl_10.item() if isinstance(prediction.wdir_tgl_10, np.float64) else prediction.wdir_tgl_10
station_prediction.wdir_tgl_10 = wdir_tgl_10

Check warning on line 302 in api/app/jobs/common_model_fetchers.py

View check run for this annotation

Codecov / codecov/patch

api/app/jobs/common_model_fetchers.py#L301-L302

Added lines #L301 - L302 were not covered by tests

if prediction_is_interpolated:
# Dealing with a numerical weather model that only has predictions at 3 hour intervals,
Expand Down

0 comments on commit 285f592

Please sign in to comment.