Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_pvgis_tmy for outputformat='csv' #2395

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/sphinx/source/whatsnew/v0.11.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
v0.11.3 (Anticipated March, 2025)
---------------------------------

Bug fixes
~~~~~~~~~
* :py:func:`~pvlib.iotools.get_pvgis_tmy` with ``outputformat='csv'`` now
works with the updated data format returned by PVGIS. (:issue:`2344`, :pull:`2395`)


Deprecations
~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions pvlib/data/tmy_45.000_8.000_2005_2023.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Latitude (decimal degrees): 45.000
Longitude (decimal degrees): 8.000
Elevation (m): 250.0
Irradiance Time Offset (h): 0.1761
month,year
1,2018
2,2007
Expand Down
12 changes: 10 additions & 2 deletions pvlib/iotools/pvgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,17 @@ def _parse_pvgis_tmy_csv(src):
inputs['longitude'] = float(src.readline().split(b':')[1])
# Elevation (m): 1389.0\r\n
inputs['elevation'] = float(src.readline().split(b':')[1])

# TMY has an extra line here: Irradiance Time Offset (h): 0.1761\r\n
line = src.readline()
if line.startswith(b'Irradiance Time Offset'):
inputs['irradiance time offset'] = float(line.split(b':')[1])
src.readline() # skip over the "month,year\r\n"
else:
# `line` is already the "month,year\r\n" line, so nothing to do
pass
# then there's a 13 row comma separated table with two columns: month, year
# which contains the year used for that month in the
src.readline() # get "month,year\r\n"
# which contains the year used for that month in the TMY
months_selected = []
for month in range(12):
months_selected.append(
Expand Down
6 changes: 5 additions & 1 deletion pvlib/tests/iotools/test_pvgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ def month_year_expected():
@pytest.fixture
def inputs_expected():
return {
'location': {'latitude': 45.0, 'longitude': 8.0, 'elevation': 250.0},
'location': {'latitude': 45.0, 'longitude': 8.0, 'elevation': 250.0,
'irradiance time offset': 0.1761},
'meteo_data': {
'radiation_db': 'PVGIS-SARAH3',
'meteo_db': 'ERA5',
Expand Down Expand Up @@ -503,6 +504,9 @@ def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
assert inputs['latitude'] == inputs_expected['location']['latitude']
assert inputs['longitude'] == inputs_expected['location']['longitude']
assert inputs['elevation'] == inputs_expected['location']['elevation']
assert (inputs['irradiance time offset']
== inputs_expected['location']['irradiance time offset']
)
for meta_value in meta:
if not meta_value:
continue
Expand Down
Loading