Skip to content

Commit 4c3ad9b

Browse files
committed
lots of pvsystem tests
1 parent 96e7eb3 commit 4c3ad9b

File tree

2 files changed

+201
-32
lines changed

2 files changed

+201
-32
lines changed

pvlib/pvsystem.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
155155
dni_extra=None, airmass=None, model='haydavies',
156156
**kwargs):
157157
"""
158-
Uses the :func:`irradiance.total_irrad` function to calculate
158+
Uses the :py:func:`irradiance.total_irrad` function to calculate
159159
the plane of array irradiance components on a tilted surface
160160
defined by
161161
``self.surface_tilt``, ``self.surface_azimuth``, and
@@ -211,7 +211,7 @@ def ashraeiam(self, aoi):
211211
"""
212212
Determine the incidence angle modifier using
213213
``self.module_parameters['b']``, ``aoi``,
214-
and the :func:`ashraeiam` function.
214+
and the :py:func:`ashraeiam` function.
215215
216216
Parameters
217217
----------
@@ -234,7 +234,7 @@ def physicaliam(self, aoi):
234234
``self.module_parameters['L']``,
235235
``self.module_parameters['n']``,
236236
``aoi``, and the
237-
:func:`physicaliam` function.
237+
:py:func:`physicaliam` function.
238238
239239
Parameters
240240
----------
@@ -252,7 +252,7 @@ def physicaliam(self, aoi):
252252

253253
def calcparams_desoto(self, poa_global, temp_cell, **kwargs):
254254
"""
255-
Use the :func:`calcparams_desoto` function, the input parameters
255+
Use the :py:func:`calcparams_desoto` function, the input parameters
256256
and ``self.module_parameters`` to calculate the module
257257
currents and resistances.
258258
@@ -272,14 +272,16 @@ def calcparams_desoto(self, poa_global, temp_cell, **kwargs):
272272
See pvsystem.calcparams_desoto for details
273273
"""
274274
return calcparams_desoto(poa_global, temp_cell,
275+
self.module_parameters['alpha_sc'],
275276
self.module_parameters,
276-
EgRef, dEgdT, **kwargs)
277+
self.module_parameters['EgRef'],
278+
self.module_parameters['dEgdT'], **kwargs)
277279

278280

