Skip to content

Commit b5e242b

Browse files
committed
really fix the nan/dropped data problem in perez
1 parent 7965325 commit b5e242b

File tree

3 files changed

+142
-158
lines changed

3 files changed

+142
-158
lines changed

docs/tutorials/irradiance.ipynb

Lines changed: 133 additions & 144 deletions
Large diffs are not rendered by default.

pvlib/irradiance.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,19 +1106,17 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11061106
# delta is the sky's "brightness"
11071107
delta = dhi * airmass / dni_extra
11081108

1109-
# keep only valid times
1110-
delta = delta[ebin.index]
1111-
z = z[ebin.index]
1112-
11131109
# The various possible sets of Perez coefficients are contained
11141110
# in a subfunction to clean up the code.
11151111
F1c, F2c = _get_perez_coefficients(modelt)
11161112

1117-
F1 = F1c[ebin, 0] + F1c[ebin, 1] * delta + F1c[ebin, 2] * z
1113+
F1 = (F1c[ebin, 0] + F1c[ebin, 1] * delta[ebin.index] +
1114+
F1c[ebin, 2] * z[ebin.index])
11181115
F1[F1 < 0] = 0
11191116
F1 = F1.astype(float)
11201117

1121-
F2 = F2c[ebin, 0] + F2c[ebin, 1] * delta + F2c[ebin, 2] * z
1118+
F2 = (F2c[ebin, 0] + F2c[ebin, 1] * delta[ebin.index] +
1119+
F2c[ebin, 2] * z[ebin.index])
11221120
F2[F2 < 0] = 0
11231121
F2 = F2.astype(float)
11241122

@@ -1135,7 +1133,7 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11351133
term2 = F1 * A[ebin.index] / B[ebin.index]
11361134
term3 = F2 * tools.sind(surface_tilt)
11371135

1138-
sky_diffuse = dhi[ebin.index] * (term1 + term2 + term3)
1136+
sky_diffuse = dhi * (term1 + term2 + term3)
11391137
sky_diffuse[sky_diffuse < 0] = 0
11401138
sky_diffuse[airmass.isnull()] = 0
11411139

pvlib/test/test_irradiance.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22
pvl_logger = logging.getLogger('pvlib')
33

4-
import datetime
5-
64
import numpy as np
75
import pandas as pd
86

@@ -20,12 +18,11 @@
2018
from . import requires_ephem
2119

2220
# setup times and location to be tested.
23-
times = pd.date_range(start=datetime.datetime(2014, 6, 24),
24-
end=datetime.datetime(2014, 6, 26), freq='1Min')
25-
2621
tus = Location(32.2, -111, 'US/Arizona', 700)
2722

28-
times_localized = times.tz_localize(tus.tz)
23+
# must include night values
24+
times = pd.date_range(start='20140624', end='20140626', freq='1Min',
25+
tz=tus.tz)
2926

3027
ephem_data = solarposition.get_solarposition(
3128
times, tus.latitude, tus.longitude, method='nrel_numpy')
@@ -145,7 +142,7 @@ def test_perez():
145142
out = irradiance.perez(40, 180, irrad_data['dhi'], irrad_data['dni'],
146143
dni_et, ephem_data['apparent_zenith'],
147144
ephem_data['azimuth'], am)
148-
assert not out.isnull().all()
145+
assert not out.isnull().any()
149146

150147
# klutcher (misspelling) will be removed in 0.3
151148
def test_total_irrad():

0 commit comments

Comments
 (0)