6
6
from __future__ import division
7
7
8
8
import numpy as np
9
+ import pandas as pd
9
10
from warnings import warn
10
11
11
12
APPARENT_ZENITH_MODELS = ('simple' , 'kasten1966' , 'kastenyoung1989' ,
@@ -20,12 +21,12 @@ def pres2alt(pressure):
20
21
21
22
Parameters
22
23
----------
23
- pressure : scalar or Series
24
+ pressure : numeric
24
25
Atmospheric pressure (Pascals)
25
26
26
27
Returns
27
28
-------
28
- altitude : scalar or Series
29
+ altitude : numeric
29
30
Altitude in meters above sea level
30
31
31
32
Notes
@@ -45,12 +46,12 @@ def pres2alt(pressure):
45
46
46
47
References
47
48
-----------
48
-
49
- "A Quick Derivation relating altitude to air pressure" from Portland
50
- State Aerospace Society, Version 1.03, 12/22/2004.
49
+ [1] "A Quick Derivation relating altitude to air pressure" from
50
+ Portland State Aerospace Society, Version 1.03, 12/22/2004.
51
51
'''
52
52
53
53
alt = 44331.5 - 4946.62 * pressure ** (0.190263 )
54
+
54
55
return alt
55
56
56
57
@@ -60,12 +61,12 @@ def alt2pres(altitude):
60
61
61
62
Parameters
62
63
----------
63
- Altitude : scalar or Series
64
+ altitude : numeric
64
65
Altitude in meters above sea level
65
66
66
67
Returns
67
68
-------
68
- Pressure : scalar or Series
69
+ pressure : numeric
69
70
Atmospheric pressure (Pascals)
70
71
71
72
Notes
@@ -85,9 +86,8 @@ def alt2pres(altitude):
85
86
86
87
References
87
88
-----------
88
-
89
- "A Quick Derivation relating altitude to air pressure" from Portland
90
- State Aerospace Society, Version 1.03, 12/22/2004.
89
+ [1] "A Quick Derivation relating altitude to air pressure" from
90
+ Portland State Aerospace Society, Version 1.03, 12/22/2004.
91
91
'''
92
92
93
93
press = 100 * ((44331.514 - altitude ) / 11880.516 ) ** (1 / 0.1902632 )
@@ -111,24 +111,22 @@ def absoluteairmass(airmass_relative, pressure=101325.):
111
111
112
112
Parameters
113
113
----------
114
-
115
- airmass_relative : scalar or Series
114
+ airmass_relative : numeric
116
115
The airmass at sea-level.
117
116
118
- pressure : scalar or Series
117
+ pressure : numeric
119
118
The site pressure in Pascal.
120
119
121
120
Returns
122
121
-------
123
- scalar or Series
122
+ airmass_absolute : numeric
124
123
Absolute (pressure corrected) airmass
125
124
126
125
References
127
126
----------
128
127
[1] C. Gueymard, "Critical analysis and performance assessment of
129
128
clear sky solar irradiance models using theoretical and measured
130
129
data," Solar Energy, vol. 51, pp. 121-138, 1993.
131
-
132
130
'''
133
131
134
132
airmass_absolute = airmass_relative * pressure / 101325.
@@ -147,15 +145,14 @@ def relativeairmass(zenith, model='kastenyoung1989'):
147
145
148
146
Parameters
149
147
----------
150
-
151
- zenith : float or Series
148
+ zenith : numeric
152
149
Zenith angle of the sun in degrees. Note that some models use
153
150
the apparent (refraction corrected) zenith angle, and some
154
151
models use the true (not refraction-corrected) zenith angle. See
155
152
model descriptions to determine which type of zenith angle is
156
153
required. Apparent zenith angles must be calculated at sea level.
157
154
158
- model : String
155
+ model : string
159
156
Available models include the following:
160
157
161
158
* 'simple' - secant(apparent zenith angle) -
@@ -175,13 +172,12 @@ def relativeairmass(zenith, model='kastenyoung1989'):
175
172
176
173
Returns
177
174
-------
178
- airmass_relative : float or Series
179
- Relative airmass at sea level. Will return NaN values for any
175
+ airmass_relative : numeric
176
+ Relative airmass at sea level. Will return NaN values for any
180
177
zenith angle greater than 90 degrees.
181
178
182
179
References
183
180
----------
184
-
185
181
[1] Fritz Kasten. "A New Table and Approximation Formula for the
186
182
Relative Optical Air Mass". Technical Report 136, Hanover, N.H.:
187
183
U.S. Army Material Command, CRREL.
@@ -207,7 +203,9 @@ def relativeairmass(zenith, model='kastenyoung1989'):
207
203
Sandia Report, (2012).
208
204
'''
209
205
210
- z = zenith
206
+ # need to filter first because python 2.7 does not support raising a
207
+ # negative number to a negative power.
208
+ z = np .where (zenith > 90 , np .nan , zenith )
211
209
zenith_rad = np .radians (z )
212
210
213
211
model = model .lower ()
@@ -237,10 +235,8 @@ def relativeairmass(zenith, model='kastenyoung1989'):
237
235
else :
238
236
raise ValueError ('%s is not a valid model for relativeairmass' , model )
239
237
240
- try :
241
- am [z > 90 ] = np .nan
242
- except TypeError :
243
- am = np .nan if z > 90 else am
238
+ if isinstance (zenith , pd .Series ):
239
+ am = pd .Series (am , index = zenith .index )
244
240
245
241
return am
246
242
@@ -282,14 +278,14 @@ def gueymard94_pw(temp_air, relative_humidity):
282
278
283
279
Parameters
284
280
----------
285
- temp_air : array-like
281
+ temp_air : numeric
286
282
ambient air temperature at the surface (C)
287
- relative_humidity : array-like
283
+ relative_humidity : numeric
288
284
relative humidity at the surface (%)
289
285
290
286
Returns
291
287
-------
292
- pw : array-like
288
+ pw : numeric
293
289
precipitable water (cm)
294
290
295
291
References
@@ -349,7 +345,7 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
349
345
Pwat where:
350
346
351
347
* 0.5 cm <= Pwat <= 5 cm
352
- * 1.0 <= AMa <= 5.0
348
+ * 1.0 <= AMa <= 5.0
353
349
* Spectral range is limited to that of CMP11 (280 nm to 2800 nm)
354
350
* spectrum simulated on a plane normal to the sun
355
351
* All other parameters fixed at G173 standard
@@ -408,8 +404,8 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
408
404
radiative transfer of sunshine: algorithms and performance
409
405
assessment. Cocoa, FL: Florida Solar Energy Center, 1995.
410
406
.. [2] Lee, Mitchell, and Panchula, Alex. "Spectral Correction for
411
- Photovoltaic Module Performance Based on Air Mass and Precipitable
412
- Water." IEEE Photovoltaic Specialists Conference, Portland, 2016
407
+ Photovoltaic Module Performance Based on Air Mass and Precipitable
408
+ Water." IEEE Photovoltaic Specialists Conference, Portland, 2016
413
409
.. [3] Marion, William F., et al. User's Manual for Data for Validating
414
410
Models for PV Module Performance. National Renewable Energy
415
411
Laboratory, 2014. http://www.nrel.gov/docs/fy14osti/61610.pdf
@@ -423,30 +419,29 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
423
419
424
420
if np .min (pw ) < 0.1 :
425
421
pw = np .maximum (pw , 0.1 )
426
- warn ('Exceptionally low Pwat values replaced with 0.1 cm to prevent' +
427
- ' model divergence' )
422
+ warn ('Exceptionally low Pwat values replaced with 0.1 cm to prevent' +
423
+ ' model divergence' )
428
424
429
425
430
426
# Warn user about Pwat data that is exceptionally high
431
427
if np .max (pw ) > 8 :
432
428
warn ('Exceptionally high Pwat values. Check input data:' +
433
- ' model may diverge in this range' )
429
+ ' model may diverge in this range' )
434
430
435
431
436
432
# *** AMa ***
437
433
# Replace Extremely High AM with AM 10 to prevent model divergence
438
434
# AM > 10 will only occur very close to sunset
439
- if np .max (airmass_absolute ) > 10 :
440
- airmass_absolute = np .minimum (airmass_absolute ,10 )
441
-
435
+ if np .max (airmass_absolute ) > 10 :
436
+ airmass_absolute = np .minimum (airmass_absolute , 10 )
437
+
442
438
# Warn user about AMa data that is exceptionally low
443
439
if np .min (airmass_absolute ) < 0.58 :
444
440
warn ('Exceptionally low air mass: ' +
445
- 'model not intended for extra-terrestrial use' )
446
- # pvl_absoluteairmass(1,pvl_alt2pres(4340)) = 0.58
447
- # Elevation of Mina Pirquita, Argentian = 4340 m. Highest elevation city
448
- # with population over 50,000.
449
-
441
+ 'model not intended for extra-terrestrial use' )
442
+ # pvl_absoluteairmass(1,pvl_alt2pres(4340)) = 0.58 Elevation of
443
+ # Mina Pirquita, Argentian = 4340 m. Highest elevation city with
444
+ # population over 50,000.
450
445
451
446
_coefficients = {}
452
447
_coefficients ['cdte' ] = (
@@ -468,9 +463,9 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
468
463
469
464
# Evaluate Spectral Shift
470
465
coeff = coefficients
471
- AMa = airmass_absolute
466
+ ama = airmass_absolute
472
467
modifier = (
473
- coeff [0 ] + coeff [1 ]* AMa + coeff [2 ]* pw + coeff [3 ]* np .sqrt (AMa ) +
474
- + coeff [4 ]* np .sqrt (pw ) + coeff [5 ]* AMa / np .sqrt (pw ))
468
+ coeff [0 ] + coeff [1 ]* ama + coeff [2 ]* pw + coeff [3 ]* np .sqrt (ama ) +
469
+ coeff [4 ]* np .sqrt (pw ) + coeff [5 ]* ama / np .sqrt (pw ))
475
470
476
471
return modifier
0 commit comments