11"""
2- The ``atmosphere`` module contains methods to calculate
3- relative and absolute airmass and to determine
4- pressure from altitude or vice versa.
2+ The ``atmosphere`` module contains methods to calculate relative and
3+ absolute airmass and to determine pressure from altitude or vice versa.
54"""
65
76from __future__ import division
87
9- import logging
10- pvl_logger = logging .getLogger ('pvlib' )
11-
128import numpy as np
139
1410APPARENT_ZENITH_MODELS = ('simple' , 'kasten1966' , 'kastenyoung1989' ,
@@ -29,7 +25,7 @@ def pres2alt(pressure):
2925 Returns
3026 -------
3127 altitude : scalar or Series
32- Altitude in meters above sea level
28+ Altitude in meters above sea level
3329
3430 Notes
3531 ------
@@ -51,22 +47,20 @@ def pres2alt(pressure):
5147
5248 "A Quick Derivation relating altitude to air pressure" from Portland
5349 State Aerospace Society, Version 1.03, 12/22/2004.
54-
5550 '''
5651
5752 alt = 44331.5 - 4946.62 * pressure ** (0.190263 )
5853 return alt
5954
6055
61-
6256def alt2pres (altitude ):
6357 '''
6458 Determine site pressure from altitude.
6559
6660 Parameters
6761 ----------
6862 Altitude : scalar or Series
69- Altitude in meters above sea level
63+ Altitude in meters above sea level
7064
7165 Returns
7266 -------
@@ -100,29 +94,28 @@ def alt2pres(altitude):
10094 return press
10195
10296
103-
10497def absoluteairmass (airmass_relative , pressure = 101325. ):
10598 '''
106- Determine absolute (pressure corrected) airmass from relative
99+ Determine absolute (pressure corrected) airmass from relative
107100 airmass and pressure
108101
109- Gives the airmass for locations not at sea-level (i.e. not at standard
110- pressure). The input argument "AMrelative" is the relative airmass. The
111- input argument "pressure" is the pressure (in Pascals) at the location
112- of interest and must be greater than 0. The calculation for
113- absolute airmass is
114-
102+ Gives the airmass for locations not at sea-level (i.e. not at
103+ standard pressure). The input argument "AMrelative" is the relative
104+ airmass. The input argument "pressure" is the pressure (in Pascals)
105+ at the location of interest and must be greater than 0. The
106+ calculation for absolute airmass is
107+
115108 .. math::
116109 absolute airmass = (relative airmass)*pressure/101325
117110
118111 Parameters
119112 ----------
120113
121- airmass_relative : scalar or Series
122- The airmass at sea-level.
114+ airmass_relative : scalar or Series
115+ The airmass at sea-level.
123116
124117 pressure : scalar or Series
125- The site pressure in Pascal.
118+ The site pressure in Pascal.
126119
127120 Returns
128121 -------
@@ -131,9 +124,9 @@ def absoluteairmass(airmass_relative, pressure=101325.):
131124
132125 References
133126 ----------
134- [1] C. Gueymard, "Critical analysis and performance assessment of
135- clear sky solar irradiance models using theoretical and measured data,"
136- Solar Energy, vol. 51, pp. 121-138, 1993.
127+ [1] C. Gueymard, "Critical analysis and performance assessment of
128+ clear sky solar irradiance models using theoretical and measured
129+ data," Solar Energy, vol. 51, pp. 121-138, 1993.
137130
138131 '''
139132
@@ -146,106 +139,106 @@ def relativeairmass(zenith, model='kastenyoung1989'):
146139 '''
147140 Gives the relative (not pressure-corrected) airmass.
148141
149- Gives the airmass at sea-level when given a sun zenith angle
150- (in degrees).
151- The ``model`` variable allows selection of different airmass models
152- (described below). If ``model`` is not
153- included or is not valid, the default model is 'kastenyoung1989'.
142+ Gives the airmass at sea-level when given a sun zenith angle (in
143+ degrees). The ``model`` variable allows selection of different
144+ airmass models (described below). If ``model`` is not included or is
145+ not valid, the default model is 'kastenyoung1989'.
154146
155147 Parameters
156148 ----------
157149
158- zenith : float or Series
159- Zenith angle of the sun in degrees.
160- Note that some models use the apparent (refraction corrected)
161- zenith angle, and some models use the true
162- (not refraction-corrected) zenith angle.
163- See model descriptions to determine which type of zenith
164- angle is required.
165- Apparent zenith angles must be calculated at sea level.
166-
167- model : String
150+ zenith : float or Series
151+ Zenith angle of the sun in degrees. Note that some models use
152+ the apparent (refraction corrected) zenith angle, and some
153+ models use the true (not refraction-corrected) zenith angle. See
154+ model descriptions to determine which type of zenith angle is
155+ required. Apparent zenith angles must be calculated at sea level.
156+
157+ model : String
168158 Available models include the following:
169-
159+
170160 * 'simple' - secant(apparent zenith angle) -
171161 Note that this gives -inf at zenith=90
172- * 'kasten1966' - See reference [1] - requires apparent sun zenith
173- * 'youngirvine1967' - See reference [2] - requires true sun zenith
174- * 'kastenyoung1989' - See reference [3] - requires apparent sun zenith
175- * 'gueymard1993' - See reference [4] - requires apparent sun zenith
176- * 'young1994' - See reference [5] - requries true sun zenith
177- * 'pickering2002' - See reference [6] - requires apparent sun zenith
162+ * 'kasten1966' - See reference [1] -
163+ requires apparent sun zenith
164+ * 'youngirvine1967' - See reference [2] -
165+ requires true sun zenith
166+ * 'kastenyoung1989' - See reference [3] -
167+ requires apparent sun zenith
168+ * 'gueymard1993' - See reference [4] -
169+ requires apparent sun zenith
170+ * 'young1994' - See reference [5] -
171+ requries true sun zenith
172+ * 'pickering2002' - See reference [6] -
173+ requires apparent sun zenith
178174
179175 Returns
180176 -------
181- airmass_relative : float or Series
182- Relative airmass at sea level. Will return NaN values for any
177+ airmass_relative : float or Series
178+ Relative airmass at sea level. Will return NaN values for any
183179 zenith angle greater than 90 degrees.
184180
185181 References
186182 ----------
187183
188184 [1] Fritz Kasten. "A New Table and Approximation Formula for the
189- Relative Optical Air Mass". Technical Report 136, Hanover, N.H.: U.S.
190- Army Material Command, CRREL.
185+ Relative Optical Air Mass". Technical Report 136, Hanover, N.H.:
186+ U.S. Army Material Command, CRREL.
191187
192- [2] A. T. Young and W. M. Irvine, "Multicolor Photoelectric Photometry
193- of the Brighter Planets," The Astronomical Journal, vol. 72,
194- pp. 945-950, 1967.
188+ [2] A. T. Young and W. M. Irvine, "Multicolor Photoelectric
189+ Photometry of the Brighter Planets," The Astronomical Journal, vol.
190+ 72, pp. 945-950, 1967.
195191
196- [3] Fritz Kasten and Andrew Young. "Revised optical air mass tables and
197- approximation formula". Applied Optics 28:4735-4738
192+ [3] Fritz Kasten and Andrew Young. "Revised optical air mass tables
193+ and approximation formula". Applied Optics 28:4735-4738
198194
199- [4] C. Gueymard, "Critical analysis and performance assessment of
200- clear sky solar irradiance models using theoretical and measured data,"
201- Solar Energy, vol. 51, pp. 121-138, 1993.
195+ [4] C. Gueymard, "Critical analysis and performance assessment of
196+ clear sky solar irradiance models using theoretical and measured
197+ data," Solar Energy, vol. 51, pp. 121-138, 1993.
202198
203- [5] A. T. Young, "AIR-MASS AND REFRACTION," Applied Optics, vol. 33,
199+ [5] A. T. Young, "AIR-MASS AND REFRACTION," Applied Optics, vol. 33,
204200 pp. 1108-1110, Feb 1994.
205201
206202 [6] Keith A. Pickering. "The Ancient Star Catalog". DIO 12:1, 20,
207-
208- [7] Matthew J. Reno, Clifford W. Hansen and Joshua S. Stein,
209- "Global Horizontal Irradiance Clear Sky Models: Implementation and Analysis"
203+
204+ [7] Matthew J. Reno, Clifford W. Hansen and Joshua S. Stein, "Global
205+ Horizontal Irradiance Clear Sky Models: Implementation and Analysis"
210206 Sandia Report, (2012).
211207 '''
212-
208+
213209 z = zenith
214210 zenith_rad = np .radians (z )
215-
211+
216212 model = model .lower ()
217-
213+
218214 if 'kastenyoung1989' == model :
219- AM = ( 1.0 / (np .cos (zenith_rad ) +
220- 0.50572 * (((6.07995 + (90 - z )) ** - 1.6364 ))) )
215+ am = (1.0 / (np .cos (zenith_rad ) +
216+ 0.50572 * (((6.07995 + (90 - z )) ** - 1.6364 ))))
221217 elif 'kasten1966' == model :
222- AM = 1.0 / (np .cos (zenith_rad ) + 0.15 * ((93.885 - z ) ** - 1.253 ))
218+ am = 1.0 / (np .cos (zenith_rad ) + 0.15 * ((93.885 - z ) ** - 1.253 ))
223219 elif 'simple' == model :
224- AM = 1.0 / np .cos (zenith_rad )
220+ am = 1.0 / np .cos (zenith_rad )
225221 elif 'pickering2002' == model :
226- AM = ( 1.0 / (np .sin (np .radians (90 - z +
227- 244.0 / (165 + 47.0 * (90 - z ) ** 1.1 )))) )
222+ am = (1.0 / (np .sin (np .radians (90 - z +
223+ 244.0 / (165 + 47.0 * (90 - z ) ** 1.1 )))))
228224 elif 'youngirvine1967' == model :
229- AM = ( (1.0 / np .cos (zenith_rad )) *
230- (1 - 0.0012 * ( (1.0 / np .cos (zenith_rad )) ** 2 ) - 1 ) )
225+ am = ((1.0 / np .cos (zenith_rad )) *
226+ (1 - 0.0012 * ((1.0 / np .cos (zenith_rad )) ** 2 ) - 1 ))
231227 elif 'young1994' == model :
232- AM = ( (1.002432 * ((np .cos (zenith_rad )) ** 2 ) +
233- 0.148386 * (np .cos (zenith_rad )) + 0.0096467 ) /
234- (np .cos (zenith_rad ) ** 3 +
235- 0.149864 * (np .cos (zenith_rad ) ** 2 ) +
236- 0.0102963 * (np .cos (zenith_rad )) + 0.000303978 ) )
228+ am = ((1.002432 * ((np .cos (zenith_rad )) ** 2 ) +
229+ 0.148386 * (np .cos (zenith_rad )) + 0.0096467 ) /
230+ (np .cos (zenith_rad ) ** 3 +
231+ 0.149864 * (np .cos (zenith_rad ) ** 2 ) +
232+ 0.0102963 * (np .cos (zenith_rad )) + 0.000303978 ))
237233 elif 'gueymard1993' == model :
238- AM = ( 1.0 / (np .cos (zenith_rad ) +
239- 0.00176759 * (z )* ((94.37515 - z ) ** - 1.21563 )) )
234+ am = (1.0 / (np .cos (zenith_rad ) +
235+ 0.00176759 * (z )* ((94.37515 - z ) ** - 1.21563 )))
240236 else :
241- pvl_logger .warning ("%s is not a valid model type for relative airmass. The 'kastenyoung1989' model was used." ,
242- model )
243- AM = ( 1.0 / (np .cos (zenith_rad ) +
244- 0.50572 * (((6.07995 + (90 - z )) ** - 1.6364 ))) )
245-
237+ raise ValueError ('%s is not a valid model for relativeairmass' , model )
238+
246239 try :
247- AM [z > 90 ] = np .nan
240+ am [z > 90 ] = np .nan
248241 except TypeError :
249- AM = np .nan if z > 90 else AM
250-
251- return AM
242+ am = np .nan if z > 90 else am
243+
244+ return am
0 commit comments