将赤道坐标转换为 alt-az 坐标非常慢
Converting equatorial to alt-az coordinates is very slow
我正在尝试将对象的赤道坐标转换为给定时间和位置的 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 may help. This problem was discussed in the issue。我认为这个问题只发生在某些版本的库中,因此将库更新到最新版本可能是一个解决方案。
如果您正在寻找快速转换为 alt-az 的工具,那么 Astropy 可能不是最好的工具。 Celest 库可以在很短的时间内完成从 ECI 和 ECEF 坐标系到高度和方位角的转换(尽管它不处理赤道转换)。也许您可以使用 astropy 转换为 ECI,并使用 Celest 进行水平转换。请注意,此库应用了一些简化,但仍然非常准确。
下面的代码应该可以解决问题。
from celest import Satellite, GroundPosition
import numpy as np
UTCTimeData = np.array(['2020-06-01 12:00:00.0340', ..., '2020-06-01 12:01:00.0340'])
ECIvec = np.array([[-4.46e+03, -5.22e+03, 1.75e-04], ..., [2.73e+03, 2.08e+03, -6.02e+03]])
toronto = GroundPosition(name="Toronto", coor=(43.662300, -79.394530))
finch = Satellite()
finch.getAltAz(groundPos=toronto, posData=ECIvec, timeData=UTCTimeData)
PyPI link: https://pypi.org/project/Celest/
这个graph.
可以看到运行时对比
我正在尝试将对象的赤道坐标转换为给定时间和位置的 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 may help. This problem was discussed in the issue。我认为这个问题只发生在某些版本的库中,因此将库更新到最新版本可能是一个解决方案。
如果您正在寻找快速转换为 alt-az 的工具,那么 Astropy 可能不是最好的工具。 Celest 库可以在很短的时间内完成从 ECI 和 ECEF 坐标系到高度和方位角的转换(尽管它不处理赤道转换)。也许您可以使用 astropy 转换为 ECI,并使用 Celest 进行水平转换。请注意,此库应用了一些简化,但仍然非常准确。
下面的代码应该可以解决问题。
from celest import Satellite, GroundPosition
import numpy as np
UTCTimeData = np.array(['2020-06-01 12:00:00.0340', ..., '2020-06-01 12:01:00.0340'])
ECIvec = np.array([[-4.46e+03, -5.22e+03, 1.75e-04], ..., [2.73e+03, 2.08e+03, -6.02e+03]])
toronto = GroundPosition(name="Toronto", coor=(43.662300, -79.394530))
finch = Satellite()
finch.getAltAz(groundPos=toronto, posData=ECIvec, timeData=UTCTimeData)
PyPI link: https://pypi.org/project/Celest/
这个graph.
可以看到运行时对比