diff --git a/docs/sphinx/source/whatsnew/v0.11.3.rst b/docs/sphinx/source/whatsnew/v0.11.3.rst index 6363275fd2..4fabc65ba3 100644 --- a/docs/sphinx/source/whatsnew/v0.11.3.rst +++ b/docs/sphinx/source/whatsnew/v0.11.3.rst @@ -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 ~~~~~~~~~~~~ diff --git a/pvlib/data/tmy_45.000_8.000_2005_2023.csv b/pvlib/data/tmy_45.000_8.000_2005_2023.csv index 33cb0d5ed4..353008e0e7 100644 --- a/pvlib/data/tmy_45.000_8.000_2005_2023.csv +++ b/pvlib/data/tmy_45.000_8.000_2005_2023.csv @@ -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 diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 3ddc3f6a91..3ab22c1ed8 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -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( diff --git a/pvlib/tests/iotools/test_pvgis.py b/pvlib/tests/iotools/test_pvgis.py index 9a999592a7..fec7f7f448 100644 --- a/pvlib/tests/iotools/test_pvgis.py +++ b/pvlib/tests/iotools/test_pvgis.py @@ -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', @@ -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