|
| 1 | +import pandas as pd |
| 2 | +from datetime import datetime |
| 3 | +from pvlib.bifacial import pvfactors_timeseries |
| 4 | +from conftest import requires_pvfactors |
| 5 | + |
| 6 | + |
| 7 | +@requires_pvfactors |
| 8 | +def test_pvfactors_timeseries(): |
| 9 | + """ Test that pvfactors is functional, using the TLDR section inputs of the |
| 10 | + package github repo README.md file: |
| 11 | + https://github.com/SunPower/pvfactors/blob/master/README.md#tldr---quick-start""" |
| 12 | + |
| 13 | + # Create some inputs |
| 14 | + timestamps = pd.DatetimeIndex([datetime(2017, 8, 31, 11), |
| 15 | + datetime(2017, 8, 31, 12)] |
| 16 | + ).set_names('timestamps') |
| 17 | + solar_zenith = [20., 10.] |
| 18 | + solar_azimuth = [110., 140.] |
| 19 | + surface_tilt = [10., 0.] |
| 20 | + surface_azimuth = [90., 90.] |
| 21 | + dni = [1000., 300.] |
| 22 | + dhi = [50., 500.] |
| 23 | + gcr = 0.4 |
| 24 | + pvrow_height = 1.75 |
| 25 | + pvrow_width = 2.44 |
| 26 | + albedo = 0.2 |
| 27 | + n_pvrows = 3 |
| 28 | + index_observed_pvrow = 1 |
| 29 | + rho_front_pvrow = 0.03 |
| 30 | + rho_back_pvrow = 0.05 |
| 31 | + horizon_band_angle = 15. |
| 32 | + |
| 33 | + # Expected values |
| 34 | + expected_ipoa_front = pd.Series([1034.96216923, 795.4423259], |
| 35 | + index=timestamps, |
| 36 | + name=(1, 'front', 'qinc')) |
| 37 | + expected_ipoa_back = pd.Series([92.11871485, 70.39404124], |
| 38 | + index=timestamps, |
| 39 | + name=(1, 'back', 'qinc')) |
| 40 | + |
| 41 | + # Test serial calculations |
| 42 | + ipoa_front, ipoa_back, df_registries = pvfactors_timeseries( |
| 43 | + solar_azimuth, solar_zenith, surface_azimuth, surface_tilt, |
| 44 | + timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo, |
| 45 | + n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow, |
| 46 | + rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow, |
| 47 | + horizon_band_angle=horizon_band_angle, |
| 48 | + run_parallel_calculations=False, n_workers_for_parallel_calcs=None) |
| 49 | + |
| 50 | + pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front) |
| 51 | + pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back) |
| 52 | + pd.testing.assert_index_equal(timestamps, df_registries.index.unique()) |
| 53 | + |
| 54 | + # Run calculations in parallel |
| 55 | + ipoa_front, ipoa_back, df_registries = pvfactors_timeseries( |
| 56 | + solar_azimuth, solar_zenith, surface_azimuth, surface_tilt, |
| 57 | + timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo, |
| 58 | + n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow, |
| 59 | + rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow, |
| 60 | + horizon_band_angle=horizon_band_angle, |
| 61 | + run_parallel_calculations=True, n_workers_for_parallel_calcs=None) |
| 62 | + |
| 63 | + pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front) |
| 64 | + pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back) |
| 65 | + pd.testing.assert_index_equal(timestamps, df_registries.index.unique()) |
| 66 | + |
| 67 | + |
| 68 | +@requires_pvfactors |
| 69 | +def test_pvfactors_timeseries_pandas_inputs(): |
| 70 | + """ Test that pvfactors is functional, using the TLDR section inputs of the |
| 71 | + package github repo README.md file, but converted to pandas Series: |
| 72 | + https://github.com/SunPower/pvfactors/blob/master/README.md#tldr---quick-start""" |
| 73 | + |
| 74 | + # Create some inputs |
| 75 | + timestamps = pd.DatetimeIndex([datetime(2017, 8, 31, 11), |
| 76 | + datetime(2017, 8, 31, 12)] |
| 77 | + ).set_names('timestamps') |
| 78 | + solar_zenith = pd.Series([20., 10.]) |
| 79 | + solar_azimuth = pd.Series([110., 140.]) |
| 80 | + surface_tilt = pd.Series([10., 0.]) |
| 81 | + surface_azimuth = pd.Series([90., 90.]) |
| 82 | + dni = pd.Series([1000., 300.]) |
| 83 | + dhi = pd.Series([50., 500.]) |
| 84 | + gcr = 0.4 |
| 85 | + pvrow_height = 1.75 |
| 86 | + pvrow_width = 2.44 |
| 87 | + albedo = 0.2 |
| 88 | + n_pvrows = 3 |
| 89 | + index_observed_pvrow = 1 |
| 90 | + rho_front_pvrow = 0.03 |
| 91 | + rho_back_pvrow = 0.05 |
| 92 | + horizon_band_angle = 15. |
| 93 | + |
| 94 | + # Expected values |
| 95 | + expected_ipoa_front = pd.Series([1034.96216923, 795.4423259], |
| 96 | + index=timestamps, |
| 97 | + name=(1, 'front', 'qinc')) |
| 98 | + expected_ipoa_back = pd.Series([92.11871485, 70.39404124], |
| 99 | + index=timestamps, |
| 100 | + name=(1, 'back', 'qinc')) |
| 101 | + |
| 102 | + # Test serial calculations |
| 103 | + ipoa_front, ipoa_back, df_registries = pvfactors_timeseries( |
| 104 | + solar_azimuth, solar_zenith, surface_azimuth, surface_tilt, |
| 105 | + timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo, |
| 106 | + n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow, |
| 107 | + rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow, |
| 108 | + horizon_band_angle=horizon_band_angle, |
| 109 | + run_parallel_calculations=False, n_workers_for_parallel_calcs=None) |
| 110 | + |
| 111 | + pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front) |
| 112 | + pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back) |
| 113 | + pd.testing.assert_index_equal(timestamps, df_registries.index.unique()) |
| 114 | + |
| 115 | + # Run calculations in parallel |
| 116 | + ipoa_front, ipoa_back, df_registries = pvfactors_timeseries( |
| 117 | + solar_azimuth, solar_zenith, surface_azimuth, surface_tilt, |
| 118 | + timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo, |
| 119 | + n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow, |
| 120 | + rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow, |
| 121 | + horizon_band_angle=horizon_band_angle, |
| 122 | + run_parallel_calculations=True, n_workers_for_parallel_calcs=None) |
| 123 | + |
| 124 | + pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front) |
| 125 | + pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back) |
| 126 | + pd.testing.assert_index_equal(timestamps, df_registries.index.unique()) |
0 commit comments