Skip to content

Fix2448 #2485

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Fix2448 #2485

Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 24 additions & 10 deletions docs/sphinx/source/user_guide/extras/nomenclature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ There is a convention on consistent variable names throughout the library:

aoi
Angle of incidence. Angle between the surface normal vector and the
vector pointing towards the sun’s center
vector pointing towards the sun's center. Must be >=0 and <=180 degrees.
Copy link
Member

Choose a reason for hiding this comment

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

Must be >=0 and <=180 degrees.

I'm mildly opposed to including this range description. I don't think that pvlib functions require that constraint. It is certainly not checked for the user. And I don't think that pvlib promises useful results if aoi falls in that range.

Is the intent here to inform a user of the usual range for this quantity? If so, and we agree to add a statement about "typical" ranges, then I don't think we should use the verb "must".

@pvlib/pvlib-maintainer please weigh in.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Cliff. I don’t think this constraint is necessary. A scan of the irradiance.py module yields the following functions with aoi as an argument:

  • poa_components has a note that says if AOI is negative or >90° then components would be zero…

Negative beam irradiation due to aoi :math:`> 90^{\circ}` or AOI

… but this is incorrect according to the code. It will only be zero if < -90° or >90°

poa_direct = np.maximum(dni * np.cos(np.radians(aoi)), 0)

  • gti_dirint has two subfunctions that depend on whether AOI is greater than or less than 90° which I think is a bug 🐞 and probable should read if abs(AOI) < 90

aoi_lt_90 = aoi < 90

If not a bug 🐞 then it seems to me that AOI is assumed to be in the range of [0, 180] but then it’s still a a bug 🐞 because AFAICT this is never enforced

  • iam.py also uses AOI for example in ASHRAE, it clearly limits abs(AOI) < 90

np.greater_equal(np.abs(aoi), 90, where=~np.isnan(aoi), out=aoi_gte_90)

Anyway, I suggest continue searching through the code, and find out what it actually says because it seems to me like there may be different assumptions

Copy link
Member

Choose a reason for hiding this comment

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

@OmarBahamida to let this PR move ahead without getting really involved, let's leave out any statements about a range of values.

When the sun is behind the surface, the value is >90 degrees.

aoi_projection
cos(aoi)
cos(aoi). When the sun is behind the surface, the value is negative.
For many uses, negative values must be set to zero.

ape
Average photon energy

apparent_zenith
Refraction-corrected solar zenith angle in degrees
Refraction-corrected solar zenith angle in degrees. Must be >=0 and <=180.
This angle accounts for atmospheric refraction effects.

apparent_elevation
Refraction-corrected solar elevation angle in degrees. Must be >=-90 and <=90.
This is the complement of apparent_zenith (90 - apparent_zenith).

bhi
Beam/direct horizontal irradiance
Expand Down Expand Up @@ -87,10 +94,10 @@ There is a convention on consistent variable names throughout the library:
Sandia Array Performance Model IV curve parameters

latitude
Latitude
Latitude in decimal degrees. Positive north of equator, negative to south.

longitude
Longitude
Longitude in decimal degrees. Positive east of prime meridian, negative to west.

pac, ac
AC power
Expand Down Expand Up @@ -141,10 +148,14 @@ There is a convention on consistent variable names throughout the library:
Diode saturation current

solar_azimuth
Azimuth angle of the sun in degrees East of North
Azimuth angle of the sun in degrees East of North. Must be >=0 and <=360.
The convention is defined as degrees east of north (e.g. North = 0°,
East = 90°, South = 180°, West = 270°).

solar_zenith
Zenith angle of the sun in degrees
Zenith angle of the sun in degrees. Must be >=0 and <=180.
This is the angle between the sun's rays and the vertical direction.
This is the complement of :term:`solar_elevation` (90 - elevation).

spectra
spectra_components
Expand All @@ -154,11 +165,14 @@ There is a convention on consistent variable names throughout the library:
is composed of direct and diffuse components.

surface_azimuth
Azimuth angle of the surface
Azimuth angle of the surface in degrees East of North. Must be >=0 and <=360.
The convention is defined as degrees east (clockwise) of north. This is pvlib's
convention; other tools may use different conventions. For example, North = 0°,
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving the sentence, "For example, North...", before the sentence, "This is pvlib's convention...".

As it is, I interpret the example as an example of some other tool's convention, not as an example of pvlib's convention.

East = 90°, South = 180°, West = 270°.

surface_tilt
Panel tilt from horizontal [°]. For example, a surface facing up = 0°,
surface facing horizon = 90°.
Panel tilt from horizontal [°]. Must be >=0 and <=180.
For example, a surface facing up = 0°, surface facing horizon = 90°.

