You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected behaviour with sun_rise_set_transit_spa #2833
Describe the bug
This may be related to #2238, #2820. For some longitudes pvlib.solarposition.sun_rise_set_transit_spa returns sunrise and sunset times that are on the same day, but for other latitudeslongitudes, the sunset time is shifted one day later. I don't think this is expected, but maybe I'm missing something?
I see the same behavior with pvlib 0.15.2 and 0.15.3a1, which I think should include the fix from #2820.
I can reproduce the issue. Note that the issue says "latitude" several places where you meant "longitude."
I'll gripe a little bit that these sunrise/sunset functions have been trouble enough that I would entertain the idea of simply dropping them, and replacing with a purely geometric calculation.
Note that the issue says "latitude" several places where you meant "longitude."
Thanks, I updated the issue.
I would entertain the idea of simply dropping them, and replacing with a purely geometric calculation.
I'm not sure what the pros and cons would be there, but for some additional context, I only just now started experimenting with sun_rise_set_transit_spa because I'm looking for a solution to this: pvlib/solposx#153.
Not having a way to elegantly/flexibly handle intervals where sunrise/sunset occur, particularly when the sun is below the horizon at the midpoint of the interval, seems like a relatively large gap in pvlib compared to common industry tools. I'm not sure if that feedback is helpful in relation to keeping/dropping these functions...
Edit: I previously posted a "fix" here, but I was misunderstanding things. Don't use what I suggested... (I think you can view the comment history if you are curious...)
In the case of spa.transit_sunrise_sunset the code was ported from NREL software, so it retains the behavior of that software, unless pvlib has wandered off trying to fix these day boundary issues.
The SPA calculator behaves similarly to what the pvlib code does now: using latitude 40, longitude -110, it returns a sunset time of 0.0736 (hours) for 1/1/2020. Although sunset time isn't dated, I'm fairly sure its supposed to be after sunrise, so that would be 1/2/2020, same as the current pvlib.
NREL SPA calculator returns sunset at 23.42 hours at 40, -100, and at 0.0736 hours at 40, -110. The calculator only returns times, not full datetimes. Its behavior is the same as pvlib. https://midcdmz.nlr.gov/solpos/spa.html
Ok, I understand this now. For the second location, sunset is simply ~40 minutes later, so shows up on the next calendar day (UTC time). Not sure why I didn't follow that yesterday. Closing this issue.
Maybe the issue should be re-named to “I don’t understand how this function is supported to work” 😅
On a more serious note, maybe the docs need to be updated somehow? Alternatively, feel free to close this if you don’t think there’s anything needed.
IMO the most valuable changes can only be provided by you in this case. Maybe the example you are running and it's meaning of the output are good additions too.
Feel free to open a PR.
Cross-posting the same comment I added to pvlib/solposx#153, that covers what I was trying to eventually do with sun_rise_set_transit_spa:
I put together a long notebook in a gist that does a few things:
approximates sunrise/sunset times with linear interpolation
tests the accuracy of that approximation (seems pretty good to me)
calculates the midpoint for the period where the sun is up
calculates the fraction of the original interval that the sun was up (e.g., for hour intervals, if sunrise was 8:40, "sunup" fraction is 20/60 = 0.333)
illustrates how this is all useful for clear sky insolation (average irradiance) and decomposition applications
I'd like to see features 3 and 4 above in some public package (pvlib or solposx) one day. Feedback/suggestions welcome. I could also move this conversation somewhere else (pvlib discussions?).
Activity
cwhanse commentedon Jul 23, 2026
I can reproduce the issue. Note that the issue says "latitude" several places where you meant "longitude."
I'll gripe a little bit that these sunrise/sunset functions have been trouble enough that I would entertain the idea of simply dropping them, and replacing with a purely geometric calculation.
williamhobbs commentedon Jul 23, 2026
Thanks, I updated the issue.
I'm not sure what the pros and cons would be there, but for some additional context, I only just now started experimenting with
sun_rise_set_transit_spabecause I'm looking for a solution to this: pvlib/solposx#153.Not having a way to elegantly/flexibly handle intervals where sunrise/sunset occur, particularly when the sun is below the horizon at the midpoint of the interval, seems like a relatively large gap in pvlib compared to common industry tools. I'm not sure if that feedback is helpful in relation to keeping/dropping these functions...
williamhobbs commentedon Jul 23, 2026
Edit: I previously posted a "fix" here, but I was misunderstanding things. Don't use what I suggested... (I think you can view the comment history if you are curious...)
cwhanse commentedon Jul 23, 2026
In the case of
spa.transit_sunrise_sunsetthe code was ported from NREL software, so it retains the behavior of that software, unless pvlib has wandered off trying to fix these day boundary issues.The SPA calculator behaves similarly to what the pvlib code does now: using latitude 40, longitude -110, it returns a sunset time of 0.0736 (hours) for 1/1/2020. Although sunset time isn't dated, I'm fairly sure its supposed to be after sunrise, so that would be 1/2/2020, same as the current pvlib.
williamhobbs commentedon Jul 23, 2026
What does the SPA calculator return for 40, -100? Or more specifically, is it consistent with 40, -110?
cwhanse commentedon Jul 24, 2026
NREL SPA calculator returns sunset at 23.42 hours at 40, -100, and at 0.0736 hours at 40, -110. The calculator only returns times, not full datetimes. Its behavior is the same as pvlib. https://midcdmz.nlr.gov/solpos/spa.html
williamhobbs commentedon Jul 24, 2026
Thanks.
Maybe the issue should be re-named to “I don’t understand how this function is supported to work” 😅
On a more serious note, maybe the docs need to be updated somehow? Alternatively, feel free to close this if you don’t think there’s anything needed.
williamhobbs commentedon Jul 24, 2026
Ok, I understand this now. For the second location, sunset is simply ~40 minutes later, so shows up on the next calendar day (UTC time). Not sure why I didn't follow that yesterday. Closing this issue.
echedey-ls commentedon Jul 24, 2026
IMO the most valuable changes can only be provided by you in this case. Maybe the example you are running and it's meaning of the output are good additions too.
Feel free to open a PR.
cwhanse commentedon Jul 24, 2026
These functions would very much benefit from an example showing the behavior that tripped you up.
williamhobbs commentedon Sep 11, 2026
Cross-posting the same comment I added to pvlib/solposx#153, that covers what I was trying to eventually do with
sun_rise_set_transit_spa:I put together a long notebook in a gist that does a few things:
Here it is: https://gist.github.com/williamhobbs/83d8db79b31ff0986a0ab4d5c5ed70d0.
I'd like to see features 3 and 4 above in some public package (pvlib or solposx) one day. Feedback/suggestions welcome. I could also move this conversation somewhere else (pvlib discussions?).