-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix erbs near zenith=90 #683
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,12 @@ date will require Python 3. (:issue:`501`) | |
|
||
API Changes | ||
~~~~~~~~~~~ | ||
|
||
* `erbs` `doy` argument changed to `datetime_or_doy` to be consistent with | ||
allowed types and similar functions (`disc`, `get_extra_radiation`). | ||
* `erbs` DataFrame vs. OrderedDict return behavior now determined by type | ||
of `datetime_or_doy` instead of `ghi` or `zenith`. | ||
* Added `min_cos_zenith` and `max_zenith` keyword arguments to `erbs`. | ||
(:issue:`681`) | ||
|
||
Enhancements | ||
~~~~~~~~~~~~ | ||
|
@@ -28,6 +33,7 @@ Bug fixes | |
* pvwatts_ac raised ZeroDivisionError when called with scalar pdc=0 | ||
and a RuntimeWarning for array(0) input. Now correctly returns 0s | ||
of the appropriate type. (:issue:`675`) | ||
* Fixed `erbs` behavior when zenith is near 90 degrees. (:issue:`681`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double ticks for rst or use func directive to erbs in api |
||
|
||
|
||
Testing | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2152,7 +2152,7 @@ def _gti_dirint_gte_90_kt_prime(aoi, solar_zenith, solar_azimuth, times, | |
return kt_prime_gte_90 | ||
|
||
|
||
def erbs(ghi, zenith, doy): | ||
def erbs(ghi, zenith, datetime_or_doy, min_cos_zenith=0.065, max_zenith=87): | ||
r""" | ||
Estimate DNI and DHI from GHI using the Erbs model. | ||
|
||
|
@@ -2179,8 +2179,15 @@ def erbs(ghi, zenith, doy): | |
Global horizontal irradiance in W/m^2. | ||
zenith: numeric | ||
True (not refraction-corrected) zenith angles in decimal degrees. | ||
doy: scalar, array or DatetimeIndex | ||
The day of the year. | ||
datetime_or_doy : int, float, array, pd.DatetimeIndex | ||
Day of year or array of days of year e.g. | ||
pd.DatetimeIndex.dayofyear, or pd.DatetimeIndex. | ||
min_cos_zenith : numeric, default 0.065 | ||
Minimum value of cos(zenith) to allow when calculating global | ||
clearness index `kt`. Equivalent to zenith = 86.273 degrees. | ||
max_zenith : numeric, default 87 | ||
Maximum value of zenith to allow in DNI calculation. DNI will be | ||
set to 0 for times with zenith values greater than `max_zenith`. | ||
|
||
Returns | ||
------- | ||
|
@@ -2205,14 +2212,10 @@ def erbs(ghi, zenith, doy): | |
disc | ||
""" | ||
|
||
dni_extra = get_extra_radiation(doy) | ||
dni_extra = get_extra_radiation(datetime_or_doy) | ||
|
||
# This Z needs to be the true Zenith angle, not apparent, | ||
# to get extraterrestrial horizontal radiation) | ||
i0_h = dni_extra * tools.cosd(zenith) | ||
|
||
kt = ghi / i0_h | ||
kt = np.maximum(kt, 0) | ||
kt = clearness_index(ghi, zenith, dni_extra, min_cos_zenith=min_cos_zenith, | ||
max_clearness_index=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 🚀 |
||
|
||
# For Kt <= 0.22, set the diffuse fraction | ||
df = 1 - 0.09*kt | ||
|
@@ -2229,14 +2232,18 @@ def erbs(ghi, zenith, doy): | |
dhi = df * ghi | ||
|
||
dni = (ghi - dhi) / tools.cosd(zenith) | ||
bad_values = (zenith > max_zenith) | (ghi < 0) | (dni < 0) | ||
dni = np.where(bad_values, 0, dni) | ||
# ensure that closure relationship remains valid | ||
dhi = np.where(bad_values, ghi, dhi) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very nice! 🚀 |
||
|
||
data = OrderedDict() | ||
data['dni'] = dni | ||
data['dhi'] = dhi | ||
data['kt'] = kt | ||
|
||
if isinstance(dni, pd.Series): | ||
data = pd.DataFrame(data) | ||
if isinstance(datetime_or_doy, pd.DatetimeIndex): | ||
data = pd.DataFrame(data, index=datetime_or_doy) | ||
|
||
return data | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might need double ticks here (and below) for ReStructured Text - this always get's me - single ticks is for
markdown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python docs seem to consistently use italics for parameters and links for functions. I don't think we have a standard here (though I recall you've done some work on this in older whats new files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in rst single ticks get interpreted as italics just like * do, anyway, not a blocker for me, so I defer to you, everything else looks great! Thanks for checking closure on
ghi = dni*cos(ze)+dhi
😸