1
- import numpy as np
2
1
import pandas as pd
3
2
from datetime import datetime
4
3
from pvlib .bifacial import pvfactors_timeseries
@@ -13,7 +12,8 @@ def test_pvfactors_timeseries():
13
12
14
13
# Create some inputs
15
14
timestamps = pd .DatetimeIndex ([datetime (2017 , 8 , 31 , 11 ),
16
- datetime (2017 , 8 , 31 , 12 )])
15
+ datetime (2017 , 8 , 31 , 12 )]
16
+ ).set_names ('timestamps' )
17
17
solar_zenith = [20. , 10. ]
18
18
solar_azimuth = [110. , 140. ]
19
19
surface_tilt = [10. , 0. ]
@@ -31,47 +31,50 @@ def test_pvfactors_timeseries():
31
31
horizon_band_angle = 15.
32
32
33
33
# Expected values
34
- expected_ipoa_front = [1034.96216923 , 795.4423259 ]
35
- expected_ipoa_back = [92.11871485 , 70.39404124 ]
36
- tolerance = 1e-6
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' ))
37
40
38
41
# Test serial calculations
39
- ipoa_front , ipoa_back , _ = pvfactors_timeseries (
42
+ ipoa_front , ipoa_back , df_registries = pvfactors_timeseries (
40
43
solar_azimuth , solar_zenith , surface_azimuth , surface_tilt ,
41
44
timestamps , dni , dhi , gcr , pvrow_height , pvrow_width , albedo ,
42
45
n_pvrows = n_pvrows , index_observed_pvrow = index_observed_pvrow ,
43
46
rho_front_pvrow = rho_front_pvrow , rho_back_pvrow = rho_back_pvrow ,
44
47
horizon_band_angle = horizon_band_angle ,
45
48
run_parallel_calculations = False , n_workers_for_parallel_calcs = None )
46
49
47
- np .testing .assert_allclose (ipoa_front , expected_ipoa_front ,
48
- atol = 0 , rtol = tolerance )
49
- np .testing .assert_allclose (ipoa_back , expected_ipoa_back ,
50
- atol = 0 , rtol = tolerance )
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 ())
51
53
52
54
# Run calculations in parallel
53
- ipoa_front , ipoa_back , _ = pvfactors_timeseries (
55
+ ipoa_front , ipoa_back , df_registries = pvfactors_timeseries (
54
56
solar_azimuth , solar_zenith , surface_azimuth , surface_tilt ,
55
57
timestamps , dni , dhi , gcr , pvrow_height , pvrow_width , albedo ,
56
58
n_pvrows = n_pvrows , index_observed_pvrow = index_observed_pvrow ,
57
59
rho_front_pvrow = rho_front_pvrow , rho_back_pvrow = rho_back_pvrow ,
58
60
horizon_band_angle = horizon_band_angle ,
59
61
run_parallel_calculations = True , n_workers_for_parallel_calcs = None )
60
62
61
- np .testing .assert_allclose (ipoa_front , expected_ipoa_front ,
62
- atol = 0 , rtol = tolerance )
63
- np .testing .assert_allclose (ipoa_back , expected_ipoa_back ,
64
- atol = 0 , rtol = tolerance )
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 ())
65
66
66
67
67
68
@requires_pvfactors
68
69
def test_pvfactors_timeseries_pandas_inputs ():
69
70
""" Test that pvfactors is functional, using the TLDR section inputs of the
70
- package github repo README.md file, but converted to pandas Series"""
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"""
71
73
72
74
# Create some inputs
73
75
timestamps = pd .DatetimeIndex ([datetime (2017 , 8 , 31 , 11 ),
74
- datetime (2017 , 8 , 31 , 12 )])
76
+ datetime (2017 , 8 , 31 , 12 )]
77
+ ).set_names ('timestamps' )
75
78
solar_zenith = pd .Series ([20. , 10. ])
76
79
solar_azimuth = pd .Series ([110. , 140. ])
77
80
surface_tilt = pd .Series ([10. , 0. ])
@@ -89,34 +92,35 @@ def test_pvfactors_timeseries_pandas_inputs():
89
92
horizon_band_angle = 15.
90
93
91
94
# Expected values
92
- expected_ipoa_front = [1034.96216923 , 795.4423259 ]
93
- expected_ipoa_back = [92.11871485 , 70.39404124 ]
94
- tolerance = 1e-6
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' ))
95
101
96
102
# Test serial calculations
97
- ipoa_front , ipoa_back , _ = pvfactors_timeseries (
103
+ ipoa_front , ipoa_back , df_registries = pvfactors_timeseries (
98
104
solar_azimuth , solar_zenith , surface_azimuth , surface_tilt ,
99
105
timestamps , dni , dhi , gcr , pvrow_height , pvrow_width , albedo ,
100
106
n_pvrows = n_pvrows , index_observed_pvrow = index_observed_pvrow ,
101
107
rho_front_pvrow = rho_front_pvrow , rho_back_pvrow = rho_back_pvrow ,
102
108
horizon_band_angle = horizon_band_angle ,
103
109
run_parallel_calculations = False , n_workers_for_parallel_calcs = None )
104
110
105
- np .testing .assert_allclose (ipoa_front , expected_ipoa_front ,
106
- atol = 0 , rtol = tolerance )
107
- np .testing .assert_allclose (ipoa_back , expected_ipoa_back ,
108
- atol = 0 , rtol = tolerance )
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 ())
109
114
110
115
# Run calculations in parallel
111
- ipoa_front , ipoa_back , _ = pvfactors_timeseries (
116
+ ipoa_front , ipoa_back , df_registries = pvfactors_timeseries (
112
117
solar_azimuth , solar_zenith , surface_azimuth , surface_tilt ,
113
118
timestamps , dni , dhi , gcr , pvrow_height , pvrow_width , albedo ,
114
119
n_pvrows = n_pvrows , index_observed_pvrow = index_observed_pvrow ,
115
120
rho_front_pvrow = rho_front_pvrow , rho_back_pvrow = rho_back_pvrow ,
116
121
horizon_band_angle = horizon_band_angle ,
117
122
run_parallel_calculations = True , n_workers_for_parallel_calcs = None )
118
123
119
- np .testing .assert_allclose (ipoa_front , expected_ipoa_front ,
120
- atol = 0 , rtol = tolerance )
121
- np .testing .assert_allclose (ipoa_back , expected_ipoa_back ,
122
- atol = 0 , rtol = tolerance )
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