Skip to content

Commit 5a1fc93

Browse files
committed
add nrel option to extraradiation
1 parent aeed5fa commit 5a1fc93

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

pvlib/irradiance.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,35 @@
3838
# Use try:except of isinstance.
3939

4040

41-
def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'):
41+
def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer',
42+
**kwargs):
4243
"""
4344
Determine extraterrestrial radiation from day of year.
4445
4546
Parameters
4647
----------
4748
datetime_or_doy : int, float, array, pd.DatetimeIndex
48-
Day of year, array of days of year e.g. pd.DatetimeIndex.dayofyear,
49-
or pd.DatetimeIndex.
49+
Day of year, array of days of year e.g.
50+
pd.DatetimeIndex.dayofyear, or pd.DatetimeIndex.
5051
5152
solar_constant : float
5253
The solar constant.
5354
5455
method : string
5556
The method by which the ET radiation should be calculated.
56-
Options include ``'pyephem', 'spencer', 'asce'``.
57+
Options include ``'pyephem', 'spencer', 'asce', 'nrel'``.
58+
59+
kwargs :
60+
Passed to solarposition.nrel_earthsun_distance
5761
5862
Returns
5963
-------
60-
float or Series
61-
64+
dni_extra : float, array, or Series
6265
The extraterrestrial radiation present in watts per square meter
63-
on a surface which is normal to the sun. Ea is of the same size as the
64-
input doy.
66+
on a surface which is normal to the sun. Ea is of the same size
67+
as the input doy.
6568
66-
'pyephem' always returns a series.
69+
'pyephem' and 'nrel' always return a Series.
6770
6871
Notes
6972
-----
@@ -72,8 +75,8 @@ def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'):
7275
7376
References
7477
----------
75-
[1] M. Reno, C. Hansen, and J. Stein, "Global Horizontal Irradiance Clear
76-
Sky Models: Implementation and Analysis", Sandia National
78+
[1] M. Reno, C. Hansen, and J. Stein, "Global Horizontal Irradiance
79+
Clear Sky Models: Implementation and Analysis", Sandia National
7780
Laboratories, SAND2012-2389, 2012.
7881
7982
[2] <http://solardat.uoregon.edu/SolarRadiationBasics.html>,
@@ -119,6 +122,10 @@ def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'):
119122
pvl_logger.debug('Calculating ET rad using pyephem method')
120123
times = input_to_datetimeindex(datetime_or_doy)
121124
RoverR0sqrd = solarposition.pyephem_earthsun_distance(times) ** (-2)
125+
elif method == 'nrel':
126+
times = input_to_datetimeindex(datetime_or_doy)
127+
RoverR0sqrd = \
128+
solarposition.nrel_earthsun_distance(times, **kwargs) ** (-2)
122129
else:
123130
raise ValueError('Invalid method: %s', method)
124131

pvlib/spa.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,12 @@ def solar_position_loop(unixtime, loc_args, out):
916916
jc = julian_century(jd)
917917
jce = julian_ephemeris_century(jde)
918918
jme = julian_ephemeris_millennium(jce)
919-
L = heliocentric_longitude(jme)
920-
B = heliocentric_latitude(jme)
921919
R = heliocentric_radius_vector(jme)
922920
if esd:
923921
out[0, i] = R
924922
continue
923+
L = heliocentric_longitude(jme)
924+
B = heliocentric_latitude(jme)
925925
Theta = geocentric_longitude(L)
926926
beta = geocentric_latitude(B)
927927
x0 = mean_elongation(jce)
@@ -1032,11 +1032,11 @@ def solar_position_numpy(unixtime, lat, lon, elev, pressure, temp, delta_t,
10321032
jc = julian_century(jd)
10331033
jce = julian_ephemeris_century(jde)
10341034
jme = julian_ephemeris_millennium(jce)
1035-
L = heliocentric_longitude(jme)
1036-
B = heliocentric_latitude(jme)
10371035
R = heliocentric_radius_vector(jme)
10381036
if esd:
10391037
return (R, )
1038+
L = heliocentric_longitude(jme)
1039+
B = heliocentric_latitude(jme)
10401040
Theta = geocentric_longitude(L)
10411041
beta = geocentric_latitude(B)
10421042
x0 = mean_elongation(jce)

pvlib/test/test_irradiance.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pvlib import irradiance
1313
from pvlib import atmosphere
1414

15-
from conftest import requires_ephem
15+
from conftest import requires_ephem, requires_numba
1616

1717
# setup times and location to be tested.
1818
tus = Location(32.2, -111, 'US/Arizona', 700)
@@ -73,6 +73,25 @@ def test_extraradiation_ephem_doyarray():
7373
irradiance.extraradiation(times.dayofyear, method='pyephem')
7474

7575

76+
def test_extraradiation_nrel_dtindex():
77+
irradiance.extraradiation(times, method='nrel')
78+
79+
80+
def test_extraradiation_nrel_scalar():
81+
assert_allclose(
82+
1382, irradiance.extraradiation(300, method='nrel').values[0],
83+
atol=10)
84+
85+
86+
def test_extraradiation_nrel_doyarray():
87+
irradiance.extraradiation(times.dayofyear, method='nrel')
88+
89+
90+
@requires_numba
91+
def test_extraradiation_nrel_numba():
92+
irradiance.extraradiation(times, method='nrel', how='numba', numthreads=8)
93+
94+
7695
def test_extraradiation_invalid():
7796
with pytest.raises(ValueError):
7897
irradiance.extraradiation(times.dayofyear, method='invalid')
@@ -268,7 +287,7 @@ def test_erbs():
268287

269288
out = irradiance.erbs(ghi, zenith, doy)
270289

271-
assert_frame_equal(out, expected)
290+
assert_frame_equal(np.round(out, 0), np.round(expected, 0))
272291

273292

274293
def test_erbs_all_scalar():
@@ -281,4 +300,4 @@ def test_erbs_all_scalar():
281300

282301
out = irradiance.erbs(ghi, zenith, doy)
283302

284-
assert_frame_equal(out, expected)
303+
assert_frame_equal(np.round(out, 0), np.round(expected, 0))

0 commit comments

Comments
 (0)