-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix incorrect nan assignments in singleaxis, allow scalar and 1d array input #573
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
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f4d97b6
fix singleaxis horizon test
wholmgren 0d0ce6f
singleaxis now accepts scalar and 1d array input
wholmgren 5604bf1
add dimension check
wholmgren 1d5a8bf
more tests, better warning control
wholmgren 02d79fb
update ci tool configs
wholmgren 7486991
more config
wholmgren 4fee6c2
fix fail_on_pvlib_version decorator does not run code when pass expected
wholmgren 33edb68
Merge remote-tracking branch 'pvlib/master' into sattilt
wholmgren 069b3d7
use predefined bools
wholmgren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ linters: | |
| flake8: | ||
| python: 3 | ||
| max-line-length: 79 | ||
| ignore: E201 | ||
| files: | ||
| ignore: | ||
| - 'pvlib/_version.py' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,10 +260,10 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
|
|
||
| Parameters | ||
| ---------- | ||
| apparent_zenith : Series | ||
| apparent_zenith : float, 1d array, or Series | ||
| Solar apparent zenith angles in decimal degrees. | ||
|
|
||
| apparent_azimuth : Series | ||
| apparent_azimuth : float, 1d array, or Series | ||
| Solar apparent azimuth angles in decimal degrees. | ||
|
|
||
| axis_tilt : float, default 0 | ||
|
|
@@ -296,7 +296,7 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
|
|
||
| Returns | ||
| ------- | ||
| DataFrame with the following columns: | ||
| dict or DataFrame with the following columns: | ||
|
|
||
| * tracker_theta: The rotation angle of the tracker. | ||
| tracker_theta = 0 is horizontal, and positive rotation angles are | ||
|
|
@@ -318,6 +318,18 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
| # MATLAB to Python conversion by | ||
| # Will Holmgren (@wholmgren), U. Arizona. March, 2015. | ||
|
|
||
| if isinstance(apparent_zenith, pd.Series): | ||
| index = apparent_zenith.index | ||
| else: | ||
| index = None | ||
|
|
||
| # convert scalars to arrays | ||
| apparent_azimuth = np.atleast_1d(apparent_azimuth) | ||
| apparent_zenith = np.atleast_1d(apparent_zenith) | ||
|
|
||
| if apparent_azimuth.ndim > 1 or apparent_zenith.ndim > 1: | ||
| raise ValueError('Input dimensions must not exceed 1') | ||
|
|
||
| # Calculate sun position x, y, z using coordinate system as in [1], Eq 2. | ||
|
|
||
| # Positive y axis is oriented parallel to earth surface along tracking axis | ||
|
|
@@ -334,15 +346,6 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
| # Rotate sun azimuth to coordinate system as in [1] | ||
| # to calculate sun position. | ||
|
|
||
| try: | ||
| pd.util.testing.assert_index_equal(apparent_azimuth.index, | ||
| apparent_zenith.index) | ||
| except AssertionError: | ||
| raise ValueError('apparent_azimuth.index and ' | ||
| 'apparent_zenith.index must match.') | ||
|
|
||
| times = apparent_azimuth.index | ||
|
|
||
| az = apparent_azimuth - 180 | ||
| apparent_elevation = 90 - apparent_zenith | ||
| x = cosd(apparent_elevation) * sind(az) | ||
|
|
@@ -408,10 +411,11 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
|
|
||
| # Calculate angle from x-y plane to projection of sun vector onto x-z plane | ||
| # and then obtain wid by translating tmp to convention for rotation angles. | ||
| wid = pd.Series(90 - np.degrees(np.arctan2(zp, xp)), index=times) | ||
| wid = 90 - np.degrees(np.arctan2(zp, xp)) | ||
|
|
||
| # filter for sun above panel horizon | ||
| wid[zp <= 0] = np.nan | ||
| zen_gt_90 = apparent_zenith > 90 | ||
| wid[apparent_zenith > 90] = np.nan | ||
|
||
|
|
||
| # Account for backtracking; modified from [1] to account for rotation | ||
| # angle convention being used here. | ||
|
|
@@ -423,14 +427,11 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
| # (always positive b/c acosd returns values between 0 and 180) | ||
| wc = np.degrees(np.arccos(temp)) | ||
|
|
||
| v = wid < 0 | ||
| widc = pd.Series(index=times) | ||
| widc[~v] = wid[~v] - wc[~v] # Eq 4 applied when wid in QI | ||
| widc[v] = wid[v] + wc[v] # Eq 4 applied when wid in QIV | ||
| # Eq 4 applied when wid in QIV (wid < 0 evalulates True), QI | ||
| tracker_theta = np.where(wid < 0, wid + wc, wid - wc) | ||
| else: | ||
| widc = wid | ||
| tracker_theta = wid | ||
|
|
||
| tracker_theta = widc.copy() | ||
| tracker_theta[tracker_theta > max_angle] = max_angle | ||
| tracker_theta[tracker_theta < -max_angle] = -max_angle | ||
|
|
||
|
|
@@ -447,7 +448,6 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
|
|
||
| # calculate angle-of-incidence on panel | ||
| aoi = np.degrees(np.arccos(np.abs(np.sum(sun_vec*panel_norm, axis=0)))) | ||
| aoi = pd.Series(aoi, index=times) | ||
|
|
||
| # calculate panel tilt and azimuth | ||
| # in a coordinate system where the panel tilt is the | ||
|
|
@@ -491,9 +491,8 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
| # surface_azimuth = pd.Series( | ||
| # np.degrees(np.arctan(projected_normal[:,1]/projected_normal[:,0])), | ||
| # index=times) | ||
| surface_azimuth = pd.Series( | ||
| np.degrees(np.arctan2(projected_normal[:, 1], projected_normal[:, 0])), | ||
| index=times) | ||
| surface_azimuth = \ | ||
| np.degrees(np.arctan2(projected_normal[:, 1], projected_normal[:, 0])) | ||
|
|
||
| # 2. Clean up atan when x-coord or y-coord is zero | ||
| # surface_azimuth[(projected_normal[:,0]==0) & (projected_normal[:,1]>0)] = 90 | ||
|
|
@@ -545,18 +544,17 @@ def singleaxis(apparent_zenith, apparent_azimuth, | |
| surface_azimuth[surface_azimuth >= 360] -= 360 | ||
|
|
||
| # Calculate surface_tilt | ||
| # Use pandas to calculate the sum because it handles nan values better. | ||
wholmgren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| surface_tilt = (90 - np.degrees(np.arccos( | ||
| pd.DataFrame(panel_norm_earth * projected_normal, | ||
| index=times).sum(axis=1)))) | ||
| dotproduct = (panel_norm_earth * projected_normal).sum(axis=1) | ||
| surface_tilt = 90 - np.degrees(np.arccos(dotproduct)) | ||
|
|
||
| # Bundle DataFrame for return values and filter for sun below horizon. | ||
| df_out = pd.DataFrame({'tracker_theta': tracker_theta, 'aoi': aoi, | ||
| 'surface_azimuth': surface_azimuth, | ||
| 'surface_tilt': surface_tilt}, | ||
| index=times) | ||
| df_out = df_out[['tracker_theta', 'aoi', | ||
| 'surface_azimuth', 'surface_tilt']] | ||
| df_out[apparent_zenith > 90] = np.nan | ||
|
|
||
| return df_out | ||
| out = {'tracker_theta': tracker_theta, 'aoi': aoi, | ||
| 'surface_azimuth': surface_azimuth, 'surface_tilt': surface_tilt} | ||
| if index is not None: | ||
| out = pd.DataFrame(out, index=index) | ||
| out = out[['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']] | ||
| out[zen_gt_90] = np.nan | ||
| else: | ||
| out = {k: np.where(zen_gt_90, np.nan, v) for k, v in out.items()} | ||
|
|
||
| return out | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.