[PYTHON] The universe is dangerous with PyEphem

Introduction

At first I was thinking about scraping easily because I wanted to get the position and age of the moon, but I found out that there is a very useful library called PyEphem. Since there is no article tagged with PyEphem in qiita, I will write it.

About PyEphem

--https://pypi.org/project/ephem/ (source) --https://rhodesmill.org/pyephem/ (reference)

For details, read the reference, but here is a simple usage.

import ephem
import datetime
from math import degrees as deg

# Body(Celestial body)Create an instance of the class.

moon = ephem.Moon()

# Observer(Observer)Create an instance of the class.

shinjuku = ephem.Observer()
shinjuku.lat = '35.6846'
shinjuku.lon = '139.7106'
shinjuku.elevation = 60
shinjuku.date = datetime.datetime.utcnow() #You can ask for the position of any date

#Calculate the celestial body seen by the observer.

moon.compute(shinjuku)
print(deg(moon.alt)) # 20.88288333068003(Elevation from the horizon(Convert to degrees with deg))
print(deg(moon.az)) # 218.0421642706897(Direction with north as 0 degrees)
print(moon.moon_phase) # 0.2820702016225599(Moon phase)
print(shinjuku.date - ephem.previous_new_moon(shinjuku.date)) # 24.138740752328886(Moon age)

The position of artificial satellites can also be calculated using data called TLE provided by orbit information provision services such as JAXA and NASA. (Also possible with pyorbital)

The TLE of the International Space Station (ISS) is https://spaceflight.nasa.gov/realdata/sightings/SSapplications/Post/JavaSSOP/orbit/ISS/SVPOST.html It is written in the section "TWO LINE MEAN ELEMENT SET`". (There are many including predictions) Since the value fluctuates due to orbit changes, it is necessary to acquire it as appropriate. The value at 2020/048/17: 15: 00.000 (February 17th? 17:15 UTC?) Is

ISS
1 25544U 98067A   20048.52024880  .00016717  00000-0  10270-3 0  9000
2 25544  51.6378 225.5202 0004926 282.0303  78.0295 15.49172297 13304

Based on the above, let's calculate the position of the ISS as seen from the current (time set in shinjuku) shinjuku.

line1 = 'ISS'
line2 = '1 25544U 98067A   20048.52024880  .00016717  00000-0  10270-3 0  9000'
line3 = '2 25544  51.6378 225.5202 0004926 282.0303  78.0295 15.49172297 13304'
iss = ephem.readtle(line1, line2, line3)

#Position seen from shinjuku
iss.compute(shinjuku)
print(deg(iss.alt)) # -51.61249863302519
print(deg(iss.az)) # 142.92199525046195

#Where the ISS is
iss.compute(datetime.datetime.utcnow())
print(deg(iss.sublat)) # -50.990213758123666
print(deg(iss.sublong)) # -139.8713732199458
print(iss.elevation) # 433325.5
print(iss.eclipsed) # True

Seen from shinjuku, it's about 51 degrees below the southeastern horizon, 430,000 meters above New Zealand's east, and looks like food.

iss.png

in conclusion

We use it to display the moon information on twitter and LINE bots running on Raspberry Pi.

pt2.png pl2.png

Recommended Posts

The universe is dangerous with PyEphem
Let's generate sentences with the topical sentence generation AI "GPT-2" that is "too dangerous"
The story that the private key is set to 600 with chmod
What is the activation function?
Kill the process with sudo kill -9
What is the Linux kernel?
Guess the password with klee
gethostbyaddr () communicates with the outside
scraping the Nikkei 225 with playwright-python
Check the code with flake8
Calibrate the model with PyCaret
Call the API with python3.
What is the interface for ...
What is the Callback function?
The image is a slug
How is the progress? Let's get on with the boom ?? in Python
March 14th is Pi Day. The story of calculating pi with python
Is the new corona really a threat? Validated with Stan (was)
Try playing with a baseball simulator # 1 Is the feed bunt effective?
Settings until the Dango project is started on the server with Pycharm