Skip to content
Open
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
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.16.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Bug fixes
~~~~~~~~~
* :py:func:`pvlib.tracking.calc_surface_orientation` returns scalar when input
is scalar (:issue:`2881`, :pull:`2882`)
* Fix :py:func:`pvlib.solarposition.solar_azimuth_analytical` returning south
instead of north at solar noon.

Enhancements
~~~~~~~~~~~~
Expand Down Expand Up @@ -62,6 +64,7 @@ Contributors
* Chen Yi (:ghuser:`chenyi6758-source`)
* Rajiv Daxini (:ghuser:`rdaxini`)
* jason-writer (:ghuser:`jason-writer`)
* :ghuser:`vera-rubin`



3 changes: 3 additions & 0 deletions pvlib/solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,9 @@ def solar_azimuth_analytical(latitude, hourangle, declination, zenith):
with np.errstate(invalid='ignore'):
sign_ha = np.sign(hourangle)

# At solar noon, use the morning branch so that north is zero radians.
sign_ha = sign_ha - 1.0 * (sign_ha == 0)

return sign_ha * np.arccos(cos_azi) + np.pi


Expand Down
16 changes: 16 additions & 0 deletions tests/test_solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,22 @@ def test_analytical_azimuth():
assert not np.isnan(azimuths).any()


@pytest.mark.parametrize('latitude,declination,expected', [
(-35., 0., 0.),
(35., 0., 180.),
(10., 20., 0.),
])
@pytest.mark.parametrize('hourangle', [
0., -0., np.array([0.]), np.array([-0.]), pd.Series([0., -0.]),
])
def test_analytical_azimuth_noon(latitude, declination, expected, hourangle):
# At noon, the sun is due north if declination exceeds latitude.
zenith = np.radians(abs(latitude - declination))
azimuth = solarposition.solar_azimuth_analytical(
np.radians(latitude), hourangle, np.radians(declination), zenith)
assert_allclose(azimuth, np.radians(expected), atol=1e-8)


def test_hour_angle():
"""
Test conversion from hours to hour angles in degrees given the following
Expand Down
Loading