8000 Calculating horizon profiles and associated shading losses by JPalakapillyKWH · Pull Request #758 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Calculating horizon profiles and associated shading losses #758

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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
691d353
first pass at horizon code in pvlib
JPalakapillyKWH Jul 19, 2019
99426ba
added most of horizon shading code
JPalakapillyKWH Jul 23, 2019
39302d6
wrapped up most code and added docstrings to irradiance
JPalakapillyKWH Jul 25, 2019
2daa5c6
added more documentation
JPalakapillyKWH Jul 29, 2019
6cb7399
reverted setup
JPalakapillyKWH Jul 29, 2019
df724e5
linted
JPalakapillyKWH Jul 29, 2019
808af03
more lints + moved import of gmaps
JPalakapillyKWH Jul 29, 2019
7573763
added scipy to setup.py and fixed bug in modelchain
JPalakapillyKWH Jul 31, 2019
3421899
moved some horizon functions to tools and fixed naming. Also wrote 2 …
JPalakapillyKWH Aug 1, 2019
b600e16
added test_horizon.py and code restructuring
JPalakapillyKWH Aug 2, 2019
b0c9193
moved horizon adjustmen to isotropic. Fixed some tests
JPalakapillyKWH Aug 2, 2019
e6beb32
removed gmaps from horizon. Deleted remnants of horizon adjusment model
JPalakapillyKWH Aug 2, 2019
10baccd
major code restructuring. much more numpy friendly now. still need to…
JPalakapillyKWH Aug 6, 2019
345eaa0
updated docstrings
JPalakapillyKWH Aug 6, 2019
5405d75
docstring changes
JPalakapillyKWH Aug 7, 2019
cc481c7
made some changes to modelchain and location due to restructuring of …
JPalakapillyKWH Aug 7, 2019
15e59eb
added one more test to modelchain
JPalakapillyKWH Aug 7, 2019
33c0bb8
threw code and some docs into horizon.rst
JPalakapillyKWH Aug 7, 2019
18ccd1a
reverted irradiance, location and modelchain (and tests) to master
JPalakapillyKWH Aug 7, 2019
d1119ab
changed dip angles to elevation angles
JPalakapillyKWH Aug 7, 2019
57c2035
removed horizon.rst for now
JPalakapillyKWH Aug 7, 2019
00017e2
added DNI correction to horizon.py
JPalakapillyKWH Aug 8, 2019
a87b797
added a test case to get 100% of diff hit
JPalakapillyKWH Aug 8, 2019
aeb5f95
minor test fix
JPalakapillyKWH Aug 8, 2019
b022f9e
docstring changes and improvement to filter_points
JPalakapillyKWH Aug 9, 2019
d07e66f
added tests for functions added in tools.py. Some docstring changes a…
JPalakapillyKWH Aug 12, 2019
2411520
minor improvements and docstring changes
JPalakapillyKWH Aug 13, 2019
210fd1c
docstring changes
JPalakapillyKWH Aug 13, 2019
a630acc
reference update
JPalakapillyKWH Aug 13, 2019
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
Prev Previous commit
Next Next commit
added DNI correction to horizon.py
  • Loading branch information
JPalakapillyKWH committed Aug 8, 2019
commit 00017e289ca254023948312ca50a66216d764df0
50 changes: 50 additions & 0 deletions pvlib/horizon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import itertools

import numpy as np
import warnings

from scipy.interpolate import RegularGridInterpolator

from pvlib import tools
Expand Down Expand Up @@ -594,3 +596,51 @@ def calculate_dtf(horizon_azimuths, horizon_angles,
second_term = .5 * c * np.cos(elev)**2
dtf += 2 * (first_term + second_term) / num_points
return dtf


def DNI_horizon_adjustment(horizon_angles, solar_zenith, solar_azimuth):
'''
Calculates an adjustment to DNI based on a horizon profile. The adjustment
is a vector of binary values with the same length as the provided
solar position values. Where the sun is below the horizon, the adjustment
vector is 0 and it is 1 elsewhere. The horizon profile must be given as a
vector with 361 values where the ith value corresponds to the ith degree
of azimuth (0-360).


Parameters
----------
horizon_angles: numeric
Elevation angle values for points that define the horizon profile. The
elevation angle of the horizon is the angle that the horizon makes with
the horizontal. It is given in degrees above the horizontal. The ith
element in this array corresponds to the ith degree of azimuth.

solar_zenith : numeric
Solar zenith angle.

solar_azimuth : numeric
Solar azimuth angle.

Returns
-------
adjustment : numeric
A vector of binary values with the same shape as the inputted solar
position values. 0 when the sun is below the horizon and 1 elsewhere.
'''
adjustment = np.ones(solar_zenith.shape)

if (horizon_angles.shape[0] != 361):
warnings.warn('For DNI adjustment, horizon_angles needs to contain'
'exactly 361 values (for each degree of azimuth 0-360).'
'Since the provided horizon_angles contains {} values,'
'no adjustment is calculated. A vector of ones is'
'returned.'.format(horizon_angles.shape[0]),
UserWarning)
return adjustment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise an exception instead of returning 1s and a warning.


rounded_solar_azimuth = np.round(solar_azimuth).astype(int)
horizon_zenith = 90 - horizon_angles[rounded_solar_azimuth]
mask = solar_zenith > horizon_zenith
adjustment[mask] = 0
return adjustment
33 changes: 33 additions & 0 deletions pvlib/test/test_horizon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import numpy as np
import pandas as pd
from numpy.testing import assert_allclose
from pvlib import horizon, tools

from test_irradiance import ephem_data, times


def test_grid_lat_lon():
grid_radius = 50
Expand Down Expand Up @@ -232,3 +235,33 @@ def test_calculate_dtf():
mask = np.logical_and((adjusted >= min_random_dtf),
(adjusted <= max_random_dtf))
assert(np.all(mask))


def test_DNI_horizon_adjustment(ephem_data):
zero_horizon = np.zeros(361)
max_horizon = np.full((361), 90.0)

zero_adjusted = horizon.DNI_horizon_adjustment(zero_horizon,
ephem_data["zenith"],
ephem_data["azimuth"])
zero_expected = np.array([0, 1, 1, 1])
assert_allclose(zero_adjusted, zero_expected, atol=1e-7)

max_adjusted = horizon.DNI_horizon_adjustment(max_horizon,
ephem_data["zenith"],
ephem_data["azimuth"])

max_expected = np.array([0, 0, 0, 0])
assert_allclose(max_adjusted, max_expected, atol=1e-7)

test_horizon = np.zeros(361)
test_horizon[145] = 75
test_horizon[287] = 20
test_horizon[67] = 10

adjusted = horizon.DNI_horizon_adjustment(test_horizon,
ephem_data["zenith"],
ephem_data["azimuth"])

expected = np.array([0, 0, 1, 0])
assert_allclose(adjusted, expected, atol=1e-7)
0