Skip to content
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

Shaded Fraction on Sloped Terrains - PR1725 partial continuation #1962

Merged
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
c87885c
Update shading.py
echedey-ls Nov 6, 2023
4fc6cd8
Minimal test
echedey-ls Nov 6, 2023
2a72f33
Implementation
echedey-ls Nov 8, 2023
d6e8067
Fix, fix, fix, fix & format
echedey-ls Nov 8, 2023
13a56d4
Format issues
echedey-ls Nov 8, 2023
f012aae
Extend tests (compare with singleaxis) & format with ruff
echedey-ls Nov 8, 2023
6dd9a3b
Format fixes
echedey-ls Nov 8, 2023
e8743db
Upgrade tests
echedey-ls Nov 9, 2023
6030774
Array -> Axis
echedey-ls Nov 9, 2023
6276382
type
echedey-ls Nov 9, 2023
509699f
Whatsnew
echedey-ls Nov 9, 2023
5ff8fd8
xd
echedey-ls Nov 9, 2023
04126e0
bruh
echedey-ls Nov 9, 2023
607a246
Minor Python optimization a la tracking.singleaxis
echedey-ls Nov 9, 2023
240b551
Comment and minor optimizations
echedey-ls Nov 9, 2023
997def6
Surface -> Axis
echedey-ls Nov 9, 2023
7912055
Elevation -> Zenith
echedey-ls Nov 9, 2023
f068e3e
Elev -> Zenith
echedey-ls Nov 9, 2023
a5f4a85
Update shading.py
echedey-ls Jan 24, 2024
a854e27
Update docstring
echedey-ls Jan 24, 2024
2d82375
Add comments from `tracking.singleaxis`
echedey-ls Jan 24, 2024
5f24721
Singleaxis implementation port & test addition, based on old pvlib.tr…
echedey-ls Jan 25, 2024
049a8cc
Update v0.10.4.rst
echedey-ls Jan 25, 2024
a3185df
Linter
echedey-ls Jan 25, 2024
b9f1a76
Code review
echedey-ls Jan 25, 2024
f7d1d80
Add Fig 5 [1] (still gotta check the built output)
echedey-ls Jan 27, 2024
1880f6a
Add caption, change size and describe in alternate text
echedey-ls Jan 27, 2024
d9f242a
rST fixes ?
echedey-ls Jan 27, 2024
379ca95
Figures have captions, images do not
echedey-ls Jan 27, 2024
62e99ad
Flip arguments order
echedey-ls Feb 8, 2024
4f584ea
I forgot :skull:
echedey-ls Feb 8, 2024
238d123
Linter are you happy now?
echedey-ls Feb 8, 2024
98a254d
Remove port test and add edge cases test
echedey-ls Feb 9, 2024
4616175
Update test_shading.py
echedey-ls Feb 9, 2024
33ffd28
Indentation xd
echedey-ls Feb 9, 2024
8526bc6
Update test_shading.py
echedey-ls Feb 9, 2024
bde3656
I forgot how to code
echedey-ls Feb 9, 2024
51e3750
Align data
echedey-ls Feb 9, 2024
35738a4
Docstring suggestion from Kevin
echedey-ls Feb 27, 2024
8d679c3
Update link to example?
echedey-ls Feb 27, 2024
4a907c1
add linear shade loss for thin films
mikofski May 4, 2023
234288d
add tests, update docs, what's new
mikofski May 4, 2023
fb0e5d1
fix what's new gh issue and pr links
mikofski May 4, 2023
aa4b6e8
fix trailing whitespace
mikofski May 4, 2023
18b2187
responding to comments
mikofski May 6, 2023
4163a72
update docstring for linear shade loss
mikofski May 6, 2023
1ebf8ea
update example in linear_shade_loss
mikofski May 6, 2023
de2144f
add figure and formulas to shaded fraction
mikofski May 6, 2023
6aa43f0
shaded fraction consistently
mikofski May 11, 2023
c34a2f6
Add alternative text to image
echedey-ls Feb 3, 2024
6b9f478
Update implementation based on PSZ PR. See description.
echedey-ls Feb 3, 2024
c3a9569
Whatsnew entries
echedey-ls Feb 3, 2024
4bb02ab
Linter
echedey-ls Feb 3, 2024
78c481e
Clear things, convert Mark's reference to a reference
echedey-ls Feb 4, 2024
0ce0d68
Linter
echedey-ls Feb 4, 2024
74b4215
Update according to changes at PSZA PR
echedey-ls Feb 15, 2024
909cc23
Another commit, another try
echedey-ls Feb 27, 2024
e3e73f6
Ahhh, I rebased too fast
echedey-ls Mar 8, 2024
cbb0b04
whatsnews
echedey-ls Mar 8, 2024
96b61a8
Update v0.10.4.rst
echedey-ls Mar 8, 2024
d2b9291
Update v0.10.3.rst
echedey-ls Mar 8, 2024
7ec4d64
Merge branch 'main' into pr1725-continuation-shaded-fraction-mikofski
echedey-ls Mar 11, 2024
bbc6115
Rename to `shaded_fraction1d`, change params to `surface_*` instead o…
echedey-ls Mar 14, 2024
39a3ba9
Left this tracker refs behind
echedey-ls Mar 14, 2024
a3ccf3e
Change rename in rst entries
echedey-ls Mar 14, 2024
e5fffca
Add another testcase
echedey-ls Mar 14, 2024
457d4b4
Improve docs references, clarify nomenclature
echedey-ls Mar 14, 2024
f11858e
Update test_shading.py
echedey-ls Mar 14, 2024
f321cc1
Merge branch 'main' into linear-shade-mikofski-pr-1725
echedey-ls Mar 24, 2024
0ab3720
Remove linear_shade_loss
echedey-ls Mar 24, 2024
e6da6e8
First implementation of the new shaded fraction model (missing figure)
echedey-ls Mar 28, 2024
4ce1655
Create Anderson_Jensen_2024_Fig3.png
echedey-ls Mar 29, 2024
60b7e2e
Update shading.py
echedey-ls Mar 29, 2024
2d23cb2
Update shading.py
echedey-ls Mar 29, 2024
78a451c
Update shading.py
echedey-ls Apr 1, 2024
28128f6
lintaaargggg
echedey-ls Apr 1, 2024
f4acf39
Fill reference
echedey-ls Apr 2, 2024
104d185
Next release 0.10.5?
echedey-ls Apr 2, 2024
894ff9f
Fix tests
echedey-ls Apr 5, 2024
f147881
Update test_shading.py
echedey-ls Apr 5, 2024
4d11294
Little improvement to table definitions
echedey-ls Apr 10, 2024
69c76cf
Change `l` to `\ell`
echedey-ls Apr 15, 2024
758f5e7
`pvlib.tracking.projected_solar_zenith_angle` to `pvlib.shading.proje…
echedey-ls Apr 15, 2024
6882dfa
pitch references to `pitch`
echedey-ls Apr 15, 2024
4ef4567
`trackers_axis_azimuth` to `axis_azimuth`
echedey-ls Apr 15, 2024
574a1a2
whatsnews
echedey-ls Apr 15, 2024
efac0b3
Update v0.10.5.rst
echedey-ls Apr 15, 2024
3a726b8
Change `tilt`s to `rotation`s and add `axis_tilt`
echedey-ls Apr 15, 2024
300b912
Forgot to update tests :skull:
echedey-ls Apr 15, 2024
497a62e
Merge branch 'main' into terrain-slope-mikofski-pr-1725
echedey-ls Apr 15, 2024
2a34f43
Merge branch 'main' into pr1725-continuation-shaded-fraction-mikofski
echedey-ls Apr 16, 2024
c1b3978
Add examples section
echedey-ls Apr 16, 2024
db8edd6
roles assumption messin w/ me docs :astonished:
echedey-ls Apr 21, 2024
d65e64d
roles assumption messin w/ me docs :astonished:
echedey-ls Apr 21, 2024
51a2dfa
Merge branch 'pr1725-continuation-shaded-fraction-mikofski' of https:…
echedey-ls Apr 22, 2024
9038097
Update shading.py
echedey-ls Apr 22, 2024
5652801
Update shading.py
echedey-ls Apr 23, 2024
31affba
Add gallery example
echedey-ls Apr 23, 2024
80ab494
This was fixed in recent sphinx-gallery releases IIRC
echedey-ls Apr 23, 2024
facde21
Extra empty line or admonition type unsupported
echedey-ls Apr 23, 2024
5a807b7
Fix example link (hopefully :pray: )
echedey-ls Apr 23, 2024
25a0f19
Update shading.py
echedey-ls Apr 23, 2024
8bdd469
Fix subsubsections?
echedey-ls Apr 24, 2024
a2e8be7
Nah, bulleted list didn't work
echedey-ls Apr 24, 2024
9f1fa97
tilted -> tracker, only affects text
echedey-ls Apr 24, 2024
37ab496
Typos and unreasonable physical values
echedey-ls Apr 24, 2024
6303583
See the Examples section below, not the unlinkable link
echedey-ls Apr 24, 2024
e785292
tracker -> row, param names, code and docs
echedey-ls Apr 24, 2024
9b98d9e
Fix broken example :wrench:
echedey-ls Apr 26, 2024
3726e4d
Apply suggestions from code review
echedey-ls May 23, 2024
4e7e36f
"the row axis/axes" instead of ``axis_azimuth``
echedey-ls May 23, 2024
59465c8
Unnecessary math mode
echedey-ls May 23, 2024
9fa2bb4
Example suggestions and text trimming
echedey-ls May 23, 2024
1be1d3e
Merge branch 'main' into terrain-slope-mikofski-pr-1725
echedey-ls May 23, 2024
0d521ee
whatsmes
echedey-ls May 23, 2024
f01bd6f
Add test to fix coverage issue
echedey-ls May 23, 2024
946cca6
Apply suggestions from code review (Adam)
echedey-ls May 24, 2024
5e4bc7d
Update docs/examples/shading/plot_shaded_fraction1d_ns_hsat_example.py
kandersolar May 24, 2024
9a7d5b7
Merge branch 'main' into pr1725-continuation-shaded-fraction-mikofski
kandersolar May 24, 2024
7f1d549
Update docs/examples/shading/plot_shaded_fraction1d_ns_hsat_example.py
kandersolar May 24, 2024
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
Diff view
185 changes: 185 additions & 0 deletions docs/examples/shading/plot_shaded_fraction1d_ns_hsat_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
"""
shaded_fraction1d N-S horizontal single-axis example
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
====================================================

This example illustrates how to calculate the shaded fraction of three rows
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
in an N-S HSAT configuration.
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
"""

# %%
# :py:func:`pvlib.shading.shaded_fraction1d` exposes a useful method for the
# calculation of the shaded fraction of the width of a solar collector. Here,
# the width is defined as the dimension perpendicular to the axis of rotation.
# This method for calculating the shaded fraction also applies to fixed-tilt
# systems with little changes.
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
#
# Reading its documentation is recommended to understand the parameters and
# the method capabilities.
#
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
# Let's start by obtaining the true-tracking angles for each of the rows and
# limiting the angles to the range of -50 to 50 degrees. This decision is
# done to allow significant shade to be used as an example.
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
#
# Key functions used in this example are:
#
# 1. :py:func:`pvlib.tracking.singleaxis` to calculate the tracking angles.
# 2. :py:func:`pvlib.shading.projected_solar_zenith_angle` to calculate the
# projected solar zenith angle.
# 3. :py:func:`pvlib.shading.shaded_fraction1d` to calculate the shaded
# fractions.
#
# .. sectionauthor:: Echedey Luis <echelual (at) gmail.com>

import pvlib

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter

# Define the solar system parameters
latitude, longitude = 28.51, -13.89
altitude = pvlib.location.lookup_altitude(latitude, longitude)

axis_tilt = 3 # degrees
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment about what this represents?

Copy link
Contributor Author

@echedey-ls echedey-ls May 23, 2024

Choose a reason for hiding this comment

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

Let me know your opinion on axis_tilt = 3 # degrees, positive is upwards in the axis_azimuth direction (edit: already commited)

axis_azimuth = 180 # degrees
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
collector_width = 3.2 # m
pitch = 4.15 # m
gcr = collector_width / pitch
cross_axis_slope = -5 # degrees
AdamRJensen marked this conversation as resolved.
Show resolved Hide resolved
surface_to_axis_offset = 0.07 # m

# Generate a time range for the simulation
times = pd.date_range(
start="2024-01-01T05",
end="2024-01-01T21",
freq="5min",
tz="Atlantic/Canary",
)

# Calculate the solar position
solar_position = pvlib.solarposition.get_solarposition(
times, latitude, longitude, altitude
)
solar_azimuth = solar_position["azimuth"]
solar_zenith = solar_position["apparent_zenith"]

# Calculate the tracking angles
rotation_angle = pvlib.tracking.singleaxis(
solar_zenith,
solar_azimuth,
axis_tilt,
axis_azimuth,
max_angle=(-50, 50), # (min, max) degrees
backtrack=False,
gcr=gcr,
cross_axis_tilt=cross_axis_slope,
)["tracker_theta"]

# %%
# The next step is to calculate the shaded fraction. Special care must be taken
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
# to ensure that the shaded or shading tracker roles are correctly assigned
# depending on the solar position.
# This means we will have a result for each row, ``eastmost_shaded_fraction``,
# ``middle_shaded_fraction``, and ``westmost_shaded_fraction``.
# Switching the parameters will be based on the
# sign of :py:func:`pvlib.shading.projected_solar_zenith_angle`.
#
# The following code is verbose to make it easier to understand the process,
# but with some effort you may be able to simplify it. This verbosity also
# allows to change the premises easily per case, e.g., in case of a tracker
# failure or with a different system configuration.

psza = pvlib.shading.projected_solar_zenith_angle(
solar_zenith, solar_azimuth, axis_tilt, axis_azimuth
)

# Calculate the shaded fraction for the eastmost row
eastmost_shaded_fraction = np.where(
psza < 0,
0, # no shaded fraction in the morning
# shaded fraction in the evening
pvlib.shading.shaded_fraction1d(
solar_zenith,
solar_azimuth,
axis_azimuth,
shaded_row_rotation=rotation_angle,
axis_tilt=axis_tilt,
collector_width=collector_width,
pitch=pitch,
surface_to_axis_offset=surface_to_axis_offset,
cross_axis_slope=cross_axis_slope,
shading_row_rotation=rotation_angle,
),
)

# Calculate the shaded fraction for the middle row
middle_shaded_fraction = np.where(
psza < 0,
# shaded fraction in the morning
pvlib.shading.shaded_fraction1d(
solar_zenith,
solar_azimuth,
axis_azimuth,
shaded_row_rotation=rotation_angle,
axis_tilt=axis_tilt,
collector_width=collector_width,
pitch=pitch,
surface_to_axis_offset=surface_to_axis_offset,
cross_axis_slope=cross_axis_slope,
shading_row_rotation=rotation_angle,
),
# shaded fraction in the evening
pvlib.shading.shaded_fraction1d(
solar_zenith,
solar_azimuth,
axis_azimuth,
shaded_row_rotation=rotation_angle,
axis_tilt=axis_tilt,
collector_width=collector_width,
pitch=pitch,
surface_to_axis_offset=surface_to_axis_offset,
cross_axis_slope=cross_axis_slope,
shading_row_rotation=rotation_angle,
),
)

# Calculate the shaded fraction for the westmost row
westmost_shaded_fraction = np.where(
psza < 0,
# shaded fraction in the morning
pvlib.shading.shaded_fraction1d(
solar_zenith,
solar_azimuth,
axis_azimuth,
shaded_row_rotation=rotation_angle,
axis_tilt=axis_tilt,
collector_width=collector_width,
pitch=pitch,
surface_to_axis_offset=surface_to_axis_offset,
cross_axis_slope=cross_axis_slope,
shading_row_rotation=rotation_angle,
),
0, # no shaded fraction in the evening
)

# %%
# Plot the shaded fraction result per row
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
plt.plot(times, eastmost_shaded_fraction, label="East-most", color="blue")
plt.plot(
times,
middle_shaded_fraction,
label="Middle",
color="green",
linewidth=3,
linestyle="--",
)
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved
plt.plot(times, westmost_shaded_fraction, label="West-most", color="red")
plt.title(r"$shaded\_fraction1d$ of each row vs time")
plt.xlabel("Time")
plt.gca().xaxis.set_major_formatter(DateFormatter("%H:%M"))
plt.ylabel("Shaded Fraction")
plt.legend()
plt.show()

# %%
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ Shading
shading.masking_angle_passias
shading.sky_diffuse_passias
shading.projected_solar_zenith_angle
shading.shaded_fraction1d

4 changes: 4 additions & 0 deletions docs/sphinx/source/whatsnew/v0.10.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Deprecations

Enhancements
~~~~~~~~~~~~
* Added function :py:func:`pvlib.shading.shaded_fraction1d`, to calculate the
shade perpendicular to ``axis_azimuth``. (:issue:`1689`, :pull:`1725`, :pull:`1962`)
echedey-ls marked this conversation as resolved.
Show resolved Hide resolved


Bug fixes
Expand All @@ -35,3 +37,5 @@ Requirements
Contributors
~~~~~~~~~~~~
* Cliff Hansen (:ghuser:`cwhanse`)
* Mark Mikofski (:ghuser:`mikofski`)
* Echedey Luis (:ghuser:`echedey-ls`)
Loading
Loading