4
4
from collections import OrderedDict
5
5
6
6
import numpy as np
7
- from numpy import nan
7
+ from numpy import nan , array
8
8
import pandas as pd
9
9
10
10
import pytest
@@ -150,6 +150,14 @@ def sapm_module_params(sam_data):
150
150
return module_parameters
151
151
152
152
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
+
153
161
def test_sapm (sapm_module_params ):
154
162
155
163
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 5 , freq = '12H' )
@@ -307,17 +315,15 @@ def test_PVSystem_sapm_effective_irradiance(sapm_module_params):
307
315
aoi , reference_irradiance = reference_irradiance )
308
316
309
317
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 ):
313
319
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
314
320
poa_data = pd .Series ([0 , 800 ], index = times )
315
321
316
322
IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
317
323
poa_data ,
318
324
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 ,
321
327
EgRef = 1.121 ,
322
328
dEgdT = - 0.0002677 )
323
329
@@ -328,13 +334,11 @@ def test_calcparams_desoto(sam_data):
328
334
assert_allclose (nNsVth , 0.473 )
329
335
330
336
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 ()
334
339
module_parameters ['EgRef' ] = 1.121
335
340
module_parameters ['dEgdT' ] = - 0.0002677
336
- system = pvsystem .PVSystem (module = module ,
337
- module_parameters = module_parameters )
341
+ system = pvsystem .PVSystem (module_parameters = module_parameters )
338
342
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
339
343
poa_data = pd .Series ([0 , 800 ], index = times )
340
344
temp_cell = 25
@@ -367,26 +371,21 @@ def test_i_from_v():
367
371
368
372
369
373
@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 ()
375
376
output = system .i_from_v (20 , .1 , .5 , 40 , 6e-7 , 7 )
376
377
assert_allclose (- 299.746389916 , output , 5 )
377
378
378
379
379
380
@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 ):
383
382
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
384
383
poa_data = pd .Series ([0 , 800 ], index = times )
385
384
IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
386
385
poa_data ,
387
386
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 ,
390
389
EgRef = 1.121 ,
391
390
dEgdT = - 0.0002677 )
392
391
out = pvsystem .singlediode (IL , I0 , Rs , Rsh , nNsVth )
@@ -424,31 +423,68 @@ def test_singlediode_floats(sam_data):
424
423
'p_mp' : 38.194165464983037 ,
425
424
'i_x' : 6.7556075876880621 ,
426
425
'i_sc' : 6.9646747613963198 ,
427
- 'v_mp' : 6.221535886625464 }
426
+ 'v_mp' : 6.221535886625464 ,
427
+ 'i' : None ,
428
+ 'v' : None }
428
429
assert isinstance (out , dict )
429
430
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 )
431
435
432
436
433
437
@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 )
440
440
expected = {'i_xx' : 4.2685798754011426 ,
441
441
'i_mp' : 6.1390251797935704 ,
442
442
'v_oc' : 8.1063001465863085 ,
443
443
'p_mp' : 38.194165464983037 ,
444
444
'i_x' : 6.7556075876880621 ,
445
445
'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 ])}
447
449
assert isinstance (out , dict )
448
450
for k , v in out .items ():
449
451
assert_allclose (expected [k ], v , atol = 3 )
450
452
451
453
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
+
452
488
def test_scale_voltage_current_power (sam_data ):
453
489
data = pd .DataFrame (
454
490
np .array ([[2 , 1.5 , 10 , 8 , 12 , 0.5 , 1.5 ]]),
0 commit comments