diff --git a/api/app/weather_models/precip_rdps_model.py b/api/app/weather_models/precip_rdps_model.py index d5fcd20f1..055be5eb7 100644 --- a/api/app/weather_models/precip_rdps_model.py +++ b/api/app/weather_models/precip_rdps_model.py @@ -9,7 +9,7 @@ from numba import vectorize from app.utils.s3 import get_client, read_into_memory from app.weather_models import ModelEnum -from app.weather_models.rdps_filename_marshaller import SourcePrefix, compose_computed_precip_rdps_key +from app.weather_models.rdps_filename_marshaller import SourcePrefix, adjust_forecast_hour, compose_computed_precip_rdps_key logger = logging.getLogger(__name__) @@ -47,7 +47,13 @@ async def compute_and_store_precip_rasters(current_time: datetime): bucket = config.get("OBJECT_STORE_BUCKET") - logger.info("Uploading RDPS 24 hour acc precip raster for date: %s, hour: %s, forecast hour: %s to %s", current_time.date().isoformat(), current_time.hour, hour, key) + logger.info( + "Uploading RDPS 24 hour acc precip raster for date: %s, hour: %s, forecast hour: %s to %s", + current_time.date().isoformat(), + current_time.hour, + adjust_forecast_hour(current_time.hour, hour), + key, + ) with tempfile.TemporaryDirectory() as temp_dir: temp_filename = os.path.join(temp_dir, current_time.date().isoformat() + "precip" + str(hour) + ".tif") # Create temp file diff --git a/api/app/weather_models/rdps_filename_marshaller.py b/api/app/weather_models/rdps_filename_marshaller.py index a3fe21cc4..87f8975e2 100644 --- a/api/app/weather_models/rdps_filename_marshaller.py +++ b/api/app/weather_models/rdps_filename_marshaller.py @@ -38,6 +38,18 @@ def model_run_for_hour(hour: int) -> Literal[0, 12]: return 0 if hour < 12 else 12 +def adjust_forecast_hour(run_hour: int, forecast_hour: int): + """ + Adjust the forecast hour given the run hour so return an offset from the run hour. + + :param run_hour: hour the model was run at + :param forecast_hour: the hour the forecast is for + :return: the adjusted hour + """ + model_hour = model_run_for_hour(run_hour) + return forecast_hour - model_hour + + def parse_rdps_filename(url: str): """Parse and return the forecast start date and run hour from the RDPS grib url.""" tokens = url.split(DELIMITER) @@ -77,7 +89,7 @@ def compose_computed_rdps_filename(forecast_start_date: datetime, run_hour: int, """Compose and return a computed RDPS url given a forecast start date, run hour and forecast hour.""" check_compose_invariants(forecast_start_date, run_hour, forecast_hour) model_hour = model_run_for_hour(run_hour) - adjusted_forecast_hour = forecast_hour - model_hour + adjusted_forecast_hour = adjust_forecast_hour(run_hour, forecast_hour) file_ext = ".grib2" if source_prefix == SourcePrefix.CMC else ".tif" return (