Skip to content

Return diffuse components from Perez transposition model #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.4.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Enhancements
separate pages for each function, class, or method. (:issue:`258`)
* Improved Linke turbidity factor time interpolation with Python `calendar`
month days and leap years (:issue:`265`)
* Added option to return diffuse components from Perez transposition model.


Other
Expand All @@ -61,3 +62,4 @@ Code Contributors
* Will Holmgren
* Volker Beutner
* Mark Mikofski
* Marc Anoma
27 changes: 25 additions & 2 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def king(surface_tilt, dhi, ghi, solar_zenith):

def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
solar_zenith, solar_azimuth, airmass,
model='allsitescomposite1990'):
model='allsitescomposite1990', return_components=False):
'''
Determine diffuse irradiance from the sky on a tilted surface using
one of the Perez models.
Expand Down Expand Up @@ -953,6 +953,10 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
* 'capecanaveral1988'
* 'albany1988'

return_components: bool (optional, default=False)
Flag used to decide whether to return the calculated diffuse components
or not.

Returns
--------
sky_diffuse : numeric
Expand Down Expand Up @@ -1043,7 +1047,26 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
else:
sky_diffuse = np.where(np.isnan(airmass), 0, sky_diffuse)

return sky_diffuse
if return_components:
diffuse_components = OrderedDict()

# Calculate the different components
diffuse_components['isotropic'] = dhi * term1
diffuse_components['circumsolar'] = dhi * term2
diffuse_components['horizon'] = dhi * term3

# Set values of components to 0 when sky_diffuse is 0
mask = sky_diffuse == 0
if isinstance(sky_diffuse, pd.Series):
diffuse_components = pd.DataFrame(diffuse_components)
diffuse_components.ix[mask] = 0
else:
diffuse_components = {k: np.where(mask, 0, v) for k, v in diffuse_components.items()}

return sky_diffuse, diffuse_components

else:
return sky_diffuse


def disc(ghi, zenith, datetime_or_doy, pressure=101325):
Expand Down
23 changes: 23 additions & 0 deletions pvlib/test/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ def test_perez():
assert_series_equal(out, expected, check_less_precise=2)


def test_perez_components():
am = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
dni = irrad_data['dni'].copy()
dni.iloc[2] = np.nan
out, df_components = irradiance.perez(40, 180, irrad_data['dhi'], dni,
dni_et, ephem_data['apparent_zenith'],
ephem_data['azimuth'], am, return_components=True)
expected = pd.Series(np.array(
[ 0. , 31.46046871, np.nan, 45.45539877]),
index=times)
expected_components = pd.DataFrame(
np.array([[ 0. , 26.84138589, np.nan, 31.72696071],
[ 0. , 0. , np.nan, 4.47966439],
[ 0. , 4.62212181, np.nan, 9.25316454]]).T,
columns=['isotropic', 'circumsolar', 'horizon'],
index=times
)
sum_components = df_components.sum(axis=1)

assert_series_equal(out, expected, check_less_precise=2)
assert_frame_equal(df_components, expected_components)
assert_series_equal(sum_components, expected, check_less_precise=2)

@needs_numpy_1_10
def test_perez_arrays():
am = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
Expand Down