Plot a equirectangular plot of the stars.
Reference: https://github.com/brandon-rhodes/astronomy-notebooks/blob/master/Stars.ipynb
%pylab inline
Populating the interactive namespace from numpy and matplotlib
tau = 2.0 * pi
import ephem
from ephem.stars import stars
print('there are {} stars in PyEphem'.format(len(stars)))
starlist = stars.values()
for star in starlist:
star.compute('2014/11/4')
degree = tau / 360.0
hour = tau / 24.0
ra_list = [star.ra / hour for star in starlist]
dec_list = [star.dec / degree for star in starlist]
scatter(ra_list, dec_list)
gca().invert_xaxis()
there are 94 stars in PyEphem
# zoom to orion
scatter(ra_list, dec_list)
axis([7.5, 3.5, -20, 20])
[7.5, 3.5, -20, 20]
orion_axes = [7.5, 3.5, -20, 20]
print('{} is magnitude {} and has spectral type {}'.format(
starlist[0].name, starlist[0].mag, starlist[0]._spect))
[star.mag for star in starlist[:5]]
mag_array = np.array([ star.mag for star in starlist ])
size_array = (5 - mag_array) ** 1.5 * 4
Gienah Corvi is magnitude 2.58 and has spectral type B8
# resize to display magnitudes of stars
scatter(ra_list, dec_list, size_array)
axis(orion_axes)
[7.5, 3.5, -20, 20]
spectral_list = [star._spect for star in starlist]
spectral_list[:10]
['B8', 'A2', 'B2', 'K5', 'B6', 'B3', 'K3', 'M1', 'B9', 'B9']
Brandon Rhodes uses a starcolors.txt (from here) to change the colors which looks extremely pretty.
from spectral_classification import build_color_chart
color_chart = build_color_chart('starcolors.txt')
I want to revisit this, because some historical descriptions describe the colors in the asterisms, like the ruddy red one
(Betelguese) by Ptolemy, but described as yellow by the Chinese, suggesting before it was a red super giant, it has doubled in size from a yellow supergiant in the beginning of the common era. (A Brief on Astrophysics in China Today - 1981) And Sima Qian mentions in Historical record yellow is like Betelgeuse
(Ancient Chinese Suggest Betelgeuse is a Young Star - 1981). Let's continue on with his example and prettify the graph.
def pretty_hours(h, pos=None):
if h % 1.0 == 0.0:
return '{:.0g}h'.format(h)
else:
return '{:.2g}h'.format(h)
def pretty_degrees(d, pos=None):
return u'{}°'.format(d)
from matplotlib.ticker import FuncFormatter
hours_formatter = FuncFormatter(pretty_hours)
degrees_formatter = FuncFormatter(pretty_degrees)
scatter(ra_list, dec_list, size_array)
axis(orion_axes)
gca().xaxis.set_major_formatter(hours_formatter)
gca().yaxis.set_major_formatter(degrees_formatter)
gca().xaxis.grid(True)
gca().yaxis.grid(True)
Well.. let's go ahead and do it anyway. I want things to be pretty too! Here is the original source. You'll also need spectral_classification.py.
"""Convert stellar spectral classes to RGB values."""
from numpy import array
def without_v(s):
return s.replace('(V)', '')
def without_parens(s):
return s.replace('(', '').replace(')', '')
def build_color_chart(path):
chart = {}
with open(path) as f:
for line in f:
if line.startswith('#'):
continue
fields = line.split()
spectral_class = fields[0]
rgb = array([ float(field) / 255.0 for field in fields[3:6] ])
chart[spectral_class] = rgb
chart[without_v(spectral_class)] = rgb
chart[without_parens(spectral_class)] = rgb
return chart
color_chart = build_color_chart('../data/starcolors.txt')
color_list = [color_chart[spectral_class + '(V)']
for spectral_class in spectral_list]
scatter(ra_list, dec_list, size_array, color_list)
axis(orion_axes)
gca().xaxis.set_major_formatter(hours_formatter)
gca().yaxis.set_major_formatter(degrees_formatter)
gca().xaxis.grid(True)
gca().yaxis.grid(True)
#savefig('stars.png')