Skip to content

Honor the EPW header time zone in get_pvgis_tmy - #2967

Closed
LYUml wants to merge 2 commits into
pvlib:mainfrom
LYUml:codex/pvgis-epw-tmy-timezone
Closed

LYUml wants to merge 2 commits into
pvlib:mainfrom
LYUml:codex/pvgis-epw-tmy-timezone

Conversation

@LYUml

@LYUml LYUml commented Nov 29, 2026 •

Copy link
Copy Markdown

Addresses the pvlib timestamp conversion reported in #2956. Thanks to @rajsingh1301 for isolating the input-format discrepancy and the leap-year case.

EPW input arrives with the fixed offset declared in its header. The previous conversion treated its local clock as UTC. This patch combines the selected TMY months on a non-leap calendar, converts the index to the requested time zone, and folds the converted rows into the requested year. Sorting the indexed frame keeps each observation with its timestamp and preserves column dtypes.

Effect on EPW users

The proposed behavior trusts the EPW header. This fixes Tokyo and exposes a discrepancy for files where the declared offset disagrees with the hourly values. At 45°N, 8°E, the bundled EPW and JSON files previously agreed for all 8,760 hours. The EPW header declares UTC+1. Its January 1 reading of 149 W/m² moves from 09:00 UTC to 08:00 UTC, one hour earlier than JSON. The release notes and API documentation direct users who need the PVGIS UTC series to outputformat='json'.

Verification

I replayed the same inputs through get_pvgis_tmy on main (b8a02a4) and on this branch with default time arguments. The table counts hours out of 8,760 when EPW and JSON GHI agree at the same UTC timestamp (numpy.isclose). It includes nighttime zeros. The 45°N, 8°E files come from the repository. The other pairs are PVGIS v5.3 responses fetched on November 29, 2026.

Site EPW header offset Matching hours on main Matching hours after patch
Tokyo +9 1,089 8,760
New Delhi +5 2,565 8,758
Denver −7 1,457 4,012
45°N, 8°E +1 8,760 4,173
London 0 4,171 4,171
Accra 0 4,103 4,103

Differences in the raw PVGIS exports. I compared the original files directly, with identical coordinates and the 2005–2023 period. For New Delhi the same five-hour offset aligns all 8,760 temperature, humidity and pressure records. At 2018-05-25 00:00 UTC, however, the original EPW gives 0.00 and the JSON gives 31.85 W/m² for GHI. At 2015-06-29 00:00 UTC they give 28.85 and 0.00 respectively. The annual difference is 3.00 Wh/m², which reordering the rows cannot change. Tokyo also has 346 DNI mismatches after alignment. The cause inside PVGIS is unverified. This patch preserves the values supplied by the requested format. New Delhi EPW, New Delhi JSON.

The public API tests cover default arguments, positive and negative source offsets, a fractional source offset, an explicit output offset, year wrap, and a leap target year. Selecting February and March from a leap source year exposes the conversion-order bug described in the issue. Four of the five regression cases fail with the main-branch conversion. Three fail if the time zone is converted before the source months are placed on a non-leap calendar.

The offline PVGIS and EPW modules passed with pandas 1.5.0, 1.5.3, and 2.2.3. The full offline suite passed with pandas 3.0.5 and 3.1.1 (1,445 passed, 110 skipped, 94 remote tests deselected, 2 expected failures on each). The changed lines pass the repository's Flake8 check.

I also ran all ten live tests in tests/iotools/test_pvgis.py on this branch and clean main with a 180-second per-test timeout. On each revision six passed, including the year-coercion test, and the same four failed when comparing live weather with historical snapshots (test_get_pvgis_tmy, test_get_pvgis_tmy_kwargs, test_get_pvgis_tmy_csv, and test_get_pvgis_tmy_epw). Even with the 2005–2023 period fixed, the service now selects January 2021 for 45°N, 8°E. The checked-in files use January 2018.

PR checklist

Codex assisted with the implementation, tests and verification.

@github-actions

Copy link
Copy Markdown

Hey @LYUml! 🎉

Thanks for opening your first pull request! We appreciate your
contribution. Please ensure you have reviewed and understood the
contributing guidelines.

If AI is used for any portion of this PR, you must vet the content
for technical accuracy.

Finally, be sure the PR description includes the PR
checklist,
and complete the items you are able to.

@cwhanse

cwhanse commented Nov 29, 2026

Copy link
Copy Markdown
Member

Maintainers are busy people. We're not going to read seven paragraphs of AI text explaining the AI's PR. If you'd like to be successful here, please edit.

@cwhanse cwhanse closed this Nov 29, 2026
@LYUml
LYUml deleted the codex/pvgis-epw-tmy-timezone branch November 30, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants