fix(pvforecast): normalize Forecast.Solar power before resampling (#1487)

Forecast.Solar supplies instantaneous power with irregular sunrise/sunset timestamps. GENETIC interprets stored values as interval averages and infers cadence from the shortest gap, so these samples create artificial coverage gaps. The prediction list API also averages away the sunset zero before interpolating, producing positive nighttime PV.

Integrate each roof plane's piecewise-linear power curve into UTC-contiguous 15-minute interval-average W before summing planes. Both hourly and quarter-hour GENETIC slots then consume the same normalized data as the prediction API, with exactly one downstream W-to-Wh conversion. Explicit sunrise/sunset zero boundaries establish the adjacent night within each forecast day. Daylight gaps longer than an hour, invalid power, absent planes and unavailable forecast days remain missing; the strict GENETIC coverage check stays in place.

Refreshes replace the current forecast and remove stale tails. Because cadence detection also sees historical records, the first refresh clears legacy forecasts containing non-aligned timestamps, including their history. Later refreshes retain normalized history. This upgrade behavior is documented.

Forecast validation errors now identify the first invalid interval and the number of invalid slots.
This commit is contained in:
Normann
2026-11-07 19:46:58 +01:00
committed by GitHub
parent 651301f9e6
commit b33953d445
5 changed files with 359 additions and 26 deletions
@@ -224,8 +224,15 @@ class ConfigOptimizationRequest(
("prices", prices),
("feed-in tariff", tariffs),
):
if not all(math.isfinite(value) for value in values[first:last]):
raise ValueError(f"Missing or invalid {key} within the control horizon.")
missing = [index for index in range(first, last) if not math.isfinite(values[index])]
if missing:
left = origin.add(seconds=missing[0] * settings.interval_sec)
right = left.add(seconds=settings.interval_sec)
raise ValueError(
f"Missing or invalid {key} within the control horizon. "
f"First invalid interval: [{left.isoformat()}, {right.isoformat()}); "
f"{len(missing)} invalid interval(s)."
)
if any(value < 0 for values in (pv, load) for value in values[first:last]):
raise ValueError("PV and load energy must be nonnegative.")
previous = ems.genetic_solution()