forked from codebox/star-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_file.py
31 lines (26 loc) · 977 Bytes
/
input_file.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
import codecs
from star_data import StarData, StarDataList
class InputFile:
def __init__(self, file_path):
self.file_path = file_path
def get_stars(self, sky_area):
"""
Expected line format:
<RA>,<DEC>,<MAG>
RA: 0 -> 24
DEC: +90 -> -90
MAG: any floating-point value
"""
matches = []
for line in codecs.open(self.file_path, 'r', 'utf-8').readlines():
parts = line.split(',')
ra, dec, mag = map(float, parts[:3])
label = '' if len(parts) < 4 else parts[3]
if mag > sky_area.mag_min: #because smaller mag values mean brighter stars
continue
if not (sky_area.ra_min <= ra <= sky_area.ra_max):
continue
if not (sky_area.dec_min <= dec <= sky_area.dec_max):
continue
matches.append(StarData(ra, dec, mag, label))
return StarDataList(matches)