-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add gallery example for simple irradiance adjustment for horizon shading #1849
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 3 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1eadff4
pvgis gallery example
spaneja cd64985
Merge branch 'pvlib:main' into pvgis_far_shading_example
spaneja 1497f61
name_update
spaneja f5eaa3c
updates_1
spaneja b767cd2
Update 2
spaneja e6fb21e
update 3
spaneja ccce3eb
Merge branch 'main' into pvgis_far_shading_example
spaneja 8ae6c7e
Update docs/sphinx/source/whatsnew/v0.10.2.rst
spaneja 64f1fe7
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 8f2bcb0
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 7eb590b
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 48313a0
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja a32abe1
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 73ef12f
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja c123c28
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja ed8a78f
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 3dae6a9
flake8 updates
spaneja fbf3121
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 1f14b6d
Update docs/examples/shading/plot_simple_irradiance_adjustment_for_ho…
spaneja 62c0595
update
spaneja 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
96 changes: 96 additions & 0 deletions
96
docs/examples/shading/plot_far_shading_with_pvgis_horizon_data.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
""" | ||
Far-Shading with PVGIS Horizon Data | ||
========================= | ||
|
||
Example of getting PVGIS horizon data, interpolating it to time-series | ||
solar-position data, and adjusting DNI and POA-global irradiance. | ||
""" | ||
|
||
# %% | ||
# This example shows how to use retrived horizon elevation angles with | ||
# corresponding horizon azimuth angles from the | ||
# :py:meth:`pvlib.iotools.get_pvgis_horizon` furntion. | ||
spaneja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# After location information and a date range is established, solar position | ||
# data is queried from :py:meth:`pvlib.solar_position.get_solar_position`. | ||
# Horizon data is then retreived, and interpolated to the solar azimuth time | ||
# series data. Finally, in times when solar elevation is greater than the | ||
# interpolated horizon elevation angle, DNI is set to 0. | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from pvlib.iotools import get_pvgis_horizon | ||
from pvlib.location import Location | ||
from pvlib.irradiance import get_total_irradiance | ||
|
||
# Golden, CO | ||
lat, lon = 39.76, -105.22 | ||
tz = 'MST' | ||
|
||
# Set times in the morning of the December solstice. | ||
times = pd.date_range( | ||
'2020-12-20 6:30', '2020-12-20 9:00', freq='1T', tz=tz, inclusive='left') | ||
spaneja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Create location object, and get solar position and clearsky irradiance data. | ||
location = Location(lat, lon, tz) | ||
solar_position = location.get_solarposition(times) | ||
clearsky = location.get_clearsky(times) | ||
|
||
# Get horizon file meta-data and data. | ||
horizon_file = get_pvgis_horizon(lat, lon) | ||
horizon_data = horizon_file[0] | ||
spaneja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Set variable names for easier reading. | ||
surface_tilt = 30 | ||
surface_azimuth = 180 | ||
solar_azimuth = solar_position.azimuth | ||
solar_zenith = solar_position.apparent_zenith | ||
solar_elevation = solar_position.apparent_elevation | ||
dni = clearsky.dni | ||
ghi = clearsky.ghi | ||
dhi = clearsky.dhi | ||
|
||
# Interpolate the horizon elevation data to the solar azimuth, and keep as a | ||
# numpy array. | ||
horizon_elevation_data = np.interp( | ||
solar_azimuth, horizon_data.index, horizon_data) | ||
|
||
# Convert to Pandas Series for easier usage. | ||
horizon_elevation_data = pd.Series(horizon_elevation_data, times) | ||
|
||
# Adjust DNI based on data - note this is returned as numpy array | ||
dni_adjusted = np.where( | ||
solar_elevation > horizon_elevation_data, dni, 0 | ||
) | ||
|
||
# Adjust GHI and set it to DHI for time-periods where 'dni_adjusted' is 0. | ||
# Note this is returned as numpy array | ||
ghi_adjusted = np.where( | ||
dni_adjusted == 0, dhi, ghi | ||
) | ||
|
||
# Transposition using the original and adjusted irradiance components. | ||
irrad_pre_adj = get_total_irradiance( | ||
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth, dni, ghi, dhi) | ||
|
||
irrad_post_adj = get_total_irradiance( | ||
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth, dni_adjusted, | ||
ghi_adjusted, dhi) | ||
|
||
# Create and plot result DataFrames. | ||
poa_global_comparison = pd.DataFrame({ | ||
'poa_global_pre-adjustment': irrad_pre_adj.poa_global, | ||
'poa_global_post-adjustment': irrad_post_adj.poa_global | ||
}) | ||
|
||
dni_comparison = pd.DataFrame({ | ||
'dni_pre-adjustment': dni, | ||
'dni_post-adjustment': dni_adjusted | ||
}) | ||
|
||
# Plot results | ||
poa_global_comparison.plot( | ||
title='POA-Global: Before and after Horizon Adjustment', | ||
ylabel='Irradiance') | ||
dni_comparison.plot( | ||
title='DNI: Before and after Horizon Adjustment', ylabel='Irradiance') |
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.
Uh oh!
There was an error while loading. Please reload this page.