-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotSky.py
119 lines (98 loc) · 4.63 KB
/
plotSky.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# plot stars on PiTFT screen
# plot planets on screen - sun, moon, mercury, venus, mars, jupiter, saturn
#
# Copyright 2014 William B. Phelps
#
import pygame
from pygame.locals import *
import math
import ephem, ephem.stars
R90 = math.radians(90) # 90 degrees in radians
stars = []
#stardata = ephem.stars.db.split("\n")
#for startxt in stardata:
# name = startxt.split(',')[0]
# if len(name)>0:
# stars.append(ephem.star(name))
#del stardata
# there are 94 names in this list and 94 in ephem.stars.db...
starnames = ['Polaris','Sirius','Canopus','Arcturus','Vega','Capella','Rigel','Procyon','Achernar','Betelgeuse','Agena',
'Altair','Aldebaran','Spica','Antares','Pollux','Fomalhaut','Mimosa','Deneb','Regulus','Adara','Castor','Shaula',
'Bellatrix','Elnath','Alnilam','Alnair','Alnitak','Alioth','Kaus Australis','Dubhe','Wezen','Alcaid','Menkalinan',
'Alhena','Peacock','Mirzam','Alphard','Hamal','Algieba','Nunki','Sirrah','Mirach','Saiph','Kochab','Rasalhague',
'Algol','Almach','Denebola','Naos','Alphecca','Mizar','Sadr','Schedar','Etamin','Mintaka','Caph','Merak','Izar',
'Enif','Phecda','Scheat','Alderamin','Markab','Menkar','Arneb','Gienah Corvi','Unukalhai','Tarazed','Cebalrai',
'Rasalgethi','Nihal','Algenib','Alcyone','Vindemiatrix','Sadalmelik','Zaurak','Minkar','Albereo',
'Alfirk','Sulafat','Megrez','Sheliak','Atlas','Thuban','Alshain','Electra','Maia','Arkab Prior','Rukbat','Alcor',
'Merope','Arkab Posterior','Taygeta']
for name in starnames:
stars.append(ephem.star(name))
del starnames
#print 'Stars: {}'.format(len(stars))
centerX = 160 # center of sky circle
centerY = 120
diameter = 120
def getxy(alt, azi): # alt, az in radians
# thanks to John at Wobbleworks for the algorithm
# r90 = math.radians(90) # 90 degrees in radians (1.5707963267948966)
r = (R90 - alt)/R90
x = r * math.sin(azi)
y = r * math.cos(azi)
# x = int(centerX - x * diameter) # flip E/W, scale to radius, center on plot
x = int(centerX + x * diameter) # scale to radius, center on plot
y = int(centerY - y * diameter) # scale to radius, center on plot
return (x,y)
class plotStars():
def __init__(self, screen, obs, sun):
self.screen = screen
self.obs = obs
self.sun = sun
for star in stars:
star.compute(self.obs)
if star.alt > 0:
sz = int(3-star.mag + 0.5) # use vmag of brighter stars for size
if sz<=1: # minimum radius - pygame draws small circles as funny squares
pygame.draw.circle(self.screen, (255,255,255), getxy(star.alt, star.az), 1, 1)
else:
pygame.draw.circle(self.screen, (255,255,255), getxy(star.alt, star.az), sz, 0)
# print 'star {} mag {} sz {}'.format(star.name, star.mag, sz)
del star
# plot 5 circles to test plot
# pygame.draw.circle(screen, (0,255,0), getxy(math.radians(90), math.radians(0)), 5, 1) # center
# pygame.draw.circle(screen, (255,0,0), getxy(math.radians(45), math.radians(0)), 5, 1) # red N
# pygame.draw.circle(screen, (0,255,0), getxy(math.radians(45), math.radians(90)), 5, 1) # green E
# pygame.draw.circle(screen, (0,0,255), getxy(math.radians(45), math.radians(180)), 5, 1) # blue S
# pygame.draw.circle(screen, (255,255,0), getxy(math.radians(45), math.radians(270)), 5, 1) # yellow W
class plotPlanets():
def __init__(self, screen, obs, sun):
self.screen = screen
self.obs = obs
self.sun = sun
self.pline = 235
self.pFont = pygame.font.SysFont('Arial', 16, bold=True)
# plot the naked eye planets
self.plotPlanet(ephem.Saturn(), (245,128,245), 3)
self.plotPlanet(ephem.Jupiter(),(245,245,128), 3)
self.plotPlanet(ephem.Mars(), (245,0,0), 3)
self.plotPlanet(ephem.Venus(), (245,245,245), 3)
self.plotPlanet(ephem.Mercury(), (128,245,245), 3)
moon = ephem.Moon()
moon.compute(obs)
if (moon.alt>0):
pygame.draw.circle(self.screen, (255,255,255), getxy(moon.alt, moon.az), 7, 0)
txt = self.pFont.render('Moon', 1, (255,255,255))
self.pline -= 15
self.screen.blit(txt, (1,self.pline))
if (sun.alt>0):
pygame.draw.circle(self.screen, (255,255,0), getxy(sun.alt, sun.az), 7, 0)
txt = self.pFont.render('Sun', 1, (255,255,0))
self.pline -= 15
self.screen.blit(txt, (1, self.pline))
def plotPlanet(self, planet, color, size):
planet.compute(self.obs)
# print "{} alt: {} az:{}".format(planet.name, math.degrees(planet.alt), math.degrees(planet.az))
if (planet.alt>0):
pygame.draw.circle(self.screen, color, getxy(planet.alt, planet.az), size, 0)
txt = self.pFont.render(planet.name, 1, color, (0,0,0))
self.pline -= 15
self.screen.blit(txt, (1, self.pline))