aman-thakral / astral

Calculations for the position of the sun and moon. Cythonized version of Simon Kennedy's original astral.
http://pypi.python.org/pypi/astral/0.5
Apache License 2.0
3 stars 0 forks source link

solar_azimuth and solar_elevation may produce incorrect results #1

Open jmpnop opened 9 years ago

jmpnop commented 9 years ago

the following calculation in solar_azimuth method:
zone = -dateandtime.utcoffset().seconds / 3600.0

for dateandtime = "31/12/2014 17:55:50" in timezone "US/Eastern" zone should be 5, but it's -19 which seems to be incorrect

aman-thakral commented 9 years ago

I haven't really looked at this code in quite some time. I will try to take a look at it soon. Would you be open to writing a unit test (or a couple) that I can work against to fix the error?

Thanks!

jmpnop commented 9 years ago

Ok, here is the test case:

astral = Astral() location = Location(["Boston","USA","42°21'N","71°03'W","US/Eastern","6"]) tz = pytz.timezone("US/Eastern") dt = datetime.datetime(2014, 12, 31, 11, 41, 30, 0, tz) solar_azimuth = astral.solar_azimuth(dt, location.latitude, location.longitude)

if you step into solar_azimuth call, at line 1505 there is a calculation which may be (I am new to astronomical calculations) incorrect, so I just wanted to bring it to your attention as I may not fully understand the logic:

zone = -dateandtime.utcoffset().seconds / 3600.0

the result for the above case is -19, while it should be (in my opinion) +5 (US/Eastern time zone has a 5 hour difference with UTC), unless I am missing what zone variable represents..

aman-thakral commented 9 years ago

I looked at your test, and it seems that the code is giving the correct output. This code was adapted from the original astral package (https://launchpad.net/astral) a number of years ago. The calculation appears to be correct. The only difference in the code is the performance improvements. I think the variable zone seems to be a named poorly. From what I've found, it is used to correct the solar time.