我正在尝试将对象的赤道坐标转换为给定时间和位置的alt-az坐标(希望)是在<5秒的运行时间中或更理想的是在<1秒的运行时间中。
在astropy tutorial for coordinate transformations之后,我设置了以下代码:
from astropy import units as u
from astropy.coordinates import SkyCoord,EarthLocation, AltAz
from astropy.time import Time
target = SkyCoord(9.81625*u.deg, 0.88806*u.deg, frame='icrs')
location = EarthLocation(lat='31d57.5m', lon='-111d35.8m', height=0*u.m)
obs_time = Time('2010-12-21 1:00')
alt_az_frame = AltAz(location=location, obstime=obs_time)
target_alt_az = target.transform_to(alt_az_frame)
print(target_alt_az.alt, target_alt_az.az)
这段代码需要20秒钟才能运行,几乎所有的代码都来自
target.transform_to(alt_az_frame)
行。是否有使用
transform_to
函数加速代码的更合适的方法,还是应该完全放弃使用astropy并从头开始编写代码?我了解SkyCoord
对象中内置了许多额外功能,而我可能不需要其中的许多功能-使用预先构建的标准化代码很方便。
最佳答案
经过一些调试后,似乎发生了这种情况,因为astropy.utils.iers.iers
的conf.iers_auto_url
是错误的URL。这是我为您解决的简单方法。
from astropy.utils.iers.iers import conf
# The desired url may change in the future
conf.iers_auto_url = 'ftp://cddis.gsfc.nasa.gov/pub/products/iers/finals2000A.all'
# Run your code here
另外,您可以执行
conf.remote_timeout = 0.1
或conf.auto_download = False
之类的操作(使用备份数据)。我找不到与此问题直接相关的文档,但阅读this page可能会有所帮助。 in the issue讨论了此问题。我认为此问题仅在某些版本的库中发生,因此将库更新为最新版本可能是一种解决方案。
关于python - 将赤道转换为alt-az坐标非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60305302/