2
2
import pandas as pd
3
3
4
4
from pvlib import modelchain , pvsystem
5
- from pvlib .modelchain import ModelChain
5
+ from pvlib .modelchain import ModelChain , SAPM , SingleDiode
6
6
from pvlib .pvsystem import PVSystem
7
7
from pvlib .location import Location
8
8
@@ -17,28 +17,80 @@ def retrieve_sam_network():
17
17
sam_data ['cecinverter' ] = pvsystem .retrieve_sam ('cecinverter' )
18
18
19
19
20
- def mc_setup ():
20
+ def get_sapm_module_parameters ():
21
21
# limit network usage
22
22
try :
23
23
modules = sam_data ['sandiamod' ]
24
24
except KeyError :
25
25
retrieve_sam_network ()
26
26
modules = sam_data ['sandiamod' ]
27
27
28
- module = modules .Canadian_Solar_CS5P_220M___2009_ .copy ()
28
+ module = 'Canadian_Solar_CS5P_220M___2009_'
29
+ module_parameters = modules [module ].copy ()
30
+
31
+ return module_parameters
32
+
33
+
34
+ def get_cec_module_parameters ():
35
+ # limit network usage
36
+ try :
37
+ modules = sam_data ['cecmod' ]
38
+ except KeyError :
39
+ retrieve_sam_network ()
40
+ modules = sam_data ['cecmod' ]
41
+
42
+ module = 'Canadian_Solar_CS5P_220M'
43
+ module_parameters = modules [module ].copy ()
44
+ module_parameters ['EgRef' ] = 1.121
45
+ module_parameters ['dEgdT' ] = - 0.0002677
46
+
47
+ return module_parameters
48
+
49
+
50
+ def get_cec_inverter_parameters ():
51
+
29
52
inverters = sam_data ['cecinverter' ]
30
- inverter = inverters ['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_' ].copy ()
53
+ inverter = 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'
54
+ inverter_parameters = inverters [inverter ].copy ()
55
+
56
+ return inverter_parameters
57
+
58
+
59
+ def sapm_setup ():
60
+
61
+ module_parameters = get_sapm_module_parameters ()
62
+
63
+ inverter_parameters = get_cec_inverter_parameters ()
64
+
65
+ system = PVSystem (module_parameters = module_parameters ,
66
+ inverter_parameters = inverter_parameters )
67
+
68
+ location = Location (32.2 , - 111 , altitude = 700 )
69
+
70
+ mc = SAPM (system , location )
71
+
72
+ return mc
73
+
31
74
32
- system = PVSystem (module_parameters = module ,
33
- inverter_parameters = inverter )
75
+ def singlediode_setup ():
76
+
77
+ module_parameters = get_cec_module_parameters ()
78
+
79
+ inverter_parameters = get_cec_inverter_parameters ()
80
+
81
+ system = PVSystem (module_parameters = module_parameters ,
82
+ inverter_parameters = inverter_parameters )
34
83
35
84
location = Location (32.2 , - 111 , altitude = 700 )
36
85
37
- return system , location
86
+ mc = SingleDiode (system , location )
87
+
88
+ return mc
38
89
39
90
40
91
def test_ModelChain_creation ():
41
- system , location = mc_setup ()
92
+ system = PVSystem ()
93
+ location = Location (32.2 , - 111 , altitude = 700 )
42
94
mc = ModelChain (system , location )
43
95
44
96
@@ -64,40 +116,63 @@ def run_orientation_strategy(strategy, expected):
64
116
assert system .surface_azimuth == expected [1 ]
65
117
66
118
67
- def test_run_model ():
68
- system , location = mc_setup ()
119
+ @raises (NotImplementedError )
120
+ def test_run_model_ModelChain ():
121
+ system = PVSystem ()
122
+ location = Location (32.2 , - 111 , altitude = 700 )
69
123
mc = ModelChain (system , location )
124
+ mc .run_model ()
125
+
126
+
127
+ def test_run_model ():
70
128
times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
71
- ac = mc .run_model (times ).ac
129
+ expected = {}
130
+ expected [SAPM ] = \
131
+ pd .Series (np .array ([ 1.82033564e+02 , - 2.00000000e-02 ]), index = times )
132
+ expected [SingleDiode ] = \
133
+ pd .Series (np .array ([179.720353871 , np .nan ]), index = times )
72
134
73
- expected = pd .Series (np .array ([ 1.82033564e+02 , - 2.00000000e-02 ]),
74
- index = times )
75
- assert_series_equal (ac , expected )
135
+ def run_test (mc ):
136
+ ac = mc .run_model (times ).ac
137
+ assert_series_equal (ac , expected [type (mc )])
138
+
139
+ for mc in (sapm_setup (), singlediode_setup ()):
140
+ yield run_test , mc
76
141
77
142
78
143
def test_run_model_with_irradiance ():
79
- system , location = mc_setup ()
80
- mc = ModelChain (system , location )
81
144
times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
82
- irradiance = pd .DataFrame ({'dni' :900 , 'ghi' :600 , 'dhi' :150 },
83
- index = times )
84
- ac = mc .run_model (times , irradiance = irradiance ).ac
145
+ irradiance = pd .DataFrame (
146
+ {'dni' : [900 , 0 ], 'ghi' : [600 , 50 ], 'dhi' : [150 , 50 ]}, index = times )
147
+ expected = {}
148
+ expected [SAPM ] = \
149
+ pd .Series (np .array ([ 1.90054749e+02 , - 2.00000000e-02 ]), index = times )
150
+ expected [SingleDiode ] = \
151
+ pd .Series (np .array ([186.979595403 , 7.89417460232 ]), index = times )
85
152
86
- expected = pd .Series (np .array ([ 1.90054749e+02 , - 2.00000000e-02 ]),
87
- index = times )
88
- assert_series_equal (ac , expected )
153
+ def run_test (mc ):
154
+ ac = mc .run_model (times , irradiance = irradiance ).ac
155
+ assert_series_equal (ac , expected [type (mc )])
156
+
157
+ for mc in (sapm_setup (), singlediode_setup ()):
158
+ yield run_test , mc
89
159
90
160
91
161
def test_run_model_with_weather ():
92
- system , location = mc_setup ()
93
- mc = ModelChain (system , location )
94
162
times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
95
- weather = pd .DataFrame ({'wind_speed' :5 , 'temp_air' :10 }, index = times )
96
- ac = mc .run_model (times , weather = weather ).ac
97
-
98
- expected = pd .Series (np .array ([ 1.99952400e+02 , - 2.00000000e-02 ]),
99
- index = times )
100
- assert_series_equal (ac , expected )
163
+ weather = pd .DataFrame ({'wind_speed' : 5 , 'temp_air' : 10 }, index = times )
164
+ expected = {}
165
+ expected [SAPM ] = \
166
+ pd .Series (np .array ([ 1.99952400e+02 , - 2.00000000e-02 ]), index = times )
167
+ expected [SingleDiode ] = \
168
+ pd .Series (np .array ([198.13564009 , np .nan ]), index = times )
169
+
170
+ def run_test (mc ):
171
+ ac = mc .run_model (times , weather = weather ).ac
172
+ assert_series_equal (ac , expected [type (mc )])
173
+
174
+ for mc in (sapm_setup (), singlediode_setup ()):
175
+ yield run_test , mc
101
176
102
177
103
178
@raises (ValueError )
0 commit comments