Skip to content

Commit 4ef2813

Browse files
Change get_pvgis_tmy coerce_year default to 1990 (#2474)
* Change get_pvgis_tmy coerce_year default to 1990 * Update tests * Add whatsnew * Specific testing of default coerce_year value * Apply suggestions from code review Co-authored-by: Kevin Anderson <[email protected]> * Update pvlib/iotools/pvgis.py Co-authored-by: Kevin Anderson <[email protected]> --------- Co-authored-by: Kevin Anderson <[email protected]>
1 parent e4d3aa4 commit 4ef2813

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Breaking Changes
1515
:py:func:`~pvlib.iotools.get_pvgis_tmy` now return ``(data,meta)``
1616
following the iotools convention instead of ``(data,months_selected,inputs,meta)``.
1717
(:pull:`2470`)
18+
* :py:func:`~pvlib.iotools.get_pvgis_tmy` now defaults to ``coerce_year=1990``,
19+
whereas the default behavior previously was to use the years of the selected
20+
months for the TMY index. (:pull:`2474`)
1821
* Remove ``outputformat='basic'`` option in :py:func:`~pvlib.iotools.get_pvgis_tmy`.
1922
(:pull:`2416`)
2023

pvlib/iotools/pvgis.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def _coerce_and_roll_tmy(tmy_data, tz, year):
434434
def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
435435
userhorizon=None, startyear=None, endyear=None,
436436
map_variables=True, url=URL, timeout=30,
437-
roll_utc_offset=None, coerce_year=None):
437+
roll_utc_offset=None, coerce_year=1990):
438438
"""
439439
Get TMY data from PVGIS.
440440
@@ -477,9 +477,11 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
477477
Use to specify a time zone other than the default UTC zero and roll
478478
dataframe by ``roll_utc_offset`` so it starts at midnight on January
479479
1st. Ignored if ``None``, otherwise will force year to ``coerce_year``.
480-
coerce_year: int, optional
481-
Use to force indices to desired year. Will default to 1990 if
482-
``coerce_year`` is not specified, but ``roll_utc_offset`` is specified.
480+
coerce_year: int, default 1990
481+
Use to force indices to desired year. Defaults to 1990. Specify
482+
``None`` to return the actual indices used for the TMY. If
483+
``coerce_year`` is ``None``, but ``roll_utc_offset`` is specified,
484+
then ``coerce_year`` will be set to the default.
483485
484486
Returns
485487
-------

tests/iotools/test_pvgis.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def pvgis_tmy_mapped_columns():
384384
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
385385
def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected,
386386
meta_expected):
387-
pvgis_data = get_pvgis_tmy(45, 8, map_variables=False)
387+
pvgis_data = get_pvgis_tmy(45, 8, map_variables=False, coerce_year=None)
388388
_compare_pvgis_tmy_json(expected, month_year_expected, inputs_expected,
389389
meta_expected, pvgis_data)
390390

@@ -428,7 +428,8 @@ def test_get_pvgis_tmy_kwargs(userhorizon_expected):
428428
_, meta = get_pvgis_tmy(45, 8, usehorizon=False, map_variables=False)
429429
assert meta['inputs']['meteo_data']['use_horizon'] is False
430430
data, _ = get_pvgis_tmy(
431-
45, 8, userhorizon=[0, 10, 20, 30, 40, 15, 25, 5], map_variables=False)
431+
45, 8, userhorizon=[0, 10, 20, 30, 40, 15, 25, 5], map_variables=False,
432+
coerce_year=None)
432433
assert np.allclose(
433434
data['G(h)'], userhorizon_expected['G(h)'].values)
434435
assert np.allclose(
@@ -486,13 +487,17 @@ def test_get_pvgis_tmy_coerce_year():
486487
for m, test_case in enumerate(noon_test_data):
487488
expected = pvgis_data[pvgis_data.index.month == m+1].iloc[12]
488489
assert all(test_case == expected)
490+
# Test that get_pvgis_tmy defaults to coerce_year=1990
491+
pvgis_data, _ = get_pvgis_tmy(45, 8)
492+
assert all(pvgis_data.index.year == 1990)
489493

490494

491495
@pytest.mark.remote_data
492496
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
493497
def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
494-
meta_expected, csv_meta):
495-
pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv', map_variables=False)
498+
meta_expected, csv_meta, coerce_year=None):
499+
pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv', map_variables=False,
500+
coerce_year=None)
496501
_compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
497502
meta_expected, csv_meta, pvgis_data)
498503

@@ -532,7 +537,8 @@ def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
532537
@pytest.mark.remote_data
533538
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
534539
def test_get_pvgis_tmy_epw(expected, epw_meta):
535-
pvgis_data = get_pvgis_tmy(45, 8, outputformat='epw', map_variables=False)
540+
pvgis_data = get_pvgis_tmy(45, 8, outputformat='epw', map_variables=False,
541+
coerce_year=None)
536542
_compare_pvgis_tmy_epw(expected, epw_meta, pvgis_data)
537543

538544

0 commit comments

Comments
 (0)