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
Probably a good idea, though it's not likely to happen as part of that PR. Are you aware of the get_sun_rise_set_transit function? It returns both sunrise and sunset. I'm less interested in get_dayduration since I think it's less likely to be used and it can easily be calculated if needed (though not totally opposed to it).
All that being said, I've found that filtering using zenith or elevation angle is usually a better approach.
I'm in need of this functionality, and am looking for opinions about implementation. I'd prefer methods attached to a PVsystem or Location object that mimic pyephem, e.g., Location.get_sunrise(date), Location.get_next_sunrise(datetime).
Currently get_sun_rise_set_transit runs solarposition.spa and returns sunrise, sunset and transit. #316 describes some odd behavior of get_sun_rise_set_transit and ideas about fixing it. Alternatively, we could request sunrise etc. from solarposition.spa (which is what get_sun_rise_set_transit is doing) or use solarposition.pyphem by adding a call to the appropriate method of the Sun object.
I'd like to avoid a workflow that calculates ephemeris twice (once to get solar position, and again to get sunrise and sunset), which is what happens with the current get_sun_rise_set_transit.
when I fixed the timezone bug in spa, I changed the SPA function code to SPA_ALL which calculates sunrise, sun-transit, and sunset times, so if it's not implemented in the numpy version of spa, you could use the NREL C version
I think sunrise/set is a perfect use for the analytical zenith function, just find where it equals zero, either using a solver, or by solving it analytically:
Location still seems like an appropriate place for this functionality.
Sorry if I'm picking at a typo, but so we're all on the same page...
there is no solarposition.spa.
pvlib.solarposition.spa_python() and pvlib.solarposition.get_sun_rise_set_transit() each import pvlib.spa by calling pvlib.solarposition._spa_python_import(). This allows for optional numba support that would not be possible using the standard imports at the top of pvlib.solarposition.
pvlib.solarposition.get_sun_rise_set_transit is a wrapper around pvlib.spa.transit_sunrise_sunset.
I'd like to avoid a workflow that calculates ephemeris twice (once to get solar position, and again to get sunrise and sunset), which is what happens with the current get_sun_rise_set_transit.
I'm not sure how avoid two different functions because it seems that they do two different things. A function to calculate sunrise/sunset should accept a date and return a collection of datetimes. A function to calculate solar position should accept a datetime and return a collection of angles. I'm having a hard time thinking outside of this box.
In any case, the get_sun_rise_set_transit function could certainly be modified to use either pyephem or pvlib.spa or an analytical solution (controllable by a kwarg). We'd want to make the API consistent for all of the methods.
Assuming it holds water, I'm curious how much more performant the above analytical solution might be. Perhaps it could be added as one of the how options to get_sun_rise_set_transit() as part of the proposed addition the to the Location API?
Your formula matches the one in my Vignola book. Maybe the SPA version gives you apparent zenith == 90?
On the rare occasions when I need sunrise/sunset times I usually have a time series of some sort I'm working with, and just interpolate the timestamp for apparent_zenith == 90. But most of the time I'm happy filtering on apparent_zenith > 90.
Sorry if I'm picking at a typo, but so we're all on the same page...
You're not, and thanks.
pvlib.solarposition.spa_python() and pvlib.solarposition.get_sun_rise_set_transit() each import pvlib.spa by calling pvlib.solarposition._spa_python_import(). This allows for optional numba support that would not be possible using the standard imports at the top of pvlib.solarposition.
This is important and I had missed this.
pvlib.solarposition.get_sun_rise_set_transit is a wrapper around pvlib.spa.transit_sunrise_sunset.
Right. Now that I look at the spa module it is clear that we won't calculate the ephemeris twice (which I had in mind when I was considering an earlier suggestion that sunrise/sunset are based on zenith, then mistakenly transposed that idea to the spa and pyephem functions).
I'm not sure how avoid two different functions because it seems that they do two different things. A function to calculate sunrise/sunset should accept a date and return a collection of datetimes. A function to calculate solar position should accept a datetime and return a collection of angles. I'm having a hard time thinking outside of this box.
@adriesse I knew the analytical functions don't account for atmospheric refraction, I just didn't realize it would be so large. Visibly the largest difference in zenith to me appears at noon, but it makes sense that refraction would be larger when the angle is greatest, ie sunrise/sunset. Always learning, thanks! @cwhanse glad you can get what you need from spa
Activity
wholmgren commentedon Jan 21, 2016
Probably a good idea, though it's not likely to happen as part of that PR. Are you aware of the get_sun_rise_set_transit function? It returns both sunrise and sunset. I'm less interested in
get_daydurationsince I think it's less likely to be used and it can easily be calculated if needed (though not totally opposed to it).All that being said, I've found that filtering using zenith or elevation angle is usually a better approach.
cwhanse commentedon Sep 18, 2018
I'm in need of this functionality, and am looking for opinions about implementation. I'd prefer methods attached to a
PVsystemorLocationobject that mimicpyephem, e.g.,Location.get_sunrise(date),Location.get_next_sunrise(datetime).Currently
get_sun_rise_set_transitrunssolarposition.spaand returns sunrise, sunset and transit. #316 describes some odd behavior ofget_sun_rise_set_transitand ideas about fixing it. Alternatively, we could request sunrise etc. fromsolarposition.spa(which is whatget_sun_rise_set_transitis doing) or usesolarposition.pyphemby adding a call to the appropriate method of the Sun object.I'd like to avoid a workflow that calculates ephemeris twice (once to get solar position, and again to get sunrise and sunset), which is what happens with the current
get_sun_rise_set_transit.Thoughts?
mikofski commentedon Sep 18, 2018
couple of ideas
when I fixed the timezone bug in spa, I changed the SPA function code to
SPA_ALLwhich calculates sunrise, sun-transit, and sunset times, so if it's not implemented in the numpy version of spa, you could use the NREL C versionI think sunrise/set is a perfect use for the analytical zenith function, just find where it equals zero, either using a solver, or by solving it analytically:
so
or
Is that right?
wholmgren commentedon Sep 19, 2018
Locationstill seems like an appropriate place for this functionality.Sorry if I'm picking at a typo, but so we're all on the same page...
solarposition.spa.pvlib.solarposition.spa_python()andpvlib.solarposition.get_sun_rise_set_transit()each importpvlib.spaby callingpvlib.solarposition._spa_python_import(). This allows for optional numba support that would not be possible using the standard imports at the top ofpvlib.solarposition.pvlib.solarposition.get_sun_rise_set_transitis a wrapper aroundpvlib.spa.transit_sunrise_sunset.I'm not sure how avoid two different functions because it seems that they do two different things. A function to calculate sunrise/sunset should accept a date and return a collection of datetimes. A function to calculate solar position should accept a datetime and return a collection of angles. I'm having a hard time thinking outside of this box.
In any case, the
get_sun_rise_set_transitfunction could certainly be modified to use eitherpyephemorpvlib.spaor an analytical solution (controllable by a kwarg). We'd want to make the API consistent for all of the methods.mikofski commentedon Sep 19, 2018
Silly me, sunset/rise is at zenith of
pi/2not zero, comments above correctedmarkcampanelli commentedon Sep 19, 2018
Assuming it holds water, I'm curious how much more performant the above analytical solution might be. Perhaps it could be added as one of the
howoptions toget_sun_rise_set_transit()as part of the proposed addition the to the Location API?mikofski commentedon Sep 19, 2018
i guess it seems to work, if I compare it to the online spa calculator I get nearly the correct sunrise/sunset times:
It's about 6 minute difference 😦
mikofski commentedon Sep 19, 2018
Maybe I should've tried the other declination or eoq formulas?
adriesse commentedon Sep 19, 2018
Your formula matches the one in my Vignola book. Maybe the SPA version gives you apparent zenith == 90?
On the rare occasions when I need sunrise/sunset times I usually have a time series of some sort I'm working with, and just interpolate the timestamp for
apparent_zenith == 90. But most of the time I'm happy filtering onapparent_zenith > 90.cwhanse commentedon Sep 19, 2018
You're not, and thanks.
This is important and I had missed this.
Right. Now that I look at the spa module it is clear that we won't calculate the ephemeris twice (which I had in mind when I was considering an earlier suggestion that sunrise/sunset are based on zenith, then mistakenly transposed that idea to the spa and pyephem functions).
We're in the same box.
mikofski commentedon Sep 19, 2018
@adriesse I knew the analytical functions don't account for atmospheric refraction, I just didn't realize it would be so large. Visibly the largest difference in zenith to me appears at noon, but it makes sense that refraction would be larger when the angle is greatest, ie sunrise/sunset. Always learning, thanks! @cwhanse glad you can get what you need from spa