forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
523 lines (433 loc) · 14.5 KB
/
conftest.py
File metadata and controls
523 lines (433 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
from pathlib import Path
import platform
import warnings
import pandas as pd
import scipy
import os
from packaging.version import Version
import pytest
from functools import wraps
import pvlib
from pvlib.location import Location
pvlib_base_version = Version(Version(pvlib.__version__).base_version)
# decorator takes one argument: the base version for which it should fail
# for example @fail_on_pvlib_version('0.7') will cause a test to fail
# on pvlib versions 0.7a, 0.7b, 0.7rc1, etc.
def fail_on_pvlib_version(version):
# second level of decorator takes the function under consideration
def wrapper(func):
# third level defers computation until the test is called
# this allows the specific test to fail at test runtime,
# rather than at decoration time (when the module is imported)
@wraps(func)
def inner(*args, **kwargs):
# fail if the version is too high
if pvlib_base_version >= Version(version):
pytest.fail('the tested function is scheduled to be '
'removed in %s' % version)
# otherwise return the function to be executed
else:
return func(*args, **kwargs)
return inner
return wrapper
def _check_pandas_assert_kwargs(kwargs):
# handles the change in API related to default
# tolerances in pandas 1.1.0. See pvlib GH #1018
if Version(pd.__version__) >= Version('1.1.0'):
if kwargs.pop('check_less_precise', False):
kwargs['atol'] = 1e-3
kwargs['rtol'] = 1e-3
else:
kwargs['atol'] = 1e-5
kwargs['rtol'] = 1e-5
else:
kwargs.pop('rtol', None)
kwargs.pop('atol', None)
return kwargs
def assert_index_equal(left, right, **kwargs):
kwargs = _check_pandas_assert_kwargs(kwargs)
pd.testing.assert_index_equal(left, right, **kwargs)
def assert_series_equal(left, right, **kwargs):
kwargs = _check_pandas_assert_kwargs(kwargs)
pd.testing.assert_series_equal(left, right, **kwargs)
def assert_frame_equal(left, right, **kwargs):
kwargs = _check_pandas_assert_kwargs(kwargs)
pd.testing.assert_frame_equal(left, right, **kwargs)
# commonly used directories in the tests
TEST_DIR = Path(__file__).parent
PVLIB_DATA_DIR = Path(pvlib.__path__[0]) / 'data'
TESTS_DATA_DIR = TEST_DIR / 'data'
# pytest-rerunfailures variables
RERUNS = 5
RERUNS_DELAY = 2
platform_is_windows = platform.system() == 'Windows'
skip_windows = pytest.mark.skipif(platform_is_windows,
reason='does not run on windows')
@pytest.fixture(scope="module")
def nrel_api_key():
"""Supplies pvlib-python's NREL Developer Network API key.
pvlib's CI utilizes a secret variable set to NREL_API_KEY
to mitigate failures associated with using the default key of
"DEMO_KEY". A user is capable of using their own key this way if
desired however the default key should suffice for testing purposes.
"""
try:
demo_key = os.environ["NREL_API_KEY"]
except KeyError:
warnings.warn(
"WARNING: NREL API KEY environment variable not set! "
"Using DEMO_KEY instead. Unexpected failures may occur."
)
demo_key = 'DEMO_KEY'
return demo_key
try:
# Attempt to load BSRN credentials used for testing pvlib.iotools.get_bsrn
bsrn_username = os.environ["BSRN_FTP_USERNAME"]
bsrn_password = os.environ["BSRN_FTP_PASSWORD"]
has_bsrn_credentials = True
except KeyError:
has_bsrn_credentials = False
requires_bsrn_credentials = pytest.mark.skipif(
not has_bsrn_credentials, reason='requires bsrn credentials')
try:
# Attempt to load SolarAnywhere API key used for testing
# pvlib.iotools.get_solaranywhere
solaranywhere_api_key = os.environ["SOLARANYWHERE_API_KEY"]
has_solaranywhere_credentials = True
except KeyError:
has_solaranywhere_credentials = False
requires_solaranywhere_credentials = pytest.mark.skipif(
not has_solaranywhere_credentials,
reason='requires solaranywhere credentials')
try:
# Attempt to load NASA EarthData credentials used for testing
# pvlib.iotools.get_merra2
earthdata_username = os.environ["EARTHDATA_USERNAME"]
earthdata_password = os.environ["EARTHDATA_PASSWORD"]
has_earthdata_credentials = True
except KeyError:
has_earthdata_credentials = False
requires_earthdata_credentials = pytest.mark.skipif(
not has_earthdata_credentials,
reason='requires EarthData credentials')
try:
import statsmodels # noqa: F401
has_statsmodels = True
except ImportError:
has_statsmodels = False
requires_statsmodels = pytest.mark.skipif(
not has_statsmodels, reason='requires statsmodels')
try:
import ephem # noqa: F401
has_ephem = True
except ImportError:
has_ephem = False
requires_ephem = pytest.mark.skipif(not has_ephem, reason='requires ephem')
def has_spa_c():
try:
from pvlib.spa_c_files.spa_py import spa_calc # noqa: F401
except ImportError:
return False
else:
return True
requires_spa_c = pytest.mark.skipif(not has_spa_c(), reason="requires spa_c")
try:
import numba # noqa: F401
has_numba = True
except ImportError:
has_numba = False
requires_numba = pytest.mark.skipif(not has_numba, reason="requires numba")
try:
import pvfactors # noqa: F401
has_pvfactors = True
except ImportError:
has_pvfactors = False
requires_pvfactors = pytest.mark.skipif(not has_pvfactors,
reason='requires pvfactors')
try:
import PySAM # noqa: F401
has_pysam = True
except ImportError:
has_pysam = False
requires_pysam = pytest.mark.skipif(not has_pysam, reason="requires PySAM")
has_pandas_2_0 = Version(pd.__version__) >= Version("2.0.0")
requires_pandas_2_0 = pytest.mark.skipif(not has_pandas_2_0,
reason="requires pandas>=2.0.0")
# single-diode equation functions have method=='chandrupatla', which relies
# on scipy.optimize.elementwise.find_root, which is only available in
# scipy>=1.15.
# TODO remove this when our minimum scipy is >=1.15
chandrupatla_available = Version(scipy.__version__) >= Version("1.15.0")
chandrupatla = pytest.param(
"chandrupatla", marks=pytest.mark.skipif(not chandrupatla_available,
reason="needs scipy 1.15")
)
@pytest.fixture()
def golden():
return Location(39.742476, -105.1786, 'America/Denver', 1830.14)
@pytest.fixture()
def golden_mst():
return Location(39.742476, -105.1786, 'MST', 1830.14)
@pytest.fixture()
def expected_solpos():
return pd.DataFrame({'elevation': 39.872046,
'apparent_zenith': 50.111622,
'azimuth': 194.340241,
'apparent_elevation': 39.888378},
index=['2003-10-17T12:30:30Z'])
@pytest.fixture(scope="session")
def sam_data():
data = {}
with warnings.catch_warnings():
# ignore messages about duplicate entries in the databases.
warnings.simplefilter("ignore", UserWarning)
data['sandiamod'] = pvlib.pvsystem.retrieve_sam('sandiamod')
data['adrinverter'] = pvlib.pvsystem.retrieve_sam('adrinverter')
return data
@pytest.fixture(scope="function")
def pvsyst_module_params():
"""
Define some PVSyst module parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'gamma_ref': 1.05,
'mu_gamma': 0.001,
'I_L_ref': 6.0,
'I_o_ref': 5e-9,
'EgRef': 1.121,
'R_sh_ref': 300,
'R_sh_0': 1000,
'R_s': 0.5,
'R_sh_exp': 5.5,
'cells_in_series': 60,
'alpha_sc': 0.001,
}
return parameters
@pytest.fixture(scope='function')
def adr_inverter_parameters():
"""
Define some ADR inverter parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'Name': 'Ablerex Electronics Co., Ltd.: ES 2200-US-240 (240Vac)'
'[CEC 2011]',
'Vac': 240.,
'Pacmax': 2110.,
'Pnom': 2200.,
'Vnom': 396.,
'Vmin': 155.,
'Vmax': 413.,
'Vdcmax': 500.,
'MPPTHi': 450.,
'MPPTLow': 150.,
'Pnt': 0.25,
'ADRCoefficients': [0.01385, 0.0152, 0.00794, 0.00286, -0.01872,
-0.01305, 0.0, 0.0, 0.0]
}
return parameters
@pytest.fixture(scope='function')
def cec_inverter_parameters():
"""
Define some CEC inverter parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'Name': 'ABB: MICRO-0.25-I-OUTD-US-208 208V [CEC 2014]',
'Vac': 208.0,
'Paco': 250.0,
'Pdco': 259.5220505,
'Vdco': 40.24260317,
'Pso': 1.771614224,
'C0': -2.48e-5,
'C1': -9.01e-5,
'C2': 6.69e-4,
'C3': -0.0189,
'Pnt': 0.02,
'Vdcmax': 65.0,
'Idcmax': 10.0,
'Mppt_low': 20.0,
'Mppt_high': 50.0,
}
return parameters
@pytest.fixture(scope='function')
def cec_module_params():
"""
Define some CEC module parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'Name': 'Example Module',
'BIPV': 'Y',
'Date': '4/28/2008',
'T_NOCT': 65,
'A_c': 0.67,
'N_s': 18,
'I_sc_ref': 7.5,
'V_oc_ref': 10.4,
'I_mp_ref': 6.6,
'V_mp_ref': 8.4,
'alpha_sc': 0.003,
'beta_oc': -0.04,
'a_ref': 0.473,
'I_L_ref': 7.545,
'I_o_ref': 1.94e-09,
'R_s': 0.094,
'R_sh_ref': 15.72,
'Adjust': 10.6,
'gamma_r': -0.5,
'Version': 'MM105',
'PTC': 48.9,
'Technology': 'Multi-c-Si',
}
return parameters
@pytest.fixture(scope='function')
def cec_module_cs5p_220m():
"""
Define Canadian Solar CS5P-220M module parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'Name': 'Canadian Solar CS5P-220M',
'BIPV': 'N',
'Date': '10/5/2009',
'T_NOCT': 42.4,
'A_c': 1.7,
'N_s': 96,
'I_sc_ref': 5.1,
'V_oc_ref': 59.4,
'I_mp_ref': 4.69,
'V_mp_ref': 46.9,
'alpha_sc': 0.004539,
'beta_oc': -0.22216,
'a_ref': 2.6373,
'I_L_ref': 5.114,
'I_o_ref': 8.196e-10,
'R_s': 1.065,
'R_sh_ref': 381.68,
'Adjust': 8.7,
'gamma_r': -0.476,
'Version': 'MM106',
'PTC': 200.1,
'Technology': 'Mono-c-Si',
}
return parameters
@pytest.fixture(scope='function')
def cec_module_spr_e20_327():
"""
Define SunPower SPR-E20-327 module parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'Name': 'SunPower SPR-E20-327',
'BIPV': 'N',
'Date': '1/14/2013',
'T_NOCT': 46,
'A_c': 1.631,
'N_s': 96,
'I_sc_ref': 6.46,
'V_oc_ref': 65.1,
'I_mp_ref': 5.98,
'V_mp_ref': 54.7,
'alpha_sc': 0.004522,
'beta_oc': -0.23176,
'a_ref': 2.6868,
'I_L_ref': 6.468,
'I_o_ref': 1.88e-10,
'R_s': 0.37,
'R_sh_ref': 298.13,
'Adjust': -0.1862,
'gamma_r': -0.386,
'Version': 'NRELv1',
'PTC': 301.4,
'Technology': 'Mono-c-Si',
}
return parameters
@pytest.fixture(scope='function')
def cec_module_fs_495():
"""
Define First Solar FS-495 module parameters for testing.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {
'Name': 'First Solar FS-495',
'BIPV': 'N',
'Date': '9/18/2014',
'T_NOCT': 44.6,
'A_c': 0.72,
'N_s': 216,
'I_sc_ref': 1.55,
'V_oc_ref': 86.5,
'I_mp_ref': 1.4,
'V_mp_ref': 67.9,
'alpha_sc': 0.000924,
'beta_oc': -0.22741,
'a_ref': 2.9482,
'I_L_ref': 1.563,
'I_o_ref': 2.64e-13,
'R_s': 6.804,
'R_sh_ref': 806.27,
'Adjust': -10.65,
'gamma_r': -0.264,
'Version': 'NRELv1',
'PTC': 89.7,
'Technology': 'CdTe',
}
return parameters
@pytest.fixture(scope='function')
def sapm_temperature_cs5p_220m():
# SAPM temperature model parameters for Canadian_Solar_CS5P_220M
# (glass/polymer) in open rack
return {'a': -3.40641, 'b': -0.0842075, 'deltaT': 3}
@pytest.fixture(scope='function')
def sapm_module_params():
"""
Define SAPM model parameters for Canadian Solar CS5P 220M module.
The scope of the fixture is set to ``'function'`` to allow tests to modify
parameters if required without affecting other tests.
"""
parameters = {'Material': 'c-Si',
'Cells_in_Series': 96,
'Parallel_Strings': 1,
'A0': 0.928385,
'A1': 0.068093,
'A2': -0.0157738,
'A3': 0.0016606,
'A4': -6.93E-05,
'B0': 1,
'B1': -0.002438,
'B2': 0.0003103,
'B3': -0.00001246,
'B4': 2.11E-07,
'B5': -1.36E-09,
'C0': 1.01284,
'C1': -0.0128398,
'C2': 0.279317,
'C3': -7.24463,
'C4': 0.996446,
'C5': 0.003554,
'C6': 1.15535,
'C7': -0.155353,
'Isco': 5.09115,
'Impo': 4.54629,
'Voco': 59.2608,
'Vmpo': 48.3156,
'Aisc': 0.000397,
'Aimp': 0.000181,
'Bvoco': -0.21696,
'Mbvoc': 0.0,
'Bvmpo': -0.235488,
'Mbvmp': 0.0,
'N': 1.4032,
'IXO': 4.97599,
'IXXO': 3.18803,
'FD': 1}
return parameters