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
@@ -148,6 +148,14 @@ def sapm_module_params(sam_data):
148
148
return module_parameters
149
149
150
150
151
+ @pytest .fixture (scope = "session" )
152
+ def cec_module_params (sam_data ):
153
+ modules = sam_data ['cecmod' ]
154
+ module = 'Example_Module'
155
+ module_parameters = modules [module ]
156
+ return module_parameters
157
+
158
+
151
159
def test_sapm (sapm_module_params ):
152
160
153
161
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 5 , freq = '12H' )
@@ -297,17 +305,15 @@ def test_PVSystem_sapm_effective_irradiance(sapm_module_params):
297
305
aoi , reference_irradiance = reference_irradiance )
298
306
299
307
300
- def test_calcparams_desoto (sam_data ):
301
- module = 'Example_Module'
302
- module_parameters = sam_data ['cecmod' ][module ]
308
+ def test_calcparams_desoto (cec_module_params ):
303
309
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
304
310
poa_data = pd .Series ([0 , 800 ], index = times )
305
311
306
312
IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
307
313
poa_data ,
308
314
temp_cell = 25 ,
309
- alpha_isc = module_parameters ['alpha_sc' ],
310
- module_parameters = module_parameters ,
315
+ alpha_isc = cec_module_params ['alpha_sc' ],
316
+ module_parameters = cec_module_params ,
311
317
EgRef = 1.121 ,
312
318
dEgdT = - 0.0002677 )
313
319
@@ -318,13 +324,11 @@ def test_calcparams_desoto(sam_data):
318
324
assert_allclose (nNsVth , 0.473 )
319
325
320
326
321
- def test_PVSystem_calcparams_desoto (sam_data ):
322
- module = 'Example_Module'
323
- module_parameters = sam_data ['cecmod' ][module ].copy ()
327
+ def test_PVSystem_calcparams_desoto (cec_module_params ):
328
+ module_parameters = cec_module_params .copy ()
324
329
module_parameters ['EgRef' ] = 1.121
325
330
module_parameters ['dEgdT' ] = - 0.0002677
326
- system = pvsystem .PVSystem (module = module ,
327
- module_parameters = module_parameters )
331
+ system = pvsystem .PVSystem (module_parameters = module_parameters )
328
332
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
329
333
poa_data = pd .Series ([0 , 800 ], index = times )
330
334
temp_cell = 25
@@ -357,69 +361,118 @@ def test_i_from_v():
357
361
358
362
359
363
@requires_scipy
360
- def test_PVSystem_i_from_v (sam_data ):
361
- module = 'Example_Module'
362
- module_parameters = sam_data ['cecmod' ][module ]
363
- system = pvsystem .PVSystem (module = module ,
364
- module_parameters = module_parameters )
364
+ def test_PVSystem_i_from_v ():
365
+ system = pvsystem .PVSystem ()
365
366
output = system .i_from_v (20 , .1 , .5 , 40 , 6e-7 , 7 )
366
367
assert_allclose (- 299.746389916 , output , 5 )
367
368
368
369
369
370
@requires_scipy
370
- def test_singlediode_series (sam_data ):
371
- module = 'Example_Module'
372
- module_parameters = sam_data ['cecmod' ][module ]
371
+ def test_singlediode_series (cec_module_params ):
373
372
times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
374
373
poa_data = pd .Series ([0 , 800 ], index = times )
375
374
IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
376
375
poa_data ,
377
376
temp_cell = 25 ,
378
- alpha_isc = module_parameters ['alpha_sc' ],
379
- module_parameters = module_parameters ,
377
+ alpha_isc = cec_module_params ['alpha_sc' ],
378
+ module_parameters = cec_module_params ,
380
379
EgRef = 1.121 ,
381
380
dEgdT = - 0.0002677 )
382
381
out = pvsystem .singlediode (IL , I0 , Rs , Rsh , nNsVth )
383
382
assert isinstance (out , pd .DataFrame )
384
383
385
384
386
385
@requires_scipy
387
- def test_singlediode_floats (sam_data ):
388
- module = 'Example_Module'
389
- module_parameters = sam_data ['cecmod' ][module ]
386
+ def test_singlediode_floats ():
390
387
out = pvsystem .singlediode (7 , 6e-7 , .1 , 20 , .5 )
391
388
expected = {'i_xx' : 4.2685798754011426 ,
392
389
'i_mp' : 6.1390251797935704 ,
393
390
'v_oc' : 8.1063001465863085 ,
394
391
'p_mp' : 38.194165464983037 ,
395
392
'i_x' : 6.7556075876880621 ,
396
393
'i_sc' : 6.9646747613963198 ,
397
- 'v_mp' : 6.221535886625464 }
394
+ 'v_mp' : 6.221535886625464 ,
395
+ 'i' : None ,
396
+ 'v' : None }
398
397
assert isinstance (out , dict )
399
398
for k , v in out .items ():
400
- assert_allclose (expected [k ], v , atol = 3 )
399
+ if k in ['i' , 'v' ]:
400
+ assert v is None
401
+ else :
402
+ assert_allclose (expected [k ], v , atol = 3 )
401
403
402
404
403
405
@requires_scipy
404
- def test_PVSystem_singlediode_floats (sam_data ):
405
- module = 'Example_Module'
406
- module_parameters = sam_data ['cecmod' ][module ]
407
- system = pvsystem .PVSystem (module = module ,
408
- module_parameters = module_parameters )
406
+ def test_PVSystem_singlediode_floats ():
407
+ system = pvsystem .PVSystem ()
409
408
out = system .singlediode (7 , 6e-7 , .1 , 20 , .5 )
410
409
expected = {'i_xx' : 4.2685798754011426 ,
411
410
'i_mp' : 6.1390251797935704 ,
412
411
'v_oc' : 8.1063001465863085 ,
413
412
'p_mp' : 38.194165464983037 ,
414
413
'i_x' : 6.7556075876880621 ,
415
414
'i_sc' : 6.9646747613963198 ,
416
- 'v_mp' : 6.221535886625464 }
415
+ 'v_mp' : 6.221535886625464 ,
416
+ 'i' : None ,
417
+ 'v' : None }
417
418
assert isinstance (out , dict )
419
+ for k , v in out .items ():
420
+ if k in ['i' , 'v' ]:
421
+ assert v is None
422
+ else :
423
+ assert_allclose (expected [k ], v , atol = 3 )
424
+
425
+
426
+ @requires_scipy
427
+ def test_singlediode_floats_ivcurve ():
428
+ out = pvsystem .singlediode (7 , 6e-7 , .1 , 20 , .5 , ivcurve_pnts = 3 )
429
+ expected = {'i_xx' : 4.2685798754011426 ,
430
+ 'i_mp' : 6.1390251797935704 ,
431
+ 'v_oc' : 8.1063001465863085 ,
432
+ 'p_mp' : 38.194165464983037 ,
433
+ 'i_x' : 6.7556075876880621 ,
434
+ 'i_sc' : 6.9646747613963198 ,
435
+ 'v_mp' : 6.221535886625464 ,
436
+ 'i' : np .array ([6.965172e+00 , 6.755882e+00 , 2.575717e-14 ]),
437
+ 'v' : np .array ([0. , 4.05315 , 8.1063 ])}
438
+ assert isinstance (out , dict )
439
+ for k , v in out .items ():
440
+ assert_allclose (expected [k ], v , atol = 3 )
441
+
442
+
443
+ @requires_scipy
444
+ def test_singlediode_series_ivcurve (cec_module_params ):
445
+ times = pd .DatetimeIndex (start = '2015-01-01' , periods = 2 , freq = '12H' )
446
+ poa_data = pd .Series ([0 , 800 ], index = times )
447
+ IL , I0 , Rs , Rsh , nNsVth = pvsystem .calcparams_desoto (
448
+ poa_data ,
449
+ temp_cell = 25 ,
450
+ alpha_isc = cec_module_params ['alpha_sc' ],
451
+ module_parameters = cec_module_params ,
452
+ EgRef = 1.121 ,
453
+ dEgdT = - 0.0002677 )
454
+
455
+ out = pvsystem .singlediode (IL , I0 , Rs , Rsh , nNsVth , ivcurve_pnts = 3 )
456
+
457
+ expected = OrderedDict ([('i_sc' , array ([ nan , 6.00675648 ])),
458
+ ('i_mp' , array ([ nan , 5.6129056 ])),
459
+ ('v_oc' , array ([ nan , 10.29530483 ])),
460
+ ('v_mp' , array ([ nan , 7.25364707 ])),
461
+ ('p_mp' , array ([ nan , 40.71403625 ])),
462
+ ('i_x' , array ([ nan , 5.74622046 ])),
463
+ ('i_xx' , array ([ nan , 4.97138154 ])),
464
+ ('i' ,
465
+ array ([[ nan , nan , nan ],
466
+ [ 6.00726296 , 5.74622046 , 0. ]])),
467
+ ('v' ,
468
+ array ([[ nan , nan , nan ],
469
+ [ 0. , 5.14765242 , 10.29530483 ]]))])
470
+
418
471
for k , v in out .items ():
419
472
assert_allclose (expected [k ], v , atol = 3 )
420
473
421
474
422
- def test_scale_voltage_current_power (sam_data ):
475
+ def test_scale_voltage_current_power ():
423
476
data = pd .DataFrame (
424
477
np .array ([[2 , 1.5 , 10 , 8 , 12 , 0.5 , 1.5 ]]),
425
478
columns = ['i_sc' , 'i_mp' , 'v_oc' , 'v_mp' , 'p_mp' , 'i_x' , 'i_xx' ],
0 commit comments