From 692d856ff99493c38d26791cba94d878b74ae80b Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 21 Feb 2025 11:02:27 -0500 Subject: [PATCH 1/4] fix CSV parsing and test --- pvlib/iotools/pvgis.py | 2 ++ pvlib/tests/iotools/test_pvgis.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 3ddc3f6a91..74a8172fe2 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -559,6 +559,8 @@ 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]) + # Irradiance Time Offset (h): 0.1761\r\n + inputs['irradiance time offset'] = float(src.readline().split(b':')[1]) # 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" diff --git a/pvlib/tests/iotools/test_pvgis.py b/pvlib/tests/iotools/test_pvgis.py index 9a999592a7..98c7d6cf16 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 From 8ef03a319779beb4996f5f1e705470026c05e453 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 21 Feb 2025 11:06:12 -0500 Subject: [PATCH 2/4] whatsnew --- docs/sphinx/source/whatsnew/v0.11.3.rst | 6 ++++++ 1 file changed, 6 insertions(+) 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 ~~~~~~~~~~~~ From dabe7b5a32514f02f74f3f81c571951b9e99b374 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 21 Feb 2025 11:13:09 -0500 Subject: [PATCH 3/4] lint --- pvlib/tests/iotools/test_pvgis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/tests/iotools/test_pvgis.py b/pvlib/tests/iotools/test_pvgis.py index 98c7d6cf16..fec7f7f448 100644 --- a/pvlib/tests/iotools/test_pvgis.py +++ b/pvlib/tests/iotools/test_pvgis.py @@ -505,8 +505,8 @@ def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, 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'] - ) + == inputs_expected['location']['irradiance time offset'] + ) for meta_value in meta: if not meta_value: continue From d12d4b6ade43c7bfd25a3e8c885d4f2d52a1600f Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 21 Feb 2025 11:28:16 -0500 Subject: [PATCH 4/4] more fixes --- pvlib/data/tmy_45.000_8.000_2005_2023.csv | 1 + pvlib/iotools/pvgis.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) 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 74a8172fe2..3ab22c1ed8 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -559,11 +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]) - # Irradiance Time Offset (h): 0.1761\r\n - inputs['irradiance time offset'] = 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(