From 5a3ad1ed0896b6b4d160bf5be6937ffc37b5c8a0 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Sat, 17 Aug 2024 13:27:45 -0400 Subject: [PATCH 1/4] fix spa numthreads warning interpolation --- pvlib/spa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/spa.py b/pvlib/spa.py index 4d2602bc3d..edfdac51e4 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -938,7 +938,7 @@ def solar_position_numba(unixtime, lat, lon, elev, pressure, temp, delta_t, if ulength < numthreads: warnings.warn('The number of threads is more than the length of ' - 'the time array. Only using %s threads.'.format(ulength)) + f'the time array. Only using {ulength} threads.') numthreads = ulength if numthreads <= 1: From b954ac8e2fcae9d0e2a573d45c11d195d0778b59 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Sat, 17 Aug 2024 13:27:54 -0400 Subject: [PATCH 2/4] add test --- pvlib/tests/test_spa.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index c7ebc5f9ae..0daf740c4e 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -423,3 +423,9 @@ def test_solar_position_multithreaded(self): nresult, self.spa.solar_position( times, lat, lon, elev, pressure, temp, delta_t, atmos_refract, numthreads=3, sst=True)[:3], 5) + + def test_solar_position_warn_too_many_threads(self): + two_timestamps = np.array([unixtimes[0], unixtimes[0]]) + with self.assertWarnsRegex(UserWarning, '.*Only using 2 threads.'): + self.spa.solar_position(two_timestamps, lat, lon, elev, pressure, + temp, delta_t, atmos_refract, numthreads=3) From e565411e788f68dad7c79b5701812b0c9cd6e114 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Mon, 23 Sep 2024 16:06:42 -0400 Subject: [PATCH 3/4] get rid of the warning altogether --- pvlib/spa.py | 2 -- pvlib/tests/test_irradiance.py | 2 +- pvlib/tests/test_solarposition.py | 6 +++--- pvlib/tests/test_spa.py | 8 +------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pvlib/spa.py b/pvlib/spa.py index edfdac51e4..132cbe6b39 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -937,8 +937,6 @@ def solar_position_numba(unixtime, lat, lon, elev, pressure, temp, delta_t, unixtime = unixtime.astype(np.float64) if ulength < numthreads: - warnings.warn('The number of threads is more than the length of ' - f'the time array. Only using {ulength} threads.') numthreads = ulength if numthreads <= 1: diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 0eb951f9a1..82463e0b0f 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -106,7 +106,7 @@ def test_get_extra_radiation_epoch_year(): @requires_numba def test_get_extra_radiation_nrel_numba(times): with warnings.catch_warnings(): - # don't warn on method reload or num threads + # don't warn on method reload warnings.simplefilter("ignore") result = irradiance.get_extra_radiation( times, method='nrel', how='numba', numthreads=4) diff --git a/pvlib/tests/test_solarposition.py b/pvlib/tests/test_solarposition.py index 472383acce..a44b0dc0e6 100644 --- a/pvlib/tests/test_solarposition.py +++ b/pvlib/tests/test_solarposition.py @@ -490,7 +490,7 @@ def test_get_solarposition_deltat(delta_t, method, expected_solpos_multi, times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=2, freq='D', tz=golden.tz) with warnings.catch_warnings(): - # don't warn on method reload or num threads + # don't warn on method reload warnings.simplefilter("ignore") ephem_data = solarposition.get_solarposition(times, golden.latitude, golden.longitude, @@ -838,7 +838,7 @@ def test_spa_python_numba_physical(expected_solpos, golden_mst): times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30), periods=1, freq='D', tz=golden_mst.tz) with warnings.catch_warnings(): - # don't warn on method reload or num threads + # don't warn on method reload # ensure that numpy is the most recently used method so that # we can use the warns filter below warnings.simplefilter("ignore") @@ -865,7 +865,7 @@ def test_spa_python_numba_physical_dst(expected_solpos, golden): periods=1, freq='D', tz=golden.tz) with warnings.catch_warnings(): - # don't warn on method reload or num threads + # don't warn on method reload warnings.simplefilter("ignore") ephem_data = solarposition.spa_python(times, golden.latitude, golden.longitude, pressure=82000, diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index 0daf740c4e..f4b6dec03d 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -234,7 +234,7 @@ def test_topocentric_azimuth_angle(self): def test_solar_position(self): with warnings.catch_warnings(): - # don't warn on method reload or num threads + # don't warn on method reload warnings.simplefilter("ignore") spa_out_0 = self.spa.solar_position( unixtimes, lat, lon, elev, pressure, temp, delta_t, @@ -423,9 +423,3 @@ def test_solar_position_multithreaded(self): nresult, self.spa.solar_position( times, lat, lon, elev, pressure, temp, delta_t, atmos_refract, numthreads=3, sst=True)[:3], 5) - - def test_solar_position_warn_too_many_threads(self): - two_timestamps = np.array([unixtimes[0], unixtimes[0]]) - with self.assertWarnsRegex(UserWarning, '.*Only using 2 threads.'): - self.spa.solar_position(two_timestamps, lat, lon, elev, pressure, - temp, delta_t, atmos_refract, numthreads=3) From caf1ae7e1f0a7d03e11574b25ba4c87926b77d0a Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Mon, 23 Sep 2024 16:11:09 -0400 Subject: [PATCH 4/4] whatsnew --- docs/sphinx/source/whatsnew/v0.11.1.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.11.1.rst b/docs/sphinx/source/whatsnew/v0.11.1.rst index 72d480e32d..de5effd3f3 100644 --- a/docs/sphinx/source/whatsnew/v0.11.1.rst +++ b/docs/sphinx/source/whatsnew/v0.11.1.rst @@ -30,6 +30,8 @@ Enhancements * Added function for calculating wind speed at different heights, :py:func:`pvlib.atmosphere.windspeed_powerlaw`. (:issue:`2118`, :pull:`2124`) +* The multithreaded SPA functions no longer emit a warning when calculating + solar positions for short time series. (:pull:`2170`) Bug fixes ~~~~~~~~~