From fe05f3b6dcd0430a9ee895d8e410a4d40a73b162 Mon Sep 17 00:00:00 2001 From: march3 Date: Fri, 1 Sep 2023 10:11:04 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/celestial_data_service.py | 38 +++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/common/celestial_data_service.py b/common/celestial_data_service.py index 465e827..185ab1e 100644 --- a/common/celestial_data_service.py +++ b/common/celestial_data_service.py @@ -220,17 +220,20 @@ def get_earth_pos_vel(dt): @param dt: @return: """ + import pytz + # 安装 astropy 包 # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com astropy - from astropy.coordinates import get_body_barycentric_posvel # 获取天体的坐标pos和速度vel - from astropy.coordinates import solar_system_ephemeris + # 获取天体的坐标pos和速度vel + from astropy.coordinates import get_body_barycentric_posvel import astropy.units as u # 单位 - import pytz + # from astropy.coordinates import solar_system_ephemeris + # print("天体名:", solar_system_ephemeris.bodies) + # ('earth', 'sun', 'moon', 'mercury', 'venus', 'earth-moon-barycenter', + # 'mars', 'jupiter', 'saturn', 'uranus', 'neptune') + print('----------------------------------------') print("北京时间:", dt.to_datetime(timezone=pytz.timezone('Asia/Shanghai'))) - # 打印天体名 - # print("天体名:", solar_system_ephemeris.bodies) - # ('earth', 'sun', 'moon', 'mercury', 'venus', 'earth-moon-barycenter', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune') # 获取地球的坐标和速度 earth_pos_vel = get_body_barycentric_posvel('earth', dt) print("地球坐标(公里):", [earth_pos_vel[0].x.to(u.km), @@ -244,11 +247,30 @@ def get_earth_pos_vel(dt): # print("速度(公里/秒):", posvel[1] * AU / SECONDS_PER_DAY) +def show_bodies_posvels(dt): + import pytz + # 安装 astropy 包 + # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com astropy + # 获取天体的坐标pos和速度vel + from astropy.coordinates import get_body_barycentric_posvel + import astropy.units as u # 单位 + from astropy.coordinates import solar_system_ephemeris as sse + print("北京时间:", dt.to_datetime(timezone=pytz.timezone('Asia/Shanghai'))) + for body_name in sse.bodies: + earth_pos_vel = get_body_barycentric_posvel(body_name, dt) + print(f"{body_name}-坐标(公里):", [earth_pos_vel[0].x.to(u.km), + earth_pos_vel[0].y.to(u.km), + earth_pos_vel[0].z.to(u.km)]) + print(f"{body_name}-速度(公里/秒):", + [earth_pos_vel[1].x.to(u.km / u.second), + earth_pos_vel[1].y.to(u.km / u.second), + earth_pos_vel[1].z.to(u.km / u.second)]) + + if __name__ == '__main__': from astropy.time import Time # 时间 - # 获取当前时间 dt = Time.now() # 指定未来的日期时间 # dt = conv_to_astropy_time('2050-01-01 12:00:00') - get_earth_pos_vel(dt) + show_bodies_posvels(dt) -- GitLab