-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobservation_mapper.py
144 lines (113 loc) · 3.52 KB
/
observation_mapper.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import sys
import math
PI = math.pi
PI_12 = PI/12
PI_720 = PI/720
PI_43200 = PI/43200
class RightAscension:
def __init__(self, h, m, s):
self.neg = False
if h < 0:
self.neg = True
self.h = abs(h)
self.m = m
self.s = s
def toRad(self):
if not self.neg:
return self.h * PI_12 + self.m * PI_720 + self.s * PI_43200
else:
return -self.h * PI_12 - self.m * PI_720 - self.s * PI_43200
def toDeg(self):
# won't bother, this works
return math.degrees(self.toRad())
class Declination:
def __init__(self, d, m, s):
self.neg = False
if d < 0:
self.neg = True
self.d = abs(d)
self.m = m
self.s = s
def toRad(self):
deg_decimal = self.d + self.m / 60 + self.s / 3600
if self.neg:
deg_decimal = -deg_decimal
return math.radians(deg_decimal)
def toDeg(self):
if not self.neg:
return self.d + self.m / 60 + self.s / 3600
else:
return -1 * (self.d + self.m / 60 + self.s / 3600)
def set_axes_equal(ax):
x_limits = ax.get_xlim3d()
y_limits = ax.get_ylim3d()
z_limits = ax.get_zlim3d()
x_range = abs(x_limits[1] - x_limits[0])
x_middle = 0
y_range = abs(y_limits[1] - y_limits[0])
y_middle = 0
z_range = abs(z_limits[1] - z_limits[0])
z_middle = 0
plot_radius = 0.7*max([x_range, y_range, z_range])
ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius])
ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius])
ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius])
def readFile(filename):
with open(filename, "r") as f:
lines = f.readlines()
return lines
def parse80(line):
ra_str = line[32:43].strip()
dec_str = line[44:55].strip()
mag_str = line[65:69].strip()
ra_str = ra_str.split(" ")
dec_str = dec_str.split(" ")
ra_floats = [float(element) for element in ra_str]
dec_floats = [float(element) for element in dec_str]
mag = float(mag_str)
RA = RightAscension(ra_floats[0], ra_floats[1], ra_floats[2])
DEC = Declination(dec_floats[0], dec_floats[1], dec_floats[2])
return RA.toRad(), DEC.toRad(), mag
def main():
args = sys.argv
if len(args) > 1:
filename = args[1]
else:
filename = input("80-column format observation filename: ")
lines = readFile(filename)
ras = []
decs = []
mags = []
for line in lines:
ra, dec, mag = parse80(line)
ras.append(ra)
decs.append(dec)
mags.append(mag)
xs = []
ys = []
zs = []
sizes = []
for i in range(len(ras)):
xs.append(math.cos(ras[i]) * math.cos(decs[i]))
ys.append(math.sin(ras[i]) * math.cos(decs[i]))
zs.append(math.sin(decs[i]))
sizes.append(((max(mags) + 1) - mags[i]) * 3)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
scatter = ax.scatter(xs, ys, zs, s=sizes, marker='o')
# Observer
ax.scatter(0, 0, 0, s=20, marker="o")
# Principal Axes
ax.plot([0, 1], [0, 0], [0, 0], color="r")
ax.plot([0, 0], [0, 1], [0, 0], color="g")
ax.plot([0, 0], [0, 0], [0, 1], color="b")
ax.set_xlabel('X (Equinox)')
ax.set_ylabel('Y')
ax.set_zlabel('Z (Pole)')
ax.set_title('Observations Plot')
set_axes_equal(ax)
plt.show()
main()