I’m considering making a fairly significant change to this integration, and releasing it as 4.0.0 (which would include what I was doing with the 3.4.4 beta.)
When you boil it done, the astral package really has two (effectively inverse) functions: time_at_elevation & solar_elevation (which could also be called elevation_at_time.) The problem, as I’ve noted before, is that these two functions don’t agree very well, probably due to lack of precision or simplifications. E.g.,
solar_elevation(time_at_elevation(X)) != X
Or, to put that another way, the difference between X and solar_elevation(time_at_elevation(X)) is often noticeable.
So, for various sensors, I chose not to use time_at_elevation (for the most part), but rather implemented a (rather crude) method of “searching” the curve resulting from the solar_elevation method for the time that would result in a particular elevation value. The idea was to make sensors that report a time at a given elevation agree with the solar elevation curve.
However, this implementation has two significant problems.
First, many of the astral package’s “built in” methods (such as sunrise, sunset, dawn, dusk, etc.) that are used for many of sun2’s sensors effectively use time_at_elevation (really its underlying method, time_of_transit, that does the grunt work.) So, they generally don’t agree with the solar elevation “curve” (and, hence, the elevation sensor.)
Second, the implementation that “searches” the “elevation curve” is overly complex. Since it’s been around for quite a while, and used by many people, I feel it generally “works”, but still, it probably uses too much CPU time, etc.
So, bottom line, I’m thinking about getting rid of the whole “search the elevation curve” implementation and replacing it with a simple call to time_at_elevation instead.
On the plus side, that would make sensors generally agree, as well as reduce code complexity and CPU usage.
On the negative side, the time_at_elevation method can sometimes return no result (i.e., indicating the sun never reaches that elevation on the given day), when the solar_elevation method for that day would return that elevation value (at some point during that day.)
Anyway, I haven’t completely decided yet, and if I do this, it will take some time, so don’t expect a 4.0.0 beta any time soon.
Mostly, I’m curious what people think about this. Should I do it or not?