sffjunkie / astral

Python calculations for the position of the sun and moon.
Apache License 2.0
237 stars 47 forks source link

Sunrise time calculation error #81

Open tz850 opened 1 year ago

tz850 commented 1 year ago

version 3.2

I used latitude 39.3528 and longitude 106.7333 to calculate the sunrise and sunset times for the whole year of 2015, starting on February 3, 2015, the calculated sunrise time was later than the sunset time, and this was the case until December 7, 2015.

my code:

lat_station_val = 39.35277777777778
lon_station_val = 106.73333333333333

location_staion9 = LocationInfo('shizuishan','china','Asia/Shanghai',lat_station_val,lon_station_val)

data_file = open("result.csv", 'w') 
data_file.write("date,sunrise,sunset\n")

start_date = date(2015, 1, 1)
for i in range(0,365):
    delta=timedelta(days=i)
    cal_date = start_date + delta

    s = sun(location_staion9.observer, date=cal_date)
    utc_sunrise = s["sunrise"]
    utc_sunset = s["sunset"]

    data_file.write("{},{},{}\n".format(cal_date.strftime('%Y-%m-%d'), utc_sunrise.strftime('%Y-%m-%d %H:%M:%S'), utc_sunset.strftime('%Y-%m-%d %H:%M:%S')))

the result:

2015-01-28,2015-01-28 00:04:28,2015-01-28 10:07:44
2015-01-29,2015-01-29 00:03:41,2015-01-29 10:08:55
2015-01-30,2015-01-30 00:02:52,2015-01-30 10:10:06
2015-01-31,2015-01-31 00:02:01,2015-01-31 10:11:16
2015-02-01,2015-02-01 00:01:08,2015-02-01 10:12:27
2015-02-02,2015-02-02 00:00:14,2015-02-02 10:13:38
**2015-02-03,2015-02-03 23:58:20,2015-02-03 10:14:49**
2015-02-04,2015-02-04 23:57:21,2015-02-04 10:16:00
2015-02-05,2015-02-05 23:56:20,2015-02-05 10:17:11
2015-02-06,2015-02-06 23:55:18,2015-02-06 10:18:21
2015-02-07,2015-02-07 23:54:14,2015-02-07 10:19:32
2015-02-08,2015-02-08 23:53:09,2015-02-08 10:20:42
2015-02-09,2015-02-09 23:52:02,2015-02-09 10:21:53
2015-02-10,2015-02-10 23:50:54,2015-02-10 10:23:03
2015-02-11,2015-02-11 23:49:45,2015-02-11 10:24:13