diff --git a/docs/sphinx/source/whatsnew/v0.12.1.rst b/docs/sphinx/source/whatsnew/v0.12.1.rst index 34502715c7..8e8b76d3a5 100644 --- a/docs/sphinx/source/whatsnew/v0.12.1.rst +++ b/docs/sphinx/source/whatsnew/v0.12.1.rst @@ -15,6 +15,9 @@ Breaking Changes :py:func:`~pvlib.iotools.get_pvgis_tmy` now return ``(data,meta)`` following the iotools convention instead of ``(data,months_selected,inputs,meta)``. (:pull:`2470`) +* :py:func:`~pvlib.iotools.get_pvgis_tmy` now defaults to ``coerce_year=1990``, + whereas the default behavior previously was to use the years of the selected + months for the TMY index. (:pull:`2474`) * Remove ``outputformat='basic'`` option in :py:func:`~pvlib.iotools.get_pvgis_tmy`. (:pull:`2416`) diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 9bfd7f5a79..6acb3fc77b 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -434,7 +434,7 @@ def _coerce_and_roll_tmy(tmy_data, tz, year): def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True, userhorizon=None, startyear=None, endyear=None, map_variables=True, url=URL, timeout=30, - roll_utc_offset=None, coerce_year=None): + roll_utc_offset=None, coerce_year=1990): """ Get TMY data from PVGIS. @@ -477,9 +477,11 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True, Use to specify a time zone other than the default UTC zero and roll dataframe by ``roll_utc_offset`` so it starts at midnight on January 1st. Ignored if ``None``, otherwise will force year to ``coerce_year``. - coerce_year: int, optional - Use to force indices to desired year. Will default to 1990 if - ``coerce_year`` is not specified, but ``roll_utc_offset`` is specified. + coerce_year: int, default 1990 + Use to force indices to desired year. Defaults to 1990. Specify + ``None`` to return the actual indices used for the TMY. If + ``coerce_year`` is ``None``, but ``roll_utc_offset`` is specified, + then ``coerce_year`` will be set to the default. Returns ------- diff --git a/tests/iotools/test_pvgis.py b/tests/iotools/test_pvgis.py index cb5f408069..32d820faae 100644 --- a/tests/iotools/test_pvgis.py +++ b/tests/iotools/test_pvgis.py @@ -384,7 +384,7 @@ def pvgis_tmy_mapped_columns(): @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected, meta_expected): - pvgis_data = get_pvgis_tmy(45, 8, map_variables=False) + pvgis_data = get_pvgis_tmy(45, 8, map_variables=False, coerce_year=None) _compare_pvgis_tmy_json(expected, month_year_expected, inputs_expected, meta_expected, pvgis_data) @@ -428,7 +428,8 @@ def test_get_pvgis_tmy_kwargs(userhorizon_expected): _, meta = get_pvgis_tmy(45, 8, usehorizon=False, map_variables=False) assert meta['inputs']['meteo_data']['use_horizon'] is False data, _ = get_pvgis_tmy( - 45, 8, userhorizon=[0, 10, 20, 30, 40, 15, 25, 5], map_variables=False) + 45, 8, userhorizon=[0, 10, 20, 30, 40, 15, 25, 5], map_variables=False, + coerce_year=None) assert np.allclose( data['G(h)'], userhorizon_expected['G(h)'].values) assert np.allclose( @@ -486,13 +487,17 @@ def test_get_pvgis_tmy_coerce_year(): for m, test_case in enumerate(noon_test_data): expected = pvgis_data[pvgis_data.index.month == m+1].iloc[12] assert all(test_case == expected) + # Test that get_pvgis_tmy defaults to coerce_year=1990 + pvgis_data, _ = get_pvgis_tmy(45, 8) + assert all(pvgis_data.index.year == 1990) @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, - meta_expected, csv_meta): - pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv', map_variables=False) + meta_expected, csv_meta, coerce_year=None): + pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv', map_variables=False, + coerce_year=None) _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, meta_expected, csv_meta, pvgis_data) @@ -532,7 +537,8 @@ def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_get_pvgis_tmy_epw(expected, epw_meta): - pvgis_data = get_pvgis_tmy(45, 8, outputformat='epw', map_variables=False) + pvgis_data = get_pvgis_tmy(45, 8, outputformat='epw', map_variables=False, + coerce_year=None) _compare_pvgis_tmy_epw(expected, epw_meta, pvgis_data)