279281
def sapm(self, poa_direct, poa_diffuse,
280282
temp_cell, airmass_absolute, aoi, **kwargs):
281283
"""
282-
Use the :func:`sapm` function, the input parameters,
284+
Use the :py:func:`sapm` function, the input parameters,
283285
and ``self.module_parameters`` to calculate
284286
Voc, Isc, Ix, Ixx, Vmp/Imp.
285287
@@ -313,7 +315,7 @@ def sapm(self, poa_direct, poa_diffuse,
313315

314316
# model now specified by self.racking_model
315317
def sapm_celltemp(self, irrad, wind, temp):
316-
"""Uses :func:`sapm_celltemp` to calculate module and cell
318+
"""Uses :py:func:`sapm_celltemp` to calculate module and cell
317319
temperatures based on ``self.racking_model`` and
318320
the input parameters.
319321
@@ -330,7 +332,7 @@ def sapm_celltemp(self, irrad, wind, temp):
330332

331333
def singlediode(self, photocurrent, saturation_current,
332334
resistance_series, resistance_shunt, nNsVth):
333-
"""Wrapper around the :func:`singlediode` function.
335+
"""Wrapper around the :py:func:`singlediode` function.
334336
335337
Parameters
336338
----------
@@ -347,7 +349,7 @@ def singlediode(self, photocurrent, saturation_current,
347349

348350
def i_from_v(self, resistance_shunt, resistance_series, nNsVth, voltage,
349351
saturation_current, photocurrent):
350-
"""Wrapper around the :func:`i_from_v` function.
352+
"""Wrapper around the :py:func:`i_from_v` function.
351353
352354
Parameters
353355
----------

pvlib/test/test_pvsystem.py

Lines changed: 190 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44

55
import numpy as np
6+
from numpy import nan
67
import pandas as pd
78

89
from nose.tools import assert_equals, assert_almost_equals
@@ -89,13 +90,41 @@ def test_systemdef_dict():
8990

9091

9192
def test_ashraeiam():
92-
thetas = pd.Series(np.linspace(-180,180,361))
93+
thetas = np.linspace(-90, 90, 9)
9394
iam = pvsystem.ashraeiam(.05, thetas)
95+
expected = np.array([ nan, 0.9193437 , 0.97928932, 0.99588039, 1. ,
96+
0.99588039, 0.97928932, 0.9193437 , nan])
97+
assert np.isclose(iam, expected, equal_nan=True).all()
98+
99+
100+
def test_PVSystem_ashraeiam():
101+
module_parameters = pd.Series({'b': 0.05})
102+
system = pvsystem.PVSystem(module='blah', inverter='blarg',
103+
module_parameters=module_parameters)
104+
thetas = np.linspace(-90, 90, 9)
105+
iam = system.ashraeiam(thetas)
106+
expected = np.array([ nan, 0.9193437 , 0.97928932, 0.99588039, 1. ,
107+
0.99588039, 0.97928932, 0.9193437 , nan])
108+
assert np.isclose(iam, expected, equal_nan=True).all()
94109

95110

96111
def test_physicaliam():
97-
thetas = pd.Series(np.linspace(-180,180,361))
112+
thetas = np.linspace(-90, 90, 9)
98113
iam = pvsystem.physicaliam(4, 0.002, 1.526, thetas)
114+
expected = np.array([ nan, 0.8893998 , 0.98797788, 0.99926198, nan,
115+
0.99926198, 0.98797788, 0.8893998 , nan])
116+
assert np.isclose(iam, expected, equal_nan=True).all()
117+
118+
119+
def test_PVSystem_physicaliam():
120+
module_parameters = pd.Series({'K': 4, 'L': 0.002, 'n': 1.526})
121+
system = pvsystem.PVSystem(module='blah', inverter='blarg',
122+
module_parameters=module_parameters)
123+
thetas = np.linspace(-90, 90, 9)
124+
iam = system.physicaliam(thetas)
125+
expected = np.array([ nan, 0.8893998 , 0.98797788, 0.99926198, nan,
126+
0.99926198, 0.98797788, 0.8893998 , nan])
127+
assert np.isclose(iam, expected, equal_nan=True).all()
99128

100129

101130
# if this completes successfully we'll be able to do more tests below.
@@ -108,46 +137,155 @@ def test_retrieve_sam_network():
108137

109138
def test_sapm():
110139
modules = sam_data['sandiamod']
111-
module = modules.Canadian_Solar_CS5P_220M___2009_
112-
113-
sapm = pvsystem.sapm(module, irrad_data['dni'],
140+
module_parameters = modules['Canadian_Solar_CS5P_220M___2009_']
141+
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
142+
irrad_data = pd.DataFrame({'dni':[0,1000], 'ghi':[0,600], 'dhi':[0,100]},
143+
index=times)
144+
am = pd.Series([0, 2.25], index=times)
145+
aoi = pd.Series([180, 30], index=times)
146+
147+
sapm = pvsystem.sapm(module_parameters, irrad_data['dni'],
114148
irrad_data['dhi'], 25, am, aoi)
149+
150+
expected = pd.DataFrame(np.array(
151+
[[ 0. , 0. , 0. , 0. ,
152+
0. , 0. , 0. , 0. ],
153+
[ 5.74526799, 5.12194115, 59.67914031, 48.41924255,
154+
248.00051089, 5.61787615, 3.52581308, 1.12848138]]),
155+
columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx',
156+
'effective_irradiance'],
157+
index=times)
158+
159+
assert_frame_equal(sapm, expected)
115160

116-
sapm = pvsystem.sapm(module.to_dict(), irrad_data['dni'],
161+
# just make sure it works with a dict input
162+
sapm = pvsystem.sapm(module_parameters.to_dict(), irrad_data['dni'],
117163
irrad_data['dhi'], 25, am, aoi)
118164

119165

166+
def test_PVSystem_sapm():
167+
modules = sam_data['sandiamod']
168+
module = 'Canadian_Solar_CS5P_220M___2009_'
169+
module_parameters = modules[module]
170+
system = pvsystem.PVSystem(module=module,
171+
module_parameters=module_parameters)
172+
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
173+
irrad_data = pd.DataFrame({'dni':[0,1000], 'ghi':[0,600], 'dhi':[0,100]},
174+
index=times)
175+
am = pd.Series([0, 2.25], index=times)
176+
aoi = pd.Series([180, 30], index=times)
177+
178+
sapm = system.sapm(irrad_data['dni'], irrad_data['dhi'], 25, am, aoi)
179+
180+
expected = pd.DataFrame(np.array(
181+
[[ 0. , 0. , 0. , 0. ,
182+
0. , 0. , 0. , 0. ],
183+
[ 5.74526799, 5.12194115, 59.67914031, 48.41924255,
184+
248.00051089, 5.61787615, 3.52581308, 1.12848138]]),
185+
columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx',
186+
'effective_irradiance'],
187+
index=times)
188+
189+
assert_frame_equal(sapm, expected)
190+
191+
120192
def test_calcparams_desoto():
121-
cecmodule = sam_data['cecmod'].Example_Module
122-
pvsystem.calcparams_desoto(irrad_data['ghi'],
123-
temp_cell=25,
124-
alpha_isc=cecmodule['alpha_sc'],
125-
module_parameters=cecmodule,
126-
EgRef=1.121,
127-
dEgdT=-0.0002677)
193+
module = 'Example_Module'
194+
module_parameters = sam_data['cecmod'][module]
195+
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
196+
poa_data = pd.Series([0, 800], index=times)
197+
198+
IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
199+
poa_data,
200+
temp_cell=25,
201+
alpha_isc=module_parameters['alpha_sc'],
202+
module_parameters=module_parameters,
203+
EgRef=1.121,
204+
dEgdT=-0.0002677)
205+
206+
assert_series_equal(np.round(IL, 3), pd.Series([0.0, 6.036], index=times))
207+
assert_almost_equals(I0, 1.943e-9)
208+
assert_almost_equals(Rs, 0.094)
209+
assert_series_equal(np.round(Rsh, 3), pd.Series([np.inf, 19.65], index=times))
210+
assert_almost_equals(nNsVth, 0.473)
211+
212+
213+
def test_PVSystem_calcparams_desoto():
214+
module = 'Example_Module'
215+
module_parameters = sam_data['cecmod'][module].copy()
216+
module_parameters['EgRef'] = 1.121
217+
module_parameters['dEgdT'] = -0.0002677
218+
system = pvsystem.PVSystem(module=module,
219+
module_parameters=module_parameters)
220+
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
221+
poa_data = pd.Series([0, 800], index=times)
222+
temp_cell = 25
223+
224+
IL, I0, Rs, Rsh, nNsVth = system.calcparams_desoto(poa_data, temp_cell)
225+
226+
assert_series_equal(np.round(IL, 3), pd.Series([0.0, 6.036], index=times))
227+
assert_almost_equals(I0, 1.943e-9)
228+
assert_almost_equals(Rs, 0.094)
229+
assert_series_equal(np.round(Rsh, 3), pd.Series([np.inf, 19.65], index=times))
230+
assert_almost_equals(nNsVth, 0.473)
231+
128232

129233
@incompatible_conda_linux_py3
130234
def test_i_from_v():
131235
output = pvsystem.i_from_v(20, .1, .5, 40, 6e-7, 7)
132236
assert_almost_equals(-299.746389916, output, 5)
133237

134238

135-
def test_singlediode_series():
136-
cecmodule = sam_data['cecmod'].Example_Module
239+
@incompatible_conda_linux_py3
240+
def test_PVSystem_i_from_v():
241+
module = 'Example_Module'
242+
module_parameters = sam_data['cecmod'][module]
243+
system = pvsystem.PVSystem(module=module,
244+
module_parameters=module_parameters)
245+
output = system.i_from_v(20, .1, .5, 40, 6e-7, 7)
246+
assert_almost_equals(-299.746389916, output, 5)
247+
248+
249+
def test_singlediode_series():
250+
module = 'Example_Module'
251+
module_parameters = sam_data['cecmod'][module]
252+
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
253+
poa_data = pd.Series([0, 800], index=times)
137254
IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
138-
irrad_data['ghi'],
255+
poa_data,
139256
temp_cell=25,
140-
alpha_isc=cecmodule['alpha_sc'],
141-
module_parameters=cecmodule,
257+
alpha_isc=module_parameters['alpha_sc'],
258+
module_parameters=module_parameters,
142259
EgRef=1.121,
143260
dEgdT=-0.0002677)
144-
out = pvsystem.singlediode(cecmodule, IL, I0, Rs, Rsh, nNsVth)
261+
out = pvsystem.singlediode(module_parameters, IL, I0, Rs, Rsh, nNsVth)
145262
assert isinstance(out, pd.DataFrame)
146263

264+
147265
@incompatible_conda_linux_py3
148-
def test_singlediode_series():
149-
cecmodule = sam_data['cecmod'].Example_Module
150-
out = pvsystem.singlediode(cecmodule, 7, 6e-7, .1, 20, .5)
266+
def test_singlediode_floats():
267+
module = 'Example_Module'
268+
module_parameters = sam_data['cecmod'][module]
269+
out = pvsystem.singlediode(module_parameters, 7, 6e-7, .1, 20, .5)
270+
expected = {'i_xx': 4.2549732697234193,
271+
'i_mp': 6.1390251797935704,
272+
'v_oc': 8.1147298764528042,
273+
'p_mp': 38.194165464983037,
274+
'i_x': 6.7556075876880621,
275+
'i_sc': 6.9646747613963198,
276+
'v_mp': 6.221535886625464}
277+
assert isinstance(out, dict)
278+
for k, v in out.items():
279+
assert_almost_equals(expected[k], v, 5)
280+
281+
282+
@incompatible_conda_linux_py3
283+
def test_PVSystem_singlediode_floats():
284+
module = 'Example_Module'
285+
module_parameters = sam_data['cecmod'][module]
286+
system = pvsystem.PVSystem(module=module,
287+
module_parameters=module_parameters)
288+
out = system.singlediode(7, 6e-7, .1, 20, .5)
151289
expected = {'i_xx': 4.2549732697234193,
152290
'i_mp': 6.1390251797935704,
153291
'v_oc': 8.1147298764528042,
@@ -192,7 +330,23 @@ def test_sapm_celltemp_with_index():
192330

193331
assert_frame_equal(expected, pvtemps)
194332

195-
333+
334+
def test_PVSystem_sapm_celltemp():
335+
system = pvsystem.PVSystem(racking_model='roof_mount_cell_glassback')
336+
times = pd.DatetimeIndex(start='2015-01-01', end='2015-01-02', freq='12H')
337+
temps = pd.Series([0, 10, 5], index=times)
338+
irrads = pd.Series([0, 500, 0], index=times)
339+
winds = pd.Series([10, 5, 0], index=times)
340+
341+
pvtemps = system.sapm_celltemp(irrads, winds, temps)
342+
343+
expected = pd.DataFrame({'temp_cell':[0., 30.56763059, 5.],
344+
'temp_module':[0., 30.06763059, 5.]},
345+
index=times)
346+
347+
assert_frame_equal(expected, pvtemps)
348+
349+
196350
def test_snlinverter():
197351
inverters = sam_data['cecinverter']
198352
testinv = 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'
@@ -204,6 +358,19 @@ def test_snlinverter():
204358
assert_series_equal(pacs, pd.Series([-0.020000, 132.004308, 250.000000]))
205359

206360

361+
def test_PVSystem_snlinverter():
362+
inverters = sam_data['cecinverter']
363+
testinv = 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'
364+
system = pvsystem.PVSystem(inverter=testinv,
365+
inverter_parameters=inverters[testinv])
366+
vdcs = pd.Series(np.linspace(0,50,3))
367+
idcs = pd.Series(np.linspace(0,11,3))
368+
pdcs = idcs * vdcs
369+
370+
pacs = system.snlinverter(vdcs, pdcs)
371+
assert_series_equal(pacs, pd.Series([-0.020000, 132.004308, 250.000000]))
372+
373+
207374
def test_snlinverter_float():
208375
inverters = sam_data['cecinverter']
209376
testinv = 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'

0 commit comments

Comments
 (0)