PyEphem日出和日落时间错误(python)

PyEphem日出和日落时间错误(python),python,time,pyephem,Python,Time,Pyephem,我在使用pyEphem获取我所在位置的准确日出和日落时间时遇到了一些困难。我已经阅读了一些问题和答案,并查看了文档,但仍然不完全清楚我做错了什么。代码如下: import datetime as dt import ephem as ep date = dt.datetime.now().strftime("%Y/%m/%d 00:00:00") lat, lon = [<redacted>, -1.4147] # Use lat and lon to create ephem

我在使用pyEphem获取我所在位置的准确日出和日落时间时遇到了一些困难。我已经阅读了一些问题和答案,并查看了文档,但仍然不完全清楚我做错了什么。代码如下:

import datetime as dt
import ephem as ep

date = dt.datetime.now().strftime("%Y/%m/%d 00:00:00")
lat, lon = [<redacted>, -1.4147]

# Use lat and lon to create ephem observer instance and update with given
# values
my_location = ep.Observer()
my_location.lat = lat
my_location.lon = lon
my_location.date = date

# Get sunrise of the current day
sunrise = my_location.next_rising(ep.Sun())
sunset = my_location.next_setting(ep.Sun())

print "Given date: {0}".format(date)
print "Detected coordinates: {0}, {1}".format(lat, lon)
print "Sunrise at {0}".format(sunrise)
print " Sunset at {0}".format(sunset)
将日期时间导入为dt
作为ep导入以弗所
date=dt.datetime.now().strftime(“%Y/%m/%d 00:00:00”)
纬度,经度=[,-1.4147]
#使用lat和lon创建ephem observer实例,并使用给定的
#价值观
我的位置=ep.Observer()
my_location.lat=lat
my_location.lon=lon
my_location.date=日期
#获取当天的日出
日出=我的位置。下一个日出(ep.Sun())
日落=我的位置。下一个设置(ep.Sun())
打印“给定日期:{0}”。格式(日期)
打印“检测到的坐标:{0},{1}”。格式(lat,lon)
打印“日出在{0}”。格式(日出)
打印“日落在{0}”。格式(日落)
这将产生以下输出:

Given date: 2015/01/31 00:00:00
Detected coordinates: <redacted>, -1.4147
Sunrise at 2015/1/31 12:28:02
 Sunset at 2015/1/31 22:47:39
给定日期:2015/01/31 00:00:00
检测到的坐标:,-1.4147
2015/1/31 12:28:02日出
2015/1/31 22:47:39日落
我所期望的是得到午夜后第一次日出(今天早上)和之后第一次日落的时间。现在我碰巧知道太阳在今天12:30之前升起(我在光天化日之下上午9:30在路上行走),我不认为有UTC偏移,因为我知道我的时区


我遗漏了什么?

如果您提供经度和纬度作为原始浮点数,那么PyEphem假设您已经完成了将它们转换为弧度的工作。1.4147弧度的值几乎是地球的八分之一。如果希望PyEphem为您转换度,请尝试使用字符串来表示度,而不是强制PyEphem转换:

lat, lon = [<redacted>, '-1.4147']
观察者
对象打印出其值是确定其设置是否正确的最佳方法


您会注意到,新的Skyfield库从PyEphem的错误中吸取了教训,它根本不进行自动转换,而是要求将值明确指定为弧度或度

您的输出中似乎出现了UTC时间偏移。虽然我确实生活在UTC+00,但似乎确实如此。这可能会有所帮助,尤其是“observer.horizon”示例也相关-日期也应以UTC(或UT1)为单位(
datetime.utcnow()
ephem.now()
),不是本地时区(
.now()
是不正确的,除非本地时区是UTC)。啊,好的,所以我需要用弧度而不是度数将角度传递到pyephem中?我没有意识到,因为皮耶芬通常以度为单位打印角度。谢谢,我稍后会测试这个,看看它是否解决了我的问题。另外,@J.F.Sebastian谢谢你,但我已经和其他评论者讨论过了:我知道我在哪个时区。
print my_location.lat
print my_location.lon