|
| 1 | +import pandas as pd |
| 2 | +from pandas.util.testing import assert_series_equal |
| 3 | +from pvlib.losses import soiling_hsu |
| 4 | +from conftest import requires_scipy |
| 5 | +import pytest |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def expected_output(): |
| 10 | + # Sample output (calculated manually) |
| 11 | + dt = pd.date_range(start=pd.datetime(2019, 1, 1, 0, 0, 0), |
| 12 | + end=pd.datetime(2019, 1, 1, 23, 59, 0), freq='1h') |
| 13 | + |
| 14 | + expected_no_cleaning = pd.Series( |
| 15 | + data=[0.884980357535360, 0.806308930084762, 0.749974647038078, |
| 16 | + 0.711804155175089, 0.687489866078621, 0.672927554408964, |
| 17 | + 0.664714899337491, 0.660345851212099, 0.658149551658860, |
| 18 | + 0.657104593968981, 0.656633344364056, 0.656431630729954, |
| 19 | + 0.656349579062171, 0.656317825078228, 0.656306121502393, |
| 20 | + 0.656302009396500, 0.656300630853678, 0.656300189543417, |
| 21 | + 0.656300054532516, 0.656300015031680, 0.656300003971846, |
| 22 | + 0.656300001006533, 0.656300000244750, 0.656300000057132], |
| 23 | + index=dt) |
| 24 | + |
| 25 | + return expected_no_cleaning |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture |
| 29 | +def expected_output_2(expected_output): |
| 30 | + # Sample output (calculated manually) |
| 31 | + dt = pd.date_range(start=pd.datetime(2019, 1, 1, 0, 0, 0), |
| 32 | + end=pd.datetime(2019, 1, 1, 23, 59, 0), freq='1h') |
| 33 | + |
| 34 | + expected_no_cleaning = expected_output |
| 35 | + |
| 36 | + expected = pd.Series(index=dt) |
| 37 | + expected[dt[:4]] = expected_no_cleaning[dt[:4]] |
| 38 | + expected[dt[4:7]] = 1. |
| 39 | + expected[dt[7]] = expected_no_cleaning[dt[0]] |
| 40 | + expected[dt[8:12]] = 1. |
| 41 | + expected[dt[12:17]] = expected_no_cleaning[dt[:5]] |
| 42 | + expected[dt[17:21]] = 1. |
| 43 | + expected[dt[21:]] = expected_no_cleaning[:3] |
| 44 | + |
| 45 | + return expected |
| 46 | + |
| 47 | + |
| 48 | +@pytest.fixture |
| 49 | +def rainfall_input(): |
| 50 | + |
| 51 | + dt = pd.date_range(start=pd.datetime(2019, 1, 1, 0, 0, 0), |
| 52 | + end=pd.datetime(2019, 1, 1, 23, 59, 0), freq='1h') |
| 53 | + rainfall = pd.Series( |
| 54 | + data=[0., 0., 0., 0., 1., 0., 0., 0., 0.5, 0.5, 0., 0., 0., 0., 0., |
| 55 | + 0., 0.3, 0.3, 0.3, 0.3, 0., 0., 0., 0.], index=dt) |
| 56 | + return rainfall |
| 57 | + |
| 58 | + |
| 59 | +@requires_scipy |
| 60 | +def test_soiling_hsu_no_cleaning(rainfall_input, expected_output): |
| 61 | + """Test Soiling HSU function""" |
| 62 | + |
| 63 | + rainfall = rainfall_input |
| 64 | + pm2_5 = 1.0 |
| 65 | + pm10 = 2.0 |
| 66 | + depo_veloc = {'2_5': 1.0, '10': 1.0} |
| 67 | + tilt = 0. |
| 68 | + expected_no_cleaning = expected_output |
| 69 | + |
| 70 | + result = soiling_hsu(rainfall=rainfall, cleaning_threshold=10., tilt=tilt, |
| 71 | + pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc, |
| 72 | + rain_accum_period=pd.Timedelta('1h')) |
| 73 | + assert_series_equal(result, expected_no_cleaning) |
| 74 | + |
| 75 | + |
| 76 | +@requires_scipy |
| 77 | +def test_soiling_hsu(rainfall_input, expected_output_2): |
| 78 | + """Test Soiling HSU function""" |
| 79 | + |
| 80 | + rainfall = rainfall_input |
| 81 | + pm2_5 = 1.0 |
| 82 | + pm10 = 2.0 |
| 83 | + depo_veloc = {'2_5': 1.0, '10': 1.0} |
| 84 | + tilt = 0. |
| 85 | + expected = expected_output_2 |
| 86 | + |
| 87 | + # three cleaning events at 4:00-6:00, 8:00-11:00, and 17:00-20:00 |
| 88 | + result = soiling_hsu(rainfall=rainfall, cleaning_threshold=0.5, tilt=tilt, |
| 89 | + pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc, |
| 90 | + rain_accum_period=pd.Timedelta('3h')) |
| 91 | + |
| 92 | + assert_series_equal(result, expected) |
0 commit comments