Skip to content

Commit 93b25ea

Browse files
committed
add nanmaximum function in tools
1 parent dd30069 commit 93b25ea

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

pvlib/irradiance.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from pvlib import atmosphere, solarposition, tools
1717
from pvlib._deprecation import deprecated
18+
from tools import nanmaximum
1819

1920
# see References section of grounddiffuse function
2021
SURFACE_ALBEDOS = {'urban': 0.18,
@@ -1147,24 +1148,24 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11471148
F2c = np.vstack((F2c, nans))
11481149

11491150
F1 = (F1c[ebin, 0] + F1c[ebin, 1] * delta + F1c[ebin, 2] * z)
1150-
F1 = np.where(np.isnan(F1), np.nan, np.maximum(F1, 0))
1151+
F1 = nanmaximum(F1, 0)
11511152

11521153
F2 = (F2c[ebin, 0] + F2c[ebin, 1] * delta + F2c[ebin, 2] * z)
1153-
F2 = np.where(np.isnan(F2), np.nan, np.maximum(F2, 0))
1154+
F2 = nanmaximum(F2, 0)
11541155

11551156
A = aoi_projection(surface_tilt, surface_azimuth,
11561157
solar_zenith, solar_azimuth)
1157-
A = np.maximum(A, 0)
1158+
A = nanmaximum(A, 0)
11581159

11591160
B = tools.cosd(solar_zenith)
1160-
B = np.where(np.isnan(B), np.nan, np.maximum(B, tools.cosd(85)))
1161+
B = nanmaximum(B, tools.cosd(85))
11611162

11621163
# Calculate Diffuse POA from sky dome
11631164
term1 = 0.5 * (1 - F1) * (1 + tools.cosd(surface_tilt))
11641165
term2 = F1 * A / B
11651166
term3 = F2 * tools.sind(surface_tilt)
11661167

1167-
sky_diffuse = np.maximum(dhi * (term1 + term2 + term3), 0)
1168+
sky_diffuse = nanmaximum(dhi * (term1 + term2 + term3), 0)
11681169

11691170
# we've preserved the input type until now, so don't ruin it!
11701171
if isinstance(sky_diffuse, pd.Series):

pvlib/tools.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ def asind(number):
8686
return res
8787

8888

89+
def nanmaximum(x1, x2):
90+
"""
91+
Element-wise maximum preserving nans, without numpy warning
92+
93+
Parameters
94+
----------
95+
array1, array2 : array_like
96+
the arrays to be compared, must have the same shape or broadcast to the
97+
same shape.
98+
99+
Returns
100+
-------
101+
y : array_like
102+
the maximum of x1 and x2, element-wise. nan is preserved.
103+
"""
104+
105+
return np.where((np.isnan(x1) | np.isnan(x2)), np.nan, np.fmax(x1, x2))
106+
107+
89108
def localize_to_utc(time, location):
90109
"""
91110
Converts or localizes a time series to UTC.

0 commit comments

Comments
 (0)