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.
--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.
We use it to display the moon information on twitter and LINE bots running on Raspberry Pi.
Recommended Posts