The field looks hourly. It isn’t.
hourly[n].precip_mm in a WeatherAPI forecast response does not represent the rainfall that fell during that specific hour. It represents cumulative precipitation from midnight local time up to and including that hour. If you’re displaying it as “rain this hour” or summing it across hours to get a storm total, you’re double-counting — sometimes by a large margin.
This isn’t a bug. It’s a consequence of how NWP model output (GFS, NAM, HRRR) handles precipitation accumulation in GRIB2 fields. Models track accumulated precip as a running sum from a reference time, and the most natural reference time is the forecast day boundary. What surfaces in the API closely mirrors that structure. The problem is that nothing in the field name or the docs makes “this is cumulative” obvious enough that developers don’t get burned by it at least once.
What the data actually looks like
Take a forecast day with moderate rain starting around 14:00 and tapering off by 18:00. You might see hourly precip_mm values like:
- 12:00 — 0.0
- 13:00 — 0.0
- 14:00 — 1.4
- 15:00 — 3.9
- 16:00 — 6.1
- 17:00 — 7.8
- 18:00 — 8.2
- 19:00 — 8.2
Naively sum those values to get a daily total and you’d get 35.6mm. The actual day total is 8.2mm. The hourly values are non-decreasing within a day because they’re cumulative. Midnight resets the counter, so the first few hours of a day look fine — you only notice the problem when rain arrives mid-day and the numbers keep climbing past what any single hour of rain should produce.
Extracting true per-interval rainfall
The fix is a backward difference: subtract the previous hour’s value from the current hour’s value. For the first hour of each day (the 00:00 slot), the value itself is the interval total.
In Python:
def extract_interval_precip(hourly_data):
"""
hourly_data: list of dicts with 'time' and 'precip_mm',
ordered chronologically and already filtered to a single forecast day.
Returns a new list with 'interval_precip_mm' added to each entry.
"""
result = []
for i, hour in enumerate(hourly_data):
if i == 0:
interval = hour['precip_mm']
else:
interval = max(0.0, hour['precip_mm'] - hourly_data[i - 1]['precip_mm'])
result.append({**hour, 'interval_precip_mm': round(interval, 2)})
return result
The max(0.0, ...) guard matters. Floating-point rounding in model output can occasionally produce a value fractionally lower than the previous hour — without the clamp you get tiny negative interval values that break downstream logic.
The midnight boundary edge case
The reset happens at local midnight for the requested location. If you stitch multiple days into one chronological array before running the backward difference, you’ll get a large spurious spike at the day boundary. Process each day’s hourly array independently before concatenating.
This interacts badly with DST transitions. Anywhere that clocks change — the US in March, the UK in October, Brazil in November — the “midnight” boundary shifts relative to UTC in ways that trip up code treating time_epoch arithmetic as equivalent to calendar-day boundaries. Use the time string field, which is always in local time, to identify day boundaries rather than epoch math.
When you need sub-daily storm totals
For a 6-hour window — flood risk thresholds, irrigation scheduling, construction go/no-go — summing interval values across a window is straightforward once you’ve done the extraction:
from datetime import datetime, timedelta
def window_precip(interval_hours, start_time_str, window_hours=6):
"""
interval_hours: output of extract_interval_precip() for a full day
start_time_str: ISO-ish time string matching the 'time' field format, e.g. '2024-07-15 14:00'
"""
start = datetime.strptime(start_time_str, '%Y-%m-%d %H:%M')
total = 0.0
for h in interval_hours:
t = datetime.strptime(h['time'], '%Y-%m-%d %H:%M')
if start <= t < start + timedelta(hours=window_hours):
total += h['interval_precip_mm']
return round(total, 2)
For a 6-hour window starting at 14:00, this correctly sums only the 14:00 through 19:00 interval values — none of the cumulative inflation.
The daily total field isn't a substitute here
day.totalprecip_mm gives you the full calendar-day total and is straightforward to trust for that purpose. It doesn't help for intra-day windows, peak intensity hours, or anything requiring per-hour granularity. If your use case is "will it rain more than 10mm in any 3-hour window this afternoon," the daily aggregate is useless and the raw hourly cumulative values will mislead you. You need the interval extraction.
HRRR vs. GFS and what it means here
For US locations within HRRR's domain, the hourly precip values are backed by a 3km grid model that resolves convective cells much better than GFS's roughly 13km grid. That gap matters for interval rainfall specifically: a convective event can dump significant rain in a single hour and then stop completely. GFS tends to spread that rainfall across adjacent hours, so backward-difference intervals look smoother than reality. If you're building threshold alerts — flag if any single hour exceeds X mm — HRRR-backed data for US locations will catch short-duration intense events that GFS smears away. Outside HRRR's domain you're on GFS or ECMWF output, and that temporal smearing is a real limitation of the underlying model, not something the API layer can fix.
A caveat on forecast horizon
All of this applies to forecast data. At Day 1, hourly precipitation intervals from a good model run are reasonably trustworthy for relative intensity — which hours are wetter than others. At Day 7, the cumulative values may still be structurally correct (non-decreasing, resetting at midnight), but the absolute amounts are speculative. A 4mm cumulative reading at 18:00 on Day 7 carries much wider error bars than the same reading at Day 1. That's not specific to WeatherAPI; it's the skill-decay problem baked into NWP output at extended horizons, and it's worth making explicit in your UI rather than rendering Day 7 hourly rain bars with the same visual weight as Day 1.
If you're validating this logic, run it against historical API calls from days where you have gauge data or radar composites to compare against. The backward-difference approach is correct; the accuracy of what you're differencing depends entirely on model quality and how far out you're forecasting.
