|
12 | 12 | from numpy.testing import assert_allclose |
13 | 13 |
|
14 | 14 | from pvlib import iam as _iam |
| 15 | +from pvlib._deprecation import pvlibDeprecationWarning |
15 | 16 |
|
16 | 17 |
|
17 | 18 | def test_ashrae(): |
@@ -171,8 +172,8 @@ def test_martin_ruiz_diffuse(): |
171 | 172 |
|
172 | 173 | def test_iam_interp(): |
173 | 174 |
|
174 | | - aoi_meas = [0.0, 45.0, 65.0, 75.0] |
175 | | - iam_meas = [1.0, 0.9, 0.8, 0.6] |
| 175 | + aoi_meas = np.array([0.0, 45.0, 65.0, 75.0]) |
| 176 | + iam_meas = np.array([1.0, 0.9, 0.8, 0.6]) |
176 | 177 |
|
177 | 178 | # simple default linear method |
178 | 179 | aoi = 55.0 |
@@ -200,18 +201,80 @@ def test_iam_interp(): |
200 | 201 | assert_series_equal(iam, expected) |
201 | 202 |
|
202 | 203 | # check beyond reference values |
203 | | - aoi = [-45, 0, 45, 85, 90, 95, 100, 105, 110] |
204 | | - expected = [0.9, 1.0, 0.9, 0.4, 0.3, 0.2, 0.1, 0.0, 0.0] |
| 204 | + aoi = np.array([-45, 0, 45, 85, 90, 95, 100, 105, 110]) |
| 205 | + expected = np.array([0.9, 1.0, 0.9, 0.4, 0.3, 0.2, 0.1, 0.0, 0.0]) |
205 | 206 | iam = _iam.interp(aoi, aoi_meas, iam_meas) |
206 | 207 | assert_allclose(iam, expected) |
207 | 208 |
|
208 | 209 | # check exception clause |
209 | 210 | with pytest.raises(ValueError): |
210 | | - _iam.interp(0.0, [0], [1]) |
| 211 | + _iam.interp(0.0, np.array([0]), np.array([1])) |
211 | 212 |
|
212 | 213 | # check exception clause |
213 | 214 | with pytest.raises(ValueError): |
214 | | - _iam.interp(0.0, [0, 90], [1, -1]) |
| 215 | + _iam.interp(0.0, np.array([0, 90]), np.array([1, -1])) |
| 216 | + |
| 217 | + # check linear after updating interp1d |
| 218 | + theta_ref = np.array([0, 60, 90]) |
| 219 | + iam_ref = np.array([1.0, 0.8, 0.0]) |
| 220 | + |
| 221 | + aoi = np.array([0, 30, 60]) |
| 222 | + iam = _iam.interp( |
| 223 | + aoi, theta_ref, iam_ref, |
| 224 | + method="linear", normalize=False) |
| 225 | + expected = np.array([1.0, 0.9, 0.8]) |
| 226 | + np.testing.assert_allclose(iam, expected) |
| 227 | + |
| 228 | + # check quadratic |
| 229 | + theta_ref = np.array([0, 30, 60, 90]) |
| 230 | + iam_ref = 1.0 - 1e-4 * theta_ref**2 |
| 231 | + aoi = np.array([15, 45, 75]) |
| 232 | + iam = _iam.interp( |
| 233 | + aoi, |
| 234 | + theta_ref, |
| 235 | + iam_ref, |
| 236 | + method="quadratic", |
| 237 | + normalize=False |
| 238 | + ) |
| 239 | + |
| 240 | + expected = 1.0 - 1e-4 * aoi**2 |
| 241 | + np.testing.assert_allclose(iam, expected, rtol=1e-12) |
| 242 | + |
| 243 | + |
| 244 | +@pytest.mark.parametrize( |
| 245 | + "method", |
| 246 | + ["nearest", "nearest-up", "zero", "slinear", "previous", "next"] |
| 247 | +) |
| 248 | +def test_iam_interp_deprecated_methods(method): |
| 249 | + theta_ref = np.array([0, 60, 90]) |
| 250 | + iam_ref = np.array([1.0, 0.8, 0.0]) |
| 251 | + |
| 252 | + with pytest.warns( |
| 253 | + pvlibDeprecationWarning, |
| 254 | + match=f"Interpolation method {method} is deprecated in pvlib" |
| 255 | + ): |
| 256 | + _iam.interp( |
| 257 | + 30, |
| 258 | + theta_ref, |
| 259 | + iam_ref, |
| 260 | + method=method |
| 261 | + ) |
| 262 | + |
| 263 | + |
| 264 | +def test_iam_interp_invalid_method(): |
| 265 | + theta_ref = np.array([0, 60, 90]) |
| 266 | + iam_ref = np.array([1.0, 0.8, 0.0]) |
| 267 | + |
| 268 | + with pytest.raises( |
| 269 | + ValueError, |
| 270 | + match="is not supported" |
| 271 | + ): |
| 272 | + _iam.interp( |
| 273 | + 30, |
| 274 | + theta_ref, |
| 275 | + iam_ref, |
| 276 | + method="unsupported" |
| 277 | + ) |
215 | 278 |
|
216 | 279 |
|
217 | 280 | @pytest.mark.parametrize('aoi,expected', [ |
|
0 commit comments