Skip to content

Instantly share code, notes, and snippets.

@FilipDominec
Last active February 10, 2016 16:04
Show Gist options
  • Save FilipDominec/222c9a2d67ff2d3dc446 to your computer and use it in GitHub Desktop.
Save FilipDominec/222c9a2d67ff2d3dc446 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Download and unpack the Hipparcos star catalog from www.astronexus.com/files/downloads/hygfull.csv.gz
Run in python to show interactive sky map with apparent star magnitude and approximate colour.
About 90000 stars are plotted within a second, you can pan and zoom the view.
Run with "--interactive no" to generate a big PDF file for printing. I could not find anything with this
level of detail on the internet.
"""
## Import common moduli
import matplotlib, sys, os, time, argparse
import matplotlib.pyplot as plt
import numpy as np
# List of interesting "Messier" objects from http://messier.seds.org/dataDec.html
#M# NGC# Type ra dec B D d
messier_objects = [
[ 1, 1952, 9, 534.5, +220100, 8.4, 6, 6.3 ],
[ 2, 7089, 2, 2133.5, -4900, 6.5, 12.9 , 37.5 ],
[ 3, 5272, 2, 1342.2, +282300, 6.2, 16.2 , 33.9 ],
[ 4, 6121, 2, 1623.6, -263200, 5.6, 26.3 , 7.2 ],
[ 5, 5904, 2, 1518.6, +20500, 5.6, 17.4 , 24.5 ],
[ 6, 6405, 1, 1740.1, -321300, 4.2, 25.0 , 1.6 ],
[ 7, 6475, 1, 1753.9, -344900, 3.3, 80.0 , .8 ],
[ 8, 6523, 4, 1803.8, -242300, 6.0, 90, 5.2 ],
[ 9, 6333, 2, 1719.2, -183100, 7.7, 9.3 , 26.7 ],
[ 10, 6254, 2, 1657.1, -40600, 6.6, 15.1 , 14.4 ],
[ 11, 6705, 1, 1851.1, -61600, 6.3, 14.0 , 6 ],
[ 12, 6218, 2, 1647.2, -15700, 6.7, 14.5 , 16.0 ],
[ 13, 6205, 2, 1641.7, +362800, 5.8, 16.6 , 25.1 ],
[ 14, 6402, 2, 1737.6, -31500, 7.6, 11.7 , 29.0 ],
[ 15, 7078, 2, 2130.0, +121000, 6.2, 12.3 , 33.6 ],
[ 16, 6611, 1, 1818.8, -134700, 6.4, 7.0 , 7 ],
[ 17, 6618, 4, 1820.8, -161100, 7.0, 11.0 , 5 ],
[ 18, 6613, 1, 1819.9, -170800, 7.5, 9.0 , 4.9 ],
[ 19, 6273, 2, 1702.6, -261600, 6.8, 13.5 , 28.4 ],
[ 20, 6514, 4, 1802.6, -230200, 9.0, 28.0 , 5.2 ],
[ 21, 6531, 1, 1804.6, -223000, 6.5, 13.0 , 4.25 ],
[ 22, 6656, 2, 1836.4, -235400, 5.1, 24.0 , 10.4 ],
[ 23, 6494, 1, 1756.8, -190100, 6.9, 27.0 , 2.15 ],
[ 24, 6603, 0, 1816.9, -182900, 4.6, 90 , 10 ],
[ 25, 4725, 1, 1831.6, -191500, 6.5, 40.0 , 2 ],
[ 26, 6694, 1, 1845.2, -92400, 8.0, 15.0 , 5 ],
[ 27, 6853, 3, 1959.6, +224300, 7.4, 8.0, 1.25 ],
[ 28, 6626, 2, 1824.5, -245200, 6.8, 11.2 , 18.6 ],
[ 29, 6913, 1, 2023.9, +383200, 7.1, 7.0 , 4.0 ],
[ 30, 7099, 2, 2140.4, -231100, 7.2, 11.0 , 26.1 ],
[ 31, 224, 5, 42.7, +411600, 3.4, 178, 2900 ],
[ 32, 221, 6, 42.7, +405200, 8.1, 8, 2900 ],
[ 33, 598, 5, 133.9, +303900, 5.7, 73, 3000 ],
[ 34, 1039, 1, 242.0, +424700, 5.5, 35.0 , 1.4 ],
[ 35, 2168, 1, 608.9, +242000, 5.3, 28.0 , 2.8 ],
[ 36, 1960, 1, 536.1, +340800, 6.3, 12.0 , 4.1 ],
[ 37, 2099, 1, 552.4, +323300, 6.2, 24.0 , 4.4 ],
[ 38, 1912, 1, 528.4, +355000, 7.4, 21.0 , 4.2 ],
[ 39, 7092, 1, 2132.2, +482600, 4.6, 32.0 , .825 ],
[ 40, 0, 0, 1222.4, +580500, 8.4, .8 , .51 ],
[ 41, 2287, 1, 646.0, -204400, 4.6, 38.0 , 2.3 ],
[ 42, 1976, 4, 535.4, -52700, 4.0, 85, 1.6 ],
[ 43, 1982, 4, 535.6, -51600, 9.0, 20, 1.6 ],
[ 44, 2632, 1, 840.1, +195900, 3.7, 95.0 , .577 ],
[ 45, 0000, 1, 347.0, +240700, 1.6, 110.0 , .38 ],
[ 46, 2437, 1, 741.8, -144900, 6.0, 27.0 , 5.4 ],
[ 47, 2422, 1, 736.6, -143000, 5.2, 30.0 , 1.6 ],
[ 48, 2548, 1, 813.8, -54800, 5.5, 54.0 , 1.5 ],
[ 49, 4472, 6, 1229.8, +80000, 8.4, 9, 60000 ],
[ 50, 2323, 1, 703.2, -82000, 6.3, 16.0 , 3 ],
[ 51, 5194, 5, 1329.9, +471200, 8.4, 11, 37000 ],
[ 51, 5195, 5, 1330.0, +471600, 9.6, 6.4, 37000 ],
[ 52, 7654, 1, 2324.2, +613500, 7.3, 13.0 , 5.0 ],
[ 53, 5024, 2, 1312.9, +181000, 7.6, 12.6 , 59.7 ],
[ 54, 6715, 2, 1855.1, -302900, 7.6, 9.1 , 88.7 ],
[ 55, 6809, 2, 1940.0, -305800, 6.3, 19.0 , 17.6 ],
[ 56, 6779, 2, 1916.6, +301100, 8.3, 7.1 , 32.9 ],
[ 57, 6720, 3, 1853.6, +330200, 8.8, 1.4, 2.3 ],
[ 58, 4579, 5, 1237.7, +114900, 9.7, 5.5, 60000 ],
[ 59, 4621, 6, 1242.0, +113900, 9.6, 5, 60000 ],
[ 60, 4649, 6, 1243.7, +113300, 8.8, 7, 60000 ],
[ 61, 4303, 5, 1221.9, +42800, 9.7, 6, 60000 ],
[ 62, 6266, 2, 1701.2, -300700, 6.5, 14.1 , 22.5 ],
[ 63, 5055, 5, 1315.8, +420200, 8.6, 10, 37000 ],
[ 64, 4826, 5, 1256.7, +214100, 8.5, 9.3, 19000 ],
[ 65, 3623, 5, 1118.9, +130500, 9.3, 8, 35000 ],
[ 66, 3627, 5, 1120.2, +125900, 8.9, 8, 35000 ],
[ 67, 2682, 1, 850.4, +114900, 6.1, 30.0 , 2.7 ],
[ 68, 4590, 2, 1239.5, -264500, 7.8, 12.0 , 33.3 ],
[ 69, 6637, 2, 1831.4, -322100, 7.6, 7.1 , 28.0 ],
[ 70, 6681, 2, 1843.2, -321800, 7.9, 7.8 , 29.4 ],
[ 71, 6838, 2, 1953.8, +184700, 8.2, 7.2 , 12.7 ],
[ 72, 6981, 2, 2053.5, -123200, 9.3, 5.9 , 55.4 ],
[ 73, 6994, 0, 2058.9, -123800, 9.0, 2.8 , 2.0 ],
[ 74, 628, 5, 136.7, +154700, 9.4, 10.2, 35000 ],
[ 75, 6864, 2, 2006.1, -215500, 8.5, 6.0 , 61.3 ],
[ 76, 650, 3, 142.4, +513400, 10.1, 2.7, 3.4 ],
[ 77, 1068, 5, 242.7, -100, 8.9, 7, 60000 ],
[ 78, 2068, 4, 546.7, +300, 8.3, 8, 1.6 ],
[ 79, 1904, 2, 524.2, -243100, 7.7, 8.7 , 42.1 ],
[ 80, 6093, 2, 1617.0, -225900, 7.3, 8.9 , 32.6 ],
[ 81, 3031, 5, 955.6, +690400, 6.9, 21, 12000 ],
[ 82, 3034, 7, 955.8, +694100, 8.4, 9, 12000 ],
[ 83, 5236, 5, 1337.0, -295200, 7.6, 11, 15000 ],
[ 84, 4374, 8, 1225.1, +125300, 9.1, 5.0 , 60000 ],
[ 85, 4382, 8, 1225.4, +181100, 9.1, 7.1, 60000 ],
[ 86, 4406, 8, 1226.2, +125700, 8.9, 7.5, 60000 ],
[ 87, 4486, 6, 1230.8, +122400, 8.6, 7.0 , 60000 ],
[ 88, 4501, 5, 1232.0, +142500, 9.6, 7, 60000 ],
[ 89, 4552, 6, 1235.7, +123300, 9.8, 4.0 , 60000 ],
[ 90, 4569, 5, 1236.8, +131000, 9.5, 9.5, 60000 ],
[ 91, 4548, 5, 1235.4, +143000, 10.2, 5.4, 60000 ],
[ 92, 6341, 2, 1717.1, +430800, 6.4, 11.2 , 26.7 ],
[ 93, 2447, 1, 744.6, -235200, 6.0, 22.0 , 3.6 ],
[ 94, 4736, 5, 1250.9, +410700, 8.2, 7, 14500 ],
[ 95, 3351, 5, 1044.0, +114200, 9.7, 4.4, 38000 ],
[ 96, 3368, 5, 1046.8, +114900, 9.2, 6, 38000 ],
[ 97, 3587, 3, 1114.8, +550100, 9.9, 3.4, 2.6 ],
[ 98, 4192, 5, 1213.8, +145400, 10.1, 9.5, 60000 ],
[ 99, 4254, 5, 1218.8, +142500, 9.9, 5.4, 60000 ],
[100, 4321, 5, 1222.9, +154900, 9.3, 7, 60000 ],
[101, 5457, 5, 1403.2, +542100, 7.9, 22.0 , 27000 ],
[102, 5866, 8, 1506.5, +554600, 9.9, 5.2, 40000 ],
[103, 581, 1, 133.2, +604200, 7.4, 6.0 , 8.5 ],
[104, 4594, 5, 1240.0, -113700, 8.0, 9, 50000 ],
[105, 3379, 6, 1047.8, +123500, 9.3, 2.0 , 38000 ],
[106, 4258, 5, 1219.0, +471800, 8.4, 19, 25000 ],
[107, 6171, 2, 1632.5, -130300, 7.9, 10.0 , 20.9 ],
[108, 3556, 5, 1111.5, +554000, 10.0, 8, 45000 ],
[109, 3953, 5, 1153.8, +522000, 10.1, 7, 55000 ],
[109, 3992, 5, 1157.6, +532300, 9.8, 7, 55000 ],
[110, 205, 6, 40.4, +414100, 8.5, 17, 2900 ]]
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--interactive', type=str, default='yes', help='otherwise outputs PDF')
args = parser.parse_args()
if args.interactive == "yes":
plt.style.use('dark_background')
cmap = getattr(matplotlib.cm, 'RdBu')
cmap = matplotlib.colors.LinearSegmentedColormap.from_list('trunc({n},{a:.2f},{b:.2f})'.format(n=cmap.name, a=.1, b=.6), cmap(np.linspace(.1, .6, 100)))
fig=plt.Figure()
## Conversion from customary notation to a real number, with an example of Sirius
def hms2angle(x):
return (np.floor(x/10000) + np.floor(x%10000./100)/60+ x%100./60./60.)
def dms2angle(xi):
x = abs(xi)
return np.sign(xi) * (np.floor(x/10000) + np.floor(x%10000./100)/60+ x%100./60./60.)
sa = hms2angle(064508.917)
sd = dms2angle(-164258.02)
#StarID,Hip,HD,HR,Gliese,BayerFlamsteed,ProperName,7-RA,8-Dec,9-Distance,10-Mag,11-AbsMag,12-Spectrum,13-ColorIndex
a,d, m,c = np.genfromtxt('hygfull.csv', usecols=[7,8,10,13], unpack=True, delimiter=',')
n = np.loadtxt('hygfull.csv', usecols=[6], unpack=True, delimiter=',', dtype=str)
if (args.interactive == "yes"):
plt.scatter(-a,d,s=2.512**(-m*.5+4), c=-c, cmap=cmap, edgecolor='', linewidth=0.0)
else:
plt.scatter(-a,d,s=2.512**(-m*.8+3), c='k', cmap=cmap, edgecolor='', linewidth=0.0)
## Ecliptic and the Milky way
dd=np.linspace(-24,0,1000)
plt.plot(dd,np.sin((-dd)/24*2*np.pi)*23.4,c='g', lw=.2)
plt.plot(dd,np.sin((-dd+5.5)/24*2*np.pi)*60,c='#3399ff', alpha=.05, lw=40)
#http://messier.seds.org/dataRA.html
if args.interactive == "yes":
color='#ffdd33'
fs=8
else:
color='k'
fs=2
for n, a, d in zip(n,a,d):
if n.strip() != "":
plt.text(-a, d, n, fontsize=fs*.8, horizontalalignment='center', verticalalignment='top', color=color)
for obj in messier_objects:
#M# NGC# Type ra dec B D d
#type: 1=Open Cluster, 2=Globular Cluster, 3=Planetary Nebula, 4=Starforming Nebula (with open cluster), 5=Spiral Galaxy, 6=Elliptical Galaxy, 7=Irregular Galaxy, 8=Lenticular (S0) Galaxy, 9=Supernova Remnant, 0=System of 4 stars or Asterism, 0=Milky Way Patch, 0=Binary star
n, N, t, a, d, B, D, dist = obj
plt.text(-hms2angle(a*100), dms2angle(d), "%s" % n,
fontsize=fs, horizontalalignment='center', verticalalignment='bottom', color=color)
plt.text(-hms2angle(a*100), dms2angle(d), ['*', 'oC','gC','pN','sN','sG','eG','iG','LG','sR'][int(t)],
color=color, fontsize=fs, horizontalalignment='center', verticalalignment='top')
plt.scatter(-hms2angle(a*100), dms2angle(d), marker="+", s=D*.3, edgecolor=color, facecolor='', linewidth=.1)
plt.scatter(-hms2angle(a*100), dms2angle(d), marker="o", s=D*.3, edgecolor=color, facecolor='', linewidth=.1)
## ==== Outputting ====
## Finish the plot + save
#plt.grid()
plt.xlim((-24,0)); plt.xscale('linear')
plt.ylim((-90,90)); plt.yscale('linear')
plt.subplots_adjust(left=.0, bottom=0, right=1, top=1, wspace=.05, hspace=.05) ## (for interactive mode)
if args.interactive == "yes":
plt.show()
else:
plt.savefig("output.pdf", bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment