Python implements astronomical calculations

28f26b88b589e70d74a7f3b8225d9c76.png

Lost little book boy

Needed after reading

2

minute

Speed ​​reading only takes 1 minute

1

   

Introduction

The ephem module provides Python with accurate astronomical computing capabilities. It can predict the orbit information of planets and satellites, and calculate data such as sunrise and sunset, star meridian time, etc. Its algorithm is accurate and reliable. Originally developed by Brandon Craig Rhodes in the 1990s, it has been expanded and supplemented over the years and has become widely used.

2

   

Install

First, make sure Python is installed on your system. You can download it from Python's official website ( https://www.python.org/downloads/ ).

Next, we need to install ephem

Open a command prompt or terminal and run the following command

pip install ephem

Now, we can write some code!

3

   

Sample code

import ephem
import datetime


# 创建一个波士顿的观测者,并设置其经纬度坐标
Boston=ephem.Observer()
Boston.lat='42.3462'
Boston.lon='-71.0978'


# 设置当前观测时间,使用datetime的now()方法
Boston.date = datetime.datetime.now()


# 设置观测者的高度、气压、温度等参数,可以提高计算精度
Boston.elevation = 3 
Boston.pressure = 1010 
Boston.temp = 25 
Boston.horizon = 0


sun = ephem.Sun()


print("Next sunrise in Boston will be: ",ephem.localtime(Boston.next_rising(sun)))
print("Next sunset in Boston will be: ",ephem.localtime(Boston.next_setting(sun)))

This code is used to predict sunrise and sunset times in Boston. The result of code execution is

Next sunrise in Boston will be:  2023-09-14 18:22:52.486944
Next sunset in Boston will be:  2023-09-15 06:56:20.622409

4

   

free community

82a56686a626c1df902c7ee9cce44cb1.jpeg

f000116896b09ac6dc920874ebf01127.gif

Guess you like

Origin blog.csdn.net/djstavaV/article/details/132867812
Recommended