Last active
December 26, 2015 05:19
-
-
Save agasiev/7100317 to your computer and use it in GitHub Desktop.
Simple HYG (http://astronexus.com/node/34) database parser and drawer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image, random | |
import csv, sys | |
h = 512 | |
w = 512 | |
img = Image.new( 'RGB', (w,h), "black") # create a new black image | |
pixels = img.load() # create the pixel map | |
xyz = [] | |
x = w/2 | |
y = h/2 | |
with open('hygxyz.csv', 'rb') as csvfile: | |
spamreader = csv.reader(csvfile, delimiter=',') | |
spamreader.next() | |
for row in spamreader: | |
if row[16] == "": row[16] = "0" | |
xyz.append([float(row[17]), float(row[18]), float(row[19]), float(row[16])]) | |
c = 0 | |
for i in range(0, len(xyz)): | |
m = 1 | |
xx = int(xyz[i][2]/m) | |
yy = int(xyz[i][0]/m) | |
zz = int(xyz[i][2]/m) | |
cc = xyz[i][3] | |
if abs(xx) < x and abs(yy) < y: | |
c+=1 | |
col = None | |
if cc <= -0.33: col = (0, 0, 0xFF) | |
if cc > -0.33 and cc <= -0.17: col = (0x69, 0x97, 0xFF) | |
if cc > -0.17 and cc <= 0.15: col = (0xAD, 0xC7, 0xFF) | |
if cc > 0.15 and cc <= 0.44: col = (0xFF, 0xF5, 0xDB) | |
if cc > 0.44 and cc <= 0.68: col = (0xF7, 0xD4, 0x72) | |
if cc > 0.68 and cc <= 1.15: col = (0xFF, 0x8E, 0x42) | |
if cc > 1.15 and cc <= 1.64: col = (0xFF, 0x67, 0x14) | |
if cc > 1.64: col = (0xFF, 0, 0) | |
pixels[x - xx, y - yy] = col | |
print c | |
img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment