Skip to content

Commit 7965325

Browse files
committed
send am through mc to perez function. fix perez nans
1 parent e8635d0 commit 7965325

File tree

4 files changed

+84
-60
lines changed

4 files changed

+84
-60
lines changed

pvlib/irradiance.py

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -967,32 +967,30 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
967967
solar_zenith, solar_azimuth, airmass,
968968
modelt='allsitescomposite1990'):
969969
'''
970-
Determine diffuse irradiance from the sky on a tilted surface using one of
971-
the Perez models.
970+
Determine diffuse irradiance from the sky on a tilted surface using
971+
one of the Perez models.
972972
973973
Perez models determine the diffuse irradiance from the sky (ground
974974
reflected irradiance is not included in this algorithm) on a tilted
975975
surface using the surface tilt angle, surface azimuth angle, diffuse
976976
horizontal irradiance, direct normal irradiance, extraterrestrial
977977
irradiance, sun zenith angle, sun azimuth angle, and relative (not
978-
pressure-corrected) airmass. Optionally a selector may be used to use
979-
any of Perez's model coefficient sets.
978+
pressure-corrected) airmass. Optionally a selector may be used to
979+
use any of Perez's model coefficient sets.
980980
981981
982982
Parameters
983983
----------
984984
985985
surface_tilt : float or Series
986-
Surface tilt angles in decimal degrees.
987-
surface_tilt must be >=0 and <=180. The tilt angle is defined as
988-
degrees from horizontal (e.g. surface facing up = 0, surface facing
989-
horizon = 90)
986+
Surface tilt angles in decimal degrees. surface_tilt must be >=0
987+
and <=180. The tilt angle is defined as degrees from horizontal
988+
(e.g. surface facing up = 0, surface facing horizon = 90)
990989
991990
surface_azimuth : float or Series
992-
Surface azimuth angles in decimal degrees.
993-
surface_azimuth must be >=0 and <=360. The Azimuth convention is defined
994-
as degrees east of north (e.g. North = 0, South=180 East = 90,
995-
West = 270).
991+
Surface azimuth angles in decimal degrees. surface_azimuth must
992+
be >=0 and <=360. The Azimuth convention is defined as degrees
993+
east of north (e.g. North = 0, South=180 East = 90, West = 270).
996994
997995
dhi : float or Series
998996
Diffuse horizontal irradiance in W/m^2.
@@ -1011,22 +1009,20 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
10111009
solar_zenith must be >=0 and <=180.
10121010
10131011
solar_azimuth : float or Series
1014-
Sun azimuth angles in decimal degrees.
1015-
solar_azimuth must be >=0 and <=360. The Azimuth convention is defined
1016-
as degrees east of north (e.g. North = 0, East = 90, West = 270).
1012+
Sun azimuth angles in decimal degrees. solar_azimuth must be >=0
1013+
and <=360. The Azimuth convention is defined as degrees east of
1014+
north (e.g. North = 0, East = 90, West = 270).
10171015
10181016
airmass : float or Series
1019-
relative (not pressure-corrected) airmass
1020-
values. If AM is a DataFrame it must be of the same size as all other
1021-
DataFrame inputs. AM must be >=0 (careful using the 1/sec(z) model of
1022-
AM generation)
1017+
Relative (not pressure-corrected) airmass values. If AM is a
1018+
DataFrame it must be of the same size as all other DataFrame
1019+
inputs. AM must be >=0 (careful using the 1/sec(z) model of AM
1020+
generation)
10231021
10241022
model : string (optional, default='allsitescomposite1990')
1025-
1026-
A string which selects the desired set of Perez
1027-
coefficients. If model is not provided as an input, the default,
1028-
'1990' will be used.
1029-
All possible model selections are:
1023+
A string which selects the desired set of Perez coefficients. If
1024+
model is not provided as an input, the default, '1990' will be
1025+
used. All possible model selections are:
10301026
10311027
* '1990'
10321028
* 'allsitescomposite1990' (same as '1990')
@@ -1046,44 +1042,42 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
10461042
10471043
float or Series
10481044
1049-
The diffuse component of the solar radiation on an
1050-
arbitrarily tilted surface defined by the Perez model as given in
1051-
reference [3].
1052-
SkyDiffuse is the diffuse component ONLY and does not include the
1053-
ground reflected irradiance or the irradiance due to the beam.
1045+
The diffuse component of the solar radiation on an arbitrarily
1046+
tilted surface defined by the Perez model as given in reference
1047+
[3]. SkyDiffuse is the diffuse component ONLY and does not
1048+
include the ground reflected irradiance or the irradiance due to
1049+
the beam.
10541050
10551051
10561052
References
10571053
----------
10581054
1059-
[1] Loutzenhiser P.G. et. al. "Empirical validation of models to compute
1060-
solar irradiance on inclined surfaces for building energy simulation"
1061-
2007, Solar Energy vol. 81. pp. 254-267
1055+
[1] Loutzenhiser P.G. et. al. "Empirical validation of models to
1056+
compute solar irradiance on inclined surfaces for building energy
1057+
simulation" 2007, Solar Energy vol. 81. pp. 254-267
10621058
1063-
[2] Perez, R., Seals, R., Ineichen, P., Stewart, R., Menicucci, D., 1987.
1064-
A new simplified version of the Perez diffuse irradiance model for tilted
1065-
surfaces. Solar Energy 39(3), 221-232.
1059+
[2] Perez, R., Seals, R., Ineichen, P., Stewart, R., Menicucci, D.,
1060+
1987. A new simplified version of the Perez diffuse irradiance model
1061+
for tilted surfaces. Solar Energy 39(3), 221-232.
10661062
1067-
[3] Perez, R., Ineichen, P., Seals, R., Michalsky, J., Stewart, R., 1990.
1068-
Modeling daylight availability and irradiance components from direct
1069-
and global irradiance. Solar Energy 44 (5), 271-289.
1063+
[3] Perez, R., Ineichen, P., Seals, R., Michalsky, J., Stewart, R.,
1064+
1990. Modeling daylight availability and irradiance components from
1065+
direct and global irradiance. Solar Energy 44 (5), 271-289.
10701066
10711067
[4] Perez, R. et. al 1988. "The Development and Verification of the
10721068
Perez Diffuse Radiation Model". SAND88-7030
10731069
'''
10741070

1075-
pvl_logger.debug('diffuse_sky.perez()')
1076-
10771071
kappa = 1.041 # for solar_zenith in radians
10781072
z = np.radians(solar_zenith) # convert to radians
10791073

10801074
# epsilon is the sky's "clearness"
10811075
eps = ((dhi + dni) / dhi + kappa * (z ** 3)) / (1 + kappa * (z ** 3))
10821076

1083-
# Perez et al define clearness bins according to the following rules.
1084-
# 1 = overcast ... 8 = clear
1085-
# (these names really only make sense for small zenith angles, but...)
1086-
# these values will eventually be used as indicies for coeffecient look ups
1077+
# Perez et al define clearness bins according to the following
1078+
# rules. 1 = overcast ... 8 = clear (these names really only make
1079+
# sense for small zenith angles, but...) these values will
1080+
# eventually be used as indicies for coeffecient look ups
10871081
ebin = eps.copy()
10881082
ebin[(eps < 1.065)] = 1
10891083
ebin[(eps >= 1.065) & (eps < 1.23)] = 2
@@ -1100,11 +1094,11 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11001094
ebin = ebin.dropna().astype(int)
11011095

11021096
# This is added because in cases where the sun is below the horizon
1103-
# (var.solar_zenith > 90) but there is still diffuse horizontal light
1104-
# (var.DHI>0), it is possible that the airmass (var.AM) could be NaN, which
1105-
# messes up later calculations. Instead, if the sun is down, and there is
1106-
# still var.DHI, we set the airmass to the airmass value on the horizon
1107-
# (approximately 37-38).
1097+
# (var.solar_zenith > 90) but there is still diffuse horizontal
1098+
# light (var.DHI>0), it is possible that the airmass (var.AM) could
1099+
# be NaN, which messes up later calculations. Instead, if the sun is
1100+
# down, and there is still var.DHI, we set the airmass to the
1101+
# airmass value on the horizon (approximately 37-38).
11081102
# var.AM(var.solar_zenith >=90 & var.DHI >0) = 37;
11091103

11101104
# var.DNI_ET[var.DNI_ET==0] = .00000001 #very hacky, fix this
@@ -1143,6 +1137,7 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11431137

11441138
sky_diffuse = dhi[ebin.index] * (term1 + term2 + term3)
11451139
sky_diffuse[sky_diffuse < 0] = 0
1140+
sky_diffuse[airmass.isnull()] = 0
11461141

11471142
return sky_diffuse
11481143

pvlib/modelchain.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ def __init__(self, system, location,
268268

269269
# calls setter
270270
self.orientation_strategy = orientation_strategy
271-
271+
272272
def __repr__(self):
273-
return ('ModelChain for: '+ str(self.system) +
273+
return ('ModelChain for: '+ str(self.system) +
274274
' orientation_startegy: ' + str(self.orientation_strategy) +
275275
' clearsky_model: ' + str(self.clearsky_model) +
276-
'transposition_model: ' + str(self.transposition_model) +
276+
'transposition_model: ' + str(self.transposition_model) +
277277
' solar_position_method: ' + str(self.solar_position_method) +
278278
'airmass_model: ' + str(self.airmass_model))
279279

@@ -360,7 +360,8 @@ def run_model(self, times, irradiance=None, weather=None):
360360
self.irradiance['dni'],
361361
self.irradiance['ghi'],
362362
self.irradiance['dhi'],
363-
model=self.transposition_model)
363+
model=self.transposition_model,
364+
airmass=self.airmass['airmass_relative'])
364365

365366
if weather is None:
366367
weather = {'wind_speed': 0, 'temp_air': 20}

pvlib/test/test_irradiance.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
times_localized = times.tz_localize(tus.tz)
2929

30-
ephem_data = solarposition.get_solarposition(times, tus.latitude,
31-
tus.longitude, method='nrel_numpy')
30+
ephem_data = solarposition.get_solarposition(
31+
times, tus.latitude, tus.longitude, method='nrel_numpy')
3232

3333
irrad_data = clearsky.ineichen(times, tus.latitude, tus.longitude,
3434
altitude=tus.altitude, linke_turbidity=3,
@@ -141,10 +141,11 @@ def test_king():
141141

142142

143143
def test_perez():
144-
AM = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
145-
irradiance.perez(40, 180, irrad_data['dhi'], irrad_data['dni'],
144+
am = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
145+
out = irradiance.perez(40, 180, irrad_data['dhi'], irrad_data['dni'],
146146
dni_et, ephem_data['apparent_zenith'],
147-
ephem_data['azimuth'], AM)
147+
ephem_data['azimuth'], am)
148+
assert not out.isnull().all()
148149

149150
# klutcher (misspelling) will be removed in 0.3
150151
def test_total_irrad():

pvlib/test/test_modelchain.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ def test_run_model_with_irradiance():
9090
assert_series_equal(ac, expected)
9191

9292

93+
def test_run_model_perez():
94+
system, location = mc_setup()
95+
mc = ModelChain(system, location, transposition_model='perez')
96+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
97+
irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150},
98+
index=times)
99+
ac = mc.run_model(times, irradiance=irradiance).ac
100+
101+
expected = pd.Series(np.array([ 190.194545796, -2.00000000e-02]),
102+
index=times)
103+
assert_series_equal(ac, expected)
104+
105+
106+
def test_run_model_gueymard_perez():
107+
system, location = mc_setup()
108+
mc = ModelChain(system, location, airmass_model='gueymard1993',
109+
transposition_model='perez')
110+
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
111+
irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150},
112+
index=times)
113+
ac = mc.run_model(times, irradiance=irradiance).ac
114+
115+
expected = pd.Series(np.array([ 190.194760203, -2.00000000e-02]),
116+
index=times)
117+
assert_series_equal(ac, expected)
118+
119+
93120
def test_run_model_with_weather():
94121
system, location = mc_setup()
95122
mc = ModelChain(system, location)
@@ -220,8 +247,8 @@ def test_basic_chain_altitude_pressure():
220247
expected = pd.Series(np.array([ 1.15771428788e+02, -2.00000000e-02]),
221248
index=times)
222249
assert_series_equal(ac, expected)
223-
224-
250+
251+
225252
def test_ModelChain___repr__():
226253
system = PVSystem()
227254
location = Location(32.2, -111, altitude=700)

0 commit comments

Comments
 (0)