-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add gallery of examples using sphinx-gallery #846
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4c8f435
draft of sunpath diagram example
kandersolar 9f2a117
add explanation text and cartesian diagram
kandersolar 46f7cd7
Delete solarposition.rst
kandersolar 4fdc129
Add sphinx-gallery and configuration
kandersolar 2b6a9f3
add sunpath example
kandersolar f04fe0b
add singleaxis tracker example
kandersolar b1d8015
linting fixes
kandersolar 92ead4e
rename "Intro Examples" to "Intro Tutorial", move "Example Gallery" u…
kandersolar 3a2f0fd
Update introtutorial.rst
kandersolar 4e13906
more linting fixes
kandersolar 937166a
last linting fix, probably
kandersolar 405d033
Merge remote-tracking branch 'upstream/master' into sunpath_example
kandersolar beabb4b
Mention example gallery in whatsnew
kandersolar b60e06b
update introtutorial link in package_overview.rst; move warnings impo…
kandersolar 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Example Gallery | ||
=============== | ||
|
||
This gallery shows examples of pvlib functionality. Community contributions are welcome! |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
Single-axis tracking | ||
==================== | ||
|
||
Examples of modeling tilt angles for single-axis tracker arrays. | ||
""" | ||
|
||
#%% | ||
# This example shows basic usage of pvlib's tracker position calculations with | ||
# :py:meth:`pvlib.tracking.singleaxis`. The examples shown here demonstrate | ||
# how the tracker parameters affect the generated tilt angles. | ||
# | ||
# Because tracker angle is based on where the sun is in the sky, calculating | ||
# solar position is always the first step. | ||
# | ||
# True-tracking | ||
# ------------- | ||
# | ||
# The basic tracking algorithm is called "true-tracking". It orients the panels | ||
# towards the sun as much as possible in order to maximize the cross section | ||
# presented towards incoming beam irradiance. | ||
|
||
from pvlib import solarposition, tracking | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
|
||
tz = 'US/Eastern' | ||
lat, lon = 40, -80 | ||
|
||
times = pd.date_range('2019-01-01', '2019-01-02', closed='left', freq='5min', | ||
tz=tz) | ||
solpos = solarposition.get_solarposition(times, lat, lon) | ||
|
||
truetracking_angles = tracking.singleaxis( | ||
apparent_zenith=solpos['apparent_zenith'], | ||
apparent_azimuth=solpos['azimuth'], | ||
axis_tilt=0, | ||
axis_azimuth=180, | ||
max_angle=90, | ||
backtrack=False, # for true-tracking | ||
gcr=0.5) # irrelevant for true-tracking | ||
|
||
truetracking_position = truetracking_angles['tracker_theta'].fillna(0) | ||
truetracking_position.plot(title='Truetracking Curve') | ||
|
||
plt.show() | ||
|
||
#%% | ||
# Backtracking | ||
# ------------- | ||
# | ||
# Because truetracking yields steep tilt angle in morning and afternoon, it | ||
# will cause row to row shading as the shadows from adjacent rows fall on each | ||
# other. To prevent this, the trackers can rotate backwards when the sun is | ||
# near the horizon -- "backtracking". The shading angle depends on row | ||
# geometry, so the gcr parameter must be specified. The greater the gcr, the | ||
# tighter the row spacing and the more aggressively the array must backtrack. | ||
|
||
fig, ax = plt.subplots() | ||
|
||
for gcr in [0.2, 0.4, 0.6]: | ||
backtracking_angles = tracking.singleaxis( | ||
apparent_zenith=solpos['apparent_zenith'], | ||
apparent_azimuth=solpos['azimuth'], | ||
axis_tilt=0, | ||
axis_azimuth=180, | ||
max_angle=90, | ||
backtrack=True, | ||
gcr=gcr) | ||
|
||
backtracking_position = backtracking_angles['tracker_theta'].fillna(0) | ||
backtracking_position.plot(title='Backtracking Curve', | ||
label='GCR:{:0.01f}'.format(gcr), | ||
ax=ax) | ||
|
||
plt.legend() | ||
plt.show() |
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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
""" | ||
Sun path diagram | ||
================ | ||
|
||
Examples of generating sunpath diagrams. | ||
""" | ||
|
||
#%% | ||
# This example shows basic usage of pvlib's solar position calculations with | ||
# :py:meth:`pvlib.solarposition.get_solarposition`. The examples shown here | ||
# will generate sunpath diagrams that shows solar position over a year. | ||
# | ||
# Polar plot | ||
# ---------- | ||
# | ||
# Below is an example plot of solar position in | ||
# `polar coordinates <https://en.wikipedia.org/wiki/Polar_coordinate_system>`_. | ||
|
||
from pvlib import solarposition | ||
import pandas as pd | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
tz = 'Asia/Calcutta' | ||
lat, lon = 28.6, 77.2 | ||
|
||
times = pd.date_range('2019-01-01 00:00:00', '2020-01-01', closed='left', | ||
freq='H', tz=tz) | ||
solpos = solarposition.get_solarposition(times, lat, lon) | ||
# remove nighttime | ||
solpos = solpos.loc[solpos['apparent_elevation'] > 0, :] | ||
|
||
ax = plt.subplot(1, 1, 1, projection='polar') | ||
# draw the analemma loops | ||
points = ax.scatter(np.radians(solpos.azimuth), solpos.apparent_zenith, | ||
s=2, label=None, c=solpos.index.dayofyear) | ||
ax.figure.colorbar(points) | ||
|
||
# draw hour labels | ||
for hour in np.unique(solpos.index.hour): | ||
# choose label position by the smallest radius for each hour | ||
subset = solpos.loc[solpos.index.hour == hour, :] | ||
r = subset.apparent_zenith | ||
pos = solpos.loc[r.idxmin(), :] | ||
ax.text(np.radians(pos['azimuth']), pos['apparent_zenith'], str(hour)) | ||
|
||
# draw individual days | ||
for date in pd.to_datetime(['2019-03-21', '2019-06-21', '2019-12-21']): | ||
times = pd.date_range(date, date+pd.Timedelta('24h'), freq='5min', tz=tz) | ||
solpos = solarposition.get_solarposition(times, lat, lon) | ||
solpos = solpos.loc[solpos['apparent_elevation'] > 0, :] | ||
label = date.strftime('%Y-%m-%d') | ||
ax.plot(np.radians(solpos.azimuth), solpos.apparent_zenith, label=label) | ||
|
||
ax.figure.legend(loc='upper left') | ||
|
||
# change coordinates to be like a compass | ||
ax.set_theta_zero_location('N') | ||
ax.set_theta_direction(-1) | ||
ax.set_rmax(90) | ||
|
||
plt.show() | ||
|
||
#%% | ||
# This is a polar plot of hourly solar zenith and azimuth. The figure-8 | ||
# patterns are called `analemmas <https://en.wikipedia.org/wiki/Analemma>`_ and | ||
# show how the sun's path slowly shifts over the course of the year . The | ||
# colored lines show the single-day sun paths for the winter and summer | ||
# solstices as well as the spring equinox. | ||
# | ||
# The soltice paths mark the boundary of the sky area that the sun traverses | ||
# over a year. The diagram shows that there is no point in the | ||
# year when is the sun directly overhead (zenith=0) -- note that this location | ||
# is north of the Tropic of Cancer. | ||
# | ||
# Examining the sun path for the summer solstice in particular shows that | ||
# the sun rises north of east, crosses into the southern sky around 10 AM for a | ||
# few hours before crossing back into the northern sky around 3 PM and setting | ||
# north of west. In contrast, the winter solstice sun path remains in the | ||
# southern sky the entire day. Moreover, the diagram shows that the winter | ||
# solstice is a shorter day than the summer soltice -- in December, the sun | ||
# rises after 7 AM and sets before 6 PM, whereas in June the sun is up before | ||
# 6 AM and sets after 7 PM. | ||
# | ||
# Another use of this diagram is to determine what times of year the sun is | ||
# blocked by obstacles. For instance, for a mountain range on the western side | ||
# of an array that extends 10 degrees above the horizon, the sun is blocked: | ||
# | ||
# - after about 6:30 PM on the summer solstice | ||
# - after about 5:30 PM on the spring equinox | ||
# - after about 4:30 PM on the winter solstice | ||
|
||
#%% | ||
# PVSyst Plot | ||
# ----------- | ||
# | ||
# PVSyst users will be more familiar with sunpath diagrams in Cartesian | ||
# coordinates: | ||
|
||
from pvlib import solarposition | ||
import pandas as pd | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
tz = 'Asia/Calcutta' | ||
lat, lon = 28.6, 77.2 | ||
times = pd.date_range('2019-01-01 00:00:00', '2020-01-01', closed='left', | ||
freq='H', tz=tz) | ||
|
||
solpos = solarposition.get_solarposition(times, lat, lon) | ||
# remove nighttime | ||
solpos = solpos.loc[solpos['apparent_elevation'] > 0, :] | ||
|
||
fig, ax = plt.subplots() | ||
points = ax.scatter(solpos.azimuth, solpos.apparent_elevation, s=2, | ||
c=solpos.index.dayofyear, label=None) | ||
fig.colorbar(points) | ||
|
||
for hour in np.unique(solpos.index.hour): | ||
# choose label position by the largest elevation for each hour | ||
subset = solpos.loc[solpos.index.hour == hour, :] | ||
height = subset.apparent_elevation | ||
pos = solpos.loc[height.idxmax(), :] | ||
ax.text(pos['azimuth'], pos['apparent_elevation'], str(hour)) | ||
|
||
for date in pd.to_datetime(['2019-03-21', '2019-06-21', '2019-12-21']): | ||
times = pd.date_range(date, date+pd.Timedelta('24h'), freq='5min', tz=tz) | ||
solpos = solarposition.get_solarposition(times, lat, lon) | ||
solpos = solpos.loc[solpos['apparent_elevation'] > 0, :] | ||
label = date.strftime('%Y-%m-%d') | ||
ax.plot(solpos.azimuth, solpos.apparent_elevation, label=label) | ||
|
||
ax.figure.legend(loc='upper left') | ||
ax.set_xlabel('Solar Azimuth (degrees)') | ||
ax.set_ylabel('Solar Elevation (degrees)') | ||
|
||
plt.show() |
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
4 changes: 2 additions & 2 deletions
4
docs/sphinx/source/introexamples.rst → docs/sphinx/source/introtutorial.rst
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
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
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.
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.
update link in
package_overview.rst
line 15