From 43afab70a33c48fc41b61b0ad425039156a233f6 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:07:14 -0600 Subject: [PATCH 1/6] Change get_pvgis_tmy coerce_year default to 1990 --- pvlib/iotools/pvgis.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 9bfd7f5a79..8385b5a08a 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. @@ -478,8 +478,10 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True, 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. + Use to force indices to desired year. Defaults to 1990. Specify ``None`` + to return the actual indicies 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 ------- From e79a4c9b34099e5fc6864f8cbd7fc3d863c491ac Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:15:19 -0600 Subject: [PATCH 2/6] Update tests --- pvlib/iotools/pvgis.py | 8 ++++---- tests/iotools/test_pvgis.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 8385b5a08a..057fe3f276 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -478,10 +478,10 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True, 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. Defaults to 1990. Specify ``None`` - to return the actual indicies used for the TMY. If ``coerce_year`` is - ``None``, but ``roll_utc_offset`` is specified, then ``coerce`` year - will be set to the default. + Use to force indices to desired year. Defaults to 1990. Specify + ``None`` to return the actual indicies 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..79845103e9 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( @@ -491,10 +492,11 @@ def test_get_pvgis_tmy_coerce_year(): @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): + meta_expected, csv_meta, coerce_year=None): pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv', map_variables=False) _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, - meta_expected, csv_meta, pvgis_data) + meta_expected, csv_meta, pvgis_data, + coerce_year=None) def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, @@ -532,7 +534,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) From 5ecdbf2287a025e70e6743e8d6a1af535ef0c826 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:22:37 -0600 Subject: [PATCH 3/6] Add whatsnew --- docs/sphinx/source/whatsnew/v0.12.1.rst | 3 +++ tests/iotools/test_pvgis.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) 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/tests/iotools/test_pvgis.py b/tests/iotools/test_pvgis.py index 79845103e9..9946982aef 100644 --- a/tests/iotools/test_pvgis.py +++ b/tests/iotools/test_pvgis.py @@ -493,10 +493,10 @@ def test_get_pvgis_tmy_coerce_year(): @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, coerce_year=None): - pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv', map_variables=False) + 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, - coerce_year=None) + meta_expected, csv_meta, pvgis_data) def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected, From 01ed3bd63d2b8e84edbb370360f713cd577aa911 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:37:04 -0600 Subject: [PATCH 4/6] Specific testing of default coerce_year value --- tests/iotools/test_pvgis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/iotools/test_pvgis.py b/tests/iotools/test_pvgis.py index 9946982aef..32d820faae 100644 --- a/tests/iotools/test_pvgis.py +++ b/tests/iotools/test_pvgis.py @@ -487,6 +487,9 @@ 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 From f8e623ee773dc05e5c7ea6030c8ce26b57e6145f Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:49:00 -0600 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Kevin Anderson --- pvlib/iotools/pvgis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 057fe3f276..5c82c71ca2 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -477,11 +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 + coerce_year: int, default 1990 Use to force indices to desired year. Defaults to 1990. Specify ``None`` to return the actual indicies used for the TMY. If ``coerce_year`` is ``None``, but ``roll_utc_offset`` is specified, - then ``coerce`` year will be set to the default. + then ``coerce_year`` will be set to the default. Returns ------- From d7e1dbcf8087abf59be7021c1299ad5ccd6f2b39 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Fri, 6 Jun 2025 13:50:42 -0600 Subject: [PATCH 6/6] Update pvlib/iotools/pvgis.py Co-authored-by: Kevin Anderson --- pvlib/iotools/pvgis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/iotools/pvgis.py b/pvlib/iotools/pvgis.py index 5c82c71ca2..6acb3fc77b 100644 --- a/pvlib/iotools/pvgis.py +++ b/pvlib/iotools/pvgis.py @@ -479,7 +479,7 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True, 1st. Ignored if ``None``, otherwise will force year to ``coerce_year``. coerce_year: int, default 1990 Use to force indices to desired year. Defaults to 1990. Specify - ``None`` to return the actual indicies used for the TMY. If + ``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.