44from collections import OrderedDict
55
66import numpy as np
7- from numpy import nan
7+ from numpy import nan , array
88import pandas as pd
99
1010import pytest
@@ -150,6 +150,14 @@ def sapm_module_params(sam_data):
150150 return module_parameters
151151
152152
153+ @pytest .fixture (scope = "session" )
154+ def cec_module_params (sam_data ):
155+ modules = sam_data ['cecmod' ]
156+ module = 'Example_Module'
157+ module_parameters = modules [module ]
158+ return module_parameters
159+
160+
153161def test_sapm (sapm_module_params ):
154162
155163 times = pd .DatetimeIndex (start = '2015-01-01' , periods = 5 , freq = '12H' )
@@ -307,17 +315,15 @@ def test_PVSystem_sapm_effective_irradiance(sapm_module_params):
307315 aoi , reference_irradiance = reference_irradiance )
308316
309317
310- def test_calcparams_desoto (sam_data ):
311- module = 'Example_Module'
312- module_parameters = sam_data ['cecmod' ][module ]
318+ def test_calcparams_desoto (cec_module_params ):
313319 times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
314320 poa_data = pd .Series ([0 , 800 ], index = times )
315321
316322 IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
317323 poa_data ,
318324 temp_cell = 25 ,
319- alpha_isc = module_parameters ['alpha_sc' ],
320- module_parameters = module_parameters ,
325+ alpha_isc = cec_module_params ['alpha_sc' ],
326+ module_parameters = cec_module_params ,
321327 EgRef = 1.121 ,
322328 dEgdT = - 0.0002677 )
323329
@@ -328,13 +334,11 @@ def test_calcparams_desoto(sam_data):
328334 assert_allclose (nNsVth , 0.473 )
329335
330336
331- def test_PVSystem_calcparams_desoto (sam_data ):
332- module = 'Example_Module'
333- module_parameters = sam_data ['cecmod' ][module ].copy ()
337+ def test_PVSystem_calcparams_desoto (cec_module_params ):
338+ module_parameters = cec_module_params .copy ()
334339 module_parameters ['EgRef' ] = 1.121
335340 module_parameters ['dEgdT' ] = - 0.0002677
336- system = pvsystem .PVSystem (module = module ,
337- module_parameters = module_parameters )
341+ system = pvsystem .PVSystem (module_parameters = module_parameters )
338342 times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
339343 poa_data = pd .Series ([0 , 800 ], index = times )
340344 temp_cell = 25
@@ -367,26 +371,21 @@ def test_i_from_v():
367371
368372
369373@requires_scipy
370- def test_PVSystem_i_from_v (sam_data ):
371- module = 'Example_Module'
372- module_parameters = sam_data ['cecmod' ][module ]
373- system = pvsystem .PVSystem (module = module ,
374- module_parameters = module_parameters )
374+ def test_PVSystem_i_from_v ():
375+ system = pvsystem .PVSystem ()
375376 output = system .i_from_v (20 , .1 , .5 , 40 , 6e-7 , 7 )
376377 assert_allclose (- 299.746389916 , output , 5 )
377378
378379
379380@requires_scipy
380- def test_singlediode_series (sam_data ):
381- module = 'Example_Module'
382- module_parameters = sam_data ['cecmod' ][module ]
381+ def test_singlediode_series (cec_module_params ):
383382 times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
384383 poa_data = pd .Series ([0 , 800 ], index = times )
385384 IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
386385 poa_data ,
387386 temp_cell = 25 ,
388- alpha_isc = module_parameters ['alpha_sc' ],
389- module_parameters = module_parameters ,
387+ alpha_isc = cec_module_params ['alpha_sc' ],
388+ module_parameters = cec_module_params ,
390389 EgRef = 1.121 ,
391390 dEgdT = - 0.0002677 )
392391 out = pvsystem .singlediode (IL , I0 , Rs , Rsh , nNsVth )
@@ -424,31 +423,68 @@ def test_singlediode_floats(sam_data):
424423 'p_mp' : 38.194165464983037 ,
425424 'i_x' : 6.7556075876880621 ,
426425 'i_sc' : 6.9646747613963198 ,
427- 'v_mp' : 6.221535886625464 }
426+ 'v_mp' : 6.221535886625464 ,
427+ 'i' : None ,
428+ 'v' : None }
428429 assert isinstance (out , dict )
429430 for k , v in out .items ():
430- assert_allclose (expected [k ], v , atol = 3 )
431+ if k in ['i' , 'v' ]:
432+ assert v is None
433+ else :
434+ assert_allclose (expected [k ], v , atol = 3 )
431435
432436
433437@requires_scipy
434- def test_PVSystem_singlediode_floats (sam_data ):
435- module = 'Example_Module'
436- module_parameters = sam_data ['cecmod' ][module ]
437- system = pvsystem .PVSystem (module = module ,
438- module_parameters = module_parameters )
439- out = system .singlediode (7 , 6e-7 , .1 , 20 , .5 )
438+ def test_singlediode_floats_ivcurve ():
439+ out = pvsystem .singlediode (7 , 6e-7 , .1 , 20 , .5 , ivcurve_pnts = 3 )
440440 expected = {'i_xx' : 4.2685798754011426 ,
441441 'i_mp' : 6.1390251797935704 ,
442442 'v_oc' : 8.1063001465863085 ,
443443 'p_mp' : 38.194165464983037 ,
444444 'i_x' : 6.7556075876880621 ,
445445 'i_sc' : 6.9646747613963198 ,
446- 'v_mp' : 6.221535886625464 }
446+ 'v_mp' : 6.221535886625464 ,
447+ 'i' : np .array ([6.965172e+00 , 6.755882e+00 , 2.575717e-14 ]),
448+ 'v' : np .array ([0. , 4.05315 , 8.1063 ])}
447449 assert isinstance (out , dict )
448450 for k , v in out .items ():
449451 assert_allclose (expected [k ], v , atol = 3 )
450452
451453
454+ @requires_scipy
455+ def test_singlediode_series_ivcurve (cec_module_params ):
456+ times = pd .DatetimeIndex (start = '2015-06-01' , periods = 3 , freq = '6H' )
457+ poa_data = pd .Series ([0 , 400 , 800 ], index = times )
458+ IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
459+ poa_data ,
460+ temp_cell = 25 ,
461+ alpha_isc = cec_module_params ['alpha_sc' ],
462+ module_parameters = cec_module_params ,
463+ EgRef = 1.121 ,
464+ dEgdT = - 0.0002677 )
465+
466+ out = pvsystem .singlediode (IL , I0 , Rs , Rsh , nNsVth , ivcurve_pnts = 3 )
467+
468+ expected = OrderedDict ([('i_sc' , array ([ nan , 3.01054475 , 6.00675648 ])),
469+ ('v_oc' , array ([ nan , 9.96886962 , 10.29530483 ])),
470+ ('i_mp' , array ([ nan , 2.65191983 , 5.28594672 ])),
471+ ('v_mp' , array ([ nan , 8.33392491 , 8.4159707 ])),
472+ ('p_mp' , array ([ nan , 22.10090078 , 44.48637274 ])),
473+ ('i_x' , array ([ nan , 2.88414114 , 5.74622046 ])),
474+ ('i_xx' , array ([ nan , 2.04340914 , 3.90007956 ])),
475+ ('v' ,
476+ array ([[ nan , nan , nan ],
477+ [ 0. , 4.98443481 , 9.96886962 ],
478+ [ 0. , 5.14765242 , 10.29530483 ]])),
479+ ('i' ,
480+ array ([[ nan , nan , nan ],
481+ [ 3.01079860e+00 , 2.88414114e+00 , 3.10862447e-14 ],
482+ [ 6.00726296e+00 , 5.74622046e+00 , 0.00000000e+00 ]]))])
483+
484+ for k , v in out .items ():
485+ assert_allclose (expected [k ], v , atol = 1e-2 )
486+
487+
452488def test_scale_voltage_current_power (sam_data ):
453489 data = pd .DataFrame (
454490 np .array ([[2 , 1.5 , 10 , 8 , 12 , 0.5 , 1.5 ]]),
0 commit comments