-
Notifications
You must be signed in to change notification settings - Fork 0
/
stars.py
160 lines (139 loc) · 4.32 KB
/
stars.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from hevelius import Bsc
import constellations
def main():
#stars = Bsc.read()
#bsc_extract_star_names()
bsc_extract_star_labels()
#write_labels(stars)
#write_names(stars)
#Stat.count(stars)
GREEK = { \
'alp': '', # alpha
'bet': '', # beta
'gam': '', # gamma
'del': '', # delta
'eps': '', # epsilon
'zet': '', # zeta
'eta': '', # eta
'the': '', # theta
'iot': '', # iota
'kap': '', # kappa
'lam': '', # lambda
'mu': '', # mu
'nu': '', # nu
'xi': '', # xi
'omi': '', # omicron
'pi': '', # pi
'pho': '', # rho
'sig': '', # sigma
'tau': '', # tau
'ups': '', # upsilon
'phi': '', # phi
'chi': '', # chi
'psi': '', # psi
'ome': '' # omega
}
def bsc_extract_star_names():
names = {}
with open('catalogs/bsc5.notes') as data:
for line in data:
if line.strip():
try:
hr = int(line[1:5]) # Harvard Revised (HR)
cat = line[7:11].strip() # Remark category abbreviation:
if cat == 'N:': # Star names
name = line[12:].strip()
if name:
if hr in names:
names[hr] = names[hr] + '; ' + name
else:
names[hr] = name
except Exception as ex:
print('Error reading star note:\n%s%s\n' % (line, ex))
bsc_write_star_data(names, 'catalogs/~bsc5_names.dat')
def bsc_extract_star_labels():
labels = {}
with open('catalogs/bsc5.dat') as data:
for line in data:
if line.strip():
hr = int(line[0:4]) # Harvard Revised Number = Bright Star Number
try:
raw = line[4:14].strip() # Name, generally Bayer and/or Flamsteed name
if raw:
label = bsc_process_label(hr, raw)
if label:
labels[hr] = label
except Exception as ex:
print('Error reading star %d: %s\n' % (hr, ex))
bsc_write_star_data(labels, 'catalogs/~bsc5_labels.dat')
def bsc_process_label(hr, label):
if len(label) <= 3:
print('Too short label: ' + label)
return None
abbr = label[-3:].lower()
if not abbr:
print('Constellations not set for %d: %s' % (hr, label))
return None
if abbr not in constellations.ABBRS:
print('Constellations not found for %d: %s' % (hr, label))
return None
num1 = ''
num2 = ''
let = ''
num_let = label[0:-3].strip()
if num_let:
#r = re.compile()
parts = re.match(r'\d*\S*\d*', num_let)
print(num_let, ': ', parts.group(0), parts.group(1), parts.group(2))
return '|{0}'.format(abbr)
def bsc_write_star_data(data, file_name):
lines = ['{0:>4} {1}\n'.format(hr, info) for hr, info in \
[(hr, data[hr]) for hr in sorted(data.keys())]]
with open(file_name, 'w') as f: f.writelines(lines)
print('File written: %s\nLines: %d\nOK' % (file_name, len(lines)))
class Stat:
def count(stars):
min_dec = -30
print('Min declination: %d\n' % min_dec)
Stat.count_till(stars, -1, min_dec)
Stat.count_till(stars, 0, min_dec)
Stat.count_till(stars, 1, min_dec)
Stat.count_till(stars, 2, min_dec)
Stat.count_till(stars, 3, min_dec)
Stat.count_till(stars, 4, min_dec)
Stat.count_till(stars, 5, min_dec)
Stat.count_till(stars, 6, min_dec)
Stat.count_till(stars, 7, min_dec)
Stat.count_till(stars, 8, min_dec)
print()
Stat.count_between(stars, -2, -1, min_dec)
Stat.count_between(stars, -1, 0, min_dec)
Stat.count_between(stars, 0, 1, min_dec)
Stat.count_between(stars, 1, 2, min_dec)
Stat.count_between(stars, 2, 3, min_dec)
Stat.count_between(stars, 3, 4, min_dec)
Stat.count_between(stars, 5, 6, min_dec)
Stat.count_between(stars, 6, 7, min_dec)
Stat.count_between(stars, 7, 8, min_dec)
print()
Stat.count_between(stars, -1.5, -0.5, min_dec)
Stat.count_between(stars, -0.5, 0.5, min_dec)
Stat.count_between(stars, 0.5, 1.5, min_dec)
Stat.count_between(stars, 1.5, 2.5, min_dec)
Stat.count_between(stars, 2.5, 3.5, min_dec)
Stat.count_between(stars, 3.5, 4.5, min_dec)
Stat.count_between(stars, 4.5, 5.5, min_dec)
Stat.count_between(stars, 5.5, 6.5, min_dec)
Stat.count_between(stars, 6.5, 7.5, min_dec)
Stat.count_between(stars, 7.5, 8.5, min_dec)
def count_between(stars, max, min, dec = -90):
c = len([s for s in stars if s.Mag > max and s.Mag <= min and s.DecD >= dec])
print('{0:0=+4.1f}m - {1:0=+4.1f}m: {2: >4}'.format(max, min, c))
def count_till(stars, min, dec = -90):
c = len([s for s in stars if s.Mag <= min and s.DecD >= dec])
print('{0:0=+4.1f}m: {1: >4}'.format(min, c))
if __name__ == '__main__':
main()