Skip to content

Commit 40a213b

Browse files
authored
Fix get_pvgis_tmy for outputformat='csv' (#2395)
* fix CSV parsing and test * whatsnew * lint * more fixes
1 parent 4b25801 commit 40a213b

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

docs/sphinx/source/whatsnew/v0.11.3.rst

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Bug fixes
3131
if/when the time zone is updated, the tz attribute is now the single source
3232
of time-zone truth, is the single time-zone setter interface, and its getter
3333
returns an IANA string. (:issue:`2340`, :pull:`2341`)
34+
* :py:func:`~pvlib.iotools.get_pvgis_tmy` with ``outputformat='csv'`` now
35+
works with the updated data format returned by PVGIS. (:issue:`2344`, :pull:`2395`)
3436

3537
Deprecations
3638
~~~~~~~~~~~~

pvlib/iotools/pvgis.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,17 @@ def _parse_pvgis_tmy_csv(src):
559559
inputs['longitude'] = float(src.readline().split(b':')[1])
560560
# Elevation (m): 1389.0\r\n
561561
inputs['elevation'] = float(src.readline().split(b':')[1])
562+
563+
# TMY has an extra line here: Irradiance Time Offset (h): 0.1761\r\n
564+
line = src.readline()
565+
if line.startswith(b'Irradiance Time Offset'):
566+
inputs['irradiance time offset'] = float(line.split(b':')[1])
567+
src.readline() # skip over the "month,year\r\n"
568+
else:
569+
# `line` is already the "month,year\r\n" line, so nothing to do
570+
pass
562571
# then there's a 13 row comma separated table with two columns: month, year
563-
# which contains the year used for that month in the
564-
src.readline() # get "month,year\r\n"
572+
# which contains the year used for that month in the TMY
565573
months_selected = []
566574
for month in range(12):
567575
months_selected.append(

tests/data/tmy_45.000_8.000_2005_2023.csv

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Latitude (decimal degrees): 45.000
22
Longitude (decimal degrees): 8.000
33
Elevation (m): 250.0
4+
Irradiance Time Offset (h): 0.1761
45
month,year
56
1,2018
67
2,2007

tests/iotools/test_pvgis.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ def month_year_expected():
328328
@pytest.fixture
329329
def inputs_expected():
330330
return {
331-
'location': {'latitude': 45.0, 'longitude': 8.0, 'elevation': 250.0},
331+
'location': {'latitude': 45.0, 'longitude': 8.0, 'elevation': 250.0,
332+
'irradiance time offset': 0.1761},
332333
'meteo_data': {
333334
'radiation_db': 'PVGIS-SARAH3',
334335
'meteo_db': 'ERA5',
@@ -510,6 +511,9 @@ def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
510511
assert inputs['latitude'] == inputs_expected['location']['latitude']
511512
assert inputs['longitude'] == inputs_expected['location']['longitude']
512513
assert inputs['elevation'] == inputs_expected['location']['elevation']
514+
assert (inputs['irradiance time offset']
515+
== inputs_expected['location']['irradiance time offset']
516+
)
513517
for meta_value in meta:
514518
if not meta_value:
515519
continue

0 commit comments

Comments
 (0)