Fix 10%/90%/CL calibrated PV values being ~2× too low with Open-Meteo#3827
Fix 10%/90%/CL calibrated PV values being ~2× too low with Open-Meteo#3827springfall2008 merged 5 commits intomainfrom
Conversation
…Meteo) Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/175ef50b-045f-4533-89cd-dbafb11a7598 Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
|
@copilot this doesn't make sense, the data should all be normalised before the calibration runs. Is this working around a bug upstream? |
The per-minute data ( The bug is only in the write-back step: after calibration computes This is not working around an upstream bug. The Open-Meteo data is correct (60-min kWh from trapezoidal integration of hourly irradiance), and the per-minute normalisation is correct. The only issue was the annotation loop not summing all plan slots that span each forecast entry's period. An alternative "normalise upstream" approach would split the 60-min entries into two 30-min entries before calling
Happy to implement either approach — let me know if you'd prefer the upstream split. |
There was a problem hiding this comment.
Pull request overview
Fixes PV calibration annotation for coarser forecast resolutions (notably Open-Meteo hourly data) so calibrated PV values reflect the full forecast-entry duration rather than only the first plan slot.
Changes:
- Extend
SolarAPI.pv_calibration()to accept aperiodand sum all plan-interval slots within each forecast entry when annotatingpv_estimateCL/pv_estimate10/pv_estimate90. - Update
fetch_pv_forecast()to pass the detected forecast period through topv_calibration(). - Add a regression test covering 60-minute forecast entries with 30-minute plan slots.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/predbat/solcast.py | Accumulates calibrated values across multiple plan slots per forecast entry and threads the detected forecast period into calibration. |
| apps/predbat/tests/test_solcast.py | Adds a regression test for 60-min forecast periods to prevent the “half-period” calibration annotation bug. |
| for entry in adj_data: | ||
| cl = entry.get("pv_estimateCL") | ||
| e10 = entry.get("pv_estimate10") | ||
| e90 = entry.get("pv_estimate90") | ||
|
|
||
| if cl is None or cl == 0: | ||
| continue | ||
|
|
When using Open-Meteo (60-min forecast slots) with the default 30-min plan interval,
pv_calibration()annotated each forecast entry with only the calibrated value from the first 30-min plan slot, silently discarding the second half of each 60-min window.Root cause
In the annotation loop, the lookup was a direct dict get for a single slot:
For a 60-min entry at minute 600,
pv_estimateCL[600]covers only minutes 600–629.pv_estimateCL[630](minutes 630–659) was never included.Changes
solcast.py—pv_calibration(): Addedperiodparameter (defaults toplan_interval_minutesfor backward compatibility). Computesslots_per_period = round(period / plan_interval_minutes)and sums all plan slots within each forecast entry's duration before storing the annotated value. Updatedfetch_pv_forecast()to passperiodthrough.tests/test_solcast.py: Addedtest_pv_calibration_60min_period— exercisespv_calibration()with 60-min forecast entries and 30-min plan slots, asserting the annotatedpv_estimateCLmatches the full-period kWh (not the half-period value the bug produced).Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.octopus.energy/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick(dns block)gitlab.com/usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED(dns block)https://api.github.com/repos/springfall2008/batpred/contents/apps/predbat/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test solcast(http block)/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick(http block)If you need me to access, download, or install something from one of these locations, you can either: