|
1 | 1 | import numpy as np |
2 | 2 | import pandas as pd |
3 | 3 |
|
| 4 | +from numpy.testing import assert_allclose |
4 | 5 | from pandas.testing import assert_series_equal |
5 | 6 | from numpy.testing import assert_allclose, assert_approx_equal |
6 | 7 | import pytest |
@@ -309,7 +310,40 @@ def test_shaded_fraction1d(sf1d_premises_and_expected): |
309 | 310 | assert isinstance(sf_vec, pd.Series) |
310 | 311 |
|
311 | 312 |
|
312 | | -def test_martinez_shade_factor(): |
| 313 | +def martinez_shade_factor_Table2(): |
| 314 | + """ |
| 315 | + Data provided in Table 2, [1] of martinez_shade_factor |
| 316 | + Returns tuple with (input: pandas.DataFrame, output: pandas.Series) |
| 317 | + Output is POWER LOSS, not POWER CORRECTION, so model result must be |
| 318 | + subtracted from 1 |
| 319 | + """ |
| 320 | + test_data = pd.DataFrame( |
| 321 | + columns=["F_GS-H", "F_GS-V", "N_shaded_blocks", "power_reduction"], |
| 322 | + data=[ |
| 323 | + [1.00, 0.09, 24, 0.88], |
| 324 | + [1.00, 0.18, 24, 0.89], |
| 325 | + [1.00, 0.36, 24, 0.90], |
| 326 | + [0.04, 0.64, 1, 0.08], |
| 327 | + [0.17, 0.45, 3, 0.22], |
| 328 | + [0.29, 0.27, 5, 0.33], |
| 329 | + [0.50, 0.09, 8, 0.46], |
| 330 | + [0.13, 1.00, 2, 0.21], |
| 331 | + [0.25, 1.00, 4, 0.40], |
| 332 | + [0.38, 1.00, 6, 0.56], |
| 333 | + [0.50, 1.00, 8, 0.54], |
| 334 | + [0.58, 0.82, 10, 0.74], |
| 335 | + [0.75, 0.73, 12, 0.81], |
| 336 | + [0.92, 0.64, 15, 0.89], |
| 337 | + ] # fmt: skip |
| 338 | + ) |
| 339 | + test_data["N_total_blocks"] = 24 # total blocks is 24 for all cases |
| 340 | + test_data["shaded_fraction"] = test_data["F_GS-H"] * test_data["F_GS-V"] |
| 341 | + test_data.drop(columns=["F_GS-H", "F_GS-V"], inplace=True) |
| 342 | + return (test_data.drop(columns="power_reduction"), test_data["power_reduction"]) |
| 343 | + |
| 344 | + |
| 345 | +def test_martinez_shade_factor(martinez_shade_factor_Table2): |
313 | 346 | """Tests pvlib.shading.martinez_shade_factor""" |
314 | | - # TODO |
315 | | - pass |
| 347 | + premises, power_reduction_expected = martinez_shade_factor_Table2 |
| 348 | + power_loss_factor = 1 - shading.martinez_shade_factor(**premises) |
| 349 | + assert_allclose(power_loss_factor, power_reduction_expected) |
0 commit comments