temp_air
Temperature of the air
Expand Down
56 changes: 56 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Simple pvlib demonstration script
import pvlib
import pandas as pd
from datetime import datetime, timedelta
import matplotlib.pyplot as plt

# Create a location object for a specific site
location = pvlib.location.Location(
latitude=40.0, # New York City latitude
longitude=-74.0, # New York City longitude
tz='America/New_York',
altitude=10 # meters above sea level
)

# Calculate solar position for a day
date = datetime(2024, 3, 15)
times = pd.date_range(date, date + timedelta(days=1), freq='1H', tz=location.tz)
solpos = location.get_solarposition(times)

# Plot solar position
plt.figure(figsize=(10, 6))
plt.plot(solpos.index, solpos['elevation'], label='Elevation')
plt.plot(solpos.index, solpos['azimuth'], label='Azimuth')
plt.title('Solar Position for New York City on March 15, 2024')
plt.xlabel('Time')
plt.ylabel('Angle (degrees)')
plt.legend()
plt.grid(True)
plt.show()

# Calculate clear sky irradiance
clearsky = location.get_clearsky(times)

# Plot clear sky irradiance
plt.figure(figsize=(10, 6))
plt.plot(clearsky.index, clearsky['ghi'], label='Global Horizontal Irradiance')
plt.plot(clearsky.index, clearsky['dni'], label='Direct Normal Irradiance')
plt.plot(clearsky.index, clearsky['dhi'], label='Diffuse Horizontal Irradiance')
plt.title('Clear Sky Irradiance for New York City on March 15, 2024')
plt.xlabel('Time')
plt.ylabel('Irradiance (W/m²)')
plt.legend()
plt.grid(True)
plt.show()

# Print some basic information
print("\nSolar Position at Solar Noon:")
noon_idx = solpos['elevation'].idxmax()
print(f"Time: {noon_idx}")
print(f"Elevation: {solpos.loc[noon_idx, 'elevation']:.2f}°")
print(f"Azimuth: {solpos.loc[noon_idx, 'azimuth']:.2f}°")

print("\nMaximum Clear Sky Irradiance:")
print(f"GHI: {clearsky['ghi'].max():.2f} W/m²")
print(f"DNI: {clearsky['dni'].max():.2f} W/m²")
print(f"DHI: {clearsky['dhi'].max():.2f} W/m²")
47 changes: 47 additions & 0 deletions tests/test_solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,3 +964,50 @@ def test_spa_python_numba_physical_dst(expected_solpos, golden):
temperature=11, delta_t=67,
atmos_refract=0.5667,
how='numpy', numthreads=1)


def test_solar_angles_spring_equinox():
"""Test solar angles for New York City on spring equinox.

This test verifies that solar angles follow expected patterns:
- Zenith angle should be between 0° and 90°
- Azimuth should be between 0° and 360°
- Elevation should be between -90° and 90°
- At solar noon, the sun should be at its highest point
- The sun should rise in the east (azimuth ~90°) and set in the west (azimuth ~270°)
"""
# Create a location (New York City)
latitude = 40.7128
longitude = -74.0060
tz = 'America/New_York'
location = Location(latitude, longitude, tz=tz)

# Create a time range for one day
start = pd.Timestamp('2024-03-20', tz=tz) # Spring equinox
times = pd.date_range(start=start, periods=24, freq='h') # Use 'h' for hourly

# Calculate solar position
solpos = location.get_solarposition(times)

# Test morning (9 AM)
morning = solpos.loc['2024-03-20 09:00:00-04:00']
assert 0 <= morning['zenith'] <= 90
assert 0 <= morning['azimuth'] <= 360
assert -90 <= morning['elevation'] <= 90
assert 90 <= morning['azimuth'] <= 180 # Sun should be in southeast

# Test solar noon (clock noon)
noon = solpos.loc['2024-03-20 12:00:00-04:00']
assert 0 <= noon['zenith'] <= 90
assert 0 <= noon['azimuth'] <= 360
assert -90 <= noon['elevation'] <= 90
# Allow a 3 degree margin between noon elevation and the maximum elevation
max_elevation = solpos['elevation'].max()
assert abs(noon['elevation'] - max_elevation) < 3.0 # Allow 3 degree difference

# Test evening (3 PM)
evening = solpos.loc['2024-03-20 15:00:00-04:00']
assert 0 <= evening['zenith'] <= 90
assert 0 <= evening['azimuth'] <= 360
assert -90 <= evening['elevation'] <= 90
assert 180 <= evening['azimuth'] <= 270 # Sun should be in southwest